Merge "Use a new config flag to decide if notification led pulsing can be turned on/off."
diff --git a/src/com/android/settings/AccessibilityTutorialActivity.java b/src/com/android/settings/AccessibilityTutorialActivity.java
index 5039970..206aa94 100644
--- a/src/com/android/settings/AccessibilityTutorialActivity.java
+++ b/src/com/android/settings/AccessibilityTutorialActivity.java
@@ -522,6 +522,9 @@
         /** Whether this module is currently focused. */
         private boolean mIsVisible;
 
+        /** Handler for sending accessibility events after the current UI action. */
+        private InstructionHandler mHandler = new InstructionHandler();
+
         /**
          * Constructs a new tutorial module for the given context and controller
          * with the specified layout.
@@ -585,8 +588,11 @@
                 return;
             }
 
-            final String text = getContext().getString(resId, formatArgs);
+            final String text = mContext.getString(resId, formatArgs);
+            mHandler.addInstruction(text);
+        }
 
+        private void addInstructionSync(CharSequence text) {
             mInstructions.setVisibility(View.VISIBLE);
             mInstructions.setText(text);
             mInstructions.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED);
@@ -661,6 +667,24 @@
         protected void setFinishVisible(boolean visible) {
             mFinish.setVisibility(visible ? VISIBLE : GONE);
         }
+
+        private class InstructionHandler extends Handler {
+            private static final int ADD_INSTRUCTION = 1;
+
+            @Override
+            public void handleMessage(Message msg) {
+                switch (msg.what) {
+                    case ADD_INSTRUCTION:
+                        final String text = (String) msg.obj;
+                        addInstructionSync(text);
+                        break;
+                }
+            }
+
+            public void addInstruction(String text) {
+                obtainMessage(ADD_INSTRUCTION, text).sendToTarget();
+            }
+        }
     }
 
     /**
diff --git a/src/com/android/settings/ApnSettings.java b/src/com/android/settings/ApnSettings.java
index 00ef3a7..57762d4 100644
--- a/src/com/android/settings/ApnSettings.java
+++ b/src/com/android/settings/ApnSettings.java
@@ -149,8 +149,8 @@
             + android.os.SystemProperties.get(TelephonyProperties.PROPERTY_ICC_OPERATOR_NUMERIC, "")
             + "\"";
 
-        Cursor cursor = managedQuery(Telephony.Carriers.CONTENT_URI, new String[] {
-                "_id", "name", "apn", "type"}, where,
+        Cursor cursor = getContentResolver().query(Telephony.Carriers.CONTENT_URI, new String[] {
+                "_id", "name", "apn", "type"}, where, null,
                 Telephony.Carriers.DEFAULT_SORT_ORDER);
 
         PreferenceGroup apnList = (PreferenceGroup) findPreference("apn_list");
@@ -254,8 +254,8 @@
     private String getSelectedApnKey() {
         String key = null;
 
-        Cursor cursor = managedQuery(PREFERAPN_URI, new String[] {"_id"},
-                null, Telephony.Carriers.DEFAULT_SORT_ORDER);
+        Cursor cursor = getContentResolver().query(PREFERAPN_URI, new String[] {"_id"},
+                null, null, Telephony.Carriers.DEFAULT_SORT_ORDER);
         if (cursor.getCount() > 0) {
             cursor.moveToFirst();
             key = cursor.getString(ID_INDEX);
diff --git a/src/com/android/settings/CryptKeeper.java b/src/com/android/settings/CryptKeeper.java
index b1de932e7..ad2655f 100644
--- a/src/com/android/settings/CryptKeeper.java
+++ b/src/com/android/settings/CryptKeeper.java
@@ -88,6 +88,7 @@
 
     /** When encryption is detected, this flag indivates whether or not we've checked for erros. */
     private boolean mValidationComplete;
+    private boolean mValidationRequested;
     /** A flag to indicate that the volume is in a bad state (e.g. partially encrypted). */
     private boolean mEncryptionGoneBad;
 
@@ -159,6 +160,7 @@
         protected Boolean doInBackground(Void... params) {
             IMountService service = getMountService();
             try {
+                Log.d(TAG, "Validating encryption state.");
                 int state = service.getEncryptionState();
                 if (state == IMountService.ENCRYPTION_STATE_NONE) {
                     Log.w(TAG, "Unexpectedly in CryptKeeper even though there is no encryption.");
@@ -177,6 +179,8 @@
             if (Boolean.FALSE.equals(result)) {
                 Log.w(TAG, "Incomplete, or corrupted encryption detected. Prompting user to wipe.");
                 mEncryptionGoneBad = true;
+            } else {
+                Log.d(TAG, "Encryption state validated. Proceeding to configure UI");
             }
             setupUi();
         }
@@ -237,9 +241,6 @@
             mWakeLock = retained.wakelock;
             Log.d(TAG, "Restoring wakelock from NonConfigurationInstanceState");
         }
-
-        // Check the encryption status to ensure something hasn't gone bad.
-        new ValidationTask().execute((Void[]) null);
     }
 
     /**
@@ -251,10 +252,7 @@
     public void onStart() {
         super.onStart();
 
-        // Check to see why we were started.
-        if (mValidationComplete) {
-            setupUi();
-        }
+        setupUi();
     }
 
     /**
@@ -272,9 +270,13 @@
         if (!"".equals(progress) || isDebugView(FORCE_VIEW_PROGRESS)) {
             setContentView(R.layout.crypt_keeper_progress);
             encryptionProgressInit();
-        } else {
+        } else if (mValidationComplete) {
             setContentView(R.layout.crypt_keeper_password_entry);
             passwordEntryInit();
+        } else if (!mValidationRequested) {
+            // We're supposed to be encrypted, but no validation has been done.
+            new ValidationTask().execute((Void[]) null);
+            mValidationRequested = true;
         }
     }