Merge "Make CarrierText handle multi-sim" into lmp-mr1-dev

This commit is contained in:
Jason Monk
2014-12-04 22:31:56 +00:00
committed by Android (Google) Code Review
6 changed files with 73 additions and 112 deletions

View File

@@ -2139,6 +2139,7 @@
<java-symbol type="string" name="system_error_manufacturer" />
<java-symbol type="dimen" name="fast_scroller_minimum_touch_target" />
<java-symbol type="array" name="config_cdma_international_roaming_indicators" />
<java-symbol type="string" name="kg_text_message_separator" />
<java-symbol type="bool" name="config_use_sim_language_file" />
</resources>

View File

@@ -380,9 +380,6 @@
you will be asked to unlock your phone using an email account.\n\n
Try again in <xliff:g id="number">%d</xliff:g> seconds.
</string>
<!-- Sequence of characters used to separate message strings in keyguard. Typically just em-dash
with spaces on either side. [CHAR LIMIT=3] -->
<string name="kg_text_message_separator" product="default">" \u2014 "</string>
<!-- The delete-widget drop target button text -->
<string name="kg_reordering_delete_drop_target_text">Remove</string>

View File

@@ -16,11 +16,17 @@
package com.android.keyguard;
import java.util.List;
import java.util.Locale;
import android.content.Context;
import android.content.res.TypedArray;
import android.text.method.SingleLineTransformationMethod;
import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager;
import android.text.TextUtils;
import android.text.method.SingleLineTransformationMethod;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import android.widget.TextView;
@@ -28,29 +34,19 @@ import com.android.internal.telephony.IccCardConstants;
import com.android.internal.telephony.IccCardConstants.State;
import com.android.internal.widget.LockPatternUtils;
import java.util.Locale;
public class CarrierText extends TextView {
private static final boolean DEBUG = KeyguardConstants.DEBUG;
private static final String TAG = "CarrierText";
private static CharSequence mSeparator;
private LockPatternUtils mLockPatternUtils;
private KeyguardUpdateMonitor mKeyguardUpdateMonitor;
private KeyguardUpdateMonitorCallback mCallback = new KeyguardUpdateMonitorCallback() {
private CharSequence mPlmn;
private CharSequence mSpn;
private State mSimState;
@Override
public void onRefreshCarrierInfo(CharSequence plmn, CharSequence spn) {
mPlmn = plmn;
mSpn = spn;
updateCarrierText(mSimState, mPlmn, mSpn);
}
@Override
public void onSimStateChanged(int subId, int slotId, State simState) {
mSimState = simState;
updateCarrierText(mSimState, mPlmn, mSpn);
public void onRefreshCarrierInfo() {
updateCarrierText();
}
public void onScreenTurnedOff(int why) {
@@ -93,14 +89,50 @@ public class CarrierText extends TextView {
setTransformationMethod(new CarrierTextTransformationMethod(mContext, useAllCaps));
}
protected void updateCarrierText(State simState, CharSequence plmn, CharSequence spn) {
setText(getCarrierTextForSimState(simState, plmn, spn));
protected void updateCarrierText() {
boolean allSimsMissing = true;
CharSequence displayText = null;
List<SubscriptionInfo> subs = mKeyguardUpdateMonitor.getSubscriptionInfo(false);
final int N = subs.size();
if (DEBUG) Log.d(TAG, "updateCarrierText(): " + N);
for (int i = 0; i < N; i++) {
State simState = mKeyguardUpdateMonitor.getSimState(subs.get(i).getSubscriptionId());
CharSequence carrierName = subs.get(i).getCarrierName();
CharSequence carrierTextForSimState = getCarrierTextForSimState(simState, carrierName);
if (DEBUG) Log.d(TAG, "Handling " + simState + " " + carrierName);
if (carrierTextForSimState != null) {
allSimsMissing = false;
displayText = concatenate(displayText, carrierTextForSimState);
}
}
if (allSimsMissing) {
if (N != 0) {
// Shows "No SIM card | Emergency calls only" on devices that are voice-capable.
// This depends on mPlmn containing the text "Emergency calls only" when the radio
// has some connectivity. Otherwise, it should be null or empty and just show
// "No SIM card"
// Grab the first subscripton, because they all should contain the emergency text,
// described above.
displayText = makeCarrierStringOnEmergencyCapable(
getContext().getText(R.string.keyguard_missing_sim_message_short),
subs.get(0).getCarrierName());
} else {
// We don't have a SubscriptionInfo to get the emergency calls only from.
// Lets just make it ourselves.
displayText = makeCarrierStringOnEmergencyCapable(
getContext().getText(R.string.keyguard_missing_sim_message_short),
getContext().getText(com.android.internal.R.string.emergency_calls_only));
}
}
setText(displayText);
}
@Override
protected void onFinishInflate() {
super.onFinishInflate();
mSeparator = getResources().getString(R.string.kg_text_message_separator);
mSeparator = getResources().getString(
com.android.internal.R.string.kg_text_message_separator);
final boolean screenOn = KeyguardUpdateMonitor.getInstance(mContext).isScreenOn();
setSelected(screenOn); // Allow marquee to work.
}
@@ -108,13 +140,14 @@ public class CarrierText extends TextView {
@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
KeyguardUpdateMonitor.getInstance(mContext).registerCallback(mCallback);
mKeyguardUpdateMonitor = KeyguardUpdateMonitor.getInstance(mContext);
mKeyguardUpdateMonitor.registerCallback(mCallback);
}
@Override
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();
KeyguardUpdateMonitor.getInstance(mContext).removeCallback(mCallback);
mKeyguardUpdateMonitor.removeCallback(mCallback);
}
/**
@@ -122,36 +155,31 @@ public class CarrierText extends TextView {
* and SPN as well as device capabilities, such as being emergency call capable.
*
* @param simState
* @param plmn
* @param text
* @param spn
* @return
* @return Carrier text if not in missing state, null otherwise.
*/
private CharSequence getCarrierTextForSimState(IccCardConstants.State simState,
CharSequence plmn, CharSequence spn) {
CharSequence text) {
CharSequence carrierText = null;
StatusMode status = getStatusForIccState(simState);
switch (status) {
case Normal:
carrierText = concatenate(plmn, spn);
carrierText = text;
break;
case SimNotReady:
carrierText = null; // nothing to display yet.
// Null is reserved for denoting missing, in this case we have nothing to display.
carrierText = ""; // nothing to display yet.
break;
case NetworkLocked:
carrierText = makeCarrierStringOnEmergencyCapable(
mContext.getText(R.string.keyguard_network_locked_message), plmn);
mContext.getText(R.string.keyguard_network_locked_message), text);
break;
case SimMissing:
// Shows "No SIM card | Emergency calls only" on devices that are voice-capable.
// This depends on mPlmn containing the text "Emergency calls only" when the radio
// has some connectivity. Otherwise, it should be null or empty and just show
// "No SIM card"
carrierText = makeCarrierStringOnEmergencyCapable(
getContext().getText(R.string.keyguard_missing_sim_message_short),
plmn);
carrierText = null;
break;
case SimPermDisabled:
@@ -160,21 +188,19 @@ public class CarrierText extends TextView {
break;
case SimMissingLocked:
carrierText = makeCarrierStringOnEmergencyCapable(
getContext().getText(R.string.keyguard_missing_sim_message_short),
plmn);
carrierText = null;
break;
case SimLocked:
carrierText = makeCarrierStringOnEmergencyCapable(
getContext().getText(R.string.keyguard_sim_locked_message),
plmn);
text);
break;
case SimPukLocked:
carrierText = makeCarrierStringOnEmergencyCapable(
getContext().getText(R.string.keyguard_sim_puk_locked_message),
plmn);
text);
break;
}

View File

@@ -153,7 +153,8 @@ class KeyguardMessageArea extends TextView {
mUpdateMonitor.registerCallback(mInfoCallback);
mHandler = new Handler(Looper.myLooper());
mSeparator = getResources().getString(R.string.kg_text_message_separator);
mSeparator = getResources().getString(
com.android.internal.R.string.kg_text_message_separator);
update();
}

View File

@@ -97,7 +97,6 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener {
// Callback messages
private static final int MSG_TIME_UPDATE = 301;
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;
private static final int MSG_PHONE_STATE_CHANGED = 306;
@@ -126,8 +125,6 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener {
private final Context mContext;
HashMap<Integer, SimData> mSimDatas = new HashMap<Integer, SimData>();
private CharSequence mTelephonyPlmn;
private CharSequence mTelephonySpn;
private int mRingMode;
private int mPhoneState;
private boolean mKeyguardIsVisible;
@@ -168,9 +165,6 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener {
case MSG_BATTERY_UPDATE:
handleBatteryUpdate((BatteryStatus) msg.obj);
break;
case MSG_CARRIER_INFO_UPDATE:
handleCarrierInfoUpdate();
break;
case MSG_SIM_STATE_CHANGE:
handleSimStateChange(msg.arg1, msg.arg2, (State) msg.obj);
break;
@@ -290,6 +284,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener {
KeyguardUpdateMonitorCallback cb = mCallbacks.get(j).get();
if (cb != null) {
cb.onSimStateChanged(data.subId, data.slotId, data.simState);
cb.onRefreshCarrierInfo();
}
}
}
@@ -435,10 +430,6 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener {
|| Intent.ACTION_TIME_CHANGED.equals(action)
|| Intent.ACTION_TIMEZONE_CHANGED.equals(action)) {
mHandler.sendEmptyMessage(MSG_TIME_UPDATE);
} else if (TelephonyIntents.SPN_STRINGS_UPDATED_ACTION.equals(action)) {
mTelephonyPlmn = getTelephonyPlmnFrom(intent);
mTelephonySpn = getTelephonySpnFrom(intent);
mHandler.sendEmptyMessage(MSG_CARRIER_INFO_UPDATE);
} else if (Intent.ACTION_BATTERY_CHANGED.equals(action)) {
final int status = intent.getIntExtra(EXTRA_STATUS, BATTERY_STATUS_UNKNOWN);
final int plugged = intent.getIntExtra(EXTRA_PLUGGED, 0);
@@ -682,7 +673,6 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener {
// Take a guess at initial SIM state, battery status and PLMN until we get an update
mBatteryStatus = new BatteryStatus(BATTERY_STATUS_UNKNOWN, 100, 0, 0);
mTelephonyPlmn = getDefaultPlmn();
// Watch for interesting updates
final IntentFilter filter = new IntentFilter();
@@ -692,7 +682,6 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener {
filter.addAction(Intent.ACTION_TIMEZONE_CHANGED);
filter.addAction(TelephonyIntents.ACTION_SIM_STATE_CHANGED);
filter.addAction(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
filter.addAction(TelephonyIntents.SPN_STRINGS_UPDATED_ACTION);
filter.addAction(AudioManager.RINGER_MODE_CHANGED_ACTION);
filter.addAction(Intent.ACTION_USER_REMOVED);
context.registerReceiver(mBroadcastReceiver, filter);
@@ -939,21 +928,6 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener {
}
}
/**
* Handle {@link #MSG_CARRIER_INFO_UPDATE}
*/
private void handleCarrierInfoUpdate() {
if (DEBUG) Log.d(TAG, "handleCarrierInfoUpdate: plmn = " + mTelephonyPlmn
+ ", spn = " + mTelephonySpn);
for (int i = 0; i < mCallbacks.size(); i++) {
KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get();
if (cb != null) {
cb.onRefreshCarrierInfo(mTelephonyPlmn, mTelephonySpn);
}
}
}
/**
* Handle {@link #MSG_SIM_STATE_CHANGE}
*/
@@ -1086,18 +1060,6 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener {
return false;
}
/**
* @param intent The intent with action {@link TelephonyIntents#SPN_STRINGS_UPDATED_ACTION}
* @return The string to use for the plmn, or null if it should not be shown.
*/
private CharSequence getTelephonyPlmnFrom(Intent intent) {
if (intent.getBooleanExtra(TelephonyIntents.EXTRA_SHOW_PLMN, false)) {
final String plmn = intent.getStringExtra(TelephonyIntents.EXTRA_PLMN);
return (plmn != null) ? plmn : getDefaultPlmn();
}
return null;
}
/**
* @return The default plmn (no service)
*/
@@ -1105,20 +1067,6 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener {
return mContext.getResources().getText(R.string.keyguard_carrier_default);
}
/**
* @param intent The intent with action {@link Telephony.Intents#SPN_STRINGS_UPDATED_ACTION}
* @return The string to use for the plmn, or null if it should not be shown.
*/
private CharSequence getTelephonySpnFrom(Intent intent) {
if (intent.getBooleanExtra(TelephonyIntents.EXTRA_SHOW_SPN, false)) {
final String spn = intent.getStringExtra(TelephonyIntents.EXTRA_SPN);
if (spn != null) {
return spn;
}
}
return null;
}
/**
* Remove the given observer's callback.
*
@@ -1159,7 +1107,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener {
callback.onTimeChanged();
callback.onRingerModeChanged(mRingMode);
callback.onPhoneStateChanged(mPhoneState);
callback.onRefreshCarrierInfo(mTelephonyPlmn, mTelephonySpn);
callback.onRefreshCarrierInfo();
callback.onClockVisibilityChanged();
for (Entry<Integer, SimData> data : mSimDatas.entrySet()) {
final SimData state = data.getValue();
@@ -1219,14 +1167,6 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener {
}
}
public CharSequence getTelephonyPlmn() {
return mTelephonyPlmn;
}
public CharSequence getTelephonySpn() {
return mTelephonySpn;
}
/**
* @return Whether the device is provisioned (whether they have gone through
* the setup wizard)
@@ -1289,7 +1229,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener {
return false;
}
private State getSimState(int subId) {
public State getSimState(int subId) {
if (mSimDatas.containsKey(subId)) {
return mSimDatas.get(subId).simState;
} else {

View File

@@ -49,12 +49,8 @@ public class KeyguardUpdateMonitorCallback {
/**
* Called when the carrier PLMN or SPN changes.
*
* @param plmn The operator name of the registered network. May be null if it shouldn't
* be displayed.
* @param spn The service provider name. May be null if it shouldn't be displayed.
*/
public void onRefreshCarrierInfo(CharSequence plmn, CharSequence spn) { }
public void onRefreshCarrierInfo() { }
/**
* Called when the ringer mode changes.