Esempio n. 1
0
  // Removes the old files if the data is wiped.
  private static void removeOldFilesIfNecessary(Context context) {
    SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context);
    int n = 0;
    try {
      n = pref.getInt(KEY_CACHE_UP_TO_DATE, 0);
    } catch (Throwable t) {
      // ignore.
    }
    if (n != 0) return;
    pref.edit().putInt(KEY_CACHE_UP_TO_DATE, 1).commit();

    /// M: [BEHAVIOR.MODIFY] @{
    /*File cacheDir = context.getExternalCacheDir();*/
    File cacheDir = FeatureHelper.getExternalCacheDir(context);
    if (cacheDir == null) {
      Log.e(TAG, "<removeOldFilesIfNecessary> failed to get cache dir");
      return;
    }
    /// @}

    String prefix = cacheDir.getAbsolutePath() + "/";

    BlobCache.deleteFiles(prefix + "imgcache");
    BlobCache.deleteFiles(prefix + "rev_geocoding");
    BlobCache.deleteFiles(prefix + "bookmark");
  }
Esempio n. 2
0
 // Return null when we cannot instantiate a BlobCache, e.g.:
 // there is no SD card found.
 // This can only be called from data thread.
 public static BlobCache getCache(
     Context context, String filename, int maxEntries, int maxBytes, int version) {
   synchronized (sCacheMap) {
     if (!sOldCheckDone) {
       removeOldFilesIfNecessary(context);
       sOldCheckDone = true;
     }
     BlobCache cache = sCacheMap.get(filename);
     if (cache == null) {
       /// M: [BEHAVIOR.MODIFY] @{
       /*File cacheDir = context.getExternalCacheDir();*/
       File cacheDir = FeatureHelper.getExternalCacheDir(context);
       if (cacheDir == null) {
         Log.e(TAG, "<getCache> failed to get cache dir");
         return null;
       }
       /// @}
       String path = cacheDir.getAbsolutePath() + "/" + filename;
       try {
         /// M: [DEBUG.ADD] @{
         Log.i(TAG, "<getCache> new BlobCache, path = " + path);
         /// @}
         cache = new BlobCache(path, maxEntries, maxBytes, false, version);
         sCacheMap.put(filename, cache);
       } catch (IOException e) {
         Log.e(TAG, "Cannot instantiate cache!", e);
       }
     }
     return cache;
   }
 }