Merge "Fix 5326463: rework sim state handling in lockscreen" into ics-factoryrom

This commit is contained in:
Jim Miller
2011-09-26 18:41:01 -07:00
committed by Android (Google) Code Review
4 changed files with 88 additions and 56 deletions

View File

@ -936,10 +936,15 @@ public class LockPatternUtils {
* *
* If there's currently a call in progress, the button will take them to the call * If there's currently a call in progress, the button will take them to the call
* @param button the button to update * @param button the button to update
* @param the phone state:
* {@link TelephonyManager#CALL_STATE_IDLE}
* {@link TelephonyManager#CALL_STATE_RINGING}
* {@link TelephonyManager#CALL_STATE_OFFHOOK}
* @param showIfCapable indicates whether the button should be shown if emergency calls are * @param showIfCapable indicates whether the button should be shown if emergency calls are
* possible on the device * possible on the device
*/ */
public void updateEmergencyCallButtonState(Button button, boolean showIfCapable) { public void updateEmergencyCallButtonState(Button button, int phoneState,
boolean showIfCapable) {
if (isEmergencyCallCapable() && showIfCapable) { if (isEmergencyCallCapable() && showIfCapable) {
button.setVisibility(View.VISIBLE); button.setVisibility(View.VISIBLE);
} else { } else {
@ -947,9 +952,8 @@ public class LockPatternUtils {
return; return;
} }
int newState = TelephonyManager.getDefault().getCallState();
int textId; int textId;
if (newState == TelephonyManager.CALL_STATE_OFFHOOK) { if (phoneState == TelephonyManager.CALL_STATE_OFFHOOK) {
// show "return to call" text and show phone icon // show "return to call" text and show phone icon
textId = R.string.lockscreen_return_to_call; textId = R.string.lockscreen_return_to_call;
int phoneCallIcon = R.drawable.stat_sys_phone_call; int phoneCallIcon = R.drawable.stat_sys_phone_call;
@ -979,22 +983,4 @@ public class LockPatternUtils {
} }
return false; return false;
} }
/**
* Performs concentenation of PLMN/SPN
* @param plmn
* @param spn
* @return
*/
public static CharSequence getCarrierString(CharSequence plmn, CharSequence spn) {
if (plmn != null && spn == null) {
return plmn;
} else if (plmn != null && spn != null) {
return plmn + "|" + spn;
} else if (plmn == null && spn != null) {
return spn;
} else {
return "";
}
}
} }

View File

@ -58,6 +58,7 @@ class KeyguardStatusViewManager implements OnClickListener {
private static final int CARRIER_HELP_TEXT = 12; private static final int CARRIER_HELP_TEXT = 12;
private static final int HELP_MESSAGE_TEXT = 13; private static final int HELP_MESSAGE_TEXT = 13;
private static final int OWNER_INFO = 14; private static final int OWNER_INFO = 14;
private static final int BATTERY_INFO = 15;
private StatusMode mStatus; private StatusMode mStatus;
private String mDateFormatString; private String mDateFormatString;
@ -84,6 +85,9 @@ class KeyguardStatusViewManager implements OnClickListener {
// last known battery level // last known battery level
private int mBatteryLevel = 100; private int mBatteryLevel = 100;
// last known SIM state
protected State mSimState;
private LockPatternUtils mLockPatternUtils; private LockPatternUtils mLockPatternUtils;
private KeyguardUpdateMonitor mUpdateMonitor; private KeyguardUpdateMonitor mUpdateMonitor;
private Button mEmergencyCallButton; private Button mEmergencyCallButton;
@ -98,6 +102,8 @@ class KeyguardStatusViewManager implements OnClickListener {
private boolean mShowingStatus; private boolean mShowingStatus;
private KeyguardScreenCallback mCallback; private KeyguardScreenCallback mCallback;
private final boolean mShowEmergencyButtonByDefault; private final boolean mShowEmergencyButtonByDefault;
private CharSequence mPlmn;
private CharSequence mSpn;
private class TransientTextManager { private class TransientTextManager {
private TextView mTextView; private TextView mTextView;
@ -151,6 +157,7 @@ class KeyguardStatusViewManager implements OnClickListener {
public KeyguardStatusViewManager(View view, KeyguardUpdateMonitor updateMonitor, public KeyguardStatusViewManager(View view, KeyguardUpdateMonitor updateMonitor,
LockPatternUtils lockPatternUtils, KeyguardScreenCallback callback, LockPatternUtils lockPatternUtils, KeyguardScreenCallback callback,
boolean showEmergencyButtonByDefault) { boolean showEmergencyButtonByDefault) {
if (DEBUG) Log.v(TAG, "KeyguardStatusViewManager()");
mContainer = view; mContainer = view;
mDateFormatString = getContext().getString(R.string.full_wday_month_day_no_year); mDateFormatString = getContext().getString(R.string.full_wday_month_day_no_year);
mLockPatternUtils = lockPatternUtils; mLockPatternUtils = lockPatternUtils;
@ -165,6 +172,12 @@ class KeyguardStatusViewManager implements OnClickListener {
mTransportView = (TransportControlView) findViewById(R.id.transport); mTransportView = (TransportControlView) findViewById(R.id.transport);
mEmergencyCallButton = (Button) findViewById(R.id.emergencyCallButton); mEmergencyCallButton = (Button) findViewById(R.id.emergencyCallButton);
mShowEmergencyButtonByDefault = showEmergencyButtonByDefault; mShowEmergencyButtonByDefault = showEmergencyButtonByDefault;
// Hide transport control view until we know we need to show it.
if (mTransportView != null) {
mTransportView.setVisibility(View.GONE);
}
if (mEmergencyCallButton != null) { if (mEmergencyCallButton != null) {
mEmergencyCallButton.setText(R.string.lockscreen_emergency_call); mEmergencyCallButton.setText(R.string.lockscreen_emergency_call);
mEmergencyCallButton.setOnClickListener(this); mEmergencyCallButton.setOnClickListener(this);
@ -173,8 +186,6 @@ class KeyguardStatusViewManager implements OnClickListener {
mTransientTextManager = new TransientTextManager(mCarrierView); mTransientTextManager = new TransientTextManager(mCarrierView);
updateEmergencyCallButtonState();
resetStatusInfo(); resetStatusInfo();
refreshDate(); refreshDate();
updateOwnerInfo(); updateOwnerInfo();
@ -187,10 +198,6 @@ class KeyguardStatusViewManager implements OnClickListener {
v.setSelected(true); v.setSelected(true);
} }
} }
// until we get an update...
setCarrierText(LockPatternUtils.getCarrierString(
mUpdateMonitor.getTelephonyPlmn(), mUpdateMonitor.getTelephonySpn()));
} }
private boolean inWidgetMode() { private boolean inWidgetMode() {
@ -248,6 +255,7 @@ class KeyguardStatusViewManager implements OnClickListener {
case INSTRUCTION_TEXT: case INSTRUCTION_TEXT:
case CARRIER_HELP_TEXT: case CARRIER_HELP_TEXT:
case HELP_MESSAGE_TEXT: case HELP_MESSAGE_TEXT:
case BATTERY_INFO:
mTransientTextManager.post(string, 0, INSTRUCTION_RESET_DELAY); mTransientTextManager.post(string, 0, INSTRUCTION_RESET_DELAY);
break; break;
@ -262,15 +270,16 @@ class KeyguardStatusViewManager implements OnClickListener {
} }
public void onPause() { public void onPause() {
if (DEBUG) Log.v(TAG, "onPause()");
mUpdateMonitor.removeCallback(mInfoCallback); mUpdateMonitor.removeCallback(mInfoCallback);
mUpdateMonitor.removeCallback(mSimStateCallback); mUpdateMonitor.removeCallback(mSimStateCallback);
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
public void onResume() { public void onResume() {
if (DEBUG) Log.v(TAG, "onResume()");
mUpdateMonitor.registerInfoCallback(mInfoCallback); mUpdateMonitor.registerInfoCallback(mInfoCallback);
mUpdateMonitor.registerSimStateCallback(mSimStateCallback); mUpdateMonitor.registerSimStateCallback(mSimStateCallback);
updateEmergencyCallButtonState();
resetStatusInfo(); resetStatusInfo();
} }
@ -399,7 +408,12 @@ class KeyguardStatusViewManager implements OnClickListener {
* Determine the current status of the lock screen given the sim state and other stuff. * Determine the current status of the lock screen given the sim state and other stuff.
*/ */
public StatusMode getStatusForIccState(IccCard.State simState) { public StatusMode getStatusForIccState(IccCard.State simState) {
boolean missingAndNotProvisioned = (!mUpdateMonitor.isDeviceProvisioned() // Since reading the SIM may take a while, we assume it is present until told otherwise.
if (simState == null) {
return StatusMode.Normal;
}
final boolean missingAndNotProvisioned = (!mUpdateMonitor.isDeviceProvisioned()
&& (simState == IccCard.State.ABSENT || simState == IccCard.State.PERM_DISABLED)); && (simState == IccCard.State.ABSENT || simState == IccCard.State.PERM_DISABLED));
// Assume we're NETWORK_LOCKED if not provisioned // Assume we're NETWORK_LOCKED if not provisioned
@ -435,22 +449,21 @@ class KeyguardStatusViewManager implements OnClickListener {
* *
* @param simState * @param simState
*/ */
private void updateWithSimStatus(State simState) { private void updateCarrierTextWithSimStatus(State simState) {
// The emergency call button no longer appears on this screen. if (DEBUG) Log.d(TAG, "updateCarrierTextWithSimStatus(), simState = " + simState);
if (DEBUG) Log.d(TAG, "updateLayout: status=" + mStatus);
CharSequence carrierText = null; CharSequence carrierText = null;
int carrierHelpTextId = 0; int carrierHelpTextId = 0;
mUnlockDisabledDueToSimState = false; mUnlockDisabledDueToSimState = false;
mStatus = getStatusForIccState(simState); mStatus = getStatusForIccState(simState);
mSimState = simState;
switch (mStatus) { switch (mStatus) {
case Normal: case Normal:
carrierText = LockPatternUtils.getCarrierString(mUpdateMonitor.getTelephonyPlmn(), carrierText = makeCarierString(mPlmn, mSpn);
mUpdateMonitor.getTelephonySpn());
break; break;
case NetworkLocked: case NetworkLocked:
carrierText = LockPatternUtils.getCarrierString(mUpdateMonitor.getTelephonyPlmn(), carrierText = makeCarierString(mPlmn,
getContext().getText(R.string.lockscreen_network_locked_message)); getContext().getText(R.string.lockscreen_network_locked_message));
carrierHelpTextId = R.string.lockscreen_instructions_when_pattern_disabled; carrierHelpTextId = R.string.lockscreen_instructions_when_pattern_disabled;
break; break;
@ -467,19 +480,19 @@ class KeyguardStatusViewManager implements OnClickListener {
break; break;
case SimMissingLocked: case SimMissingLocked:
carrierText = LockPatternUtils.getCarrierString(mUpdateMonitor.getTelephonyPlmn(), carrierText = makeCarierString(mPlmn,
getContext().getText(R.string.lockscreen_missing_sim_message_short)); getContext().getText(R.string.lockscreen_missing_sim_message_short));
carrierHelpTextId = R.string.lockscreen_missing_sim_instructions; carrierHelpTextId = R.string.lockscreen_missing_sim_instructions;
mUnlockDisabledDueToSimState = true; mUnlockDisabledDueToSimState = true;
break; break;
case SimLocked: case SimLocked:
carrierText = LockPatternUtils.getCarrierString(mUpdateMonitor.getTelephonyPlmn(), carrierText = makeCarierString(mPlmn,
getContext().getText(R.string.lockscreen_sim_locked_message)); getContext().getText(R.string.lockscreen_sim_locked_message));
break; break;
case SimPukLocked: case SimPukLocked:
carrierText = LockPatternUtils.getCarrierString(mUpdateMonitor.getTelephonyPlmn(), carrierText = makeCarierString(mPlmn,
getContext().getText(R.string.lockscreen_sim_puk_locked_message)); getContext().getText(R.string.lockscreen_sim_puk_locked_message));
if (!mLockPatternUtils.isPukUnlockScreenEnable()) { if (!mLockPatternUtils.isPukUnlockScreenEnable()) {
mUnlockDisabledDueToSimState = true; mUnlockDisabledDueToSimState = true;
@ -489,7 +502,6 @@ class KeyguardStatusViewManager implements OnClickListener {
setCarrierText(carrierText); setCarrierText(carrierText);
setCarrierHelpText(carrierHelpTextId); setCarrierHelpText(carrierHelpTextId);
updateEmergencyCallButtonState();
} }
private View findViewById(int id) { private View findViewById(int id) {
@ -552,10 +564,11 @@ class KeyguardStatusViewManager implements OnClickListener {
} }
} }
private void updateEmergencyCallButtonState() { private void updateEmergencyCallButtonState(int phoneState) {
if (mEmergencyCallButton != null) { if (mEmergencyCallButton != null) {
boolean showIfCapable = mShowEmergencyButtonByDefault || mUnlockDisabledDueToSimState; boolean showIfCapable = mShowEmergencyButtonByDefault || mUnlockDisabledDueToSimState;
mLockPatternUtils.updateEmergencyCallButtonState(mEmergencyCallButton, showIfCapable); mLockPatternUtils.updateEmergencyCallButtonState(mEmergencyCallButton,
phoneState, showIfCapable);
} }
} }
@ -567,7 +580,8 @@ class KeyguardStatusViewManager implements OnClickListener {
mShowingBatteryInfo = showBatteryInfo; mShowingBatteryInfo = showBatteryInfo;
mPluggedIn = pluggedIn; mPluggedIn = pluggedIn;
mBatteryLevel = batteryLevel; mBatteryLevel = batteryLevel;
updateStatusLines(true); final MutableInt tmpIcon = new MutableInt(0);
update(BATTERY_INFO, getAltTextMessage(tmpIcon));
} }
public void onTimeChanged() { public void onTimeChanged() {
@ -575,15 +589,17 @@ class KeyguardStatusViewManager implements OnClickListener {
} }
public void onRefreshCarrierInfo(CharSequence plmn, CharSequence spn) { public void onRefreshCarrierInfo(CharSequence plmn, CharSequence spn) {
setCarrierText(LockPatternUtils.getCarrierString(plmn, spn)); mPlmn = plmn;
mSpn = spn;
updateCarrierTextWithSimStatus(mSimState);
} }
public void onRingerModeChanged(int state) { public void onRingerModeChanged(int state) {
} }
public void onPhoneStateChanged(String newState) { public void onPhoneStateChanged(int phoneState) {
updateEmergencyCallButtonState(); updateEmergencyCallButtonState(phoneState);
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
@ -595,7 +611,7 @@ class KeyguardStatusViewManager implements OnClickListener {
private SimStateCallback mSimStateCallback = new SimStateCallback() { private SimStateCallback mSimStateCallback = new SimStateCallback() {
public void onSimStateChanged(State simState) { public void onSimStateChanged(State simState) {
updateWithSimStatus(simState); updateCarrierTextWithSimStatus(simState);
} }
}; };
@ -604,4 +620,22 @@ class KeyguardStatusViewManager implements OnClickListener {
mCallback.takeEmergencyCallAction(); mCallback.takeEmergencyCallAction();
} }
} }
/**
* Performs concentenation of PLMN/SPN
* @param plmn
* @param spn
* @return
*/
private static CharSequence makeCarierString(CharSequence plmn, CharSequence spn) {
if (plmn != null && spn == null) {
return plmn;
} else if (plmn != null && spn != null) {
return plmn + "|" + spn;
} else if (plmn == null && spn != null) {
return spn;
} else {
return "";
}
}
} }

View File

@ -88,6 +88,8 @@ public class KeyguardUpdateMonitor {
private ArrayList<InfoCallback> mInfoCallbacks = Lists.newArrayList(); private ArrayList<InfoCallback> mInfoCallbacks = Lists.newArrayList();
private ArrayList<SimStateCallback> mSimStateCallbacks = Lists.newArrayList(); private ArrayList<SimStateCallback> mSimStateCallbacks = Lists.newArrayList();
private ContentObserver mContentObserver; private ContentObserver mContentObserver;
private int mRingMode;
private int mPhoneState;
// messages for the handler // messages for the handler
private static final int MSG_TIME_UPDATE = 301; private static final int MSG_TIME_UPDATE = 301;
@ -271,13 +273,21 @@ public class KeyguardUpdateMonitor {
protected void handlePhoneStateChanged(String newState) { protected void handlePhoneStateChanged(String newState) {
if (DEBUG) Log.d(TAG, "handlePhoneStateChanged(" + newState + ")"); if (DEBUG) Log.d(TAG, "handlePhoneStateChanged(" + newState + ")");
if (TelephonyManager.EXTRA_STATE_IDLE.equals(newState)) {
mPhoneState = TelephonyManager.CALL_STATE_IDLE;
} else if (TelephonyManager.EXTRA_STATE_OFFHOOK.equals(newState)) {
mPhoneState = TelephonyManager.CALL_STATE_OFFHOOK;
} else if (TelephonyManager.EXTRA_STATE_RINGING.equals(newState)) {
mPhoneState = TelephonyManager.CALL_STATE_RINGING;
}
for (int i = 0; i < mInfoCallbacks.size(); i++) { for (int i = 0; i < mInfoCallbacks.size(); i++) {
mInfoCallbacks.get(i).onPhoneStateChanged(newState); mInfoCallbacks.get(i).onPhoneStateChanged(mPhoneState);
} }
} }
protected void handleRingerModeChange(int mode) { protected void handleRingerModeChange(int mode) {
if (DEBUG) Log.d(TAG, "handleRingerModeChange(" + mode + ")"); if (DEBUG) Log.d(TAG, "handleRingerModeChange(" + mode + ")");
mRingMode = mode;
for (int i = 0; i < mInfoCallbacks.size(); i++) { for (int i = 0; i < mInfoCallbacks.size(); i++) {
mInfoCallbacks.get(i).onRingerModeChanged(mode); mInfoCallbacks.get(i).onRingerModeChanged(mode);
} }
@ -459,7 +469,7 @@ public class KeyguardUpdateMonitor {
* {@link TelephonyManager@EXTRA_STATE_RINGING} * {@link TelephonyManager@EXTRA_STATE_RINGING}
* {@link TelephonyManager#EXTRA_STATE_OFFHOOK * {@link TelephonyManager#EXTRA_STATE_OFFHOOK
*/ */
void onPhoneStateChanged(String newState); void onPhoneStateChanged(int phoneState);
/** /**
* Called when visibility of lockscreen clock changes, such as when * Called when visibility of lockscreen clock changes, such as when
@ -484,8 +494,12 @@ public class KeyguardUpdateMonitor {
public void registerInfoCallback(InfoCallback callback) { public void registerInfoCallback(InfoCallback callback) {
if (!mInfoCallbacks.contains(callback)) { if (!mInfoCallbacks.contains(callback)) {
mInfoCallbacks.add(callback); mInfoCallbacks.add(callback);
// notify the register the current state right away // Notify listener of the current state
// TODO: need call other callback methods callback.onRefreshBatteryInfo(shouldShowBatteryInfo(), isPluggedIn(mBatteryStatus),
mBatteryLevel);
callback.onTimeChanged();
callback.onRingerModeChanged(mRingMode);
callback.onPhoneStateChanged(mPhoneState);
callback.onRefreshCarrierInfo(mTelephonyPlmn, mTelephonySpn); callback.onRefreshCarrierInfo(mTelephonyPlmn, mTelephonySpn);
} else { } else {
if (DEBUG) Log.e(TAG, "Object tried to add another INFO callback", if (DEBUG) Log.e(TAG, "Object tried to add another INFO callback",
@ -500,9 +514,7 @@ public class KeyguardUpdateMonitor {
public void registerSimStateCallback(SimStateCallback callback) { public void registerSimStateCallback(SimStateCallback callback) {
if (!mSimStateCallbacks.contains(callback)) { if (!mSimStateCallbacks.contains(callback)) {
mSimStateCallbacks.add(callback); mSimStateCallbacks.add(callback);
// notify the register the current sim state right away, // Notify listener of the current state
// otherwise the register won't receive any state until
// sim state gets changed again.
callback.onSimStateChanged(mSimState); callback.onSimStateChanged(mSimState);
} else { } else {
if (DEBUG) Log.e(TAG, "Object tried to add another SIM callback", if (DEBUG) Log.e(TAG, "Object tried to add another SIM callback",

View File

@ -782,7 +782,7 @@ public class KeyguardViewMediator implements KeyguardViewCallback,
// Don't play lockscreen SFX if the screen went off due to // Don't play lockscreen SFX if the screen went off due to
// timeout. // timeout.
mSuppressNextLockSound = true; mSuppressNextLockSound = true;
doKeyguardLocked(); doKeyguardLocked();
} }
} }
@ -793,7 +793,7 @@ public class KeyguardViewMediator implements KeyguardViewCallback,
if (TelephonyManager.EXTRA_STATE_IDLE.equals(mPhoneState) // call ending if (TelephonyManager.EXTRA_STATE_IDLE.equals(mPhoneState) // call ending
&& !mScreenOn // screen off && !mScreenOn // screen off
&& mExternallyEnabled) { // not disabled by any app && mExternallyEnabled) { // not disabled by any app
// note: this is a way to gracefully reenable the keyguard when the call // note: this is a way to gracefully reenable the keyguard when the call
// ends and the screen is off without always reenabling the keyguard // ends and the screen is off without always reenabling the keyguard
// each time the screen turns off while in call (and having an occasional ugly // each time the screen turns off while in call (and having an occasional ugly
@ -1297,7 +1297,7 @@ public class KeyguardViewMediator implements KeyguardViewCallback,
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
public void onPhoneStateChanged(String newState) { public void onPhoneStateChanged(int phoneState) {
// ignored // ignored
} }