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

Commit 5836158f authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Remove on/off toggle for physical SIMs" into qt-dev

parents 564fcb90 e548fc63
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -203,4 +203,14 @@
        android:title="@string/mobile_network_erase_sim"
        settings:controller="com.android.settings.network.telephony.DeleteSimProfilePreferenceController" />

    <PreferenceCategory
        android:key="footer_container"
        android:title="@string/summary_placeholder"
        android:layout="@layout/preference_category_no_label"
        settings:controller="com.android.settings.network.telephony.DisableSimFooterPreferenceController">
        <com.android.settingslib.widget.FooterPreference
            android:key="disable_sim_explanation"
            android:title="@string/mobile_network_disable_sim_explanation" />
    </PreferenceCategory>

</PreferenceScreen>
+9 −4
Original line number Diff line number Diff line
@@ -118,14 +118,19 @@ public class MobileNetworkListController extends AbstractPreferenceController im
                if (mSubscriptionManager.isActiveSubscriptionId(subId)) {
                    pref.setSummary(R.string.mobile_network_active_sim);
                } else {
                    pref.setSummary(R.string.mobile_network_inactive_sim);
                    pref.setSummary(mContext.getString(R.string.mobile_network_tap_to_activate,
                            SubscriptionUtil.getDisplayName(info)));
                }
            }

            pref.setOnPreferenceClickListener(clickedPref -> {
                if (!info.isEmbedded() && !mSubscriptionManager.isActiveSubscriptionId(subId)) {
                    mSubscriptionManager.setSubscriptionEnabled(subId, true);
                } else {
                    final Intent intent = new Intent(mContext, MobileNetworkActivity.class);
                    intent.putExtra(Settings.EXTRA_SUB_ID, info.getSubscriptionId());
                    mContext.startActivity(intent);
                }
                return true;
            });
            mPreferences.put(subId, pref);
+17 −4
Original line number Diff line number Diff line
@@ -108,7 +108,14 @@ public class MobileNetworkSummaryController extends AbstractPreferenceController
            }
            return null;
        } else if (subs.size() == 1) {
            final SubscriptionInfo info = subs.get(0);
            final int subId = info.getSubscriptionId();
            if (!info.isEmbedded() && !mSubscriptionManager.isActiveSubscriptionId(subId)) {
                return mContext.getString(R.string.mobile_network_tap_to_activate,
                        SubscriptionUtil.getDisplayName(info));
            } else {
                return subs.get(0).getDisplayName();
            }
        } else {
            final int count = subs.size();
            return mContext.getResources().getQuantityString(R.plurals.mobile_network_summary_count,
@@ -154,9 +161,15 @@ public class MobileNetworkSummaryController extends AbstractPreferenceController

            if (subs.size() == 1) {
                mPreference.setOnPreferenceClickListener((Preference pref) -> {
                    final SubscriptionInfo info = subs.get(0);
                    final int subId = info.getSubscriptionId();
                    if (!info.isEmbedded() && !mSubscriptionManager.isActiveSubscriptionId(subId)) {
                        mSubscriptionManager.setSubscriptionEnabled(subId, true);
                    } else {
                        final Intent intent = new Intent(mContext, MobileNetworkActivity.class);
                        intent.putExtra(Settings.EXTRA_SUB_ID, subs.get(0).getSubscriptionId());
                        mContext.startActivity(intent);
                    }
                    return true;
                });
            } else {
+8 −2
Original line number Diff line number Diff line
@@ -25,12 +25,10 @@ import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import android.telephony.UiccSlotInfo;
import android.text.TextUtils;

import androidx.annotation.VisibleForTesting;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class SubscriptionUtil {
@@ -107,4 +105,12 @@ public class SubscriptionUtil {
        }
        return subscriptions;
    }

    public static String getDisplayName(SubscriptionInfo info) {
        final CharSequence name = info.getDisplayName();
        if (name != null) {
            return name.toString();
        }
        return "";
    }
}
+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.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;

import com.android.settings.core.BasePreferenceController;
import com.android.settings.network.SubscriptionUtil;

public class DisableSimFooterPreferenceController extends BasePreferenceController {
    private int mSubId;

    public DisableSimFooterPreferenceController(Context context, String preferenceKey) {
        super(context, preferenceKey);
        mSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
    }

    public void init(int subId) {
        mSubId = subId;
    }

    @Override
    public int getAvailabilityStatus() {
        if (mSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
            return CONDITIONALLY_UNAVAILABLE;
        }
        for (SubscriptionInfo info : SubscriptionUtil.getAvailableSubscriptions(mContext)) {
            if (info.getSubscriptionId() == mSubId) {
                if (info.isEmbedded()) {
                    return CONDITIONALLY_UNAVAILABLE;
                }
                break;
            }
        }
        return AVAILABLE;
    }
}
Loading