+++ /dev/null
-<?xml version="1.0" encoding="utf-8"?>
-<!--
- Copyright (C) 2008 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.
--->
-
-<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
-
- <Preference
- android:key="carrier_settings_key"
- android:title="@string/carrier_settings_title">
- <!-- b/114749736, create a preference controller to build intent -->
- </Preference>
-
-</PreferenceScreen>
android:title="@string/select_automatically"
android:persistent="false"/>
- <com.android.settings.mobilenetwork.NetworkSelectListPreference
+ <com.android.settings.network.telephony.NetworkSelectListPreference
android:key="button_network_select_key"
android:title="@string/network_select_title"
android:persistent="false"/>
settings:controller="com.android.settings.network.telephony.cdma.CdmaApnPreferenceController"/>
</PreferenceCategory>
+ <Preference
+ android:key="carrier_settings_key"
+ android:title="@string/carrier_settings_title"
+ settings:controller="com.android.settings.network.telephony.CarrierPreferenceController">
+ </Preference>
+
</PreferenceScreen>
--- /dev/null
+/*
+ * 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.os.PersistableBundle;
+import android.telephony.CarrierConfigManager;
+
+import androidx.annotation.VisibleForTesting;
+import androidx.preference.Preference;
+
+import com.android.settings.core.BasePreferenceController;
+
+/**
+ * Preference controller for "Carrier Settings"
+ */
+public class CarrierPreferenceController extends BasePreferenceController {
+
+ @VisibleForTesting
+ CarrierConfigManager mCarrierConfigManager;
+ private int mSubId;
+
+ public CarrierPreferenceController(Context context, String key) {
+ super(context, key);
+ mCarrierConfigManager = new CarrierConfigManager(context);
+ }
+
+ public void init(int subId) {
+ mSubId = subId;
+ }
+
+ @Override
+ public int getAvailabilityStatus() {
+ final PersistableBundle carrierConfig = mCarrierConfigManager.getConfigForSubId(mSubId);
+
+ // Return available if it is in CDMA or GSM mode, and the flag is on
+ return carrierConfig != null
+ && carrierConfig.getBoolean(CarrierConfigManager.KEY_CARRIER_SETTINGS_ENABLE_BOOL)
+ && (MobileNetworkUtils.isCdmaOptions(mContext, mSubId)
+ || MobileNetworkUtils.isGsmOptions(mContext, mSubId))
+ ? AVAILABLE
+ : CONDITIONALLY_UNAVAILABLE;
+ }
+
+ @Override
+ public boolean handlePreferenceTreeClick(Preference preference) {
+ if (getPreferenceKey().equals(preference.getKey())) {
+ //TODO(b/117651939): start carrier settings activity
+ return true;
+ }
+
+ return false;
+ }
+}
package com.android.settings.network.telephony;
-import android.os.PersistableBundle;
-import android.telephony.CarrierConfigManager;
-import android.telephony.TelephonyManager;
-
import androidx.preference.Preference;
import androidx.preference.PreferenceFragmentCompat;
import androidx.preference.PreferenceScreen;
public class CdmaOptions {
private static final String LOG_TAG = "CdmaOptions";
- private CarrierConfigManager mCarrierConfigManager;
- private Preference mButtonCarrierSettings;
-
private static final String BUTTON_CDMA_SYSTEM_SELECT_KEY = "cdma_system_select_key";
private static final String BUTTON_CDMA_SUBSCRIPTION_KEY = "cdma_subscription_key";
- private static final String BUTTON_CARRIER_SETTINGS_KEY = "carrier_settings_key";
private PreferenceFragmentCompat mPrefFragment;
- private PreferenceScreen mPrefScreen;
- private int mSubId;
public CdmaOptions(PreferenceFragmentCompat prefFragment, PreferenceScreen prefScreen,
int subId) {
mPrefFragment = prefFragment;
- mPrefScreen = prefScreen;
- mPrefFragment.addPreferencesFromResource(R.xml.cdma_options);
- mCarrierConfigManager = new CarrierConfigManager(prefFragment.getContext());
-
- // Initialize preferences.
- mButtonCarrierSettings = mPrefScreen.findPreference(BUTTON_CARRIER_SETTINGS_KEY);
-
- updateSubscriptionId(subId);
- }
-
- protected void updateSubscriptionId(int subId) {
- mSubId = subId;
-
- PersistableBundle carrierConfig = mCarrierConfigManager.getConfigForSubId(mSubId);
- // Read platform settings for carrier settings
- boolean addCarrierSettings =
- carrierConfig.getBoolean(CarrierConfigManager.KEY_CARRIER_SETTINGS_ENABLE_BOOL);
-
- // Making no assumptions of whether they are added or removed at this point.
- // Calling add or remove explicitly to make sure they are updated.
-
-
- if (addCarrierSettings) {
- mPrefScreen.addPreference(mButtonCarrierSettings);
- } else {
- mPrefScreen.removePreference(mButtonCarrierSettings);
- }
}
public boolean preferenceTreeClick(Preference preference) {
+ //TODO(b/114749736): handle it in preferenceController and remove this file
if (preference.getKey().equals(BUTTON_CDMA_SYSTEM_SELECT_KEY)) {
log("preferenceTreeClick: return BUTTON_CDMA_ROAMING_KEY true");
return true;
use(MobileDataPreferenceController.class).init(getFragmentManager(), mSubId);
use(CdmaApnPreferenceController.class).init(mSubId);
+ use(CarrierPreferenceController.class).init(mSubId);
mCdmaSystemSelectPreferenceController = use(CdmaSystemSelectPreferenceController.class);
mCdmaSystemSelectPreferenceController.init(getPreferenceManager(), mSubId);
// the open dialog gets dismissed or detached after pause / resume.
if (mCdmaOptions == null) {
mCdmaOptions = new CdmaOptions(prefFragment, prefScreen, subId);
- } else {
- mCdmaOptions.updateSubscriptionId(subId);
}
}
return false;
}
+ public static boolean isGsmOptions(Context context, int subId) {
+ if (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
+ return false;
+ }
+ final TelephonyManager telephonyManager = TelephonyManager.from(context)
+ .createForSubscriptionId(subId);
+
+ if (telephonyManager.getPhoneType() == PhoneConstants.PHONE_TYPE_GSM) {
+ return true;
+ }
+
+ return false;
+ }
+
/**
* Return {@code true} if it is world mode, and we may show advanced options in telephony
* settings
--- /dev/null
+/*
+ * 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.android.settings.core.BasePreferenceController.AVAILABLE;
+import static com.android.settings.core.BasePreferenceController.CONDITIONALLY_UNAVAILABLE;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.spy;
+
+import android.content.Context;
+import android.os.PersistableBundle;
+import android.telephony.CarrierConfigManager;
+import android.telephony.SubscriptionManager;
+import android.telephony.TelephonyManager;
+
+import com.android.internal.telephony.PhoneConstants;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+import com.android.settingslib.RestrictedPreference;
+
+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 CarrierPreferenceControllerTest {
+ private static final int SUB_ID = 2;
+
+ @Mock
+ private TelephonyManager mTelephonyManager;
+ @Mock
+ private TelephonyManager mInvalidTelephonyManager;
+ @Mock
+ private SubscriptionManager mSubscriptionManager;
+ @Mock
+ private CarrierConfigManager mCarrierConfigManager;
+
+ private CarrierPreferenceController mController;
+ private RestrictedPreference mPreference;
+ private Context mContext;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+
+ mContext = spy(RuntimeEnvironment.application);
+ doReturn(mTelephonyManager).when(mContext).getSystemService(Context.TELEPHONY_SERVICE);
+ doReturn(mSubscriptionManager).when(mContext).getSystemService(SubscriptionManager.class);
+ doReturn(mTelephonyManager).when(mTelephonyManager).createForSubscriptionId(SUB_ID);
+ doReturn(mInvalidTelephonyManager).when(mTelephonyManager).createForSubscriptionId(
+ SubscriptionManager.INVALID_SUBSCRIPTION_ID);
+
+ mPreference = new RestrictedPreference(mContext);
+ mController = new CarrierPreferenceController(mContext, "mobile_data");
+ mController.init(SUB_ID);
+ mController.mCarrierConfigManager = mCarrierConfigManager;
+ mPreference.setKey(mController.getPreferenceKey());
+ }
+
+ @Test
+ public void getAvailabilityStatus_cdmaWithFlagOff_returnUnavailable() {
+ doReturn(PhoneConstants.PHONE_TYPE_CDMA).when(mTelephonyManager).getPhoneType();
+ final PersistableBundle bundle = new PersistableBundle();
+ bundle.putBoolean(CarrierConfigManager.KEY_CARRIER_SETTINGS_ENABLE_BOOL, false);
+ doReturn(bundle).when(mCarrierConfigManager).getConfigForSubId(SUB_ID);
+
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(CONDITIONALLY_UNAVAILABLE);
+ }
+
+ @Test
+ public void getAvailabilityStatus_cdmaWithFlagOnreturnAvailable() {
+ doReturn(PhoneConstants.PHONE_TYPE_CDMA).when(mTelephonyManager).getPhoneType();
+ final PersistableBundle bundle = new PersistableBundle();
+ bundle.putBoolean(CarrierConfigManager.KEY_CARRIER_SETTINGS_ENABLE_BOOL, true);
+ doReturn(bundle).when(mCarrierConfigManager).getConfigForSubId(SUB_ID);
+
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
+ }
+
+ @Test
+ public void getAvailabilityStatus_gsmWithFlagOnreturnAvailable() {
+ doReturn(PhoneConstants.PHONE_TYPE_GSM).when(mTelephonyManager).getPhoneType();
+ final PersistableBundle bundle = new PersistableBundle();
+ bundle.putBoolean(CarrierConfigManager.KEY_CARRIER_SETTINGS_ENABLE_BOOL, true);
+ doReturn(bundle).when(mCarrierConfigManager).getConfigForSubId(SUB_ID);
+
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
+ }
+}