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

Commit 75bc6adb authored by Pengquan Meng's avatar Pengquan Meng Committed by Gerrit Code Review
Browse files

Merge "Supported multiple cell broadcast receivers"

parents 90925537 454f7c1c
Loading
Loading
Loading
Loading
+35 −22
Original line number Diff line number Diff line
@@ -45,6 +45,8 @@ public class CellBroadcastHandler extends WakeLockStateMachine {

    private final LocalLog mLocalLog = new LocalLog(100);

    private static final String EXTRA_MESSAGE = "message";

    private CellBroadcastHandler(Context context, Phone phone) {
        this("CellBroadcastHandler", context, phone);
    }
@@ -106,24 +108,10 @@ public class CellBroadcastHandler extends WakeLockStateMachine {
            intent = new Intent(Telephony.Sms.Intents.SMS_EMERGENCY_CB_RECEIVED_ACTION);
            //Emergency alerts need to be delivered with high priority
            intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
            // Explicitly send the intent to the default cell broadcast receiver.
            intent.setPackage(mContext.getResources().getString(
                    com.android.internal.R.string.config_defaultCellBroadcastReceiverPkg));
            receiverPermission = Manifest.permission.RECEIVE_EMERGENCY_BROADCAST;
            appOp = AppOpsManager.OP_RECEIVE_EMERGECY_SMS;
        } else {
            msg = "Dispatching SMS CB, SmsCbMessage is: " + message;
            log(msg);
            mLocalLog.log(msg);
            intent = new Intent(Telephony.Sms.Intents.SMS_CB_RECEIVED_ACTION);
            // Send implicit intent since there are various 3rd party carrier apps listen to
            // this intent.
            intent.addFlags(Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
            receiverPermission = Manifest.permission.RECEIVE_SMS;
            appOp = AppOpsManager.OP_RECEIVE_SMS;
        }

        intent.putExtra("message", message);
            intent.putExtra(EXTRA_MESSAGE, message);
            SubscriptionManager.putPhoneIdAndSubIdExtra(intent, mPhone.getPhoneId());

            if (Build.IS_DEBUGGABLE) {
@@ -135,14 +123,39 @@ public class CellBroadcastHandler extends WakeLockStateMachine {
                    Intent additionalIntent = new Intent(intent);
                    additionalIntent.setPackage(additionalPackage);
                    mContext.sendOrderedBroadcastAsUser(additionalIntent, UserHandle.ALL,
                        receiverPermission, appOp, null, getHandler(), Activity.RESULT_OK, null,
                        null);
                            receiverPermission, appOp, null, getHandler(), Activity.RESULT_OK,
                            null, null);
                }
            }

            String[] pkgs = mContext.getResources().getStringArray(
                    com.android.internal.R.array.config_defaultCellBroadcastReceiverPkgs);
            mReceiverCount.addAndGet(pkgs.length);
            for (String pkg : pkgs) {
                // Explicitly send the intent to all the configured cell broadcast receivers.
                intent.setPackage(pkg);
                mContext.sendOrderedBroadcastAsUser(intent, UserHandle.ALL, receiverPermission,
                        appOp, mReceiver, getHandler(), Activity.RESULT_OK, null, null);
            }
        } else {
            msg = "Dispatching SMS CB, SmsCbMessage is: " + message;
            log(msg);
            mLocalLog.log(msg);
            intent = new Intent(Telephony.Sms.Intents.SMS_CB_RECEIVED_ACTION);
            // Send implicit intent since there are various 3rd party carrier apps listen to
            // this intent.
            intent.addFlags(Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
            receiverPermission = Manifest.permission.RECEIVE_SMS;
            appOp = AppOpsManager.OP_RECEIVE_SMS;

            intent.putExtra(EXTRA_MESSAGE, message);
            SubscriptionManager.putPhoneIdAndSubIdExtra(intent, mPhone.getPhoneId());

            mReceiverCount.incrementAndGet();
            mContext.sendOrderedBroadcastAsUser(intent, UserHandle.ALL, receiverPermission, appOp,
                    mReceiver, getHandler(), Activity.RESULT_OK, null, null);
        }
    }

    @Override
    public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
+7 −1
Original line number Diff line number Diff line
@@ -28,6 +28,8 @@ import android.telephony.Rlog;
import com.android.internal.util.State;
import com.android.internal.util.StateMachine;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * Generic state machine for handling messages and waiting for ordered broadcasts to complete.
 * Subclasses implement {@link #handleSmsMessage}, which returns true to transition into waiting
@@ -55,6 +57,8 @@ public abstract class WakeLockStateMachine extends StateMachine {
    @UnsupportedAppUsage
    protected Context mContext;

    protected AtomicInteger mReceiverCount = new AtomicInteger(0);

    /** Wakelock release delay when returning to idle state. */
    private static final int WAKE_LOCK_TIMEOUT = 3000;

@@ -213,8 +217,10 @@ public abstract class WakeLockStateMachine extends StateMachine {
    protected final BroadcastReceiver mReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            if (mReceiverCount.decrementAndGet() == 0) {
                sendMessage(EVENT_BROADCAST_COMPLETE);
            }
        }
    };

    /**
+13 −6
Original line number Diff line number Diff line
@@ -102,14 +102,19 @@ public final class CdmaServiceCategoryProgramHandler extends WakeLockStateMachin
        }

        Intent intent = new Intent(Intents.SMS_SERVICE_CATEGORY_PROGRAM_DATA_RECEIVED_ACTION);
        intent.setPackage(mContext.getResources().getString(
                com.android.internal.R.string.config_defaultCellBroadcastReceiverPkg));
        intent.putExtra("sender", sms.getOriginatingAddress());
        intent.putParcelableArrayListExtra("program_data", programDataList);
        SubscriptionManager.putPhoneIdAndSubIdExtra(intent, mPhone.getPhoneId());

        String[] pkgs = mContext.getResources().getStringArray(
                com.android.internal.R.array.config_defaultCellBroadcastReceiverPkgs);
        mReceiverCount.addAndGet(pkgs.length);
        for (String pkg : pkgs) {
            intent.setPackage(pkg);
            mContext.sendOrderedBroadcast(intent, Manifest.permission.RECEIVE_SMS,
                    AppOpsManager.OP_RECEIVE_SMS, mScpResultsReceiver,
                    getHandler(), Activity.RESULT_OK, null, null);
        }
        return true;
    }

@@ -122,8 +127,10 @@ public final class CdmaServiceCategoryProgramHandler extends WakeLockStateMachin
        public void onReceive(Context context, Intent intent) {
            sendScpResults();
            if (DBG) log("mScpResultsReceiver finished");
            if (mReceiverCount.decrementAndGet() == 0) {
                sendMessage(EVENT_BROADCAST_COMPLETE);
            }
        }

        private void sendScpResults() {
            int resultCode = getResultCode();
+3 −3
Original line number Diff line number Diff line
@@ -99,9 +99,9 @@ public class GsmCellBroadcastHandlerTest extends TelephonyTest {

    @Ignore
    public void testBroadcastSms() {
        mContextFixture.putResource(
                com.android.internal.R.string.config_defaultCellBroadcastReceiverPkg,
                "fake.cellbroadcastreceiver");
        mContextFixture.putStringArrayResource(
                com.android.internal.R.array.config_defaultCellBroadcastReceiverPkgs,
                new String[]{"fake.cellbroadcastreceiver"});

        Settings.Secure.putString(mContext.getContentResolver(),
                CMAS_ADDITIONAL_BROADCAST_PKG, "another.fake.pkg");