Refactor carrier settings

Only show it when:
1. It is in CDMA or GSM mode
2. CarrierConfig tell settings to show it

Bug: 114749736
Test: RunSettingsRoboTests

Change-Id: I45ecbc86c793ebec602142be208058e2043a2ba7
This commit is contained in:
jackqdyulei
2018-10-12 13:50:28 -07:00
parent 2de3d28138
commit 1d133e3f04
8 changed files with 199 additions and 66 deletions

View File

@@ -0,0 +1,68 @@
/*
* 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;
}
}

View File

@@ -16,10 +16,6 @@
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;
@@ -32,50 +28,18 @@ import com.android.settings.R;
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;

View File

@@ -401,6 +401,7 @@ public class MobileNetworkFragment extends DashboardFragment implements
use(MobileDataPreferenceController.class).init(getFragmentManager(), mSubId);
use(CdmaApnPreferenceController.class).init(mSubId);
use(CarrierPreferenceController.class).init(mSubId);
mCdmaSystemSelectPreferenceController = use(CdmaSystemSelectPreferenceController.class);
mCdmaSystemSelectPreferenceController.init(getPreferenceManager(), mSubId);
@@ -1798,8 +1799,6 @@ public class MobileNetworkFragment extends DashboardFragment implements
// the open dialog gets dismissed or detached after pause / resume.
if (mCdmaOptions == null) {
mCdmaOptions = new CdmaOptions(prefFragment, prefScreen, subId);
} else {
mCdmaOptions.updateSubscriptionId(subId);
}
}

View File

@@ -275,6 +275,20 @@ public class MobileNetworkUtils {
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