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

Commit f1d040a0 authored by Zoey Chen's avatar Zoey Chen
Browse files

[Settings] eSIM transfer: MobileNetworkListFragment

 - Remove the eSIM/pSIM category and separators
 - Add pSIM/eSIM icon for SIMs

Screenshot: https://hsv.googleplex.com/5263071317590016

Bug: 261810065
Test: atest NetworkProviderSimListControllerTest
Change-Id: If4b8659c377698e682093e1508699bfc96855b29
parent 9ca3255c
Loading
Loading
Loading
Loading
+27 −0
Original line number Diff line number Diff line
<!--
  Copyright (C) 2022 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.
  -->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
        android:width="24dp"
        android:height="24dp"
        android:viewportWidth="24"
        android:viewportHeight="24"
        android:tint="?android:attr/colorControlNormal"
>
    <path android:fillColor="@android:color/white"
          android:pathData="M18,2h-8L4,8v12c0,1.1 0.9,2 2,2h12c1.1,0 2,-0.9 2,-2V4C20,2.9 19.1,2 18,2zM18,4v16H6V8.83L10.83,4H18z"/>
    <path android:fillColor="@android:color/white"
          android:pathData="M16,13l-4,4l-4,-4l1.41,-1.41L11,13.17V9.02L13,9v4.17l1.59,-1.59L16,13z"/>
</vector>
 No newline at end of file
+2 −2
Original line number Diff line number Diff line
@@ -10230,8 +10230,8 @@
    <string name="subscription_available">Available</string>
    <!-- Title of item shown at the bottom of the page listing multiple mobile service
         subscriptions; tapping it leads to a UI to add more [CHAR LIMIT=40] -->
    <string name="mobile_network_list_add_more">Add more</string>
         subscriptions; tapping it leads to a UI to add more SIMs [CHAR LIMIT=40] -->
    <string name="mobile_network_list_add_more">Add SIM</string>
    <!-- Summary for an item in the page listing multiple mobile service subscriptions, indicating
         that service is active and is tied to a physical SIM card [CHAR LIMIT=40] -->
    <string name="mobile_network_active_sim">Active / SIM</string>
+3 −10
Original line number Diff line number Diff line
@@ -21,20 +21,13 @@

    <PreferenceCategory
        android:key="provider_model_sim_category"
        android:title="@string/sim_category_title"
        android:title="@string/summary_placeholder"
        android:layout="@layout/preference_category_no_label"
        android:order="20"
        settings:controller="com.android.settings.network.NetworkProviderSimsCategoryController"/>

    <PreferenceCategory
        android:key="provider_model_downloaded_sim_category"
        android:title="@string/downloaded_sim_category_title"
        android:order="25"
        settings:controller=
            "com.android.settings.network.NetworkProviderDownloadedSimsCategoryController"
        settings:allowDividerAbove="true"/>

    <com.android.settingslib.RestrictedPreference
        android:key="add_more"
        android:key="add_sim"
        settings:isPreferenceVisible="false"
        settings:userRestriction="no_config_mobile_networks"
        settings:useAdminDisabledSummary="true"
+0 −173
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;

import static com.android.settings.Utils.SETTINGS_PACKAGE_NAME;

import static androidx.lifecycle.Lifecycle.Event.ON_PAUSE;
import static androidx.lifecycle.Lifecycle.Event.ON_RESUME;

import android.content.Context;
import android.content.Intent;
import android.provider.Settings;
import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager;
import android.util.ArrayMap;

import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.LifecycleObserver;
import androidx.lifecycle.OnLifecycleEvent;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;

import com.android.internal.annotations.VisibleForTesting;
import com.android.settings.R;
import com.android.settings.network.telephony.MobileNetworkUtils;
import com.android.settingslib.core.AbstractPreferenceController;

import java.util.List;
import java.util.Map;

/**
 * This populates the entries on a page which lists all available mobile subscriptions. Each entry
 * has the name of the subscription with some subtext giving additional detail, and clicking on the
 * entry brings you to a details page for that network.
 *
 * @deprecated This class will be removed in Android U, use
 * {@link NetworkProviderSimsCategoryController} and
 * {@link NetworkProviderDownloadedSimsCategoryController} instead.
 */
@Deprecated
public class MobileNetworkListController extends AbstractPreferenceController implements
        LifecycleObserver, SubscriptionsChangeListener.SubscriptionsChangeListenerClient {
    private static final String TAG = "MobileNetworkListCtlr";

    @VisibleForTesting
    static final String KEY_ADD_MORE = "add_more";

    private SubscriptionManager mSubscriptionManager;
    private SubscriptionsChangeListener mChangeListener;
    private PreferenceScreen mPreferenceScreen;
    private Map<Integer, Preference> mPreferences;

    public MobileNetworkListController(Context context, Lifecycle lifecycle) {
        super(context);
        mSubscriptionManager = context.getSystemService(SubscriptionManager.class);
        mChangeListener = new SubscriptionsChangeListener(context, this);
        mPreferences = new ArrayMap<>();
        lifecycle.addObserver(this);
    }

    @OnLifecycleEvent(ON_RESUME)
    public void onResume() {
        mChangeListener.start();
        update();
    }

    @OnLifecycleEvent(ON_PAUSE)
    public void onPause() {
        mChangeListener.stop();
    }

    @Override
    public void displayPreference(PreferenceScreen screen) {
        super.displayPreference(screen);
        mPreferenceScreen = screen;
        mPreferenceScreen.findPreference(KEY_ADD_MORE).setVisible(
                MobileNetworkUtils.showEuiccSettings(mContext));
        update();
    }

    private void update() {
        if (mPreferenceScreen == null) {
            return;
        }

        // Since we may already have created some preferences previously, we first grab the list of
        // those, then go through the current available subscriptions making sure they are all
        // present in the screen, and finally remove any now-outdated ones.
        final Map<Integer, Preference> existingPreferences = mPreferences;
        mPreferences = new ArrayMap<>();

        final List<SubscriptionInfo> subscriptions = SubscriptionUtil.getAvailableSubscriptions(
                mContext);
        for (SubscriptionInfo info : subscriptions) {
            final int subId = info.getSubscriptionId();
            Preference pref = existingPreferences.remove(subId);
            if (pref == null) {
                pref = new Preference(mPreferenceScreen.getContext());
                mPreferenceScreen.addPreference(pref);
            }
            final CharSequence displayName = SubscriptionUtil.getUniqueSubscriptionDisplayName(
                    info, mContext);
            pref.setTitle(displayName);

            if (info.isEmbedded()) {
                if (mSubscriptionManager.isActiveSubscriptionId(subId)) {
                    pref.setSummary(R.string.mobile_network_active_esim);
                } else {
                    pref.setSummary(R.string.mobile_network_inactive_esim);
                }
            } else {
                if (mSubscriptionManager.isActiveSubscriptionId(subId)) {
                    pref.setSummary(R.string.mobile_network_active_sim);
                } else if (SubscriptionUtil.showToggleForPhysicalSim(mSubscriptionManager)) {
                    pref.setSummary(mContext.getString(R.string.mobile_network_inactive_sim));
                } else {
                    pref.setSummary(mContext.getString(R.string.mobile_network_tap_to_activate,
                            displayName));
                }
            }

            pref.setOnPreferenceClickListener(clickedPref -> {
                if (!info.isEmbedded() && !mSubscriptionManager.isActiveSubscriptionId(subId)
                        && !SubscriptionUtil.showToggleForPhysicalSim(mSubscriptionManager)) {
                    SubscriptionUtil.startToggleSubscriptionDialogActivity(mContext, subId, true);
                } else {
                    final Intent intent = new Intent(Settings.ACTION_NETWORK_OPERATOR_SETTINGS);
                    intent.setPackage(SETTINGS_PACKAGE_NAME);
                    intent.putExtra(Settings.EXTRA_SUB_ID, info.getSubscriptionId());
                    mContext.startActivity(intent);
                }
                return true;
            });
            mPreferences.put(subId, pref);
        }
        for (Preference pref : existingPreferences.values()) {
            mPreferenceScreen.removePreference(pref);
        }
    }

    @Override
    public boolean isAvailable() {
        return true;
    }

    @Override
    public String getPreferenceKey() {
        return null;
    }

    @Override
    public void onAirplaneModeChanged(boolean airplaneModeEnabled) {
    }

    @Override
    public void onSubscriptionsChanged() {
        update();
    }
}
+4 −7
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import androidx.recyclerview.widget.RecyclerView;

import com.android.settings.R;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.network.telephony.MobileNetworkUtils;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settingslib.search.SearchIndexable;
@@ -38,9 +39,7 @@ public class MobileNetworkListFragment extends DashboardFragment {
    private static final String LOG_TAG = "NetworkListFragment";

    static final String KEY_PREFERENCE_CATEGORY_SIM = "provider_model_sim_category";
    @VisibleForTesting
    static final String KEY_PREFERENCE_CATEGORY_DOWNLOADED_SIM =
            "provider_model_downloaded_sim_category";
    private static final String KEY_ADD_SIM = "add_sim";

    @Override
    public void onResume() {
@@ -50,6 +49,8 @@ public class MobileNetworkListFragment extends DashboardFragment {
        if (prefListView != null) {
            prefListView.setItemAnimator(null);
        }

        findPreference(KEY_ADD_SIM).setVisible(MobileNetworkUtils.showEuiccSettings(getContext()));
    }

    @Override
@@ -79,10 +80,6 @@ public class MobileNetworkListFragment extends DashboardFragment {
                new NetworkProviderSimsCategoryController(context, KEY_PREFERENCE_CATEGORY_SIM,
                        getSettingsLifecycle(), this);
        controllers.add(simCategoryPrefCtrl);
        NetworkProviderDownloadedSimsCategoryController downloadedSimsCategoryCtrl =
                new NetworkProviderDownloadedSimsCategoryController(context,
                        KEY_PREFERENCE_CATEGORY_DOWNLOADED_SIM, getSettingsLifecycle(), this);
        controllers.add(downloadedSimsCategoryCtrl);

        return controllers;
    }
Loading