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

Commit 4b8ef66c authored by Xiangyu/Malcolm Chen's avatar Xiangyu/Malcolm Chen Committed by android-build-merger
Browse files

Merge changes from topic "126637721"

am: 9763d788

Change-Id: Ia1b93ffad154d8e149d172dd7694b4c58add03a9
parents 742ea8f0 9763d788
Loading
Loading
Loading
Loading
+43 −1
Original line number Original line Diff line number Diff line
@@ -17,6 +17,9 @@
package com.android.systemui.statusbar.policy;
package com.android.systemui.statusbar.policy;


import static android.net.NetworkCapabilities.NET_CAPABILITY_VALIDATED;
import static android.net.NetworkCapabilities.NET_CAPABILITY_VALIDATED;
import static android.telephony.PhoneStateListener.LISTEN_ACTIVE_DATA_SUBSCRIPTION_ID_CHANGE;

import static com.android.internal.telephony.PhoneConstants.MAX_PHONE_COUNT_DUAL_SIM;


import android.content.BroadcastReceiver;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Context;
@@ -35,6 +38,7 @@ import android.os.Looper;
import android.os.PersistableBundle;
import android.os.PersistableBundle;
import android.provider.Settings;
import android.provider.Settings;
import android.telephony.CarrierConfigManager;
import android.telephony.CarrierConfigManager;
import android.telephony.PhoneStateListener;
import android.telephony.ServiceState;
import android.telephony.ServiceState;
import android.telephony.SignalStrength;
import android.telephony.SignalStrength;
import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionInfo;
@@ -96,6 +100,16 @@ public class NetworkControllerImpl extends BroadcastReceiver
    private final CurrentUserTracker mUserTracker;
    private final CurrentUserTracker mUserTracker;
    private Config mConfig;
    private Config mConfig;


    private PhoneStateListener mPhoneStateListener = new PhoneStateListener() {
        @Override
        public void onActiveDataSubscriptionIdChanged(int subId) {
            mActiveMobileDataSubscription = subId;
            doUpdateMobileControllers();
        }
    };

    private int mActiveMobileDataSubscription = SubscriptionManager.INVALID_SUBSCRIPTION_ID;

    // Subcontrollers.
    // Subcontrollers.
    @VisibleForTesting
    @VisibleForTesting
    final WifiSignalController mWifiSignalController;
    final WifiSignalController mWifiSignalController;
@@ -269,6 +283,7 @@ public class NetworkControllerImpl extends BroadcastReceiver
            mSubscriptionListener = new SubListener();
            mSubscriptionListener = new SubListener();
        }
        }
        mSubscriptionManager.addOnSubscriptionsChangedListener(mSubscriptionListener);
        mSubscriptionManager.addOnSubscriptionsChangedListener(mSubscriptionListener);
        mPhone.listen(mPhoneStateListener, LISTEN_ACTIVE_DATA_SUBSCRIPTION_ID_CHANGE);


        // broadcasts
        // broadcasts
        IntentFilter filter = new IntentFilter();
        IntentFilter filter = new IntentFilter();
@@ -513,6 +528,7 @@ public class NetworkControllerImpl extends BroadcastReceiver


    @VisibleForTesting
    @VisibleForTesting
    void handleConfigurationChanged() {
    void handleConfigurationChanged() {
        updateMobileControllers();
        for (int i = 0; i < mMobileSignalControllers.size(); i++) {
        for (int i = 0; i < mMobileSignalControllers.size(); i++) {
            MobileSignalController controller = mMobileSignalControllers.valueAt(i);
            MobileSignalController controller = mMobileSignalControllers.valueAt(i);
            controller.setConfiguration(mConfig);
            controller.setConfiguration(mConfig);
@@ -527,13 +543,39 @@ public class NetworkControllerImpl extends BroadcastReceiver
        doUpdateMobileControllers();
        doUpdateMobileControllers();
    }
    }


    private void filterMobileSubscriptionInSameGroup(List<SubscriptionInfo> subscriptions) {
        if (subscriptions.size() == MAX_PHONE_COUNT_DUAL_SIM) {
            SubscriptionInfo info1 = subscriptions.get(0);
            SubscriptionInfo info2 = subscriptions.get(1);
            if (info1.getGroupUuid() != null && info1.getGroupUuid().equals(info2.getGroupUuid())) {
                // If both subscriptions are primary, show both.
                if (!info1.isOpportunistic() && !info2.isOpportunistic()) return;

                // If carrier required, always show signal bar of primary subscription.
                // Otherwise, show whichever subscription is currently active for Internet.
                boolean alwaysShowPrimary = CarrierConfigManager.getDefaultConfig()
                        .getBoolean(CarrierConfigManager
                        .KEY_ALWAYS_SHOW_PRIMARY_SIGNAL_BAR_IN_OPPORTUNISTIC_NETWORK_BOOLEAN);
                if (alwaysShowPrimary) {
                    subscriptions.remove(info1.isOpportunistic() ? info1 : info2);
                } else {
                    subscriptions.remove(info1.getSubscriptionId() == mActiveMobileDataSubscription
                            ? info2 : info1);
                }
            }
        }
    }

    @VisibleForTesting
    @VisibleForTesting
    void doUpdateMobileControllers() {
    void doUpdateMobileControllers() {
        List<SubscriptionInfo> subscriptions = mSubscriptionManager
        List<SubscriptionInfo> subscriptions = mSubscriptionManager
                .getActiveSubscriptionInfoList(true);
                .getActiveSubscriptionInfoList(false);
        if (subscriptions == null) {
        if (subscriptions == null) {
            subscriptions = Collections.emptyList();
            subscriptions = Collections.emptyList();
        }
        }

        filterMobileSubscriptionInSameGroup(subscriptions);

        // If there have been no relevant changes to any of the subscriptions, we can leave as is.
        // If there have been no relevant changes to any of the subscriptions, we can leave as is.
        if (hasCorrectMobileControllers(subscriptions)) {
        if (hasCorrectMobileControllers(subscriptions)) {
            // Even if the controllers are correct, make sure we have the right no sims state.
            // Even if the controllers are correct, make sure we have the right no sims state.
+14 −0
Original line number Original line Diff line number Diff line
@@ -2489,6 +2489,18 @@ public class CarrierConfigManager {
    public static final String KEY_EMERGENCY_NUMBER_PREFIX_STRING_ARRAY =
    public static final String KEY_EMERGENCY_NUMBER_PREFIX_STRING_ARRAY =
            "emergency_number_prefix_string_array";
            "emergency_number_prefix_string_array";


    /**
     * Indicates when a carrier has a primary subscription and an opportunistic subscription active,
     * and when Internet data is switched to opportunistic network, whether to still show
     * signal bar of primary network. By default it will be false, meaning whenever data
     * is going over opportunistic network, signal bar will reflect signal strength and rat
     * icon of that network.
     *
     * @hide
     */
    public static final String KEY_ALWAYS_SHOW_PRIMARY_SIGNAL_BAR_IN_OPPORTUNISTIC_NETWORK_BOOLEAN =
            "always_show_primary_signal_bar_in_opportunistic_network_boolean";

    /**
    /**
     * Determines whether the carrier wants to cancel the cs reject notification automatically
     * Determines whether the carrier wants to cancel the cs reject notification automatically
     * when the voice registration state changes.
     * when the voice registration state changes.
@@ -2922,6 +2934,8 @@ public class CarrierConfigManager {
        sDefaults.putString(KEY_5G_ICON_CONFIGURATION_STRING,
        sDefaults.putString(KEY_5G_ICON_CONFIGURATION_STRING,
                "connected_mmwave:None,connected:5G,not_restricted:None,restricted:None");
                "connected_mmwave:None,connected:5G,not_restricted:None,restricted:None");
        sDefaults.putBoolean(KEY_AUTO_CANCEL_CS_REJECT_NOTIFICATION, false);
        sDefaults.putBoolean(KEY_AUTO_CANCEL_CS_REJECT_NOTIFICATION, false);
        sDefaults.putBoolean(KEY_ALWAYS_SHOW_PRIMARY_SIGNAL_BAR_IN_OPPORTUNISTIC_NETWORK_BOOLEAN,
                false);
    }
    }


    /**
    /**
+16 −21
Original line number Original line Diff line number Diff line
@@ -1271,7 +1271,7 @@ public class SubscriptionManager {
        if (!userVisibleOnly || activeList == null) {
        if (!userVisibleOnly || activeList == null) {
            return activeList;
            return activeList;
        } else {
        } else {
            return activeList.stream().filter(subInfo -> !shouldHideSubscription(subInfo))
            return activeList.stream().filter(subInfo -> isSubscriptionVisible(subInfo))
                    .collect(Collectors.toList());
                    .collect(Collectors.toList());
        }
        }
    }
    }
@@ -2877,32 +2877,27 @@ public class SubscriptionManager {
    }
    }


    /**
    /**
     * Whether system UI should hide a subscription. If it's a bundled opportunistic
     * Whether a subscription is visible to API caller. If it's a bundled opportunistic
     * subscription, it shouldn't show up in anywhere in Settings app, dialer app,
     * subscription, it should be hidden anywhere in Settings, dialer, status bar etc.
     * or status bar. Exception is if caller is carrier app, in which case they will
     * Exception is if caller owns carrier privilege, in which case they will
     * want to see their own hidden subscriptions.
     * want to see their own hidden subscriptions.
     *
     *
     * @param info the subscriptionInfo to check against.
     * @param info the subscriptionInfo to check against.
     * @return true if this subscription should be hidden.
     * @return true if this subscription should be visible to the API caller.
     *
     *
     * @hide
     */
     */
    public boolean shouldHideSubscription(SubscriptionInfo info) {
    private boolean isSubscriptionVisible(SubscriptionInfo info) {
        if (info == null) return false;
        if (info == null) return false;


        // If hasCarrierPrivileges or canManageSubscription returns true, it means caller
        // If subscription is NOT grouped opportunistic subscription, it's visible.
        // has carrier privilege.
        if (TextUtils.isEmpty(info.getGroupUuid()) || !info.isOpportunistic()) return true;
        boolean hasCarrierPrivilegePermission = (info.isEmbedded() && canManageSubscription(info))
                || TelephonyManager.from(mContext).hasCarrierPrivileges(info.getSubscriptionId());

        return isInvisibleSubscription(info) && !hasCarrierPrivilegePermission;
    }


    /**
        // If the caller is the carrier app and owns the subscription, it should be visible
     * @hide
        // to the caller.
     */
        boolean hasCarrierPrivilegePermission = TelephonyManager.from(mContext)
    public static boolean isInvisibleSubscription(SubscriptionInfo info) {
                .hasCarrierPrivileges(info.getSubscriptionId())
        return info != null && !TextUtils.isEmpty(info.getGroupUuid()) && info.isOpportunistic();
                || (info.isEmbedded() && canManageSubscription(info));
        return hasCarrierPrivilegePermission;
    }
    }


    /**
    /**
@@ -2930,7 +2925,7 @@ public class SubscriptionManager {
            for (SubscriptionInfo info : availableList) {
            for (SubscriptionInfo info : availableList) {
                // Opportunistic subscriptions are considered invisible
                // Opportunistic subscriptions are considered invisible
                // to users so they should never be returned.
                // to users so they should never be returned.
                if (isInvisibleSubscription(info)) continue;
                if (!isSubscriptionVisible(info)) continue;


                String groupUuid = info.getGroupUuid();
                String groupUuid = info.getGroupUuid();
                if (groupUuid == null) {
                if (groupUuid == null) {
@@ -2952,7 +2947,7 @@ public class SubscriptionManager {
    }
    }


    /**
    /**
     * Enabled or disable a subscription. This is currently used in the settings page.
     * Enables or disables a subscription. This is currently used in the settings page.
     *
     *
     * <p>
     * <p>
     * Permissions android.Manifest.permission.MODIFY_PHONE_STATE is required
     * Permissions android.Manifest.permission.MODIFY_PHONE_STATE is required