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

Commit ba7572d3 authored by Jack Yu's avatar Jack Yu
Browse files

Reset cell broadcast config before enabling all channels

Before cell broadcast config service enabling all channels, it
reset all channels that were previously enabled. This will make
sure the full channel config can be pushed down to modem. This
also solved the issue that channel config not sending to modem
when SIM is swapped. Note that a hidden API is added and will
be unhide in the next Android release.

Also fixed the inconsistent/incorrect permission enforcement
for cell broadcast range enablement.

Fix: 155027085
Test: Manual
Merged-In: I8d84bff9110a62b4464067b85099ee78aec6c9fe
Change-Id: I8d84bff9110a62b4464067b85099ee78aec6c9fe
parent 4f4d7c5c
Loading
Loading
Loading
Loading
+17 −33
Original line number Diff line number Diff line
@@ -24,11 +24,8 @@ import android.Manifest;
import android.app.AppOpsManager;
import android.app.PendingIntent;
import android.compat.annotation.UnsupportedAppUsage;
import android.content.BroadcastReceiver;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.database.Cursor;
import android.database.sqlite.SQLiteException;
@@ -40,11 +37,9 @@ import android.os.Looper;
import android.os.Message;
import android.os.UserManager;
import android.provider.Telephony;
import android.telephony.CarrierConfigManager;
import android.telephony.SmsCbMessage;
import android.telephony.SmsManager;
import android.telephony.SmsMessage;
import android.telephony.SubscriptionManager;
import android.telephony.emergency.EmergencyNumber;
import android.util.LocalLog;
import android.util.Log;
@@ -190,24 +185,6 @@ public class IccSmsInterfaceManager {
        mAppOps = appOps;
        mDispatchersController = dispatchersController;
        mSmsPermissions = new SmsPermissions(phone, context, appOps);

        mContext.registerReceiver(
                new BroadcastReceiver() {
                    @Override
                    public void onReceive(Context context, Intent intent) {
                        if (CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED
                                .equals(intent.getAction())) {
                            if (mPhone.getPhoneId() == intent.getIntExtra(
                                    CarrierConfigManager.EXTRA_SLOT_INDEX,
                                    SubscriptionManager.INVALID_SIM_SLOT_INDEX)) {
                                new Thread(() -> {
                                    log("Carrier config changed. Update ranges.");
                                    mCellBroadcastRangeManager.updateRanges();
                                }).start();
                            }
                        }
                    }
                }, new IntentFilter(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED));
    }

    private void enforceNotOnHandlerThread(String methodName) {
@@ -957,7 +934,7 @@ public class IccSmsInterfaceManager {
    }

    public boolean enableCellBroadcastRange(int startMessageId, int endMessageId, int ranType) {
        mContext.enforceCallingPermission("android.permission.RECEIVE_EMERGENCY_BROADCAST",
        mContext.enforceCallingPermission(android.Manifest.permission.RECEIVE_EMERGENCY_BROADCAST,
                "enabling cell broadcast range [" + startMessageId + "-" + endMessageId + "]. "
                        + "ranType=" + ranType);
        if (ranType == SmsCbMessage.MESSAGE_FORMAT_3GPP) {
@@ -970,7 +947,7 @@ public class IccSmsInterfaceManager {
    }

    public boolean disableCellBroadcastRange(int startMessageId, int endMessageId, int ranType) {
        mContext.enforceCallingPermission("android.permission.RECEIVE_EMERGENCY_BROADCAST",
        mContext.enforceCallingPermission(android.Manifest.permission.RECEIVE_EMERGENCY_BROADCAST,
                "disabling cell broadcast range [" + startMessageId + "-" + endMessageId
                        + "]. ranType=" + ranType);
        if (ranType == SmsCbMessage.MESSAGE_FORMAT_3GPP) {
@@ -985,8 +962,7 @@ public class IccSmsInterfaceManager {
    @UnsupportedAppUsage
    synchronized public boolean enableGsmBroadcastRange(int startMessageId, int endMessageId) {

        mContext.enforceCallingPermission(
                "android.permission.RECEIVE_SMS",
        mContext.enforceCallingPermission(android.Manifest.permission.RECEIVE_EMERGENCY_BROADCAST,
                "Enabling cell broadcast SMS");

        String client = mContext.getPackageManager().getNameForUid(
@@ -1016,8 +992,7 @@ public class IccSmsInterfaceManager {
    @UnsupportedAppUsage
    synchronized public boolean disableGsmBroadcastRange(int startMessageId, int endMessageId) {

        mContext.enforceCallingPermission(
                "android.permission.RECEIVE_SMS",
        mContext.enforceCallingPermission(android.Manifest.permission.RECEIVE_EMERGENCY_BROADCAST,
                "Disabling cell broadcast SMS");

        String client = mContext.getPackageManager().getNameForUid(
@@ -1047,8 +1022,7 @@ public class IccSmsInterfaceManager {
    @UnsupportedAppUsage
    synchronized public boolean enableCdmaBroadcastRange(int startMessageId, int endMessageId) {

        mContext.enforceCallingPermission(
                "android.permission.RECEIVE_SMS",
        mContext.enforceCallingPermission(android.Manifest.permission.RECEIVE_EMERGENCY_BROADCAST,
                "Enabling cdma broadcast SMS");

        String client = mContext.getPackageManager().getNameForUid(
@@ -1077,8 +1051,7 @@ public class IccSmsInterfaceManager {
    @UnsupportedAppUsage
    synchronized public boolean disableCdmaBroadcastRange(int startMessageId, int endMessageId) {

        mContext.enforceCallingPermission(
                "android.permission.RECEIVE_SMS",
        mContext.enforceCallingPermission(android.Manifest.permission.RECEIVE_EMERGENCY_BROADCAST,
                "Disabling cell broadcast SMS");

        String client = mContext.getPackageManager().getNameForUid(
@@ -1104,6 +1077,17 @@ public class IccSmsInterfaceManager {
        return true;
    }

    /**
     * Reset all cell broadcast ranges. Previously enabled ranges will become invalid after this.
     */
    public void resetAllCellBroadcastRanges() {
        mContext.enforceCallingPermission(android.Manifest.permission.RECEIVE_EMERGENCY_BROADCAST,
                "resetAllCellBroadcastRanges");
        mCdmaBroadcastRangeManager.clearRanges();
        mCellBroadcastRangeManager.clearRanges();
        log("Cell broadcast ranges reset.");
    }

    class CellBroadcastRangeManager extends IntRangeManager {
        private ArrayList<SmsBroadcastConfigInfo> mConfigList =
                new ArrayList<SmsBroadcastConfigInfo>();
+7 −0
Original line number Diff line number Diff line
@@ -188,6 +188,13 @@ public abstract class IntRangeManager {

    protected IntRangeManager() {}

    /**
     * Clear all the ranges.
     */
    public synchronized void clearRanges() {
        mRanges.clear();
    }

    /**
     * Enable a range for the specified client and update ranges
     * if necessary. If {@link #finishUpdate} returns failure,
+18 −0
Original line number Diff line number Diff line
@@ -822,4 +822,22 @@ public class SmsController extends ISmsImplBase {
            return 0;
        }
    }

    /**
     * Reset all cell broadcast ranges. Previously enabled ranges will become invalid after this.
     *
     * @param subId Subscription index
     * @return {@code true} if succeeded, otherwise {@code false}.
     */
    @Override
    public boolean resetAllCellBroadcastRanges(int subId) {
        IccSmsInterfaceManager iccSmsIntMgr = getIccSmsInterfaceManager(subId);
        if (iccSmsIntMgr != null) {
            iccSmsIntMgr.resetAllCellBroadcastRanges();
            return true;
        } else {
            Rlog.e(LOG_TAG, "iccSmsIntMgr is null for " + " subId: " + subId);
            return false;
        }
    }
}