Skip to content

Commit

Permalink
[Android WebView] Enable disk access in data dir locking code
Browse files Browse the repository at this point in the history
Dir locking code needs to run synchronously before starting
the browser process, as if we figure out that the dir is
already in use we need to avoid starting the browser, as
it will mess up the data.

Thus the only way to alleviate strict mode violation is to
enable disk access.

BUG=558377,593353

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

Cr-Commit-Position: refs/heads/master@{#380738}
(cherry picked from commit c092dc5)

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

Cr-Commit-Position: refs/branch-heads/2661@{crosswalk-project#199}
Cr-Branched-From: ef6f6ae-refs/heads/master@{#378081}
  • Loading branch information
Mikhail Naganov committed Mar 11, 2016
1 parent 2ceb746 commit c1fd03e
Showing 1 changed file with 20 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package org.chromium.android_webview;

import android.content.Context;
import android.os.StrictMode;

import org.chromium.android_webview.policy.AwPolicyProvider;
import org.chromium.base.CommandLine;
Expand Down Expand Up @@ -93,20 +94,26 @@ public void run() {
}

private static void tryObtainingDataDirLockOrDie(Context context) {
String dataPath = PathUtils.getDataDirectory(context);
File lockFile = new File(dataPath, EXCLUSIVE_LOCK_FILE);
boolean success = false;
StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
StrictMode.allowThreadDiskWrites();
try {
// Note that the file is not closed intentionally.
RandomAccessFile file = new RandomAccessFile(lockFile, "rw");
sExclusiveFileLock = file.getChannel().tryLock();
success = sExclusiveFileLock != null;
} catch (IOException e) {
Log.w(TAG, "Failed to create lock file " + lockFile, e);
}
if (!success) {
Log.w(TAG, "The app may have another WebView opened in a separate process. "
+ "This is not recommended and may stop working in future versions.");
String dataPath = PathUtils.getDataDirectory(context);
File lockFile = new File(dataPath, EXCLUSIVE_LOCK_FILE);
boolean success = false;
try {
// Note that the file is not closed intentionally.
RandomAccessFile file = new RandomAccessFile(lockFile, "rw");
sExclusiveFileLock = file.getChannel().tryLock();
success = sExclusiveFileLock != null;
} catch (IOException e) {
Log.w(TAG, "Failed to create lock file " + lockFile, e);
}
if (!success) {
Log.w(TAG, "The app may have another WebView opened in a separate process. "
+ "This is not recommended and may stop working in future versions.");
}
} finally {
StrictMode.setThreadPolicy(oldPolicy);
}
}
}

0 comments on commit c1fd03e

Please sign in to comment.