summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYoungtae Cha <youngtaecha@google.com>2022-08-10 01:13:56 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2022-08-10 01:13:56 +0000
commit8bbba7661ad6093198edfa28bd51a2feb49d6501 (patch)
tree3660a132c71cf7b87340db45fc84965d1e953951
parent76cf1785f70929b37f8e337ab6d10db5803be9b1 (diff)
parent078e3b467cc875354673289267d37db5f3789241 (diff)
downloadCellBroadcastReceiver-8bbba7661ad6093198edfa28bd51a2feb49d6501.tar.gz
Merge "Test code for removing FLAG_ONE_SHOT of PendingIntent" into tm-mainline-prod
-rw-r--r--tests/unit/src/com/android/cellbroadcastreceiver/unit/CellBroadcastAlertDialogTest.java59
-rw-r--r--tests/unit/src/com/android/cellbroadcastreceiver/unit/CellBroadcastInternalReceiverTest.java6
2 files changed, 65 insertions, 0 deletions
diff --git a/tests/unit/src/com/android/cellbroadcastreceiver/unit/CellBroadcastAlertDialogTest.java b/tests/unit/src/com/android/cellbroadcastreceiver/unit/CellBroadcastAlertDialogTest.java
index 65f4d1d93..79ce9fb81 100644
--- a/tests/unit/src/com/android/cellbroadcastreceiver/unit/CellBroadcastAlertDialogTest.java
+++ b/tests/unit/src/com/android/cellbroadcastreceiver/unit/CellBroadcastAlertDialogTest.java
@@ -16,6 +16,8 @@
package com.android.cellbroadcastreceiver.unit;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.atLeastOnce;
@@ -24,9 +26,16 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
+import android.app.ActivityManager;
+import android.app.ContentProviderHolder;
+import android.app.IActivityManager;
import android.app.Notification;
import android.app.NotificationManager;
+import android.app.PendingIntent;
+import android.content.IContentProvider;
import android.content.Intent;
+import android.content.pm.ApplicationInfo;
+import android.content.pm.ProviderInfo;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.Bundle;
@@ -38,9 +47,12 @@ import android.os.PowerManager;
import android.telephony.SmsCbMessage;
import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager;
+import android.util.Singleton;
+import android.view.IWindowManager;
import android.view.KeyEvent;
import android.view.View;
import android.view.ViewGroup;
+import android.view.WindowManagerGlobal;
import android.widget.ImageView;
import android.widget.TextView;
@@ -57,6 +69,7 @@ import org.mockito.Captor;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
+import java.lang.reflect.Field;
import java.util.ArrayList;
public class CellBroadcastAlertDialogTest extends
@@ -71,6 +84,15 @@ public class CellBroadcastAlertDialogTest extends
@Mock
private IThermalService.Stub mMockedThermalService;
+ @Mock
+ private IActivityManager.Stub mMockedActivityManager;
+
+ @Mock
+ IWindowManager.Stub mWindowManagerService;
+
+ @Captor
+ private ArgumentCaptor<Integer> mFlags;
+
@Captor
private ArgumentCaptor<Integer> mInt;
@@ -89,6 +111,8 @@ public class CellBroadcastAlertDialogTest extends
private ArrayList<SmsCbMessage> mMessageList;
+ MockedServiceManager mMockedActivityManagerHelper;
+
@Override
protected Intent createActivityIntent() {
mMessageList = new ArrayList<>(1);
@@ -120,11 +144,33 @@ public class CellBroadcastAlertDialogTest extends
SubscriptionInfo mockSubInfo = mock(SubscriptionInfo.class);
doReturn(mockSubInfo).when(mockSubManager).getActiveSubscriptionInfo(anyInt());
+ ProviderInfo providerInfo = new ProviderInfo();
+ providerInfo.authority = "test";
+ providerInfo.applicationInfo = new ApplicationInfo();
+ providerInfo.applicationInfo.uid = 999;
+ ContentProviderHolder holder = new ContentProviderHolder(providerInfo);
+ doReturn(holder).when(mMockedActivityManager)
+ .getContentProvider(any(), any(), any(), anyInt(), anyBoolean());
+ holder.provider = mock(IContentProvider.class);
+
+ Singleton<IActivityManager> activityManagerSingleton = new Singleton<IActivityManager>() {
+ @Override
+ protected IActivityManager create() {
+ return mMockedActivityManager;
+ }
+ };
+
+ mMockedActivityManagerHelper = new MockedServiceManager();
+ mMockedActivityManagerHelper.replaceService("window", mWindowManagerService);
+ mMockedActivityManagerHelper.replaceInstance(ActivityManager.class,
+ "IActivityManagerSingleton", null, activityManagerSingleton);
+
CellBroadcastSettings.resetResourcesCache();
}
@After
public void tearDown() throws Exception {
+ mMockedActivityManagerHelper.restoreAllServices();
super.tearDown();
}
@@ -180,6 +226,19 @@ public class CellBroadcastAlertDialogTest extends
b.getCharSequence(Notification.EXTRA_TITLE).toString()));
assertEquals(CellBroadcastAlertServiceTest.createMessage(98235).getMessageBody(),
b.getCharSequence(Notification.EXTRA_TEXT));
+
+ verify(mMockedActivityManager, times(2))
+ .getIntentSenderWithFeature(anyInt(), any(), any(), any(), any(), anyInt(),
+ any(), any(), mFlags.capture(), any(), anyInt());
+
+ assertTrue((PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE)
+ == mFlags.getAllValues().get(0));
+ assertTrue((PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE)
+ == mFlags.getAllValues().get(1));
+
+ Field field = ((Class) WindowManagerGlobal.class).getDeclaredField("sWindowManagerService");
+ field.setAccessible(true);
+ field.set(null, null);
}
public void testDoNotAddToNotificationOnStop() throws Throwable {
diff --git a/tests/unit/src/com/android/cellbroadcastreceiver/unit/CellBroadcastInternalReceiverTest.java b/tests/unit/src/com/android/cellbroadcastreceiver/unit/CellBroadcastInternalReceiverTest.java
index e89e31f86..7bb0cdef8 100644
--- a/tests/unit/src/com/android/cellbroadcastreceiver/unit/CellBroadcastInternalReceiverTest.java
+++ b/tests/unit/src/com/android/cellbroadcastreceiver/unit/CellBroadcastInternalReceiverTest.java
@@ -32,6 +32,7 @@ import android.os.UserManager;
import com.android.cellbroadcastreceiver.CellBroadcastInternalReceiver;
import com.android.cellbroadcastreceiver.CellBroadcastReceiver;
+import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
@@ -73,4 +74,9 @@ public class CellBroadcastInternalReceiverTest extends CellBroadcastTest {
verify(mReceiver).startConfigServiceToEnableChannels(any());
}
+ @After
+ public void tearDown() throws Exception {
+ super.tearDown();
+ }
+
}