Make RadioInfo settings menu work for mSIM

Just add a spinner to the top of the screen which lets you select the
phoneIndex. Upating this value updates the mTelephonyManager
mImsManager, and mPhoneStateListener to use the selected phoneIndex and
the subscription associated with it.

Also adds fields for current subId and default data sim subId.

Test: manual test (on single sim)
Fixes: 128033739
Change-Id: Id075e3bffe20523d8ceeb8f2e4320f995abdab55
This commit is contained in:
Jordan Liu
2019-04-02 12:13:31 -07:00
parent 76c3a0c90a
commit 77c522c7b1
3 changed files with 148 additions and 25 deletions

View File

@@ -25,6 +25,19 @@
android:descendantFocusability="beforeDescendants" android:descendantFocusability="beforeDescendants"
android:focusableInTouchMode="true"> android:focusableInTouchMode="true">
<!-- Phone index -->
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/phone_index_label"
style="@style/info_label"
/>
<Spinner android:id="@+id/phoneIndex"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<!-- IMEI --> <!-- IMEI -->
<LinearLayout style="@style/entry_layout"> <LinearLayout style="@style/entry_layout">
<TextView android:text="@string/radio_info_imei_label" style="@style/info_label" /> <TextView android:text="@string/radio_info_imei_label" style="@style/info_label" />
@@ -37,6 +50,18 @@
<TextView android:id="@+id/number" style="@style/info_value" /> <TextView android:id="@+id/number" style="@style/info_value" />
</LinearLayout> </LinearLayout>
<!-- Subscription ID -->
<LinearLayout style="@style/entry_layout">
<TextView android:text="@string/radio_info_subid" style="@style/info_label" />
<TextView android:id="@+id/subid" style="@style/info_value" />
</LinearLayout>
<!-- Default data subscription -->
<LinearLayout style="@style/entry_layout">
<TextView android:text="@string/radio_info_dds" style="@style/info_label" />
<TextView android:id="@+id/dds" style="@style/info_value" />
</LinearLayout>
<!-- IMSI --> <!-- IMSI -->
<LinearLayout style="@style/entry_layout"> <LinearLayout style="@style/entry_layout">
<TextView android:text="@string/radio_info_imsi_label" style="@style/info_label" /> <TextView android:text="@string/radio_info_imsi_label" style="@style/info_label" />

View File

@@ -484,6 +484,10 @@
<!-- HTTP proxy settings. Title for Proxy-Auto Config URL. [CHAR LIMIT=25] --> <!-- HTTP proxy settings. Title for Proxy-Auto Config URL. [CHAR LIMIT=25] -->
<string name="proxy_url_title">"PAC URL: "</string> <string name="proxy_url_title">"PAC URL: "</string>
<!-- Radio Info screen. Label for a status item. Used for diagnostic info screens, precise translation isn't needed -->
<string name="radio_info_subid">Current subId:</string>
<!-- Radio Info screen. Label for a status item. Used for diagnostic info screens, precise translation isn't needed -->
<string name="radio_info_dds">SubId of default data SIM:</string>
<!-- Radio Info screen. Label for a status item. Used for diagnostic info screens, precise translation isn't needed --> <!-- Radio Info screen. Label for a status item. Used for diagnostic info screens, precise translation isn't needed -->
<string name="radio_info_dl_kbps">DL Bandwidth (kbps):</string> <string name="radio_info_dl_kbps">DL Bandwidth (kbps):</string>
<!-- Radio Info screen. Label for a status item. Used for diagnostic info screens, precise translation isn't needed --> <!-- Radio Info screen. Label for a status item. Used for diagnostic info screens, precise translation isn't needed -->
@@ -531,6 +535,8 @@
<!-- Radio Info screen. Label for a status item. Used for diagnostic info screens, precise translation isn't needed --> <!-- Radio Info screen. Label for a status item. Used for diagnostic info screens, precise translation isn't needed -->
<string name="radio_info_data_network_type_label">Data Network Type:</string> <string name="radio_info_data_network_type_label">Data Network Type:</string>
<!-- Radio Info screen. Label for a status item. Used for diagnostic info screens, precise translation isn't needed --> <!-- Radio Info screen. Label for a status item. Used for diagnostic info screens, precise translation isn't needed -->
<string name="phone_index_label">Select phone index</string>
<!-- Radio Info screen. Label for a status item. Used for diagnostic info screens, precise translation isn't needed -->
<string name="radio_info_set_perferred_label">Set Preferred Network Type:</string> <string name="radio_info_set_perferred_label">Set Preferred Network Type:</string>
<!-- Radio Info screen. Label for a status item. Used for diagnostic info screens, precise translation isn't needed --> <!-- Radio Info screen. Label for a status item. Used for diagnostic info screens, precise translation isn't needed -->
<string name="radio_info_ping_hostname_v4">Ping Hostname(www.google.com) IPv4:</string> <string name="radio_info_ping_hostname_v4">Ping Hostname(www.google.com) IPv4:</string>

View File

@@ -127,6 +127,7 @@ public class RadioInfo extends Activity {
"Unknown" "Unknown"
}; };
private static String[] mPhoneIndexLabels;
private static final int CELL_INFO_LIST_RATE_DISABLED = Integer.MAX_VALUE; private static final int CELL_INFO_LIST_RATE_DISABLED = Integer.MAX_VALUE;
private static final int CELL_INFO_LIST_RATE_MAX = 0; private static final int CELL_INFO_LIST_RATE_MAX = 0;
@@ -162,7 +163,7 @@ public class RadioInfo extends Activity {
60000 60000
}; };
private void log(String s) { private static void log(String s) {
Log.d(TAG, s); Log.d(TAG, s);
} }
@@ -173,15 +174,17 @@ public class RadioInfo extends Activity {
private static final int EVENT_QUERY_SMSC_DONE = 1005; private static final int EVENT_QUERY_SMSC_DONE = 1005;
private static final int EVENT_UPDATE_SMSC_DONE = 1006; private static final int EVENT_UPDATE_SMSC_DONE = 1006;
private static final int MENU_ITEM_SELECT_BAND = 0; private static final int MENU_ITEM_SELECT_BAND = 0;
private static final int MENU_ITEM_VIEW_ADN = 1; private static final int MENU_ITEM_VIEW_ADN = 1;
private static final int MENU_ITEM_VIEW_FDN = 2; private static final int MENU_ITEM_VIEW_FDN = 2;
private static final int MENU_ITEM_VIEW_SDN = 3; private static final int MENU_ITEM_VIEW_SDN = 3;
private static final int MENU_ITEM_GET_IMS_STATUS = 4; private static final int MENU_ITEM_GET_IMS_STATUS = 4;
private static final int MENU_ITEM_TOGGLE_DATA = 5; private static final int MENU_ITEM_TOGGLE_DATA = 5;
private TextView mDeviceId; //DeviceId is the IMEI in GSM and the MEID in CDMA private TextView mDeviceId; //DeviceId is the IMEI in GSM and the MEID in CDMA
private TextView number; private TextView number;
private TextView mSubscriptionId;
private TextView mDds;
private TextView mSubscriberId; private TextView mSubscriberId;
private TextView callState; private TextView callState;
private TextView operatorName; private TextView operatorName;
@@ -221,6 +224,7 @@ public class RadioInfo extends Activity {
private Switch cbrsDataSwitch; private Switch cbrsDataSwitch;
private Switch dsdsSwitch; private Switch dsdsSwitch;
private Spinner preferredNetworkType; private Spinner preferredNetworkType;
private Spinner mSelectPhoneIndex;
private Spinner cellInfoRefreshRateSpinner; private Spinner cellInfoRefreshRateSpinner;
private ConnectivityManager mConnectivityManager; private ConnectivityManager mConnectivityManager;
@@ -239,6 +243,7 @@ public class RadioInfo extends Activity {
private int mPreferredNetworkTypeResult; private int mPreferredNetworkTypeResult;
private int mCellInfoRefreshRateIndex; private int mCellInfoRefreshRateIndex;
private int mSelectedPhoneIndex;
private final NetworkRequest mDefaultNetworkRequest = new NetworkRequest.Builder() private final NetworkRequest mDefaultNetworkRequest = new NetworkRequest.Builder()
.addTransportType(NetworkCapabilities.TRANSPORT_CELLULAR) .addTransportType(NetworkCapabilities.TRANSPORT_CELLULAR)
@@ -348,6 +353,21 @@ public class RadioInfo extends Activity {
preferredNetworkType.setSelection(mPreferredNetworkTypeResult, true); preferredNetworkType.setSelection(mPreferredNetworkTypeResult, true);
} }
private void updatePhoneIndex(int phoneIndex, int subId) {
// unregister listeners on the old subId
mTelephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_NONE);
mTelephonyManager.setCellInfoListRate(CELL_INFO_LIST_RATE_DISABLED);
// update the subId
mTelephonyManager = mTelephonyManager.createForSubscriptionId(subId);
mImsManager = ImsManager.getInstance(getApplicationContext(), phoneIndex);
// update the phoneId
phone = PhoneFactory.getPhone(phoneIndex);
updateAllFields();
}
private Handler mHandler = new Handler() { private Handler mHandler = new Handler() {
@Override @Override
public void handleMessage(Message msg) { public void handleMessage(Message msg) {
@@ -408,13 +428,15 @@ public class RadioInfo extends Activity {
mConnectivityManager = (ConnectivityManager)getSystemService(CONNECTIVITY_SERVICE); mConnectivityManager = (ConnectivityManager)getSystemService(CONNECTIVITY_SERVICE);
phone = PhoneFactory.getDefaultPhone(); phone = PhoneFactory.getDefaultPhone();
//TODO: Need to update this if the default phoneId changes?
// Better to have an instance per phone?
mImsManager = ImsManager.getInstance(getApplicationContext(), mImsManager = ImsManager.getInstance(getApplicationContext(),
SubscriptionManager.getDefaultVoicePhoneId()); SubscriptionManager.getDefaultVoicePhoneId());
mPhoneIndexLabels = getPhoneIndexLabels(mTelephonyManager);
mDeviceId = (TextView) findViewById(R.id.imei); mDeviceId = (TextView) findViewById(R.id.imei);
number = (TextView) findViewById(R.id.number); number = (TextView) findViewById(R.id.number);
mSubscriptionId = (TextView) findViewById(R.id.subid);
mDds = (TextView) findViewById(R.id.dds);
mSubscriberId = (TextView) findViewById(R.id.imsi); mSubscriberId = (TextView) findViewById(R.id.imsi);
callState = (TextView) findViewById(R.id.call); callState = (TextView) findViewById(R.id.call);
operatorName = (TextView) findViewById(R.id.operator); operatorName = (TextView) findViewById(R.id.operator);
@@ -441,10 +463,17 @@ public class RadioInfo extends Activity {
mPhyChanConfig = (TextView) findViewById(R.id.phy_chan_config); mPhyChanConfig = (TextView) findViewById(R.id.phy_chan_config);
preferredNetworkType = (Spinner) findViewById(R.id.preferredNetworkType); preferredNetworkType = (Spinner) findViewById(R.id.preferredNetworkType);
ArrayAdapter<String> adapter = new ArrayAdapter<String> (this, ArrayAdapter<String> preferredNetworkTypeAdapter = new ArrayAdapter<String> (this,
android.R.layout.simple_spinner_item, mPreferredNetworkLabels); android.R.layout.simple_spinner_item, mPreferredNetworkLabels);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); preferredNetworkTypeAdapter
preferredNetworkType.setAdapter(adapter); .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
preferredNetworkType.setAdapter(preferredNetworkTypeAdapter);
mSelectPhoneIndex = (Spinner) findViewById(R.id.phoneIndex);
ArrayAdapter<String> phoneIndexAdapter = new ArrayAdapter<String> (this,
android.R.layout.simple_spinner_item, mPhoneIndexLabels);
phoneIndexAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
mSelectPhoneIndex.setAdapter(phoneIndexAdapter);
cellInfoRefreshRateSpinner = (Spinner) findViewById(R.id.cell_info_rate_select); cellInfoRefreshRateSpinner = (Spinner) findViewById(R.id.cell_info_rate_select);
ArrayAdapter<String> cellInfoAdapter = new ArrayAdapter<String>(this, ArrayAdapter<String> cellInfoAdapter = new ArrayAdapter<String>(this,
@@ -508,6 +537,7 @@ public class RadioInfo extends Activity {
mCellInfoRefreshRateIndex = 0; //disabled mCellInfoRefreshRateIndex = 0; //disabled
mPreferredNetworkTypeResult = mPreferredNetworkLabels.length - 1; //Unknown mPreferredNetworkTypeResult = mPreferredNetworkLabels.length - 1; //Unknown
mSelectedPhoneIndex = 0; //phone 0
//FIXME: Replace with TelephonyManager call //FIXME: Replace with TelephonyManager call
phone.getPreferredNetworkType( phone.getPreferredNetworkType(
@@ -522,6 +552,10 @@ public class RadioInfo extends Activity {
log("Started onResume"); log("Started onResume");
updateAllFields();
}
private void updateAllFields() {
updateMessageWaiting(); updateMessageWaiting();
updateCallRedirect(); updateCallRedirect();
updateDataState(); updateDataState();
@@ -534,6 +568,7 @@ public class RadioInfo extends Activity {
updateLocation(mCellLocationResult); updateLocation(mCellLocationResult);
updateCellInfo(mCellInfoResult); updateCellInfo(mCellInfoResult);
updateSubscriptionIds();
mPingHostnameV4.setText(mPingHostnameResultV4); mPingHostnameV4.setText(mPingHostnameResultV4);
mPingHostnameV6.setText(mPingHostnameResultV6); mPingHostnameV6.setText(mPingHostnameResultV6);
@@ -547,6 +582,10 @@ public class RadioInfo extends Activity {
preferredNetworkType.setSelection(mPreferredNetworkTypeResult, true); preferredNetworkType.setSelection(mPreferredNetworkTypeResult, true);
preferredNetworkType.setOnItemSelectedListener(mPreferredNetworkHandler); preferredNetworkType.setOnItemSelectedListener(mPreferredNetworkHandler);
// set phone index
mSelectPhoneIndex.setSelection(mSelectedPhoneIndex, true);
mSelectPhoneIndex.setOnItemSelectedListener(mSelectPhoneIndexHandler);
radioPowerOnSwitch.setOnCheckedChangeListener(mRadioPowerOnChangeListener); radioPowerOnSwitch.setOnCheckedChangeListener(mRadioPowerOnChangeListener);
imsVolteProvisionedSwitch.setOnCheckedChangeListener(mImsVolteCheckedChangeListener); imsVolteProvisionedSwitch.setOnCheckedChangeListener(mImsVolteCheckedChangeListener);
imsVtProvisionedSwitch.setOnCheckedChangeListener(mImsVtCheckedChangeListener); imsVtProvisionedSwitch.setOnCheckedChangeListener(mImsVtCheckedChangeListener);
@@ -558,19 +597,7 @@ public class RadioInfo extends Activity {
cbrsDataSwitch.setOnCheckedChangeListener(mCbrsDataSwitchChangeListener); cbrsDataSwitch.setOnCheckedChangeListener(mCbrsDataSwitchChangeListener);
} }
mTelephonyManager.listen(mPhoneStateListener, registerPhoneStateListener();
PhoneStateListener.LISTEN_CALL_STATE
//b/27803938 - RadioInfo currently cannot read PRECISE_CALL_STATE
// | PhoneStateListener.LISTEN_PRECISE_CALL_STATE
| PhoneStateListener.LISTEN_DATA_CONNECTION_STATE
| PhoneStateListener.LISTEN_DATA_ACTIVITY
| PhoneStateListener.LISTEN_CELL_LOCATION
| PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR
| PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR
| PhoneStateListener.LISTEN_CELL_INFO
| PhoneStateListener.LISTEN_SERVICE_STATE
| PhoneStateListener.LISTEN_SIGNAL_STRENGTHS
| PhoneStateListener.LISTEN_PHYSICAL_CHANNEL_CONFIGURATION);
mConnectivityManager.registerNetworkCallback( mConnectivityManager.registerNetworkCallback(
mDefaultNetworkRequest, mNetworkCallback, mHandler); mDefaultNetworkRequest, mNetworkCallback, mHandler);
@@ -606,6 +633,8 @@ public class RadioInfo extends Activity {
mPreferredNetworkTypeResult = b.getInt("mPreferredNetworkTypeResult", mPreferredNetworkTypeResult = b.getInt("mPreferredNetworkTypeResult",
mPreferredNetworkLabels.length - 1); mPreferredNetworkLabels.length - 1);
mSelectedPhoneIndex = b.getInt("mSelectedPhoneIndex", 0);
mCellInfoRefreshRateIndex = b.getInt("mCellInfoRefreshRateIndex", 0); mCellInfoRefreshRateIndex = b.getInt("mCellInfoRefreshRateIndex", 0);
} }
@@ -616,6 +645,7 @@ public class RadioInfo extends Activity {
outState.putString("mHttpClientTestResult", mHttpClientTestResult); outState.putString("mHttpClientTestResult", mHttpClientTestResult);
outState.putInt("mPreferredNetworkTypeResult", mPreferredNetworkTypeResult); outState.putInt("mPreferredNetworkTypeResult", mPreferredNetworkTypeResult);
outState.putInt("mSelectedPhoneIndex", mSelectedPhoneIndex);
outState.putInt("mCellInfoRefreshRateIndex", mCellInfoRefreshRateIndex); outState.putInt("mCellInfoRefreshRateIndex", mCellInfoRefreshRateIndex);
} }
@@ -661,6 +691,34 @@ public class RadioInfo extends Activity {
return true; return true;
} }
// returns array of string labels for each phone index. The array index is equal to the phone
// index.
private static String[] getPhoneIndexLabels(TelephonyManager tm) {
int phones = tm.getPhoneCount();
String[] labels = new String[phones];
for (int i = 0; i < phones; i++) {
labels[i] = "Phone " + i;
}
return labels;
}
// register mPhoneStateListener for relevant fields using the current TelephonyManager
private void registerPhoneStateListener() {
mTelephonyManager.listen(mPhoneStateListener,
PhoneStateListener.LISTEN_CALL_STATE
//b/27803938 - RadioInfo currently cannot read PRECISE_CALL_STATE
// | PhoneStateListener.LISTEN_PRECISE_CALL_STATE
| PhoneStateListener.LISTEN_DATA_CONNECTION_STATE
| PhoneStateListener.LISTEN_DATA_ACTIVITY
| PhoneStateListener.LISTEN_CELL_LOCATION
| PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR
| PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR
| PhoneStateListener.LISTEN_CELL_INFO
| PhoneStateListener.LISTEN_SERVICE_STATE
| PhoneStateListener.LISTEN_SIGNAL_STRENGTHS
| PhoneStateListener.LISTEN_PHYSICAL_CHANNEL_CONFIGURATION);
}
private void updateDnsCheckState() { private void updateDnsCheckState() {
//FIXME: Replace with a TelephonyManager call //FIXME: Replace with a TelephonyManager call
dnsCheckState.setText(phone.isDnsCheckDisabled() ? dnsCheckState.setText(phone.isDnsCheckDisabled() ?
@@ -882,6 +940,11 @@ public class RadioInfo extends Activity {
mCellInfo.setText(buildCellInfoString(arrayCi)); mCellInfo.setText(buildCellInfoString(arrayCi));
} }
private final void updateSubscriptionIds() {
mSubscriptionId.setText(Integer.toString(phone.getSubId()));
mDds.setText(Integer.toString(SubscriptionManager.getDefaultDataSubscriptionId()));
}
private final void private final void
updateMessageWaiting() { updateMessageWaiting() {
mMwi.setText(String.valueOf(mMwiValue)); mMwi.setText(String.valueOf(mMwiValue));
@@ -1502,6 +1565,35 @@ public class RadioInfo extends Activity {
} }
}; };
AdapterView.OnItemSelectedListener mSelectPhoneIndexHandler =
new AdapterView.OnItemSelectedListener() {
public void onItemSelected(AdapterView parent, View v, int pos, long id) {
if (pos >= 0 && pos <= mPhoneIndexLabels.length - 1) {
// the array position is equal to the phone index
int phoneIndex = pos;
Phone[] phones = PhoneFactory.getPhones();
if (phones == null || phones.length <= phoneIndex) {
log("phoneIndex " + phoneIndex + " is invalid");
return;
}
log("switching to phone " + phoneIndex);
// getSubId says it takes a slotIndex, but it actually takes a phone index
int[] subIds = SubscriptionManager.getSubId(phoneIndex);
if (subIds == null || subIds.length < 1) {
log("no subscription found for phoneIndex " + phoneIndex);
return;
}
mSelectedPhoneIndex = phoneIndex;
updatePhoneIndex(phoneIndex, subIds[0]);
}
}
public void onNothingSelected(AdapterView parent) {
}
};
AdapterView.OnItemSelectedListener mCellInfoRefreshRateHandler = AdapterView.OnItemSelectedListener mCellInfoRefreshRateHandler =
new AdapterView.OnItemSelectedListener() { new AdapterView.OnItemSelectedListener() {