Refactor EuiccPreference
Bug: 114749736 Test: RunSettingsRoboTests Change-Id: I7192e40c5ff6eb064f29517c21021a095d505d7f
This commit is contained in:
@@ -73,7 +73,8 @@
|
||||
|
||||
<Preference
|
||||
android:key="carrier_settings_euicc_key"
|
||||
android:title="@string/carrier_settings_euicc" />
|
||||
android:title="@string/carrier_settings_euicc"
|
||||
settings:controller="com.android.settings.network.telephony.EuiccPreferenceController" />
|
||||
|
||||
<PreferenceCategory
|
||||
android:key="calling"
|
||||
|
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.PersistableBundle;
|
||||
import android.provider.Settings;
|
||||
import android.telephony.CarrierConfigManager;
|
||||
import android.telephony.SubscriptionManager;
|
||||
import android.telephony.TelephonyManager;
|
||||
import android.telephony.euicc.EuiccManager;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
|
||||
/**
|
||||
* Preference controller for "Euicc preference"
|
||||
*/
|
||||
public class EuiccPreferenceController extends BasePreferenceController {
|
||||
|
||||
private TelephonyManager mTelephonyManager;
|
||||
private int mSubId;
|
||||
|
||||
public EuiccPreferenceController(Context context, String key) {
|
||||
super(context, key);
|
||||
mTelephonyManager = context.getSystemService(TelephonyManager.class);
|
||||
mSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
return MobileNetworkUtils.showEuiccSettings(mContext)
|
||||
? AVAILABLE
|
||||
: CONDITIONALLY_UNAVAILABLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getSummary() {
|
||||
return mTelephonyManager.getSimOperatorName();
|
||||
}
|
||||
|
||||
public void init(int subId) {
|
||||
mSubId = subId;
|
||||
mTelephonyManager = TelephonyManager.from(mContext).createForSubscriptionId(mSubId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handlePreferenceTreeClick(Preference preference) {
|
||||
if (TextUtils.equals(preference.getKey(), getPreferenceKey())) {
|
||||
Intent intent = new Intent(EuiccManager.ACTION_MANAGE_EMBEDDED_SUBSCRIPTIONS);
|
||||
mContext.startActivity(intent);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
@@ -122,7 +122,6 @@ public class MobileNetworkFragment extends DashboardFragment implements
|
||||
|
||||
//UI objects
|
||||
private SwitchPreference mButton4glte;
|
||||
private Preference mEuiccSettingsPref;
|
||||
private PreferenceCategory mCallingCategory;
|
||||
private Preference mWiFiCallingPref;
|
||||
private SwitchPreference mVideoCallingPref;
|
||||
@@ -222,10 +221,6 @@ public class MobileNetworkFragment extends DashboardFragment implements
|
||||
REQUEST_CODE_EXIT_ECM);
|
||||
}
|
||||
return true;
|
||||
} else if (preference == mEuiccSettingsPref) {
|
||||
Intent intent = new Intent(EuiccManager.ACTION_MANAGE_EMBEDDED_SUBSCRIPTIONS);
|
||||
startActivity(intent);
|
||||
return true;
|
||||
} else if (preference == mWiFiCallingPref || preference == mVideoCallingPref) {
|
||||
return false;
|
||||
}
|
||||
@@ -279,6 +274,7 @@ public class MobileNetworkFragment extends DashboardFragment implements
|
||||
use(EnabledNetworkModePreferenceController.class).init(mSubId);
|
||||
use(Enhanced4gLtePreferenceController.class).init(mSubId);
|
||||
use(DataServiceSetupPreferenceController.class).init(mSubId);
|
||||
use(EuiccPreferenceController.class).init(mSubId);
|
||||
|
||||
mCdmaSystemSelectPreferenceController = use(CdmaSystemSelectPreferenceController.class);
|
||||
mCdmaSystemSelectPreferenceController.init(getPreferenceManager(), mSubId);
|
||||
@@ -319,12 +315,6 @@ public class MobileNetworkFragment extends DashboardFragment implements
|
||||
mShow4GForLTE = false;
|
||||
}
|
||||
|
||||
//get UI object references
|
||||
PreferenceScreen prefSet = getPreferenceScreen();
|
||||
|
||||
mEuiccSettingsPref = prefSet.findPreference(BUTTON_CARRIER_SETTINGS_EUICC_KEY);
|
||||
mEuiccSettingsPref.setOnPreferenceChangeListener(this);
|
||||
|
||||
// Initialize mActiveSubInfo
|
||||
int max = mSubscriptionManager.getActiveSubscriptionInfoCountMax();
|
||||
mActiveSubInfos = mSubscriptionManager.getActiveSubscriptionInfoList();
|
||||
@@ -450,12 +440,6 @@ public class MobileNetworkFragment extends DashboardFragment implements
|
||||
|
||||
if (hasActiveSubscriptions) {
|
||||
updateBodyAdvancedFields(activity, prefSet, mSubId, hasActiveSubscriptions);
|
||||
} else {
|
||||
// Shows the "Carrier" preference that allows user to add a e-sim profile.
|
||||
if (MobileNetworkUtils.showEuiccSettings(getContext())) {
|
||||
mEuiccSettingsPref.setSummary(null /* summary */);
|
||||
prefSet.addPreference(mEuiccSettingsPref);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -468,16 +452,6 @@ public class MobileNetworkFragment extends DashboardFragment implements
|
||||
log("updateBody: isLteOnCdma=" + isLteOnCdma + " phoneSubId=" + phoneSubId);
|
||||
}
|
||||
|
||||
if (MobileNetworkUtils.showEuiccSettings(getContext())) {
|
||||
prefSet.addPreference(mEuiccSettingsPref);
|
||||
String spn = mTelephonyManager.getSimOperatorName();
|
||||
if (TextUtils.isEmpty(spn)) {
|
||||
mEuiccSettingsPref.setSummary(null);
|
||||
} else {
|
||||
mEuiccSettingsPref.setSummary(spn);
|
||||
}
|
||||
}
|
||||
|
||||
int settingsNetworkMode = android.provider.Settings.Global.getInt(
|
||||
getContext().getContentResolver(),
|
||||
android.provider.Settings.Global.PREFERRED_NETWORK_MODE + phoneSubId,
|
||||
@@ -880,8 +854,7 @@ public class MobileNetworkFragment extends DashboardFragment implements
|
||||
// For ListPreferences, we log it here without a value, only indicating it's clicked to
|
||||
// open the list dialog. When a value is chosen, another MetricsEvent is logged with
|
||||
// new value in onPreferenceChange.
|
||||
if (preference == mEuiccSettingsPref
|
||||
|| preference == mWiFiCallingPref
|
||||
if (preference == mWiFiCallingPref
|
||||
|| preference == preferenceScreen.findPreference(BUTTON_CDMA_SYSTEM_SELECT_KEY)
|
||||
|| preference == preferenceScreen.findPreference(BUTTON_CDMA_SUBSCRIPTION_KEY)
|
||||
|| preference == preferenceScreen.findPreference(BUTTON_GSM_APN_EXPAND_KEY)
|
||||
@@ -915,8 +888,6 @@ public class MobileNetworkFragment extends DashboardFragment implements
|
||||
|
||||
if (preference == null) {
|
||||
return MetricsProto.MetricsEvent.VIEW_UNKNOWN;
|
||||
} else if (preference == mEuiccSettingsPref) {
|
||||
return MetricsProto.MetricsEvent.ACTION_MOBILE_NETWORK_EUICC_SETTING;
|
||||
} else if (preference == mWiFiCallingPref) {
|
||||
return MetricsProto.MetricsEvent.ACTION_MOBILE_NETWORK_WIFI_CALLING;
|
||||
} else if (preference == mVideoCallingPref) {
|
||||
|
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.telephony.TelephonyManager;
|
||||
import android.telephony.euicc.EuiccManager;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
public class EuiccPreferenceControllerTest {
|
||||
private static final int SUB_ID = 2;
|
||||
|
||||
@Mock
|
||||
private TelephonyManager mTelephonyManager;
|
||||
|
||||
private EuiccPreferenceController mController;
|
||||
private Preference 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(mTelephonyManager).createForSubscriptionId(SUB_ID);
|
||||
|
||||
mPreference = new Preference(mContext);
|
||||
mController = new EuiccPreferenceController(mContext, "euicc");
|
||||
mController.init(SUB_ID);
|
||||
mPreference.setKey(mController.getPreferenceKey());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void handlePreferenceTreeClick_startActivity() {
|
||||
ArgumentCaptor<Intent> captor = ArgumentCaptor.forClass(Intent.class);
|
||||
|
||||
mController.handlePreferenceTreeClick(mPreference);
|
||||
|
||||
verify(mContext).startActivity(captor.capture());
|
||||
assertThat(captor.getValue().getAction()).isEqualTo(
|
||||
EuiccManager.ACTION_MANAGE_EMBEDDED_SUBSCRIPTIONS);
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user