Additional changes to SubscriptionManager API as per API council.
bug: 17575308
Change-Id: Idd98aa46c15a9219ccf28091c62602ac8bf16c62
diff --git a/src/com/android/phone/MobileNetworkSettings.java b/src/com/android/phone/MobileNetworkSettings.java
index afeebd8..6cf0d7e 100644
--- a/src/com/android/phone/MobileNetworkSettings.java
+++ b/src/com/android/phone/MobileNetworkSettings.java
@@ -102,6 +102,8 @@
private static final String UP_ACTIVITY_CLASS =
"com.android.settings.Settings$WirelessSettingsActivity";
+ private SubscriptionManager mSubscriptionManager;
+
//UI objects
private ListPreference mButtonPreferredNetworkMode;
private ListPreference mButtonEnabledNetworks;
@@ -110,7 +112,7 @@
private Preference mLteDataServicePref;
private static final String iface = "rmnet0"; //TODO: this will go away
- private List<SubscriptionInfo> mSelectableSubInfos = null;
+ private List<SubscriptionInfo> mSelectableSubInfos = new ArrayList<SubscriptionInfo>();
private UserManager mUm;
private Phone mPhone;
@@ -274,9 +276,12 @@
super.onCreate(icicle);
final Context context = getApplicationContext();
- mSelectableSubInfos = new ArrayList<SubscriptionInfo>();
+ mPhone = PhoneGlobals.getPhone();
+ mHandler = new MyHandler();
+ mUm = (UserManager) getSystemService(Context.USER_SERVICE);
final TelephonyManager tm =
(TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
+ mSubscriptionManager = SubscriptionManager.from(this);
for (int i = 0; i < tm.getSimCount(); i++) {
SubscriptionInfo sir = findRecordBySlotId(i);
@@ -285,10 +290,6 @@
}
}
- mPhone = PhoneGlobals.getPhone();
- mHandler = new MyHandler();
- mUm = (UserManager) getSystemService(Context.USER_SERVICE);
-
if (mUm.hasUserRestriction(UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
mUnavailable = true;
setContentView(R.layout.telephony_disallowed_preference_screen);
@@ -1089,16 +1090,18 @@
* finds a record with slotId.
* Since the number of SIMs are few, an array is fine.
*/
- public static SubscriptionInfo findRecordBySlotId(final int slotId) {
+ public SubscriptionInfo findRecordBySlotId(final int slotId) {
final List<SubscriptionInfo> subInfoList =
- SubscriptionManager.getActiveSubscriptionInfoList();
- final int subInfoLength = subInfoList.size();
+ mSubscriptionManager.getActiveSubscriptionInfoList();
+ if (subInfoList != null) {
+ final int subInfoLength = subInfoList.size();
- for (int i = 0; i < subInfoLength; ++i) {
- final SubscriptionInfo sir = subInfoList.get(i);
- if (sir.getSimSlotIndex() == slotId) {
- //Right now we take the first subscription on a SIM.
- return sir;
+ for (int i = 0; i < subInfoLength; ++i) {
+ final SubscriptionInfo sir = subInfoList.get(i);
+ if (sir.getSimSlotIndex() == slotId) {
+ //Right now we take the first subscription on a SIM.
+ return sir;
+ }
}
}
diff --git a/src/com/android/phone/PhoneInterfaceManager.java b/src/com/android/phone/PhoneInterfaceManager.java
index 1ca4a8c..dc6bc1b 100644
--- a/src/com/android/phone/PhoneInterfaceManager.java
+++ b/src/com/android/phone/PhoneInterfaceManager.java
@@ -133,13 +133,14 @@
/** The singleton instance. */
private static PhoneInterfaceManager sInstance;
- PhoneGlobals mApp;
- Phone mPhone;
- CallManager mCM;
- AppOpsManager mAppOps;
- MainThreadHandler mMainThreadHandler;
+ private PhoneGlobals mApp;
+ private Phone mPhone;
+ private CallManager mCM;
+ private AppOpsManager mAppOps;
+ private MainThreadHandler mMainThreadHandler;
+ private SubscriptionManager mSubscriptionManager;
+ private SharedPreferences mTelephonySharedPreferences;
- SharedPreferences mTelephonySharedPreferences;
private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
private static final String PREF_ENABLE_VIDEO_CALLING = "enable_video_calling";
@@ -726,6 +727,8 @@
mMainThreadHandler = new MainThreadHandler();
mTelephonySharedPreferences =
PreferenceManager.getDefaultSharedPreferences(mPhone.getContext());
+ mSubscriptionManager = SubscriptionManager.from(app);
+
publish();
}
@@ -790,11 +793,13 @@
}
boolean isValid = false;
- List<SubscriptionInfo> slist = SubscriptionManager.getActiveSubscriptionInfoList();
- for (SubscriptionInfo subInfoRecord : slist) {
- if (subInfoRecord.getSubscriptionId() == subId) {
- isValid = true;
- break;
+ List<SubscriptionInfo> slist = mSubscriptionManager.getActiveSubscriptionInfoList();
+ if (slist != null) {
+ for (SubscriptionInfo subInfoRecord : slist) {
+ if (subInfoRecord.getSubscriptionId() == subId) {
+ isValid = true;
+ break;
+ }
}
}
if (isValid == false) {
diff --git a/src/com/android/phone/settings/PhoneAccountSettingsFragment.java b/src/com/android/phone/settings/PhoneAccountSettingsFragment.java
index 784be0f..ce517ee 100644
--- a/src/com/android/phone/settings/PhoneAccountSettingsFragment.java
+++ b/src/com/android/phone/settings/PhoneAccountSettingsFragment.java
@@ -50,6 +50,7 @@
private String LOG_TAG = PhoneAccountSettingsFragment.class.getSimpleName();
private TelecomManager mTelecomManager;
+ private SubscriptionManager mSubscriptionManager;
private PreferenceCategory mAccountList;
@@ -66,6 +67,7 @@
super.onCreate(icicle);
mTelecomManager = TelecomManager.from(getActivity());
+ mSubscriptionManager = SubscriptionManager.from(getActivity());
}
@Override
@@ -301,7 +303,11 @@
}
private void initAccountList() {
- for (SubscriptionInfo subscription : SubscriptionManager.getActiveSubscriptionInfoList()) {
+ List<SubscriptionInfo> sil = mSubscriptionManager.getActiveSubscriptionInfoList();
+ if (sil == null) {
+ return;
+ }
+ for (SubscriptionInfo subscription : sil) {
CharSequence label = subscription.getDisplayName();
Intent intent = new Intent(TelecomManager.ACTION_SHOW_CALL_SETTINGS);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
diff --git a/src/com/android/services/telephony/TelecomAccountRegistry.java b/src/com/android/services/telephony/TelecomAccountRegistry.java
index 3523288..c105fff 100644
--- a/src/com/android/services/telephony/TelecomAccountRegistry.java
+++ b/src/com/android/services/telephony/TelecomAccountRegistry.java
@@ -27,8 +27,8 @@
import android.telephony.PhoneStateListener;
import android.telephony.ServiceState;
import android.telephony.SubscriptionInfo;
-import android.telephony.SubscriptionListener;
import android.telephony.SubscriptionManager;
+import android.telephony.SubscriptionManager.OnSubscriptionsChangedListener;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
@@ -82,7 +82,7 @@
// Populate the phone account data.
int subId = mPhone.getSubId();
int color = PhoneAccount.NO_COLOR;
- int slotId = SubscriptionManager.INVALID_SLOT_ID;
+ int slotId = SubscriptionManager.INVALID_SIM_SLOT_INDEX;
String line1Number = mTelephonyManager.getLine1NumberForSubscriber(subId);
if (line1Number == null) {
line1Number = "";
@@ -108,7 +108,8 @@
CharSequence subDisplayName = null;
// We can only get the real slotId from the SubInfoRecord, we can't calculate the
// slotId from the subId or the phoneId in all instances.
- SubscriptionInfo record = SubscriptionManager.getSubscriptionInfoForSubscriber(subId);
+ SubscriptionInfo record =
+ mSubscriptionManager.getActiveSubscriptionInfo(subId);
if (record != null) {
subDisplayName = record.getDisplayName();
slotId = record.getSimSlotIndex();
@@ -170,9 +171,10 @@
}
}
- private final SubscriptionListener mSubscriptionListener = new SubscriptionListener() {
+ private OnSubscriptionsChangedListener mOnSubscriptionsChangedListener =
+ new OnSubscriptionsChangedListener() {
@Override
- public void onSubscriptionInfoChanged() {
+ public void onSubscriptionsChanged() {
// Any time the SubscriptionInfo changes...rerun the setup
tearDownAccounts();
setupAccounts();
@@ -195,6 +197,7 @@
private final Context mContext;
private final TelecomManager mTelecomManager;
private final TelephonyManager mTelephonyManager;
+ private final SubscriptionManager mSubscriptionManager;
private List<AccountEntry> mAccounts = new LinkedList<AccountEntry>();
private int mServiceState = ServiceState.STATE_POWER_OFF;
@@ -202,6 +205,7 @@
mContext = context;
mTelecomManager = TelecomManager.from(context);
mTelephonyManager = TelephonyManager.from(context);
+ mSubscriptionManager = SubscriptionManager.from(context);
}
static synchronized final TelecomAccountRegistry getInstance(Context context) {
@@ -216,13 +220,14 @@
*/
void setupOnBoot() {
// TODO: When this object "finishes" we should unregister by invoking
- // SubscriptionManager.unregister(mContext, mSubscriptionListener);
+ // SubscriptionManager.getInstance(mContext).unregister(mOnSubscriptionsChangedListener);
// This is not strictly necessary because it will be unregistered if the
// notification fails but it is good form.
- // Register for SubscriptionInfo list changes
- SubscriptionManager.register(mContext, mSubscriptionListener,
- SubscriptionListener.LISTEN_SUBSCRIPTION_INFO_LIST_CHANGED);
+ // Register for SubscriptionInfo list changes which is guaranteed
+ // to invoke onSubscriptionsChanged the first time.
+ SubscriptionManager.from(mContext).registerOnSubscriptionsChangedListener(
+ mOnSubscriptionsChangedListener);
// We also need to listen for changes to the service state (e.g. emergency -> in service)
// because this could signal a removal or addition of a SIM in a single SIM phone.