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

* commit 'd601c6c5c38fcbf66ab1cca83fcd2e100ea019aa':
  Make CarrierText handle multi-sim
This commit is contained in:
Jason Monk
2014-12-04 22:38:58 +00:00
committed by Android Git Automerger
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="string" name="system_error_manufacturer" />
<java-symbol type="dimen" name="fast_scroller_minimum_touch_target" /> <java-symbol type="dimen" name="fast_scroller_minimum_touch_target" />
<java-symbol type="array" name="config_cdma_international_roaming_indicators" /> <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" /> <java-symbol type="bool" name="config_use_sim_language_file" />
</resources> </resources>

View File

@@ -380,9 +380,6 @@
you will be asked to unlock your phone using an email account.\n\n 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. Try again in <xliff:g id="number">%d</xliff:g> seconds.
</string> </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 --> <!-- The delete-widget drop target button text -->
<string name="kg_reordering_delete_drop_target_text">Remove</string> <string name="kg_reordering_delete_drop_target_text">Remove</string>

View File

@@ -16,11 +16,17 @@
package com.android.keyguard; package com.android.keyguard;
import java.util.List;
import java.util.Locale;
import android.content.Context; import android.content.Context;
import android.content.res.TypedArray; 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.TextUtils;
import android.text.method.SingleLineTransformationMethod;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.util.Log;
import android.view.View; import android.view.View;
import android.widget.TextView; 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.telephony.IccCardConstants.State;
import com.android.internal.widget.LockPatternUtils; import com.android.internal.widget.LockPatternUtils;
import java.util.Locale;
public class CarrierText extends TextView { public class CarrierText extends TextView {
private static final boolean DEBUG = KeyguardConstants.DEBUG;
private static final String TAG = "CarrierText";
private static CharSequence mSeparator; private static CharSequence mSeparator;
private LockPatternUtils mLockPatternUtils; private LockPatternUtils mLockPatternUtils;
private KeyguardUpdateMonitor mKeyguardUpdateMonitor;
private KeyguardUpdateMonitorCallback mCallback = new KeyguardUpdateMonitorCallback() { private KeyguardUpdateMonitorCallback mCallback = new KeyguardUpdateMonitorCallback() {
private CharSequence mPlmn;
private CharSequence mSpn;
private State mSimState;
@Override @Override
public void onRefreshCarrierInfo(CharSequence plmn, CharSequence spn) { public void onRefreshCarrierInfo() {
mPlmn = plmn; updateCarrierText();
mSpn = spn;
updateCarrierText(mSimState, mPlmn, mSpn);
}
@Override
public void onSimStateChanged(int subId, int slotId, State simState) {
mSimState = simState;
updateCarrierText(mSimState, mPlmn, mSpn);
} }
public void onScreenTurnedOff(int why) { public void onScreenTurnedOff(int why) {
@@ -93,14 +89,50 @@ public class CarrierText extends TextView {
setTransformationMethod(new CarrierTextTransformationMethod(mContext, useAllCaps)); setTransformationMethod(new CarrierTextTransformationMethod(mContext, useAllCaps));
} }
protected void updateCarrierText(State simState, CharSequence plmn, CharSequence spn) { protected void updateCarrierText() {
setText(getCarrierTextForSimState(simState, plmn, spn)); 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 @Override
protected void onFinishInflate() { protected void onFinishInflate() {
super.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(); final boolean screenOn = KeyguardUpdateMonitor.getInstance(mContext).isScreenOn();
setSelected(screenOn); // Allow marquee to work. setSelected(screenOn); // Allow marquee to work.
} }
@@ -108,13 +140,14 @@ public class CarrierText extends TextView {
@Override @Override
protected void onAttachedToWindow() { protected void onAttachedToWindow() {
super.onAttachedToWindow(); super.onAttachedToWindow();
KeyguardUpdateMonitor.getInstance(mContext).registerCallback(mCallback); mKeyguardUpdateMonitor = KeyguardUpdateMonitor.getInstance(mContext);
mKeyguardUpdateMonitor.registerCallback(mCallback);
} }
@Override @Override
protected void onDetachedFromWindow() { protected void onDetachedFromWindow() {
super.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. * and SPN as well as device capabilities, such as being emergency call capable.
* *
* @param simState * @param simState
* @param plmn * @param text
* @param spn * @param spn
* @return * @return Carrier text if not in missing state, null otherwise.
*/ */
private CharSequence getCarrierTextForSimState(IccCardConstants.State simState, private CharSequence getCarrierTextForSimState(IccCardConstants.State simState,
CharSequence plmn, CharSequence spn) { CharSequence text) {
CharSequence carrierText = null; CharSequence carrierText = null;
StatusMode status = getStatusForIccState(simState); StatusMode status = getStatusForIccState(simState);
switch (status) { switch (status) {
case Normal: case Normal:
carrierText = concatenate(plmn, spn); carrierText = text;
break; break;
case SimNotReady: 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; break;
case NetworkLocked: case NetworkLocked:
carrierText = makeCarrierStringOnEmergencyCapable( carrierText = makeCarrierStringOnEmergencyCapable(
mContext.getText(R.string.keyguard_network_locked_message), plmn); mContext.getText(R.string.keyguard_network_locked_message), text);
break; break;
case SimMissing: case SimMissing:
// Shows "No SIM card | Emergency calls only" on devices that are voice-capable. carrierText = null;
// 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);
break; break;
case SimPermDisabled: case SimPermDisabled:
@@ -160,21 +188,19 @@ public class CarrierText extends TextView {
break; break;
case SimMissingLocked: case SimMissingLocked:
carrierText = makeCarrierStringOnEmergencyCapable( carrierText = null;
getContext().getText(R.string.keyguard_missing_sim_message_short),
plmn);
break; break;
case SimLocked: case SimLocked:
carrierText = makeCarrierStringOnEmergencyCapable( carrierText = makeCarrierStringOnEmergencyCapable(
getContext().getText(R.string.keyguard_sim_locked_message), getContext().getText(R.string.keyguard_sim_locked_message),
plmn); text);
break; break;
case SimPukLocked: case SimPukLocked:
carrierText = makeCarrierStringOnEmergencyCapable( carrierText = makeCarrierStringOnEmergencyCapable(
getContext().getText(R.string.keyguard_sim_puk_locked_message), getContext().getText(R.string.keyguard_sim_puk_locked_message),
plmn); text);
break; break;
} }

View File

@@ -153,7 +153,8 @@ class KeyguardMessageArea extends TextView {
mUpdateMonitor.registerCallback(mInfoCallback); mUpdateMonitor.registerCallback(mInfoCallback);
mHandler = new Handler(Looper.myLooper()); 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(); update();
} }

View File

@@ -97,7 +97,6 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener {
// Callback messages // Callback messages
private static final int MSG_TIME_UPDATE = 301; private static final int MSG_TIME_UPDATE = 301;
private static final int MSG_BATTERY_UPDATE = 302; 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_SIM_STATE_CHANGE = 304;
private static final int MSG_RINGER_MODE_CHANGED = 305; private static final int MSG_RINGER_MODE_CHANGED = 305;
private static final int MSG_PHONE_STATE_CHANGED = 306; private static final int MSG_PHONE_STATE_CHANGED = 306;
@@ -126,8 +125,6 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener {
private final Context mContext; private final Context mContext;
HashMap<Integer, SimData> mSimDatas = new HashMap<Integer, SimData>(); HashMap<Integer, SimData> mSimDatas = new HashMap<Integer, SimData>();
private CharSequence mTelephonyPlmn;
private CharSequence mTelephonySpn;
private int mRingMode; private int mRingMode;
private int mPhoneState; private int mPhoneState;
private boolean mKeyguardIsVisible; private boolean mKeyguardIsVisible;
@@ -168,9 +165,6 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener {
case MSG_BATTERY_UPDATE: case MSG_BATTERY_UPDATE:
handleBatteryUpdate((BatteryStatus) msg.obj); handleBatteryUpdate((BatteryStatus) msg.obj);
break; break;
case MSG_CARRIER_INFO_UPDATE:
handleCarrierInfoUpdate();
break;
case MSG_SIM_STATE_CHANGE: case MSG_SIM_STATE_CHANGE:
handleSimStateChange(msg.arg1, msg.arg2, (State) msg.obj); handleSimStateChange(msg.arg1, msg.arg2, (State) msg.obj);
break; break;
@@ -290,6 +284,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener {
KeyguardUpdateMonitorCallback cb = mCallbacks.get(j).get(); KeyguardUpdateMonitorCallback cb = mCallbacks.get(j).get();
if (cb != null) { if (cb != null) {
cb.onSimStateChanged(data.subId, data.slotId, data.simState); 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_TIME_CHANGED.equals(action)
|| Intent.ACTION_TIMEZONE_CHANGED.equals(action)) { || Intent.ACTION_TIMEZONE_CHANGED.equals(action)) {
mHandler.sendEmptyMessage(MSG_TIME_UPDATE); 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)) { } else if (Intent.ACTION_BATTERY_CHANGED.equals(action)) {
final int status = intent.getIntExtra(EXTRA_STATUS, BATTERY_STATUS_UNKNOWN); final int status = intent.getIntExtra(EXTRA_STATUS, BATTERY_STATUS_UNKNOWN);
final int plugged = intent.getIntExtra(EXTRA_PLUGGED, 0); 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 // 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); mBatteryStatus = new BatteryStatus(BATTERY_STATUS_UNKNOWN, 100, 0, 0);
mTelephonyPlmn = getDefaultPlmn();
// Watch for interesting updates // Watch for interesting updates
final IntentFilter filter = new IntentFilter(); final IntentFilter filter = new IntentFilter();
@@ -692,7 +682,6 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener {
filter.addAction(Intent.ACTION_TIMEZONE_CHANGED); filter.addAction(Intent.ACTION_TIMEZONE_CHANGED);
filter.addAction(TelephonyIntents.ACTION_SIM_STATE_CHANGED); filter.addAction(TelephonyIntents.ACTION_SIM_STATE_CHANGED);
filter.addAction(TelephonyManager.ACTION_PHONE_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(AudioManager.RINGER_MODE_CHANGED_ACTION);
filter.addAction(Intent.ACTION_USER_REMOVED); filter.addAction(Intent.ACTION_USER_REMOVED);
context.registerReceiver(mBroadcastReceiver, filter); 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} * Handle {@link #MSG_SIM_STATE_CHANGE}
*/ */
@@ -1086,18 +1060,6 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener {
return false; 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) * @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); 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. * Remove the given observer's callback.
* *
@@ -1159,7 +1107,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener {
callback.onTimeChanged(); callback.onTimeChanged();
callback.onRingerModeChanged(mRingMode); callback.onRingerModeChanged(mRingMode);
callback.onPhoneStateChanged(mPhoneState); callback.onPhoneStateChanged(mPhoneState);
callback.onRefreshCarrierInfo(mTelephonyPlmn, mTelephonySpn); callback.onRefreshCarrierInfo();
callback.onClockVisibilityChanged(); callback.onClockVisibilityChanged();
for (Entry<Integer, SimData> data : mSimDatas.entrySet()) { for (Entry<Integer, SimData> data : mSimDatas.entrySet()) {
final SimData state = data.getValue(); 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 * @return Whether the device is provisioned (whether they have gone through
* the setup wizard) * the setup wizard)
@@ -1289,7 +1229,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener {
return false; return false;
} }
private State getSimState(int subId) { public State getSimState(int subId) {
if (mSimDatas.containsKey(subId)) { if (mSimDatas.containsKey(subId)) {
return mSimDatas.get(subId).simState; return mSimDatas.get(subId).simState;
} else { } else {

View File

@@ -49,12 +49,8 @@ public class KeyguardUpdateMonitorCallback {
/** /**
* Called when the carrier PLMN or SPN changes. * 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. * Called when the ringer mode changes.