String timestampFile = checkPakTimestamp();
if (timestampFile != null) {
- deleteFiles();
+ deleteFiles(mContext);
}
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(
// returning null? It might be useful to gather UMA here too to track if
// this happens with regularity.
Log.w(LOGTAG, "Exception unpacking required pak resources: " + e.getMessage());
- deleteFiles();
+ deleteFiles(mContext);
return null;
}
}
private ResourceExtractor(Context context) {
- mContext = context.getApplicationContext();
- mAppDataDir = getAppDataDir();
- mOutputDir = getOutputDir();
+ mContext = context;
+ mAppDataDir = getAppDataDirFromContext(mContext);
+ mOutputDir = getOutputDirFromContext(mContext);
}
public void waitForCompletion() {
try {
mExtractTask.get();
+ // ResourceExtractor is not needed any more.
+ // Release static objects to avoid leak of Context.
+ sIntercepter = null;
+ sInstance = null;
} catch (CancellationException e) {
// Don't leave the files in an inconsistent state.
- deleteFiles();
+ deleteFiles(mContext);
} catch (ExecutionException e2) {
- deleteFiles();
+ deleteFiles(mContext);
} catch (InterruptedException e3) {
- deleteFiles();
+ deleteFiles(mContext);
}
}
mExtractTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
- private File getAppDataDir() {
- return new File(PathUtils.getDataDirectory(mContext));
+ public static File getAppDataDirFromContext(Context context) {
+ return new File(PathUtils.getDataDirectory(context.getApplicationContext()));
}
- private File getOutputDir() {
- return new File(getAppDataDir(), "paks");
+ public static File getOutputDirFromContext(Context context) {
+ return new File(getAppDataDirFromContext(context), "paks");
}
/**
* lead to malfunction/UX misbehavior. So, we regard failing to update them
* as an error.
*/
- private void deleteFiles() {
- File icudata = new File(getAppDataDir(), ICU_DATA_FILENAME);
+ public static void deleteFiles(Context context) {
+ File icudata = new File(getAppDataDirFromContext(context), ICU_DATA_FILENAME);
if (icudata.exists() && !icudata.delete()) {
Log.e(LOGTAG, "Unable to remove the icudata " + icudata.getName());
}
- File dir = getOutputDir();
+ File dir = getOutputDirFromContext(context);
if (dir.exists()) {
File[] files = dir.listFiles();
for (File file : files) {