summaryrefslogtreecommitdiffstats
path: root/core/java/com
diff options
context:
space:
mode:
authorBrad Fitzpatrick <bradfitz@android.com>2010-08-23 18:30:08 -0700
committerBrad Fitzpatrick <bradfitz@android.com>2010-08-23 18:30:08 -0700
commit90881005182936e443cb6cd9fb7eff21f83206f5 (patch)
tree68e7cd2d90783463a105148474412db291d4ad23 /core/java/com
parent3e05a0beb2fad0b21558019d2adf6805da70e10e (diff)
downloadframeworks_base-90881005182936e443cb6cd9fb7eff21f83206f5.zip
frameworks_base-90881005182936e443cb6cd9fb7eff21f83206f5.tar.gz
frameworks_base-90881005182936e443cb6cd9fb7eff21f83206f5.tar.bz2
Don't touch the VFS during window relayout.
yaffs2 is single-threaded and any disk access during window drawing (or animation in this case) can cause UI stutters / unresponsiveness for hundreds of milliseconds. BUG=2941119 Change-Id: Ifdce8337027ab25d1ea844934fa787ffe68263c4
Diffstat (limited to 'core/java/com')
-rw-r--r--core/java/com/android/internal/widget/LockPatternUtils.java65
1 files changed, 35 insertions, 30 deletions
diff --git a/core/java/com/android/internal/widget/LockPatternUtils.java b/core/java/com/android/internal/widget/LockPatternUtils.java
index dbbd286..c788605 100644
--- a/core/java/com/android/internal/widget/LockPatternUtils.java
+++ b/core/java/com/android/internal/widget/LockPatternUtils.java
@@ -19,6 +19,7 @@ package com.android.internal.widget;
import android.app.admin.DevicePolicyManager;
import android.content.ContentResolver;
import android.content.Context;
+import android.os.FileObserver;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.SystemClock;
@@ -33,6 +34,7 @@ import com.android.internal.R;
import com.android.internal.telephony.ITelephony;
import com.google.android.collect.Lists;
+import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
@@ -40,6 +42,7 @@ import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.util.Arrays;
import java.util.List;
+import java.util.concurrent.atomic.AtomicBoolean;
/**
* Utilities for the lock patten and its settings.
@@ -48,8 +51,9 @@ public class LockPatternUtils {
private static final String TAG = "LockPatternUtils";
- private static final String LOCK_PATTERN_FILE = "/system/gesture.key";
- private static final String LOCK_PASSWORD_FILE = "/system/password.key";
+ private static final String SYSTEM_DIRECTORY = "/system/";
+ private static final String LOCK_PATTERN_FILE = "gesture.key";
+ private static final String LOCK_PASSWORD_FILE = "password.key";
/**
* The maximum number of incorrect attempts before the user is prevented
@@ -98,6 +102,10 @@ public class LockPatternUtils {
private static String sLockPatternFilename;
private static String sLockPasswordFilename;
+ private static final AtomicBoolean sHaveNonZeroPatternFile = new AtomicBoolean(false);
+ private static final AtomicBoolean sHaveNonZeroPasswordFile = new AtomicBoolean(false);
+ private static FileObserver sPasswordObserver;
+
public DevicePolicyManager getDevicePolicyManager() {
if (mDevicePolicyManager == null) {
mDevicePolicyManager =
@@ -115,14 +123,31 @@ public class LockPatternUtils {
public LockPatternUtils(Context context) {
mContext = context;
mContentResolver = context.getContentResolver();
- // Initialize the location of gesture lock file
+
+ // Initialize the location of gesture & PIN lock files
if (sLockPatternFilename == null) {
- sLockPatternFilename = android.os.Environment.getDataDirectory()
- .getAbsolutePath() + LOCK_PATTERN_FILE;
- sLockPasswordFilename = android.os.Environment.getDataDirectory()
- .getAbsolutePath() + LOCK_PASSWORD_FILE;
+ String dataSystemDirectory =
+ android.os.Environment.getDataDirectory().getAbsolutePath() +
+ SYSTEM_DIRECTORY;
+ sLockPatternFilename = dataSystemDirectory + LOCK_PATTERN_FILE;
+ sLockPasswordFilename = dataSystemDirectory + LOCK_PASSWORD_FILE;
+ sHaveNonZeroPatternFile.set(new File(sLockPatternFilename).length() > 0);
+ sHaveNonZeroPasswordFile.set(new File(sLockPasswordFilename).length() > 0);
+ int fileObserverMask = FileObserver.CLOSE_WRITE | FileObserver.DELETE |
+ FileObserver.MOVED_TO | FileObserver.CREATE;
+ sPasswordObserver = new FileObserver(dataSystemDirectory, fileObserverMask) {
+ public void onEvent(int event, String path) {
+ if (LOCK_PATTERN_FILE.equals(path)) {
+ Log.d(TAG, "lock pattern file changed");
+ sHaveNonZeroPatternFile.set(new File(sLockPatternFilename).length() > 0);
+ } else if (LOCK_PASSWORD_FILE.equals(path)) {
+ Log.d(TAG, "lock password file changed");
+ sHaveNonZeroPasswordFile.set(new File(sLockPasswordFilename).length() > 0);
+ }
+ }
+ };
+ sPasswordObserver.startWatching();
}
-
}
public int getRequestedMinimumPasswordLength() {
@@ -202,31 +227,11 @@ public class LockPatternUtils {
}
/**
- * Checks to see if the given file exists and contains any data. Returns true if it does,
- * false otherwise.
- * @param filename
- * @return true if file exists and is non-empty.
- */
- private boolean nonEmptyFileExists(String filename) {
- try {
- // Check if we can read a byte from the file
- RandomAccessFile raf = new RandomAccessFile(filename, "r");
- raf.readByte();
- raf.close();
- return true;
- } catch (FileNotFoundException fnfe) {
- return false;
- } catch (IOException ioe) {
- return false;
- }
- }
-
- /**
* Check to see if the user has stored a lock pattern.
* @return Whether a saved pattern exists.
*/
public boolean savedPatternExists() {
- return nonEmptyFileExists(sLockPatternFilename);
+ return sHaveNonZeroPatternFile.get();
}
/**
@@ -234,7 +239,7 @@ public class LockPatternUtils {
* @return Whether a saved pattern exists.
*/
public boolean savedPasswordExists() {
- return nonEmptyFileExists(sLockPasswordFilename);
+ return sHaveNonZeroPasswordFile.get();
}
/**