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

Commit badf2b02 authored by chen xu's avatar chen xu
Browse files

notify on all the subIds with carrier privileges

right now we only notify the first matching subId with carrier privilege
for TelephonyRegistry API notifyCarrierNetworkChange. We should notify
all matching subIds.

Bug: 130443663
Test: Manual
Change-Id: I4f64955d2f6e3c70383a3a00407168b9d39a2aa2
parent a23242a4
Loading
Loading
Loading
Loading
+21 −23
Original line number Diff line number Diff line
@@ -66,6 +66,7 @@ import com.android.internal.telephony.PhoneConstantConversions;
import com.android.internal.telephony.PhoneConstants;
import com.android.internal.telephony.TelephonyIntents;
import com.android.internal.telephony.TelephonyPermissions;
import com.android.internal.util.ArrayUtils;
import com.android.internal.util.DumpUtils;
import com.android.internal.util.IndentingPrintWriter;
import com.android.server.am.BatteryStatsService;
@@ -1164,28 +1165,24 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub {

    @Override
    public void notifyCarrierNetworkChange(boolean active) {
        // only CarrierService with carrier privilege rule should have the permission.
        int subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
        try {
            subId = Arrays.stream(SubscriptionManager.from(mContext)
        // only CarrierService with carrier privilege rule should have the permission
        int[] subIds = Arrays.stream(SubscriptionManager.from(mContext)
                    .getActiveSubscriptionIdList())
                    .filter(i -> TelephonyPermissions.checkCarrierPrivilegeForSubId(i))
                    .findFirst().getAsInt();
        } catch (NoSuchElementException ex) {
                    .filter(i -> TelephonyPermissions.checkCarrierPrivilegeForSubId(i)).toArray();
        if (ArrayUtils.isEmpty(subIds)) {
            loge("notifyCarrierNetworkChange without carrier privilege");
        }
            // the active subId does not have carrier privilege.
        if (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
            throw new SecurityException("notifyCarrierNetworkChange without carrier privilege");
        }

        synchronized (mRecords) {
            mCarrierNetworkChangeState = active;
            for (int subId : subIds) {
                int phoneId = SubscriptionManager.getPhoneId(subId);

                if (VDBG) {
                    log("notifyCarrierNetworkChange: active=" + active + "subId: " + subId);
                }

        synchronized (mRecords) {
            mCarrierNetworkChangeState = active;
                for (Record r : mRecords) {
                    if (r.matchPhoneStateListenerEvent(
                            PhoneStateListener.LISTEN_CARRIER_NETWORK_CHANGE) &&
@@ -1197,6 +1194,7 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub {
                        }
                    }
                }
            }
            handleRemoveListLocked();
        }
    }