Fix 2270597: Add callback to watch ringer state and update lock screen UI when it changes.
diff --git a/policy/com/android/internal/policy/impl/KeyguardUpdateMonitor.java b/policy/com/android/internal/policy/impl/KeyguardUpdateMonitor.java
index 58905a1..3483405 100644
--- a/policy/com/android/internal/policy/impl/KeyguardUpdateMonitor.java
+++ b/policy/com/android/internal/policy/impl/KeyguardUpdateMonitor.java
@@ -25,6 +25,7 @@
 import static android.os.BatteryManager.BATTERY_STATUS_CHARGING;
 import static android.os.BatteryManager.BATTERY_STATUS_FULL;
 import static android.os.BatteryManager.BATTERY_STATUS_UNKNOWN;
+import android.media.AudioManager;
 import android.os.Handler;
 import android.os.Message;
 import android.provider.Settings;
@@ -69,9 +70,9 @@
     private boolean mKeyguardBypassEnabled;
 
     private boolean mDevicePluggedIn;
-    
+
     private boolean mDeviceProvisioned;
-    
+
     private int mBatteryLevel;
 
     private CharSequence mTelephonyPlmn;
@@ -86,7 +87,7 @@
     private ArrayList<InfoCallback> mInfoCallbacks = Lists.newArrayList();
     private ArrayList<SimStateCallback> mSimStateCallbacks = Lists.newArrayList();
     private ContentObserver mContentObserver;
-    
+
 
     // messages for the handler
     private static final int MSG_CONFIGURATION_CHANGED = 300;
@@ -94,14 +95,15 @@
     private static final int MSG_BATTERY_UPDATE = 302;
     private static final int MSG_CARRIER_INFO_UPDATE = 303;
     private static final int MSG_SIM_STATE_CHANGE = 304;
+    private static final int MSG_RINGER_MODE_CHANGED = 305;
 
 
     /**
-     * When we receive a 
-     * {@link com.android.internal.telephony.TelephonyIntents#ACTION_SIM_STATE_CHANGED} broadcast, 
+     * When we receive a
+     * {@link com.android.internal.telephony.TelephonyIntents#ACTION_SIM_STATE_CHANGED} broadcast,
      * and then pass a result via our handler to {@link KeyguardUpdateMonitor#handleSimStateChange},
      * we need a single object to pass to the handler.  This class helps decode
-     * the intent and provide a {@link SimCard.State} result. 
+     * the intent and provide a {@link SimCard.State} result.
      */
     private static class SimArgs {
 
@@ -140,7 +142,7 @@
 
     public KeyguardUpdateMonitor(Context context) {
         mContext = context;
-        
+
         mHandler = new Handler() {
             @Override
             public void handleMessage(Message msg) {
@@ -160,6 +162,9 @@
                     case MSG_SIM_STATE_CHANGE:
                         handleSimStateChange((SimArgs) msg.obj);
                         break;
+                    case MSG_RINGER_MODE_CHANGED:
+                        handleRingerModeChange(msg.arg1);
+                        break;
                 }
             }
         };
@@ -169,7 +174,7 @@
 
         mDeviceProvisioned = Settings.Secure.getInt(
                 mContext.getContentResolver(), Settings.Secure.DEVICE_PROVISIONED, 0) != 0;
-     
+
         // Since device can't be un-provisioned, we only need to register a content observer
         // to update mDeviceProvisioned when we are...
         if (!mDeviceProvisioned) {
@@ -177,7 +182,7 @@
                 @Override
                 public void onChange(boolean selfChange) {
                     super.onChange(selfChange);
-                    mDeviceProvisioned = Settings.Secure.getInt(mContext.getContentResolver(), 
+                    mDeviceProvisioned = Settings.Secure.getInt(mContext.getContentResolver(),
                         Settings.Secure.DEVICE_PROVISIONED, 0) != 0;
                     if (mDeviceProvisioned && mContentObserver != null) {
                         // We don't need the observer anymore...
@@ -187,17 +192,17 @@
                     if (DEBUG) Log.d(TAG, "DEVICE_PROVISIONED state = " + mDeviceProvisioned);
                 }
             };
-            
+
             mContext.getContentResolver().registerContentObserver(
                     Settings.Secure.getUriFor(Settings.Secure.DEVICE_PROVISIONED),
                     false, mContentObserver);
-            
+
             // prevent a race condition between where we check the flag and where we register the
             // observer by grabbing the value once again...
-            mDeviceProvisioned = Settings.Secure.getInt(mContext.getContentResolver(), 
+            mDeviceProvisioned = Settings.Secure.getInt(mContext.getContentResolver(),
                 Settings.Secure.DEVICE_PROVISIONED, 0) != 0;
         }
-        
+
         mInPortrait = queryInPortrait();
         mKeyboardOpen = queryKeyboardOpen();
 
@@ -217,6 +222,7 @@
         filter.addAction(Intent.ACTION_TIMEZONE_CHANGED);
         filter.addAction(TelephonyIntents.ACTION_SIM_STATE_CHANGED);
         filter.addAction(SPN_STRINGS_UPDATED_ACTION);
+        filter.addAction(AudioManager.RINGER_MODE_CHANGED_ACTION);
         context.registerReceiver(new BroadcastReceiver() {
 
             public void onReceive(Context context, Intent intent) {
@@ -242,15 +248,25 @@
                             pluggedInStatus,
                             batteryLevel);
                     mHandler.sendMessage(msg);
-                } else if (TelephonyIntents.ACTION_SIM_STATE_CHANGED.equals(action)){
+                } else if (TelephonyIntents.ACTION_SIM_STATE_CHANGED.equals(action)) {
                     mHandler.sendMessage(mHandler.obtainMessage(
                             MSG_SIM_STATE_CHANGE,
                             new SimArgs(intent)));
+                } else if (AudioManager.RINGER_MODE_CHANGED_ACTION.equals(action)) {
+                    mHandler.sendMessage(mHandler.obtainMessage(MSG_RINGER_MODE_CHANGED,
+                            intent.getIntExtra(AudioManager.EXTRA_RINGER_MODE, -1), 0));
                 }
             }
         }, filter);
     }
 
+    protected void handleRingerModeChange(int mode) {
+        if (DEBUG) Log.d(TAG, "handleRingerModeChange(" + mode + ")");
+        for (int i = 0; i < mInfoCallbacks.size(); i++) {
+            mInfoCallbacks.get(i).onRingerModeChanged(mode);
+        }
+    }
+
     /**
      * Handle {@link #MSG_CONFIGURATION_CHANGED}
      */
@@ -443,7 +459,7 @@
     }
 
     /**
-     * Callback for general information releveant to lock screen.
+     * Callback for general information relevant to lock screen.
      */
     interface InfoCallback {
         void onRefreshBatteryInfo(boolean showBatteryInfo, boolean pluggedIn, int batteryLevel);
@@ -455,6 +471,13 @@
          * @param spn The service provider name.  May be null if it shouldn't be displayed.
          */
         void onRefreshCarrierInfo(CharSequence plmn, CharSequence spn);
+
+        /**
+         * Called when the ringer mode changes.
+         * @param state the current ringer state, as defined in
+         * {@link AudioManager#RINGER_MODE_CHANGED_ACTION}
+         */
+        void onRingerModeChanged(int state);
     }
 
     /**
diff --git a/policy/com/android/internal/policy/impl/LockScreen.java b/policy/com/android/internal/policy/impl/LockScreen.java
index 67fe0b3..6da03ab 100644
--- a/policy/com/android/internal/policy/impl/LockScreen.java
+++ b/policy/com/android/internal/policy/impl/LockScreen.java
@@ -36,7 +36,6 @@
 
 import java.util.Date;
 import java.io.File;
-import java.text.SimpleDateFormat;
 
 /**
  * The screen within {@link LockPatternKeyguardView} that shows general
@@ -562,7 +561,7 @@
     public boolean needsInput() {
         return false;
     }
-    
+
     /** {@inheritDoc} */
     public void onPause() {
 
@@ -577,4 +576,13 @@
     public void cleanUp() {
         mUpdateMonitor.removeCallback(this);
     }
+
+    /** {@inheritDoc} */
+    public void onRingerModeChanged(int state) {
+        boolean silent = AudioManager.RINGER_MODE_SILENT == state;
+        if (silent != mSilentMode) {
+            mSilentMode = silent;
+            updateRightTabResources();
+        }
+    }
 }
diff --git a/policy/com/android/internal/policy/impl/UnlockScreen.java b/policy/com/android/internal/policy/impl/UnlockScreen.java
index e413d6b..e090ac5 100644
--- a/policy/com/android/internal/policy/impl/UnlockScreen.java
+++ b/policy/com/android/internal/policy/impl/UnlockScreen.java
@@ -104,7 +104,7 @@
      * Keeps track of the last time we poked the wake lock during dispatching
      * of the touch event, initalized to something gauranteed to make us
      * poke it when the user starts drawing the pattern.
-     * @see #dispatchTouchEvent(android.view.MotionEvent) 
+     * @see #dispatchTouchEvent(android.view.MotionEvent)
      */
     private long mLastPokeTime = -UNLOCK_PATTERN_WAKE_INTERVAL_MS;
 
@@ -167,7 +167,7 @@
         if (DEBUG) Log.d(TAG,
             "UnlockScreen() ctor: totalFailedAttempts="
                  + totalFailedAttempts + ", mFailedPat...="
-                 + mFailedPatternAttemptsSinceLastTimeout 
+                 + mFailedPatternAttemptsSinceLastTimeout
                  );
 
         if (mUpdateMonitor.isInPortrait()) {
@@ -250,7 +250,7 @@
         if (DEBUG) Log.d(TAG, "setEnableFallback(" + state + ")");
         mEnableFallback = state;
     }
-    
+
     private void resetStatusInfo() {
         mInstructions = null;
         mShowingBatteryInfo = mUpdateMonitor.shouldShowBatteryInfo();
@@ -368,6 +368,11 @@
         mCarrier.setText(LockScreen.getCarrierString(plmn, spn));
     }
 
+    /** {@inheritDoc} */
+    public void onRingerModeChanged(int state) {
+        // not currently used
+    }
+
     // ---------- SimStateCallback
 
     /** {@inheritDoc} */
@@ -391,7 +396,7 @@
     public boolean needsInput() {
         return false;
     }
-    
+
     /** {@inheritDoc} */
     public void onPause() {
         if (mCountdownTimer != null) {
@@ -409,9 +414,9 @@
         mLockPatternView.enableInput();
         mLockPatternView.setEnabled(true);
         mLockPatternView.clearPattern();
-        
+
         // show "forgot pattern?" button if we have an alternate authentication method
-        mForgotPatternButton.setVisibility(mCallback.doesFallbackUnlockScreenExist() 
+        mForgotPatternButton.setVisibility(mCallback.doesFallbackUnlockScreenExist()
                 ? View.VISIBLE : View.INVISIBLE);
 
         // if the user is currently locked out, enforce it.
@@ -457,7 +462,7 @@
 
         public void onPatternCellAdded(List<Cell> pattern) {
             // To guard against accidental poking of the wakelock, look for
-            // the user actually trying to draw a pattern of some minimal length. 
+            // the user actually trying to draw a pattern of some minimal length.
             if (pattern.size() > MIN_PATTERN_BEFORE_POKE_WAKELOCK) {
                 mCallback.pokeWakelock(UNLOCK_PATTERN_WAKE_INTERVAL_MS);
             }