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

Commit f0d4a373 authored by Antony Sargent's avatar Antony Sargent
Browse files

Add carrier settings version to network details page

This adds a preference showing the carrier settings version to the
mobile network details page.

Bug: 123995414
Test: make RunSettingsRoboTests
Change-Id: I7b80ead0eadb7375b4404262337e47f75102125c
parent ad6cc282
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -10503,6 +10503,9 @@
    <string name="preferred_network_mode_dialogtitle">Preferred network type</string>
    <!-- Mobile network settings screen, name of the option to manage carrier profiles on devices which support embedded carrier profiles [CHAR LIMIT=NONE] -->
    <string name="carrier_settings_euicc">Carrier</string>
    <!-- Mobile network settings screen, a string showing the version of carrier settings for this
         subscription [CHAR LIMIT=NONE] -->
    <string name="carrier_settings_version">Settings version</string>
    <!-- Mobile network settings screen, name for call settings category [CHAR LIMIT=NONE] -->
    <string name="call_category">Calling</string>
+6 −0
Original line number Diff line number Diff line
@@ -98,6 +98,12 @@
        android:title="@string/carrier_settings_euicc"
        settings:controller="com.android.settings.network.telephony.EuiccPreferenceController" />

    <Preference
        android:key="carrier_settings_version_key"
        android:title="@string/carrier_settings_version"
        settings:controller="com.android.settings.network.telephony.CarrierSettingsVersionPreferenceController"
        settings:enableCopying="true" />

    <PreferenceCategory
        android:key="calling_category"
        android:title="@string/call_category">
+54 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2019 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 android.telephony.SubscriptionManager;

import com.android.settings.core.BasePreferenceController;

public class CarrierSettingsVersionPreferenceController extends BasePreferenceController {

    private int mSubscriptionId;
    private CarrierConfigManager mManager;

    public CarrierSettingsVersionPreferenceController(Context context, String preferenceKey) {
        super(context, preferenceKey);
        mManager = context.getSystemService(CarrierConfigManager.class);
        mSubscriptionId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
    }

    public void init(int subscriptionId) {
        mSubscriptionId = subscriptionId;
    }

    @Override
    public CharSequence getSummary() {
        final PersistableBundle config = mManager.getConfigForSubId(mSubscriptionId);
        if (config == null) {
            return null;
        }
        return config.getString(CarrierConfigManager.KEY_CARRIER_CONFIG_VERSION_STRING);
    }

    @Override
    public int getAvailabilityStatus() {
        return AVAILABLE;
    }
}
+1 −0
Original line number Diff line number Diff line
@@ -133,6 +133,7 @@ public class MobileNetworkSettings extends RestrictedDashboardFragment {
          use(CallsDefaultSubscriptionController.class).init(getLifecycle());
          use(SmsDefaultSubscriptionController.class).init(getLifecycle());
          use(MobileNetworkSwitchController.class).init(getLifecycle(), mSubId);
          use(CarrierSettingsVersionPreferenceController.class).init(mSubId);
        }
        use(MobileDataPreferenceController.class).init(getFragmentManager(), mSubId);
        use(RoamingPreferenceController.class).init(getFragmentManager(), mSubId);
+73 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2019 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 android.content.Context;
import android.os.PersistableBundle;
import android.telephony.CarrierConfigManager;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.Shadows;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowCarrierConfigManager;

@RunWith(RobolectricTestRunner.class)
@Config(shadows = ShadowCarrierConfigManager.class)
public class CarrierSettingsVersionPreferenceControllerTest {

    private ShadowCarrierConfigManager mCarrierConfigManager;
    private CarrierSettingsVersionPreferenceController mController;
    private int mSubscriptionId = 1234;

    @Before
    public void setUp() {
        MockitoAnnotations.initMocks(this);
        final Context context = RuntimeEnvironment.application;
        mController = new CarrierSettingsVersionPreferenceController(context, "dummy_key");
        mController.init(mSubscriptionId);
        mCarrierConfigManager = Shadows.shadowOf(
                context.getSystemService(CarrierConfigManager.class));
    }

    @Test
    public void getSummary_nullConfig_noCrash() {
        mCarrierConfigManager.setConfigForSubId(mSubscriptionId, null);
        assertThat(mController.getSummary()).isNull();
    }

    @Test
    public void getSummary_nullVersionString_noCrash() {
        mCarrierConfigManager.setConfigForSubId(mSubscriptionId, new PersistableBundle());
        assertThat(mController.getSummary()).isNull();
    }

    @Test
    public void getSummary_hasVersionString_correctSummary() {
        final PersistableBundle bundle = new PersistableBundle();
        bundle.putString(CarrierConfigManager.KEY_CARRIER_CONFIG_VERSION_STRING,
                "test_version_123");
        mCarrierConfigManager.setConfigForSubId(mSubscriptionId, bundle);
        assertThat(mController.getSummary()).isEqualTo("test_version_123");
    }
}