am 760d266a: Merge change I9987ba41 into eclair

Merge commit '760d266a4195db5f3f3dee94be9e0c020cf4051f' into eclair-plus-aosp

* commit '760d266a4195db5f3f3dee94be9e0c020cf4051f':
  Fix 2270597: Add callback to watch ringer state and update lock screen UI when it changes.
This commit is contained in:
Jim Miller
2009-11-24 14:04:38 -08:00
committed by Android Git Automerger
3 changed files with 60 additions and 24 deletions

View File

@@ -25,6 +25,7 @@ import android.database.ContentObserver;
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 @@ public class KeyguardUpdateMonitor {
private boolean mKeyguardBypassEnabled;
private boolean mDevicePluggedIn;
private boolean mDeviceProvisioned;
private int mBatteryLevel;
private CharSequence mTelephonyPlmn;
@@ -86,7 +87,7 @@ public class KeyguardUpdateMonitor {
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 @@ public class KeyguardUpdateMonitor {
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 class KeyguardUpdateMonitor {
public KeyguardUpdateMonitor(Context context) {
mContext = context;
mHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
@@ -160,6 +162,9 @@ public class KeyguardUpdateMonitor {
case MSG_SIM_STATE_CHANGE:
handleSimStateChange((SimArgs) msg.obj);
break;
case MSG_RINGER_MODE_CHANGED:
handleRingerModeChange(msg.arg1);
break;
}
}
};
@@ -169,7 +174,7 @@ public class KeyguardUpdateMonitor {
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 @@ public class KeyguardUpdateMonitor {
@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 @@ public class KeyguardUpdateMonitor {
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 @@ public class KeyguardUpdateMonitor {
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 @@ public class KeyguardUpdateMonitor {
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 @@ public class KeyguardUpdateMonitor {
}
/**
* 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 @@ public class KeyguardUpdateMonitor {
* @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);
}
/**

View File

@@ -36,7 +36,6 @@ import android.os.SystemProperties;
import java.util.Date;
import java.io.File;
import java.text.SimpleDateFormat;
/**
* The screen within {@link LockPatternKeyguardView} that shows general
@@ -562,7 +561,7 @@ class LockScreen extends LinearLayout implements KeyguardScreen, KeyguardUpdateM
public boolean needsInput() {
return false;
}
/** {@inheritDoc} */
public void onPause() {
@@ -577,4 +576,13 @@ class LockScreen extends LinearLayout implements KeyguardScreen, KeyguardUpdateM
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();
}
}
}

View File

@@ -104,7 +104,7 @@ class UnlockScreen extends LinearLayoutWithDefaultTouchRecepient
* 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 @@ class UnlockScreen extends LinearLayoutWithDefaultTouchRecepient
if (DEBUG) Log.d(TAG,
"UnlockScreen() ctor: totalFailedAttempts="
+ totalFailedAttempts + ", mFailedPat...="
+ mFailedPatternAttemptsSinceLastTimeout
+ mFailedPatternAttemptsSinceLastTimeout
);
if (mUpdateMonitor.isInPortrait()) {
@@ -250,7 +250,7 @@ class UnlockScreen extends LinearLayoutWithDefaultTouchRecepient
if (DEBUG) Log.d(TAG, "setEnableFallback(" + state + ")");
mEnableFallback = state;
}
private void resetStatusInfo() {
mInstructions = null;
mShowingBatteryInfo = mUpdateMonitor.shouldShowBatteryInfo();
@@ -368,6 +368,11 @@ class UnlockScreen extends LinearLayoutWithDefaultTouchRecepient
mCarrier.setText(LockScreen.getCarrierString(plmn, spn));
}
/** {@inheritDoc} */
public void onRingerModeChanged(int state) {
// not currently used
}
// ---------- SimStateCallback
/** {@inheritDoc} */
@@ -391,7 +396,7 @@ class UnlockScreen extends LinearLayoutWithDefaultTouchRecepient
public boolean needsInput() {
return false;
}
/** {@inheritDoc} */
public void onPause() {
if (mCountdownTimer != null) {
@@ -409,9 +414,9 @@ class UnlockScreen extends LinearLayoutWithDefaultTouchRecepient
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 @@ class UnlockScreen extends LinearLayoutWithDefaultTouchRecepient
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);
}