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

Commit 574370b4 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Send CMAS broadcast to additional package"

parents 029e2678 252459db
Loading
Loading
Loading
Loading
+15 −12
Original line number Diff line number Diff line
@@ -16,14 +16,17 @@

package com.android.internal.telephony;

import static android.provider.Settings.Secure.CMAS_ADDITIONAL_BROADCAST_PKG;

import android.Manifest;
import android.app.Activity;
import android.app.AppOpsManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.Message;
import android.os.UserHandle;
import android.provider.Settings;
import android.provider.Telephony;
import android.telephony.SmsCbMessage;
import android.telephony.SubscriptionManager;
@@ -92,21 +95,21 @@ public class CellBroadcastHandler extends WakeLockStateMachine {
            appOp = AppOpsManager.OP_RECEIVE_SMS;
        }
        // explicitly send it to the default cell broadcast receiver only.
        intent.setComponent(getDefaultCellBroadcastReceiverApp(mContext));
        intent.setPackage(mContext.getResources().getString(
                com.android.internal.R.string.config_defaultCellBroadcastReceiverPkg));
        intent.putExtra("message", message);
        SubscriptionManager.putPhoneIdAndSubIdExtra(intent, mPhone.getPhoneId());
        mContext.sendOrderedBroadcastAsUser(intent, UserHandle.ALL, receiverPermission, appOp,
                mReceiver, getHandler(), Activity.RESULT_OK, null, null);
    }

    /**
     * Get the default cell broadcast receiver component name.
     * @param context Device context
     * @return Component name of the default cell broadcast receiver
     */
    public static ComponentName getDefaultCellBroadcastReceiverApp(Context context) {
        String defaultCellBroadcastReceiver = context.getResources().getString(
                com.android.internal.R.string.config_defaultCellBroadcastReceiverComponent);
        return ComponentName.unflattenFromString(defaultCellBroadcastReceiver);
        if (Build.IS_DEBUGGABLE) {
            String additionalPackage = Settings.Secure.getString(mContext.getContentResolver(),
                    CMAS_ADDITIONAL_BROADCAST_PKG);
            if (additionalPackage != null) {
                intent.setPackage(additionalPackage);
                mContext.sendOrderedBroadcastAsUser(intent, UserHandle.ALL, receiverPermission,
                        appOp, mReceiver, getHandler(), Activity.RESULT_OK, null, null);
            }
        }
    }
}
+2 −2
Original line number Diff line number Diff line
@@ -30,7 +30,6 @@ import android.telephony.SubscriptionManager;
import android.telephony.cdma.CdmaSmsCbProgramData;
import android.telephony.cdma.CdmaSmsCbProgramResults;

import com.android.internal.telephony.CellBroadcastHandler;
import com.android.internal.telephony.CommandsInterface;
import com.android.internal.telephony.WakeLockStateMachine;
import com.android.internal.telephony.cdma.sms.BearerData;
@@ -103,7 +102,8 @@ public final class CdmaServiceCategoryProgramHandler extends WakeLockStateMachin
        }

        Intent intent = new Intent(Intents.SMS_SERVICE_CATEGORY_PROGRAM_DATA_RECEIVED_ACTION);
        intent.setComponent(CellBroadcastHandler.getDefaultCellBroadcastReceiverApp(mContext));
        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());
+37 −9
Original line number Diff line number Diff line
@@ -16,14 +16,26 @@

package com.android.internal.telephony.gsm;

import static org.junit.Assert.assertTrue;
import static android.provider.Settings.Secure.CMAS_ADDITIONAL_BROADCAST_PKG;

import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.anyBoolean;
import static org.mockito.Mockito.anyInt;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;

import android.Manifest;
import android.app.Activity;
import android.app.AppOpsManager;
import android.content.BroadcastReceiver;
import android.content.Intent;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.UserHandle;
import android.provider.Settings;
import android.provider.Telephony;
import android.test.suitebuilder.annotation.SmallTest;

@@ -37,6 +49,8 @@ import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;

import java.util.List;

public class GsmCellBroadcastHandlerTest extends TelephonyTest {
    @Mock
    private SmsStorageMonitor mSmsStorageMonitor;
@@ -86,8 +100,11 @@ public class GsmCellBroadcastHandlerTest extends TelephonyTest {
    @Test @SmallTest
    public void testBroadcastSms() {
        mContextFixture.putResource(
                com.android.internal.R.string.config_defaultCellBroadcastReceiverComponent,
                "fake.cellbroadcastreceiver.component");
                com.android.internal.R.string.config_defaultCellBroadcastReceiverPkg,
                "fake.cellbroadcastreceiver");

        Settings.Secure.putString(mContext.getContentResolver(),
                CMAS_ADDITIONAL_BROADCAST_PKG, "another.fake.pkg");
        mSimulatedCommands.notifyGsmBroadcastSms(new byte[] {
                (byte)0xc0, //geographical scope
                (byte)0x01, //serial number
@@ -96,12 +113,23 @@ public class GsmCellBroadcastHandlerTest extends TelephonyTest {
                (byte)0x01, //message identifier
                (byte)0x01
        });
        TelephonyTestUtils.waitForMs(50);
        TelephonyTestUtils.waitForMs(100);
        ArgumentCaptor<Intent> intentArgumentCaptor = ArgumentCaptor.forClass(Intent.class);
        verify(mContextFixture.getTestDouble()).sendBroadcast(intentArgumentCaptor.capture());
        assertTrue(intentArgumentCaptor.getValue().getAction().equals(
                Telephony.Sms.Intents.SMS_EMERGENCY_CB_RECEIVED_ACTION) ||
                intentArgumentCaptor.getValue().getAction().equals(
                        Telephony.Sms.Intents.SMS_CB_RECEIVED_ACTION));
        verify(mContextFixture.getTestDouble(), times(2)).sendOrderedBroadcastAsUser(
                intentArgumentCaptor.capture(), eq(UserHandle.ALL),
                eq(Manifest.permission.RECEIVE_SMS), eq(AppOpsManager.OP_RECEIVE_SMS),
                any(BroadcastReceiver.class), any(Handler.class), eq(Activity.RESULT_OK), eq(null),
                eq(null));

        List<Intent> intentList = intentArgumentCaptor.getAllValues();

        assertEquals(Telephony.Sms.Intents.SMS_CB_RECEIVED_ACTION,
                intentList.get(0).getAction());
        // TODO: uncomment the following once ArgumentCaptor's bug is fixed.
        // assertEquals("fake.cellbroadcastreceiver", intentList.get(0).getPackage());

        assertEquals(Telephony.Sms.Intents.SMS_CB_RECEIVED_ACTION,
                intentList.get(1).getAction());
        assertEquals("another.fake.pkg", intentList.get(0).getPackage());
    }
}