Bug 906030 - Don't create profiles when checking if they're locked. r=bnicholson
--- a/mobile/android/base/GeckoProfile.java
+++ b/mobile/android/base/GeckoProfile.java
@@ -63,17 +63,17 @@ public final class GeckoProfile {
if (context instanceof GeckoApp) {
// Check for a cached profile on this context already
// TODO: We should not be caching profile information on the Activity context
if (((GeckoApp)context).mProfile != null) {
return ((GeckoApp)context).mProfile;
}
GeckoProfile guest = GeckoProfile.getGuestProfile(context);
- // if the guest profile exists and is locked, return it
+ // if the guest profile is locked, return it
if (guest != null && guest.locked()) {
return guest;
}
// Otherwise, get the default profile for the Activity
return get(context, ((GeckoApp)context).getDefaultProfileName());
}
@@ -226,42 +226,54 @@ public final class GeckoProfile {
}
// Warning, Changing the lock file state from outside apis will cause this to become out of sync
public boolean locked() {
if (mLocked != LockState.UNDEFINED) {
return mLocked == LockState.LOCKED;
}
- File lockFile = new File(getDir(), LOCK_FILE_NAME);
- boolean res = lockFile.exists();
- mLocked = res ? LockState.LOCKED : LockState.UNLOCKED;
- return res;
+ // Don't use getDir() as it will create a dir if none exists
+ if (mDir != null && mDir.exists()) {
+ File lockFile = new File(mDir, LOCK_FILE_NAME);
+ boolean res = lockFile.exists();
+ mLocked = res ? LockState.LOCKED : LockState.UNLOCKED;
+ } else {
+ mLocked = LockState.UNLOCKED;
+ }
+
+ return mLocked == LockState.LOCKED;
}
public boolean lock() {
try {
+ // If this dir doesn't exist getDir will create it for us
File lockFile = new File(getDir(), LOCK_FILE_NAME);
boolean result = lockFile.createNewFile();
if (result) {
mLocked = LockState.LOCKED;
} else {
mLocked = LockState.UNLOCKED;
}
return result;
} catch(IOException ex) {
Log.e(LOGTAG, "Error locking profile", ex);
}
mLocked = LockState.UNLOCKED;
return false;
}
public boolean unlock() {
+ // Don't use getDir() as it will create a dir
+ if (mDir == null || !mDir.exists()) {
+ return true;
+ }
+
try {
- File lockFile = new File(getDir(), LOCK_FILE_NAME);
+ File lockFile = new File(mDir, LOCK_FILE_NAME);
boolean result = delete(lockFile);
if (result) {
mLocked = LockState.UNLOCKED;
} else {
mLocked = LockState.LOCKED;
}
return result;
} catch(IOException ex) {