Refactor Cdma preference in ECM
When phone is in ECM mode and Cdma preference is clicked, it should first pop up ECM exit dialog. If user click yes, then it should launch normal dialog. This CL create a Cdma preference to stop launch normal dialog when in ECM mode. Bug: 114749736 Test: RunSettingsRoboTests Change-Id: Iba887d9fc49770b21cf0421ecc0120d63da43ef9
This commit is contained in:
@@ -99,7 +99,7 @@
|
|||||||
|
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
|
|
||||||
<ListPreference
|
<com.android.settings.network.telephony.cdma.CdmaListPreference
|
||||||
android:key="cdma_system_select_key"
|
android:key="cdma_system_select_key"
|
||||||
android:title="@string/cdma_system_select_title"
|
android:title="@string/cdma_system_select_title"
|
||||||
android:summary="@string/cdma_system_select_summary"
|
android:summary="@string/cdma_system_select_summary"
|
||||||
@@ -108,7 +108,7 @@
|
|||||||
android:dialogTitle="@string/cdma_system_select_dialogtitle"
|
android:dialogTitle="@string/cdma_system_select_dialogtitle"
|
||||||
settings:controller="com.android.settings.network.telephony.cdma.CdmaSystemSelectPreferenceController"/>
|
settings:controller="com.android.settings.network.telephony.cdma.CdmaSystemSelectPreferenceController"/>
|
||||||
|
|
||||||
<ListPreference
|
<com.android.settings.network.telephony.cdma.CdmaListPreference
|
||||||
android:key="cdma_subscription_key"
|
android:key="cdma_subscription_key"
|
||||||
android:title="@string/cdma_subscription_title"
|
android:title="@string/cdma_subscription_title"
|
||||||
android:summary="@string/cdma_subscription_summary"
|
android:summary="@string/cdma_subscription_summary"
|
||||||
|
@@ -19,6 +19,7 @@ package com.android.settings.network.telephony;
|
|||||||
import static android.provider.Telephony.Carriers.ENFORCE_MANAGED_URI;
|
import static android.provider.Telephony.Carriers.ENFORCE_MANAGED_URI;
|
||||||
|
|
||||||
import android.app.ActionBar;
|
import android.app.ActionBar;
|
||||||
|
import android.app.Activity;
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
@@ -41,6 +42,7 @@ import android.text.TextUtils;
|
|||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
|
|
||||||
|
import androidx.annotation.VisibleForTesting;
|
||||||
import androidx.fragment.app.FragmentActivity;
|
import androidx.fragment.app.FragmentActivity;
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
import androidx.preference.PreferenceCategory;
|
import androidx.preference.PreferenceCategory;
|
||||||
@@ -73,6 +75,8 @@ public class MobileNetworkFragment extends DashboardFragment implements
|
|||||||
private static final String LOG_TAG = "NetworkSettings";
|
private static final String LOG_TAG = "NetworkSettings";
|
||||||
private static final boolean DBG = true;
|
private static final boolean DBG = true;
|
||||||
public static final int REQUEST_CODE_EXIT_ECM = 17;
|
public static final int REQUEST_CODE_EXIT_ECM = 17;
|
||||||
|
@VisibleForTesting
|
||||||
|
static final String KEY_CLICKED_PREF = "key_clicked_pref";
|
||||||
|
|
||||||
//String keys for preference lookup
|
//String keys for preference lookup
|
||||||
private static final String BUTTON_PREFERED_NETWORK_MODE = "preferred_network_mode_key";
|
private static final String BUTTON_PREFERED_NETWORK_MODE = "preferred_network_mode_key";
|
||||||
@@ -123,9 +127,8 @@ public class MobileNetworkFragment extends DashboardFragment implements
|
|||||||
|
|
||||||
//GsmUmts options and Cdma options
|
//GsmUmts options and Cdma options
|
||||||
GsmUmtsOptions mGsmUmtsOptions;
|
GsmUmtsOptions mGsmUmtsOptions;
|
||||||
CdmaOptions mCdmaOptions;
|
|
||||||
|
|
||||||
private Preference mClickedPreference;
|
private String mClickedPrefKey;
|
||||||
private boolean mShow4GForLTE;
|
private boolean mShow4GForLTE;
|
||||||
private boolean mIsGlobalCdma;
|
private boolean mIsGlobalCdma;
|
||||||
private boolean mOnlyAutoSelectInHomeNW;
|
private boolean mOnlyAutoSelectInHomeNW;
|
||||||
@@ -148,6 +151,7 @@ public class MobileNetworkFragment extends DashboardFragment implements
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
sendMetricsEventPreferenceClicked(getPreferenceScreen(), preference);
|
sendMetricsEventPreferenceClicked(getPreferenceScreen(), preference);
|
||||||
|
final String key = preference.getKey();
|
||||||
|
|
||||||
/** TODO: Refactor and get rid of the if's using subclasses */
|
/** TODO: Refactor and get rid of the if's using subclasses */
|
||||||
if (preference.getKey().equals(BUTTON_4G_LTE_KEY)) {
|
if (preference.getKey().equals(BUTTON_4G_LTE_KEY)) {
|
||||||
@@ -155,16 +159,13 @@ public class MobileNetworkFragment extends DashboardFragment implements
|
|||||||
} else if (mGsmUmtsOptions != null &&
|
} else if (mGsmUmtsOptions != null &&
|
||||||
mGsmUmtsOptions.preferenceTreeClick(preference) == true) {
|
mGsmUmtsOptions.preferenceTreeClick(preference) == true) {
|
||||||
return true;
|
return true;
|
||||||
} else if (mCdmaOptions != null &&
|
} else if (TextUtils.equals(key, BUTTON_CDMA_SYSTEM_SELECT_KEY)
|
||||||
mCdmaOptions.preferenceTreeClick(preference) == true) {
|
|| TextUtils.equals(key, BUTTON_CDMA_SUBSCRIPTION_KEY)) {
|
||||||
if (mTelephonyManager.getEmergencyCallbackMode()) {
|
if (mTelephonyManager.getEmergencyCallbackMode()) {
|
||||||
|
|
||||||
mClickedPreference = preference;
|
|
||||||
|
|
||||||
// In ECM mode launch ECM app dialog
|
|
||||||
startActivityForResult(
|
startActivityForResult(
|
||||||
new Intent(TelephonyIntents.ACTION_SHOW_NOTICE_ECM_BLOCK_OTHERS, null),
|
new Intent(TelephonyIntents.ACTION_SHOW_NOTICE_ECM_BLOCK_OTHERS, null),
|
||||||
REQUEST_CODE_EXIT_ECM);
|
REQUEST_CODE_EXIT_ECM);
|
||||||
|
mClickedPrefKey = key;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -262,6 +263,15 @@ public class MobileNetworkFragment extends DashboardFragment implements
|
|||||||
|
|
||||||
updatePhone();
|
updatePhone();
|
||||||
Log.i(LOG_TAG, "onCreate:-");
|
Log.i(LOG_TAG, "onCreate:-");
|
||||||
|
|
||||||
|
onRestoreInstance(icicle);
|
||||||
|
}
|
||||||
|
|
||||||
|
@VisibleForTesting
|
||||||
|
void onRestoreInstance(Bundle icicle) {
|
||||||
|
if (icicle != null) {
|
||||||
|
mClickedPrefKey = icicle.getString(KEY_CLICKED_PREF);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -342,6 +352,12 @@ public class MobileNetworkFragment extends DashboardFragment implements
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSaveInstanceState(Bundle outState) {
|
||||||
|
super.onSaveInstanceState(outState);
|
||||||
|
outState.putString(KEY_CLICKED_PREF, mClickedPrefKey);
|
||||||
|
}
|
||||||
|
|
||||||
private boolean hasActiveSubscriptions() {
|
private boolean hasActiveSubscriptions() {
|
||||||
return mSubId != SubscriptionManager.INVALID_SUBSCRIPTION_ID;
|
return mSubId != SubscriptionManager.INVALID_SUBSCRIPTION_ID;
|
||||||
}
|
}
|
||||||
@@ -405,9 +421,7 @@ public class MobileNetworkFragment extends DashboardFragment implements
|
|||||||
== ServiceState.STATE_IN_SERVICE) {
|
== ServiceState.STATE_IN_SERVICE) {
|
||||||
|
|
||||||
final int phoneType = mTelephonyManager.getPhoneType();
|
final int phoneType = mTelephonyManager.getPhoneType();
|
||||||
if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) {
|
if (phoneType == PhoneConstants.PHONE_TYPE_GSM) {
|
||||||
updateCdmaOptions(this, prefSet, mSubId);
|
|
||||||
} else if (phoneType == PhoneConstants.PHONE_TYPE_GSM) {
|
|
||||||
updateGsmUmtsOptions(this, prefSet, phoneSubId);
|
updateGsmUmtsOptions(this, prefSet, phoneSubId);
|
||||||
} else {
|
} else {
|
||||||
throw new IllegalStateException("Unexpected phone type: " + phoneType);
|
throw new IllegalStateException("Unexpected phone type: " + phoneType);
|
||||||
@@ -420,7 +434,6 @@ public class MobileNetworkFragment extends DashboardFragment implements
|
|||||||
// set the listener for the mButtonPreferredNetworkMode list preference so we can issue
|
// set the listener for the mButtonPreferredNetworkMode list preference so we can issue
|
||||||
// change Preferred Network Mode.
|
// change Preferred Network Mode.
|
||||||
|
|
||||||
updateCdmaOptions(this, prefSet, mSubId);
|
|
||||||
updateGsmUmtsOptions(this, prefSet, phoneSubId);
|
updateGsmUmtsOptions(this, prefSet, phoneSubId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -513,33 +526,17 @@ public class MobileNetworkFragment extends DashboardFragment implements
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean is4gLtePrefEnabled(PersistableBundle carrierConfig) {
|
|
||||||
return (mTelephonyManager.getCallState(mSubId)
|
|
||||||
== TelephonyManager.CALL_STATE_IDLE)
|
|
||||||
&& mImsMgr != null
|
|
||||||
&& mImsMgr.isNonTtyOrTtyOnVolteEnabled()
|
|
||||||
&& carrierConfig.getBoolean(
|
|
||||||
CarrierConfigManager.KEY_EDITABLE_ENHANCED_4G_LTE_BOOL);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
switch (requestCode) {
|
switch (requestCode) {
|
||||||
case REQUEST_CODE_EXIT_ECM:
|
case REQUEST_CODE_EXIT_ECM:
|
||||||
Boolean isChoiceYes = data.getBooleanExtra(
|
if (resultCode != Activity.RESULT_CANCELED) {
|
||||||
EXTRA_EXIT_ECM_RESULT, false);
|
// If the phone exits from ECM mode, show the CDMA
|
||||||
if (isChoiceYes) {
|
final Preference preference = getPreferenceScreen()
|
||||||
// If the phone exits from ECM mode, show the CDMA Options
|
.findPreference(mClickedPrefKey);
|
||||||
final String key = mClickedPreference.getKey();
|
if (preference != null) {
|
||||||
if (TextUtils.equals(key,
|
preference.performClick();
|
||||||
mCdmaSystemSelectPreferenceController.getPreferenceKey())) {
|
|
||||||
mCdmaSystemSelectPreferenceController.showDialog();
|
|
||||||
} else if (TextUtils.equals(key,
|
|
||||||
mCdmaSubscriptionPreferenceController.getPreferenceKey())) {
|
|
||||||
mCdmaSubscriptionPreferenceController.showDialog();
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
// do nothing
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -624,14 +621,6 @@ public class MobileNetworkFragment extends DashboardFragment implements
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void controlCdmaOptions(boolean enable) {
|
|
||||||
PreferenceScreen prefSet = getPreferenceScreen();
|
|
||||||
if (prefSet == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
updateCdmaOptions(this, prefSet, mSubId);
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isSupportTdscdma() {
|
private boolean isSupportTdscdma() {
|
||||||
if (getResources().getBoolean(R.bool.config_support_tdscdma)) {
|
if (getResources().getBoolean(R.bool.config_support_tdscdma)) {
|
||||||
return true;
|
return true;
|
||||||
@@ -733,16 +722,6 @@ public class MobileNetworkFragment extends DashboardFragment implements
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateCdmaOptions(PreferenceFragmentCompat prefFragment, PreferenceScreen prefScreen,
|
|
||||||
int subId) {
|
|
||||||
// We don't want to re-create CdmaOptions if already exists. Otherwise, the preferences
|
|
||||||
// inside it will also be re-created which causes unexpected behavior. For example,
|
|
||||||
// the open dialog gets dismissed or detached after pause / resume.
|
|
||||||
if (mCdmaOptions == null) {
|
|
||||||
mCdmaOptions = new CdmaOptions(prefFragment, prefScreen, subId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Intent buildPhoneAccountConfigureIntent(
|
private static Intent buildPhoneAccountConfigureIntent(
|
||||||
Context context, PhoneAccountHandle accountHandle) {
|
Context context, PhoneAccountHandle accountHandle) {
|
||||||
Intent intent = buildConfigureIntent(
|
Intent intent = buildConfigureIntent(
|
||||||
|
@@ -82,6 +82,9 @@ public abstract class CdmaBasePreferenceController extends BasePreferenceControl
|
|||||||
public void displayPreference(PreferenceScreen screen) {
|
public void displayPreference(PreferenceScreen screen) {
|
||||||
super.displayPreference(screen);
|
super.displayPreference(screen);
|
||||||
mPreference = screen.findPreference(getPreferenceKey());
|
mPreference = screen.findPreference(getPreferenceKey());
|
||||||
|
if (mPreference instanceof CdmaListPreference) {
|
||||||
|
((CdmaListPreference) mPreference).setSubId(mSubId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -0,0 +1,46 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2018 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.android.settings.network.telephony.cdma;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.telephony.TelephonyManager;
|
||||||
|
import android.util.AttributeSet;
|
||||||
|
|
||||||
|
import androidx.preference.ListPreference;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@link ListPreference} that will launch ECM dialog when in ECM mode
|
||||||
|
*/
|
||||||
|
public class CdmaListPreference extends ListPreference {
|
||||||
|
private TelephonyManager mTelephonyManager;
|
||||||
|
|
||||||
|
public CdmaListPreference(Context context, AttributeSet attrs) {
|
||||||
|
super(context, attrs);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onClick() {
|
||||||
|
// Only show dialog when it is not in ECM
|
||||||
|
if (mTelephonyManager == null || !mTelephonyManager.getEmergencyCallbackMode()) {
|
||||||
|
super.onClick();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSubId(int subId) {
|
||||||
|
mTelephonyManager = TelephonyManager.from(getContext()).createForSubscriptionId(subId);
|
||||||
|
}
|
||||||
|
}
|
@@ -77,14 +77,6 @@ public class CdmaSubscriptionPreferenceController extends CdmaBasePreferenceCont
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void showDialog() {
|
|
||||||
final int mode = Settings.Global.getInt(mContext.getContentResolver(),
|
|
||||||
Settings.Global.CDMA_SUBSCRIPTION_MODE, Phone.PREFERRED_CDMA_SUBSCRIPTION);
|
|
||||||
|
|
||||||
mPreference.setValue(Integer.toString(mode));
|
|
||||||
mPreferenceManager.showDialog(mPreference);
|
|
||||||
}
|
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
boolean deviceSupportsNvAndRuim() {
|
boolean deviceSupportsNvAndRuim() {
|
||||||
// retrieve the list of subscription types supported by device.
|
// retrieve the list of subscription types supported by device.
|
||||||
|
@@ -62,12 +62,6 @@ public class CdmaSystemSelectPreferenceController extends CdmaBasePreferenceCont
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void showDialog() {
|
|
||||||
if (!mTelephonyManager.getEmergencyCallbackMode()) {
|
|
||||||
mPreferenceManager.showDialog(mPreference);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void resetCdmaRoamingModeToDefault() {
|
private void resetCdmaRoamingModeToDefault() {
|
||||||
final ListPreference listPreference = (ListPreference) mPreference;
|
final ListPreference listPreference = (ListPreference) mPreference;
|
||||||
//set the mButtonCdmaRoam
|
//set the mButtonCdmaRoam
|
||||||
|
@@ -0,0 +1,71 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2018 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.android.settings.network.telephony.cdma;
|
||||||
|
|
||||||
|
import static org.mockito.Mockito.doReturn;
|
||||||
|
import static org.mockito.Mockito.never;
|
||||||
|
import static org.mockito.Mockito.spy;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.telephony.TelephonyManager;
|
||||||
|
|
||||||
|
import androidx.preference.PreferenceManager;
|
||||||
|
|
||||||
|
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mockito.Mock;
|
||||||
|
import org.mockito.MockitoAnnotations;
|
||||||
|
import org.robolectric.RuntimeEnvironment;
|
||||||
|
|
||||||
|
@RunWith(SettingsRobolectricTestRunner.class)
|
||||||
|
public class CdmaListPreferenceTest {
|
||||||
|
private static final int SUB_ID = 2;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private TelephonyManager mTelephonyManager;
|
||||||
|
@Mock
|
||||||
|
private PreferenceManager mPreferenceManager;
|
||||||
|
|
||||||
|
private CdmaListPreference mPreference;
|
||||||
|
private Context mContext;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
MockitoAnnotations.initMocks(this);
|
||||||
|
|
||||||
|
mContext = spy(RuntimeEnvironment.application);
|
||||||
|
doReturn(mTelephonyManager).when(mContext).getSystemService(Context.TELEPHONY_SERVICE);
|
||||||
|
doReturn(mTelephonyManager).when(mContext).getSystemService(TelephonyManager.class);
|
||||||
|
doReturn(mTelephonyManager).when(mTelephonyManager).createForSubscriptionId(SUB_ID);
|
||||||
|
|
||||||
|
mPreference = spy(new CdmaListPreference(mContext, null));
|
||||||
|
mPreference.setSubId(SUB_ID);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void onClick_inEcm_doNothing() {
|
||||||
|
doReturn(true).when(mTelephonyManager).getEmergencyCallbackMode();
|
||||||
|
|
||||||
|
mPreference.onClick();
|
||||||
|
|
||||||
|
verify(mPreferenceManager, never()).showDialog(mPreference);
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user