Commit 6dc7551d authored by benm's avatar benm Committed by Commit bot

Fix strict mode violations in Android.

BUG=408525

Review URL: https://codereview.chromium.org/513173002

Cr-Commit-Position: refs/heads/master@{#292380}
parent 97c48c6f
......@@ -24,15 +24,24 @@ public class AwAssets {
@CalledByNative
public static long[] openAsset(Context context, String fileName) {
AssetFileDescriptor afd = null;
try {
AssetManager manager = context.getAssets();
AssetFileDescriptor afd = manager.openFd(fileName);
afd = manager.openFd(fileName);
return new long[] { afd.getParcelFileDescriptor().detachFd(),
afd.getStartOffset(),
afd.getLength() };
} catch (IOException e) {
Log.e(LOGTAG, "Error while loading asset " + fileName + ": " + e.getMessage());
Log.e(LOGTAG, "Error while loading asset " + fileName + ": " + e);
return new long[] {-1, -1, -1};
} finally {
try {
if (afd != null) {
afd.close();
}
} catch (IOException e2) {
Log.e(LOGTAG, "Unable to close AssetFileDescriptor", e2);
}
}
}
}
......@@ -53,12 +53,13 @@ public class ResourceExtractor {
@Override
protected Void doInBackground(Void... unused) {
if (!mOutputDir.exists() && !mOutputDir.mkdirs()) {
final File outputDir = getOutputDir();
if (!outputDir.exists() && !outputDir.mkdirs()) {
Log.e(LOGTAG, "Unable to create pak resources directory!");
return null;
}
String timestampFile = checkPakTimestamp();
String timestampFile = checkPakTimestamp(outputDir);
if (timestampFile != null) {
deleteFiles();
}
......@@ -73,7 +74,7 @@ public class ResourceExtractor {
&& filenames.size() >= sMandatoryPaks.length) {
boolean filesPresent = true;
for (String file : filenames) {
if (!new File(mOutputDir, file).exists()) {
if (!new File(outputDir, file).exists()) {
filesPresent = false;
break;
}
......@@ -112,7 +113,7 @@ public class ResourceExtractor {
continue;
}
boolean isICUData = file.equals(ICU_DATA_FILENAME);
File output = new File(isICUData ? mAppDataDir : mOutputDir, file);
File output = new File(isICUData ? getAppDataDir() : outputDir, file);
if (output.exists()) {
continue;
}
......@@ -170,7 +171,7 @@ public class ResourceExtractor {
if (timestampFile != null) {
try {
new File(mOutputDir, timestampFile).createNewFile();
new File(outputDir, timestampFile).createNewFile();
} catch (IOException e) {
// Worst case we don't write a timestamp, so we'll re-extract the resource
// paks next start up.
......@@ -190,7 +191,7 @@ public class ResourceExtractor {
// Note that we do this to avoid adding a BroadcastReceiver on
// android.content.Intent#ACTION_PACKAGE_CHANGED as that causes process churn
// on (re)installation of *all* APK files.
private String checkPakTimestamp() {
private String checkPakTimestamp(File outputDir) {
final String TIMESTAMP_PREFIX = "pak_timestamp-";
PackageManager pm = mContext.getPackageManager();
PackageInfo pi = null;
......@@ -207,7 +208,7 @@ public class ResourceExtractor {
String expectedTimestamp = TIMESTAMP_PREFIX + pi.versionCode + "-" + pi.lastUpdateTime;
String[] timestamps = mOutputDir.list(new FilenameFilter() {
String[] timestamps = outputDir.list(new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
return name.startsWith(TIMESTAMP_PREFIX);
......@@ -231,8 +232,6 @@ public class ResourceExtractor {
private final Context mContext;
private ExtractTask mExtractTask;
private final File mAppDataDir;
private final File mOutputDir;
private static ResourceExtractor sInstance;
......@@ -272,8 +271,6 @@ public class ResourceExtractor {
private ResourceExtractor(Context context) {
mContext = context.getApplicationContext();
mAppDataDir = getAppDataDir();
mOutputDir = getOutputDir();
}
public void waitForCompletion() {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment