From 49f9a2ca7bdc2fa97824551dca1b391e3d7252fa Mon Sep 17 00:00:00 2001 From: Steve Kondik Date: Wed, 21 Sep 2016 10:40:24 -0700 Subject: Revert "RIL: Squash changes to default SIM handling" This reverts commit 04824aa53f70b5977d3f89f325b69b98624e79f3. Change-Id: I70ddee6f0d5ec38773db000f76ac2d528ef62d61 --- .../android/internal/telephony/PhoneFactory.java | 12 -- .../android/internal/telephony/SmsApplication.java | 12 -- .../internal/telephony/SubscriptionController.java | 45 ++----- .../telephony/SubscriptionInfoUpdater.java | 131 +++------------------ .../internal/telephony/UiccSmsController.java | 15 +-- 5 files changed, 29 insertions(+), 186 deletions(-) diff --git a/src/java/com/android/internal/telephony/PhoneFactory.java b/src/java/com/android/internal/telephony/PhoneFactory.java index 29e6ac281..bf0e3fe1a 100644 --- a/src/java/com/android/internal/telephony/PhoneFactory.java +++ b/src/java/com/android/internal/telephony/PhoneFactory.java @@ -363,14 +363,6 @@ public class PhoneFactory { return prompt; } - /* Sets User SMS Prompt property, enable or not */ - public static void setSMSPromptEnabled(boolean enabled) { - int value = (enabled == false) ? 0 : 1; - Settings.Global.putInt(sContext.getContentResolver(), - Settings.Global.MULTI_SIM_SMS_PROMPT, value); - Rlog.d(LOG_TAG, "setSMSPromptOption to " + enabled); - } - /** * Makes a {@link ImsPhone} object. * @return the {@code ImsPhone} object or null if the exception occured @@ -510,8 +502,4 @@ public class PhoneFactory { } pw.decreaseIndent(); } - - public static SubscriptionInfoUpdater getSubscriptionInfoUpdater() { - return sSubInfoRecordUpdater; - } } diff --git a/src/java/com/android/internal/telephony/SmsApplication.java b/src/java/com/android/internal/telephony/SmsApplication.java index aac4f50dd..bf90350ef 100644 --- a/src/java/com/android/internal/telephony/SmsApplication.java +++ b/src/java/com/android/internal/telephony/SmsApplication.java @@ -41,7 +41,6 @@ import android.provider.Telephony.Sms.Intents; import android.telephony.Rlog; import android.telephony.SmsManager; import android.telephony.TelephonyManager; -import android.text.TextUtils; import android.util.Log; import com.android.internal.content.PackageMonitor; @@ -63,7 +62,6 @@ public final class SmsApplication { private static final String BLUETOOTH_PACKAGE_NAME = "com.android.bluetooth"; private static final String MMS_SERVICE_PACKAGE_NAME = "com.android.mms.service"; private static final String TELEPHONY_PROVIDER_PACKAGE_NAME = "com.android.providers.telephony"; - private static final String DEFAULT_SYSTEM_MMS_PACKAGE_NAME = "com.android.messaging"; private static final String SCHEME_SMS = "sms"; private static final String SCHEME_SMSTO = "smsto"; @@ -916,16 +914,6 @@ public final class SmsApplication { return false; } - /** - * @hide - */ - public static boolean canSmsAppHandleAlwaysAsk(Context context) { - final ComponentName defaultMmsApplication = SmsApplication.getDefaultMmsApplication(context, - false); - return TextUtils.equals(DEFAULT_SYSTEM_MMS_PACKAGE_NAME, - defaultMmsApplication.getPackageName()); - } - private static String getDefaultSmsApplicationPackageName(Context context) { final ComponentName component = getDefaultSmsApplication(context, false); if (component != null) { diff --git a/src/java/com/android/internal/telephony/SubscriptionController.java b/src/java/com/android/internal/telephony/SubscriptionController.java index 22fa195f2..a72392f92 100644 --- a/src/java/com/android/internal/telephony/SubscriptionController.java +++ b/src/java/com/android/internal/telephony/SubscriptionController.java @@ -186,14 +186,7 @@ public class SubscriptionController extends ISub.Stub { } private boolean isSubInfoReady() { - final SubscriptionInfoUpdater subUpdater = PhoneFactory.getSubscriptionInfoUpdater(); - return subUpdater != null && sSlotIdxToSubId.size() == subUpdater.getInsertedSimCount(); - } - - private boolean isSingleSimActiveOnMSIM() { - final SubscriptionInfoUpdater subUpdater = PhoneFactory.getSubscriptionInfoUpdater(); - return subUpdater != null && subUpdater.getInsertedSimCount() == 1 - && getActiveSubInfoCountMax() > 1; + return sSlotIdxToSubId.size() > 0; } private SubscriptionController(Phone phone) { @@ -687,7 +680,7 @@ public class SubscriptionController extends ISub.Stub { @Override public int getActiveSubInfoCountMax() { // FIXME: This valid now but change to use TelephonyDevController in the future - return TelephonyManager.getDefault().getSimCount(); + return mTelephonyManager.getSimCount(); } /** @@ -778,28 +771,22 @@ public class SubscriptionController extends ISub.Stub { // may not be true, for instance with multiple subs per slot. // But is true at the moment. sSlotIdxToSubId.put(slotId, subId); - int simCount = PhoneFactory.getSubscriptionInfoUpdater() - .getInsertedSimCount(); + int subIdCountMax = getActiveSubInfoCountMax(); int defaultSubId = getDefaultSubId(); if (DBG) { logdl("[addSubInfoRecord]" + " sSlotIdxToSubId.size=" + sSlotIdxToSubId.size() + " slotId=" + slotId + " subId=" + subId - + " defaultSubId=" + defaultSubId + " simCount=" + simCount); - } - - if (!isSubInfoReady()) { - continue; + + " defaultSubId=" + defaultSubId + " simCount=" + subIdCountMax); } // Set the default sub if not set or if single sim device if (!SubscriptionManager.isValidSubscriptionId(defaultSubId) - || simCount == 1 || (!isActiveSubId(defaultSubId))) { + || subIdCountMax == 1 || (!isActiveSubId(defaultSubId))) { setDefaultFallbackSubId(subId); } // If single sim device, set this subscription as the default for everything - if (simCount == 1 - && TelephonyManager.getDefault().getSimCount() == 1) { + if (subIdCountMax == 1) { if (DBG) { logdl("[addSubInfoRecord] one sim set defaults to subId=" + subId); } @@ -1388,10 +1375,6 @@ public class SubscriptionController extends ISub.Stub { @Override public int getDefaultSmsSubId() { - if (isSingleSimActiveOnMSIM()) { - if (VDBG) logd("[getDefaultSmsSubId] overridden to current single active sim"); - return mDefaultFallbackSubId; - } int subId = Settings.Global.getInt(mContext.getContentResolver(), Settings.Global.MULTI_SIM_SMS_SUBSCRIPTION, SubscriptionManager.INVALID_SUBSCRIPTION_ID); @@ -1423,10 +1406,6 @@ public class SubscriptionController extends ISub.Stub { @Override public int getDefaultVoiceSubId() { - if (isSingleSimActiveOnMSIM()) { - if (VDBG) logd("[getDefaultVoiceSubId] overridden to current single active sim"); - return mDefaultFallbackSubId; - } int subId = Settings.Global.getInt(mContext.getContentResolver(), Settings.Global.MULTI_SIM_VOICE_CALL_SUBSCRIPTION, SubscriptionManager.INVALID_SUBSCRIPTION_ID); @@ -1436,10 +1415,6 @@ public class SubscriptionController extends ISub.Stub { @Override public int getDefaultDataSubId() { - if (isSingleSimActiveOnMSIM()) { - if (VDBG) logd("[getDefaultDataSubId] overridden to current single active sim"); - return mDefaultFallbackSubId; - } int subId = Settings.Global.getInt(mContext.getContentResolver(), Settings.Global.MULTI_SIM_DATA_CALL_SUBSCRIPTION, SubscriptionManager.INVALID_SUBSCRIPTION_ID); @@ -1492,10 +1467,8 @@ public class SubscriptionController extends ISub.Stub { // FIXME is this still needed? updateAllDataConnectionTrackers(); - if (!isSingleSimActiveOnMSIM()) { - Settings.Global.putInt(mContext.getContentResolver(), - Settings.Global.MULTI_SIM_DATA_CALL_SUBSCRIPTION, subId); - } + Settings.Global.putInt(mContext.getContentResolver(), + Settings.Global.MULTI_SIM_DATA_CALL_SUBSCRIPTION, subId); broadcastDefaultDataSubIdChanged(subId); } @@ -1530,7 +1503,7 @@ public class SubscriptionController extends ISub.Stub { if (SubscriptionManager.isValidSubscriptionId(subId)) { int phoneId = getPhoneId(subId); if (phoneId >= 0 && (phoneId < mTelephonyManager.getPhoneCount() - || isSingleSimActiveOnMSIM())) { + || mTelephonyManager.getSimCount() == 1)) { if (DBG) logdl("[setDefaultFallbackSubId] set mDefaultFallbackSubId=" + subId); mDefaultFallbackSubId = subId; // Update MCC MNC device configuration information diff --git a/src/java/com/android/internal/telephony/SubscriptionInfoUpdater.java b/src/java/com/android/internal/telephony/SubscriptionInfoUpdater.java index 507d8054e..bc982f3ca 100644 --- a/src/java/com/android/internal/telephony/SubscriptionInfoUpdater.java +++ b/src/java/com/android/internal/telephony/SubscriptionInfoUpdater.java @@ -52,7 +52,6 @@ import com.android.internal.telephony.uicc.IccUtils; import java.io.FileDescriptor; import java.io.PrintWriter; -import java.util.BitSet; import java.util.HashMap; import java.util.Iterator; import java.util.List; @@ -76,9 +75,6 @@ public class SubscriptionInfoUpdater extends Handler { private static final int EVENT_SIM_IO_ERROR = 6; private static final int EVENT_SIM_UNKNOWN = 7; private static final int EVENT_SIM_RESTRICTED = 8; - private static final int EVENT_UPDATE_INSERTED_SIM_COUNT = 9; - - private static final int DELAY_MILLIS = 500; private static final String ICCID_STRING_FOR_NO_SIM = ""; /** @@ -106,8 +102,6 @@ public class SubscriptionInfoUpdater extends Handler { // Key used to read/write the current IMSI. Updated on SIM_STATE_CHANGED - LOADED. public static final String CURR_SUBID = "curr_subid"; - // Key used to determine if the number of sims in the device has changed - private static final String PREF_LAST_SEEN_SIM_COUNT = "previous_update_sim_count"; private static Phone[] mPhone; private static Context mContext = null; @@ -121,9 +115,6 @@ public class SubscriptionInfoUpdater extends Handler { // The current foreground user ID. private int mCurrentlyActiveUserId; private CarrierServiceBindHelper mCarrierServiceBindHelper; - private boolean mIsShutdown; - private int mCurrentSimCount = 0; - private BitSet mLockedSims = new BitSet(PROJECT_SIM_NUM); public SubscriptionInfoUpdater(Context context, Phone[] phone, CommandsInterface[] ci) { logd("Constructor invoked"); @@ -133,12 +124,10 @@ public class SubscriptionInfoUpdater extends Handler { mSubscriptionManager = SubscriptionManager.from(mContext); mPackageManager = IPackageManager.Stub.asInterface(ServiceManager.getService("package")); mUserManager = (UserManager) mContext.getSystemService(Context.USER_SERVICE); - mIsShutdown = false; IntentFilter intentFilter = new IntentFilter(TelephonyIntents.ACTION_SIM_STATE_CHANGED); intentFilter.addAction(IccCardProxy.ACTION_INTERNAL_SIM_STATE_CHANGED); intentFilter.addAction(Intent.ACTION_USER_UNLOCKED); - intentFilter.addAction(Intent.ACTION_SHUTDOWN); mContext.registerReceiver(sReceiver, intentFilter); mCarrierServiceBindHelper = new CarrierServiceBindHelper(mContext); @@ -212,11 +201,6 @@ public class SubscriptionInfoUpdater extends Handler { return; } - if (action.equals(Intent.ACTION_SHUTDOWN)) { - mIsShutdown = true; - return; - } - if (!action.equals(TelephonyIntents.ACTION_SIM_STATE_CHANGED) && !action.equals(IccCardProxy.ACTION_INTERNAL_SIM_STATE_CHANGED)) { return; @@ -256,16 +240,6 @@ public class SubscriptionInfoUpdater extends Handler { logd("Ignoring simStatus: " + simStatus); } } - - if (IccCardConstants.INTENT_VALUE_ICC_LOCKED.equals(simStatus)) { - mLockedSims.set(slotId); - update(slotId); - } else if (IccCardConstants.INTENT_VALUE_ICC_READY.equals(simStatus) - || IccCardConstants.INTENT_VALUE_ICC_LOADED.equals(simStatus)) { - mLockedSims.clear(slotId); - update(slotId); - } - logd("[Receiver]-"); } }; @@ -325,7 +299,9 @@ public class SubscriptionInfoUpdater extends Handler { logd("Query IccId fail: " + ar.exception); } logd("sIccId[" + slotId + "] = " + mIccId[slotId]); - update(slotId); + if (isAllIccIdQueryDone()) { + updateSubscriptionInfoByIccId(); + } broadcastSimStateChanged(slotId, IccCardConstants.INTENT_VALUE_ICC_LOCKED, uObj.reason); if (!ICCID_STRING_FOR_NO_SIM.equals(mIccId[slotId])) { @@ -372,14 +348,6 @@ public class SubscriptionInfoUpdater extends Handler { updateCarrierServices(msg.arg1, IccCardConstants.INTENT_VALUE_ICC_CARD_RESTRICTED); break; - case EVENT_UPDATE_INSERTED_SIM_COUNT: - logd("EVENT_UPDATE_INSERTED_SIM_COUNT: locked sims: " + mLockedSims.cardinality()); - if (isAllIccIdQueryDone() && !hasMessages(EVENT_UPDATE_INSERTED_SIM_COUNT)) { - updateSubscriptionInfoByIccId(); - logd("update inserted sim count, current sim count: " + mCurrentSimCount); - } - break; - default: logd("Unknown msg:" + msg.what); } @@ -401,6 +369,7 @@ public class SubscriptionInfoUpdater extends Handler { mIccId[slotId] = null; } + IccFileHandler fileHandler = mPhone[slotId].getIccCard() == null ? null : mPhone[slotId].getIccCard().getIccFileHandler(); @@ -419,14 +388,6 @@ public class SubscriptionInfoUpdater extends Handler { } else { logd("sFh[" + slotId + "] is null, ignore"); } - update(slotId); - } - - private void update(int slotId) { - sendMessageDelayed(obtainMessage(EVENT_UPDATE_INSERTED_SIM_COUNT, slotId), DELAY_MILLIS); - if (isAllIccIdQueryDone()) { - updateSubscriptionInfoByIccId(); - } } protected void handleSimLoaded(int slotId) { @@ -445,7 +406,10 @@ public class SubscriptionInfoUpdater extends Handler { return; } mIccId[slotId] = records.getIccId(); - update(slotId); + + if (isAllIccIdQueryDone()) { + updateSubscriptionInfoByIccId(); + } int subId = SubscriptionManager.DEFAULT_SUBSCRIPTION_ID; int[] subIds = SubscriptionController.getInstance().getSubId(slotId); @@ -558,7 +522,9 @@ public class SubscriptionInfoUpdater extends Handler { logd("SIM" + (slotId + 1) + " hot plug out or error"); } mIccId[slotId] = ICCID_STRING_FOR_NO_SIM; - update(slotId); + if (isAllIccIdQueryDone()) { + updateSubscriptionInfoByIccId(); + } updateCarrierServices(slotId, simState); } @@ -569,11 +535,7 @@ public class SubscriptionInfoUpdater extends Handler { synchronized protected void updateSubscriptionInfoByIccId() { logd("updateSubscriptionInfoByIccId:+ Start"); - // only update external state if we have no pending updates pending - boolean update = !hasMessages(EVENT_UPDATE_INSERTED_SIM_COUNT); - if (update) { - mSubscriptionManager.clearSubscriptionInfo(); - } + mSubscriptionManager.clearSubscriptionInfo(); for (int i = 0; i < PROJECT_SIM_NUM; i++) { mInsertSimState[i] = SIM_NOT_CHANGE; @@ -587,7 +549,6 @@ public class SubscriptionInfoUpdater extends Handler { } } logd("insertedSimCount = " + insertedSimCount); - mCurrentSimCount = insertedSimCount; int index = 0; for (int i = 0; i < PROJECT_SIM_NUM; i++) { @@ -648,13 +609,13 @@ public class SubscriptionInfoUpdater extends Handler { if (mInsertSimState[i] == SIM_NOT_INSERT) { logd("updateSubscriptionInfoByIccId: No SIM inserted in slot " + i + " this time"); } else { - if (mInsertSimState[i] > 0 && update) { + if (mInsertSimState[i] > 0) { //some special SIMs may have the same IccIds, add suffix to distinguish them //FIXME: addSubInfoRecord can return an error. mSubscriptionManager.addSubscriptionInfoRecord(mIccId[i] + Integer.toString(mInsertSimState[i]), i); logd("SUB" + (i + 1) + " has invalid IccId"); - } else if (update)/*if (sInsertSimState[i] != SIM_NOT_INSERT)*/ { + } else /*if (sInsertSimState[i] != SIM_NOT_INSERT)*/ { mSubscriptionManager.addSubscriptionInfoRecord(mIccId[i], i); } if (isNewSim(mIccId[i], oldIccId)) { @@ -705,66 +666,12 @@ public class SubscriptionInfoUpdater extends Handler { } } - if (update && !mIsShutdown && mLockedSims.cardinality() == 0) { - final int previousUpdateSimCount = previousUpdateSimCount(); - if (previousUpdateSimCount != insertedSimCount) { - logd("number of sims changed, resetting sms prompt, old sim count: " - + previousUpdateSimCount); - if (insertedSimCount == 1 && PROJECT_SIM_NUM > 1) { - // 1 sim, msim device: clear stale defaults (doesn't clear inactive subs) - mSubscriptionManager.clearDefaultsForInactiveSubIds(); - - // then disable sms prompt (sms app will default to inserted sim) - PhoneFactory.setSMSPromptEnabled(false); // can't prompt for 1 sim - - // finally, disable data if this single sim isn't our our selected data sim previously - int realStoredDataSub = Settings.Global.getInt(mContext.getContentResolver(), - Settings.Global.MULTI_SIM_DATA_CALL_SUBSCRIPTION, - SubscriptionManager.INVALID_SUBSCRIPTION_ID); - - if (realStoredDataSub != SubscriptionManager.INVALID_SUBSCRIPTION_ID && - realStoredDataSub != SubscriptionManager.getDefaultDataSubscriptionId()) { - logd("switching data off; real stored sub: " + realStoredDataSub - + ", and we think the default sub id is now: " - + SubscriptionManager.getDefaultDataSubscriptionId()); - PhoneFactory.getDefaultPhone().setDataEnabled(false); - } - } else if (insertedSimCount > 1) { - // we now have multiple sims, maybe enable the SMS prompt if no valid - // sub is ready to handle SMS - PhoneFactory.setSMSPromptEnabled(!SubscriptionManager.isValidSubscriptionId( - SubscriptionManager.getDefaultSmsSubscriptionId())); - } - setPreviousUpdateSimCount(insertedSimCount); - } - // Ensure the modems are mapped correctly - // will not override MSIM settings with 1 sim in the device. - mSubscriptionManager.setDefaultDataSubId(SubscriptionManager.getDefaultDataSubscriptionId()); - SubscriptionController.getInstance().notifySubscriptionInfoChanged(); - } else if (update && !mIsShutdown) { - // we have locked sims, need to update so we can unlock them - SubscriptionController.getInstance().notifySubscriptionInfoChanged(); - } - logd("updateSubscriptionInfoByIccId:- SsubscriptionInfo update complete"); - } - - private int previousUpdateSimCount() { - return PreferenceManager.getDefaultSharedPreferences(mContext) - .getInt(PREF_LAST_SEEN_SIM_COUNT, 0); - } + // Ensure the modems are mapped correctly + mSubscriptionManager.setDefaultDataSubId( + mSubscriptionManager.getDefaultDataSubscriptionId()); - private void setPreviousUpdateSimCount(int simCount) { - PreferenceManager.getDefaultSharedPreferences(mContext) - .edit() - .putInt(PREF_LAST_SEEN_SIM_COUNT, simCount) - .apply(); - } - - protected int getInsertedSimCount() { - if (!isAllIccIdQueryDone()) { - return 0; - } - return mCurrentSimCount; + SubscriptionController.getInstance().notifySubscriptionInfoChanged(); + logd("updateSubscriptionInfoByIccId:- SsubscriptionInfo update complete"); } private boolean isNewSim(String iccId, String[] oldIccId) { diff --git a/src/java/com/android/internal/telephony/UiccSmsController.java b/src/java/com/android/internal/telephony/UiccSmsController.java index 0afb686b1..740a4d927 100755 --- a/src/java/com/android/internal/telephony/UiccSmsController.java +++ b/src/java/com/android/internal/telephony/UiccSmsController.java @@ -292,13 +292,6 @@ public class UiccSmsController extends ISms.Stub { @Override public boolean isSmsSimPickActivityNeeded(int subId) { final Context context = ActivityThread.currentApplication().getApplicationContext(); - boolean canCurrentAppHandleAlwaysAsk = SmsApplication.canSmsAppHandleAlwaysAsk(context); - if (!isSMSPromptEnabled() && canCurrentAppHandleAlwaysAsk) { - Rlog.d(LOG_TAG, "isSmsSimPickActivityNeeded: false, sms prompt disabled."); - // user knows best - return false; - } - TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); List subInfoList; @@ -322,17 +315,11 @@ public class UiccSmsController extends ISms.Stub { // If reached here and multiple SIMs and subs present, sms sim pick activity is needed if (subInfoLength > 0 && telephonyManager.getSimCount() > 1) { - final SubscriptionInfoUpdater subscriptionInfoUpdater - = PhoneFactory.getSubscriptionInfoUpdater(); - if (subscriptionInfoUpdater != null) { - // use the *real* inserted sim count if we can - return subscriptionInfoUpdater.getInsertedSimCount() > 1; - } return true; } } - return !canCurrentAppHandleAlwaysAsk; + return false; } @Override -- cgit v1.2.3