Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1d133e3f authored by jackqdyulei's avatar jackqdyulei
Browse files

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
parent 2de3d281
Loading
Loading
Loading
Loading

res/xml/cdma_options.xml

deleted100644 → 0
+0 −26
Original line number Diff line number Diff line
<?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>
+1 −1
Original line number Diff line number Diff line
@@ -27,7 +27,7 @@
            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"/>
+6 −0
Original line number Diff line number Diff line
@@ -119,4 +119,10 @@
            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>
+68 −0
Original line number Diff line number Diff line
/*
 * 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;
    }
}
+1 −37
Original line number Diff line number Diff line
@@ -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;
Loading