Benjamin Franz | 563707b | 2017-06-29 15:06:13 +0100 | [diff] [blame] | 1 | /* |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 2 | * Copyright (C) 2018 The Android Open Source Project |
Benjamin Franz | 563707b | 2017-06-29 15:06:13 +0100 | [diff] [blame] | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
Benjamin Franz | 563707b | 2017-06-29 15:06:13 +0100 | [diff] [blame] | 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 14 | * limitations under the License |
Benjamin Franz | 563707b | 2017-06-29 15:06:13 +0100 | [diff] [blame] | 15 | */ |
| 16 | |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 17 | package com.android.server.wm; |
Benjamin Franz | 563707b | 2017-06-29 15:06:13 +0100 | [diff] [blame] | 18 | |
Yuhan Zhao | f3b3d41 | 2020-01-24 23:37:13 +0000 | [diff] [blame] | 19 | import static android.content.pm.ActivityInfo.LOCK_TASK_LAUNCH_MODE_DEFAULT; |
Benjamin Franz | 563707b | 2017-06-29 15:06:13 +0100 | [diff] [blame] | 20 | import static android.content.pm.ApplicationInfo.FLAG_SUSPENDED; |
Suprabh Shukla | 3c3af14 | 2018-03-30 00:28:37 -0700 | [diff] [blame] | 21 | |
Tadashi G. Takaoka | a7a6695 | 2018-11-16 15:04:21 +0900 | [diff] [blame] | 22 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.when; |
Suprabh Shukla | 3c3af14 | 2018-03-30 00:28:37 -0700 | [diff] [blame] | 23 | import static com.android.server.pm.PackageManagerService.PLATFORM_PACKAGE_NAME; |
| 24 | |
Benjamin Franz | 563707b | 2017-06-29 15:06:13 +0100 | [diff] [blame] | 25 | import static org.junit.Assert.assertEquals; |
| 26 | import static org.junit.Assert.assertFalse; |
| 27 | import static org.junit.Assert.assertTrue; |
| 28 | import static org.mockito.ArgumentMatchers.eq; |
| 29 | import static org.mockito.ArgumentMatchers.nullable; |
Benjamin Franz | 563707b | 2017-06-29 15:06:13 +0100 | [diff] [blame] | 30 | |
Wale Ogunwale | 86b7446 | 2018-07-02 08:42:43 -0700 | [diff] [blame] | 31 | import android.app.ActivityManagerInternal; |
Benjamin Franz | 563707b | 2017-06-29 15:06:13 +0100 | [diff] [blame] | 32 | import android.app.KeyguardManager; |
| 33 | import android.app.admin.DevicePolicyManagerInternal; |
| 34 | import android.content.Context; |
| 35 | import android.content.Intent; |
| 36 | import android.content.pm.ActivityInfo; |
| 37 | import android.content.pm.ApplicationInfo; |
Suprabh Shukla | 3c3af14 | 2018-03-30 00:28:37 -0700 | [diff] [blame] | 38 | import android.content.pm.PackageManagerInternal; |
Suprabh Shukla | 389cb6f | 2018-10-01 18:20:39 -0700 | [diff] [blame] | 39 | import android.content.pm.SuspendDialogInfo; |
Benjamin Franz | 563707b | 2017-06-29 15:06:13 +0100 | [diff] [blame] | 40 | import android.content.pm.UserInfo; |
| 41 | import android.os.UserHandle; |
| 42 | import android.os.UserManager; |
Ben Gruver | eb8fd1c | 2018-03-07 13:24:18 -0800 | [diff] [blame] | 43 | import android.platform.test.annotations.Presubmit; |
Adrian Roos | 3150dbf | 2018-03-28 18:06:52 +0200 | [diff] [blame] | 44 | import android.testing.DexmakerShareClassLoaderRule; |
Benjamin Franz | 563707b | 2017-06-29 15:06:13 +0100 | [diff] [blame] | 45 | |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 46 | import androidx.test.filters.SmallTest; |
| 47 | |
Yuhan Zhao | f3b3d41 | 2020-01-24 23:37:13 +0000 | [diff] [blame] | 48 | import com.android.internal.app.BlockedAppActivity; |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 49 | import com.android.internal.app.HarmfulAppWarningActivity; |
Suprabh Shukla | 125c771 | 2018-05-07 17:00:07 -0700 | [diff] [blame] | 50 | import com.android.internal.app.SuspendedAppActivity; |
Benjamin Franz | 563707b | 2017-06-29 15:06:13 +0100 | [diff] [blame] | 51 | import com.android.internal.app.UnlaunchableAppActivity; |
| 52 | import com.android.server.LocalServices; |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 53 | import com.android.server.am.ActivityManagerService; |
Ben Gruver | eb8fd1c | 2018-03-07 13:24:18 -0800 | [diff] [blame] | 54 | import com.android.server.pm.PackageManagerService; |
Benjamin Franz | 563707b | 2017-06-29 15:06:13 +0100 | [diff] [blame] | 55 | |
| 56 | import org.junit.Before; |
Adrian Roos | 3150dbf | 2018-03-28 18:06:52 +0200 | [diff] [blame] | 57 | import org.junit.Rule; |
Benjamin Franz | 563707b | 2017-06-29 15:06:13 +0100 | [diff] [blame] | 58 | import org.junit.Test; |
| 59 | import org.mockito.Mock; |
| 60 | import org.mockito.MockitoAnnotations; |
| 61 | |
| 62 | /** |
| 63 | * Unit tests for {@link ActivityStartInterceptorTest}. |
| 64 | * |
| 65 | * Build/Install/Run: |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 66 | * atest WmTests:ActivityStartInterceptorTest |
Benjamin Franz | 563707b | 2017-06-29 15:06:13 +0100 | [diff] [blame] | 67 | */ |
| 68 | @SmallTest |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 69 | @Presubmit |
Benjamin Franz | 563707b | 2017-06-29 15:06:13 +0100 | [diff] [blame] | 70 | public class ActivityStartInterceptorTest { |
| 71 | private static final int TEST_USER_ID = 1; |
| 72 | private static final int TEST_REAL_CALLING_UID = 2; |
| 73 | private static final int TEST_REAL_CALLING_PID = 3; |
| 74 | private static final String TEST_CALLING_PACKAGE = "com.test.caller"; |
| 75 | private static final int TEST_START_FLAGS = 4; |
| 76 | private static final Intent ADMIN_SUPPORT_INTENT = |
| 77 | new Intent("com.test.ADMIN_SUPPORT"); |
| 78 | private static final Intent CONFIRM_CREDENTIALS_INTENT = |
| 79 | new Intent("com.test.CONFIRM_CREDENTIALS"); |
| 80 | private static final UserInfo PARENT_USER_INFO = new UserInfo(0 /* userId */, "parent", |
| 81 | 0 /* flags */); |
| 82 | private static final String TEST_PACKAGE_NAME = "com.test.package"; |
| 83 | |
Adrian Roos | 3150dbf | 2018-03-28 18:06:52 +0200 | [diff] [blame] | 84 | @Rule |
| 85 | public final DexmakerShareClassLoaderRule mDexmakerShareClassLoaderRule = |
| 86 | new DexmakerShareClassLoaderRule(); |
| 87 | |
Benjamin Franz | 563707b | 2017-06-29 15:06:13 +0100 | [diff] [blame] | 88 | @Mock |
| 89 | private Context mContext; |
| 90 | @Mock |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 91 | private ActivityManagerService mAm; |
| 92 | @Mock |
| 93 | private ActivityTaskManagerService mService; |
Benjamin Franz | 563707b | 2017-06-29 15:06:13 +0100 | [diff] [blame] | 94 | @Mock |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 95 | private RootWindowContainer mRootWindowContainer; |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 96 | @Mock |
Benjamin Franz | 563707b | 2017-06-29 15:06:13 +0100 | [diff] [blame] | 97 | private ActivityStackSupervisor mSupervisor; |
| 98 | @Mock |
| 99 | private DevicePolicyManagerInternal mDevicePolicyManager; |
| 100 | @Mock |
Suprabh Shukla | 3c3af14 | 2018-03-30 00:28:37 -0700 | [diff] [blame] | 101 | private PackageManagerInternal mPackageManagerInternal; |
| 102 | @Mock |
Benjamin Franz | 563707b | 2017-06-29 15:06:13 +0100 | [diff] [blame] | 103 | private UserManager mUserManager; |
| 104 | @Mock |
Benjamin Franz | 563707b | 2017-06-29 15:06:13 +0100 | [diff] [blame] | 105 | private KeyguardManager mKeyguardManager; |
Ben Gruver | eb8fd1c | 2018-03-07 13:24:18 -0800 | [diff] [blame] | 106 | @Mock |
| 107 | private PackageManagerService mPackageManager; |
Wale Ogunwale | 86b7446 | 2018-07-02 08:42:43 -0700 | [diff] [blame] | 108 | @Mock |
| 109 | private ActivityManagerInternal mAmInternal; |
Yuhan Zhao | f3b3d41 | 2020-01-24 23:37:13 +0000 | [diff] [blame] | 110 | @Mock |
| 111 | private LockTaskController mLockTaskController; |
Benjamin Franz | 563707b | 2017-06-29 15:06:13 +0100 | [diff] [blame] | 112 | |
| 113 | private ActivityStartInterceptor mInterceptor; |
| 114 | private ActivityInfo mAInfo = new ActivityInfo(); |
| 115 | |
| 116 | @Before |
| 117 | public void setUp() { |
Benjamin Franz | 563707b | 2017-06-29 15:06:13 +0100 | [diff] [blame] | 118 | MockitoAnnotations.initMocks(this); |
Wale Ogunwale | 86b7446 | 2018-07-02 08:42:43 -0700 | [diff] [blame] | 119 | mService.mAmInternal = mAmInternal; |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 120 | mInterceptor = new ActivityStartInterceptor( |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 121 | mService, mSupervisor, mRootWindowContainer, mContext); |
Benjamin Franz | 563707b | 2017-06-29 15:06:13 +0100 | [diff] [blame] | 122 | mInterceptor.setStates(TEST_USER_ID, TEST_REAL_CALLING_PID, TEST_REAL_CALLING_UID, |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame^] | 123 | TEST_START_FLAGS, TEST_CALLING_PACKAGE, null); |
Benjamin Franz | 563707b | 2017-06-29 15:06:13 +0100 | [diff] [blame] | 124 | |
Wale Ogunwale | 86b7446 | 2018-07-02 08:42:43 -0700 | [diff] [blame] | 125 | // Mock ActivityManagerInternal |
| 126 | LocalServices.removeServiceForTest(ActivityManagerInternal.class); |
| 127 | LocalServices.addService(ActivityManagerInternal.class, mAmInternal); |
| 128 | |
Benjamin Franz | 563707b | 2017-06-29 15:06:13 +0100 | [diff] [blame] | 129 | // Mock DevicePolicyManagerInternal |
| 130 | LocalServices.removeServiceForTest(DevicePolicyManagerInternal.class); |
| 131 | LocalServices.addService(DevicePolicyManagerInternal.class, |
| 132 | mDevicePolicyManager); |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 133 | when(mDevicePolicyManager.createShowAdminSupportIntent(TEST_USER_ID, true)) |
Benjamin Franz | 563707b | 2017-06-29 15:06:13 +0100 | [diff] [blame] | 134 | .thenReturn(ADMIN_SUPPORT_INTENT); |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 135 | when(mService.getPackageManagerInternalLocked()).thenReturn(mPackageManagerInternal); |
Benjamin Franz | 563707b | 2017-06-29 15:06:13 +0100 | [diff] [blame] | 136 | |
| 137 | // Mock UserManager |
| 138 | when(mContext.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager); |
| 139 | when(mUserManager.getProfileParent(TEST_USER_ID)).thenReturn(PARENT_USER_INFO); |
| 140 | |
| 141 | // Mock KeyguardManager |
| 142 | when(mContext.getSystemService(Context.KEYGUARD_SERVICE)).thenReturn(mKeyguardManager); |
| 143 | when(mKeyguardManager.createConfirmDeviceCredentialIntent( |
joshmccloskey | 15c0a44 | 2019-10-18 16:09:06 -0700 | [diff] [blame] | 144 | nullable(CharSequence.class), nullable(CharSequence.class), eq(TEST_USER_ID), |
| 145 | eq(true))).thenReturn(CONFIRM_CREDENTIALS_INTENT); |
Benjamin Franz | 563707b | 2017-06-29 15:06:13 +0100 | [diff] [blame] | 146 | |
Ben Gruver | eb8fd1c | 2018-03-07 13:24:18 -0800 | [diff] [blame] | 147 | // Mock PackageManager |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 148 | when(mService.getPackageManager()).thenReturn(mPackageManager); |
Ben Gruver | eb8fd1c | 2018-03-07 13:24:18 -0800 | [diff] [blame] | 149 | when(mPackageManager.getHarmfulAppWarning(TEST_PACKAGE_NAME, TEST_USER_ID)) |
| 150 | .thenReturn(null); |
| 151 | |
Yuhan Zhao | f3b3d41 | 2020-01-24 23:37:13 +0000 | [diff] [blame] | 152 | // Mock LockTaskController |
| 153 | mAInfo.lockTaskLaunchMode = LOCK_TASK_LAUNCH_MODE_DEFAULT; |
| 154 | when(mService.getLockTaskController()).thenReturn(mLockTaskController); |
| 155 | when(mLockTaskController.isActivityAllowed( |
| 156 | TEST_USER_ID, TEST_PACKAGE_NAME, LOCK_TASK_LAUNCH_MODE_DEFAULT)) |
| 157 | .thenReturn(true); |
| 158 | |
Benjamin Franz | 563707b | 2017-06-29 15:06:13 +0100 | [diff] [blame] | 159 | // Initialise activity info |
Benjamin Franz | 563707b | 2017-06-29 15:06:13 +0100 | [diff] [blame] | 160 | mAInfo.applicationInfo = new ApplicationInfo(); |
Suprabh Shukla | 3c3af14 | 2018-03-30 00:28:37 -0700 | [diff] [blame] | 161 | mAInfo.packageName = mAInfo.applicationInfo.packageName = TEST_PACKAGE_NAME; |
Benjamin Franz | 563707b | 2017-06-29 15:06:13 +0100 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | @Test |
Suprabh Shukla | 3c3af14 | 2018-03-30 00:28:37 -0700 | [diff] [blame] | 165 | public void testSuspendedByAdminPackage() { |
Benjamin Franz | 563707b | 2017-06-29 15:06:13 +0100 | [diff] [blame] | 166 | // GIVEN the package we're about to launch is currently suspended |
| 167 | mAInfo.applicationInfo.flags = FLAG_SUSPENDED; |
| 168 | |
Suprabh Shukla | 3c3af14 | 2018-03-30 00:28:37 -0700 | [diff] [blame] | 169 | when(mPackageManagerInternal.getSuspendingPackage(TEST_PACKAGE_NAME, TEST_USER_ID)) |
| 170 | .thenReturn(PLATFORM_PACKAGE_NAME); |
| 171 | |
Benjamin Franz | 563707b | 2017-06-29 15:06:13 +0100 | [diff] [blame] | 172 | // THEN calling intercept returns true |
| 173 | assertTrue(mInterceptor.intercept(null, null, mAInfo, null, null, 0, 0, null)); |
| 174 | |
| 175 | // THEN the returned intent is the admin support intent |
| 176 | assertEquals(ADMIN_SUPPORT_INTENT, mInterceptor.mIntent); |
| 177 | } |
| 178 | |
| 179 | @Test |
Suprabh Shukla | 125c771 | 2018-05-07 17:00:07 -0700 | [diff] [blame] | 180 | public void testSuspendedPackage() { |
Suprabh Shukla | 125c771 | 2018-05-07 17:00:07 -0700 | [diff] [blame] | 181 | final String suspendingPackage = "com.test.suspending.package"; |
Louis Chang | 97f743f | 2019-11-26 13:03:10 +0800 | [diff] [blame] | 182 | final SuspendDialogInfo dialogInfo = suspendPackage(suspendingPackage); |
Suprabh Shukla | 125c771 | 2018-05-07 17:00:07 -0700 | [diff] [blame] | 183 | // THEN calling intercept returns true |
| 184 | assertTrue(mInterceptor.intercept(null, null, mAInfo, null, null, 0, 0, null)); |
| 185 | |
| 186 | // Check intent parameters |
Suprabh Shukla | 389cb6f | 2018-10-01 18:20:39 -0700 | [diff] [blame] | 187 | assertEquals(dialogInfo, |
| 188 | mInterceptor.mIntent.getParcelableExtra(SuspendedAppActivity.EXTRA_DIALOG_INFO)); |
Suprabh Shukla | 125c771 | 2018-05-07 17:00:07 -0700 | [diff] [blame] | 189 | assertEquals(suspendingPackage, |
| 190 | mInterceptor.mIntent.getStringExtra(SuspendedAppActivity.EXTRA_SUSPENDING_PACKAGE)); |
| 191 | assertEquals(TEST_PACKAGE_NAME, |
| 192 | mInterceptor.mIntent.getStringExtra(SuspendedAppActivity.EXTRA_SUSPENDED_PACKAGE)); |
| 193 | assertEquals(TEST_USER_ID, mInterceptor.mIntent.getIntExtra(Intent.EXTRA_USER_ID, -1000)); |
| 194 | } |
| 195 | |
Louis Chang | 97f743f | 2019-11-26 13:03:10 +0800 | [diff] [blame] | 196 | private SuspendDialogInfo suspendPackage(String suspendingPackage) { |
| 197 | mAInfo.applicationInfo.flags = FLAG_SUSPENDED; |
| 198 | final SuspendDialogInfo dialogInfo = new SuspendDialogInfo.Builder() |
| 199 | .setMessage("Test Message") |
| 200 | .setIcon(0x11110001) |
| 201 | .build(); |
| 202 | when(mPackageManagerInternal.getSuspendingPackage(TEST_PACKAGE_NAME, TEST_USER_ID)) |
| 203 | .thenReturn(suspendingPackage); |
| 204 | when(mPackageManagerInternal.getSuspendedDialogInfo(TEST_PACKAGE_NAME, suspendingPackage, |
| 205 | TEST_USER_ID)).thenReturn(dialogInfo); |
| 206 | return dialogInfo; |
| 207 | } |
| 208 | |
Suprabh Shukla | 125c771 | 2018-05-07 17:00:07 -0700 | [diff] [blame] | 209 | @Test |
Yuhan Zhao | f3b3d41 | 2020-01-24 23:37:13 +0000 | [diff] [blame] | 210 | public void testInterceptLockTaskModeViolationPackage() { |
| 211 | when(mLockTaskController.isActivityAllowed( |
| 212 | TEST_USER_ID, TEST_PACKAGE_NAME, LOCK_TASK_LAUNCH_MODE_DEFAULT)) |
| 213 | .thenReturn(false); |
| 214 | |
| 215 | assertTrue(mInterceptor.intercept(null, null, mAInfo, null, null, 0, 0, null)); |
| 216 | |
| 217 | assertTrue(BlockedAppActivity.createIntent(TEST_USER_ID, TEST_PACKAGE_NAME) |
| 218 | .filterEquals(mInterceptor.mIntent)); |
| 219 | } |
| 220 | |
| 221 | @Test |
Benjamin Franz | 563707b | 2017-06-29 15:06:13 +0100 | [diff] [blame] | 222 | public void testInterceptQuietProfile() { |
| 223 | // GIVEN that the user the activity is starting as is currently in quiet mode |
| 224 | when(mUserManager.isQuietModeEnabled(eq(UserHandle.of(TEST_USER_ID)))).thenReturn(true); |
| 225 | |
| 226 | // THEN calling intercept returns true |
| 227 | assertTrue(mInterceptor.intercept(null, null, mAInfo, null, null, 0, 0, null)); |
| 228 | |
| 229 | // THEN the returned intent is the quiet mode intent |
| 230 | assertTrue(UnlaunchableAppActivity.createInQuietModeDialogIntent(TEST_USER_ID) |
| 231 | .filterEquals(mInterceptor.mIntent)); |
| 232 | } |
| 233 | |
| 234 | @Test |
Louis Chang | 97f743f | 2019-11-26 13:03:10 +0800 | [diff] [blame] | 235 | public void testInterceptQuietProfileWhenPackageSuspended() { |
| 236 | suspendPackage("com.test.suspending.package"); |
| 237 | // GIVEN that the user the activity is starting as is currently in quiet mode |
| 238 | when(mUserManager.isQuietModeEnabled(eq(UserHandle.of(TEST_USER_ID)))).thenReturn(true); |
| 239 | |
| 240 | // THEN calling intercept returns true |
| 241 | assertTrue(mInterceptor.intercept(null, null, mAInfo, null, null, 0, 0, null)); |
| 242 | |
| 243 | // THEN the returned intent is the quiet mode intent |
| 244 | assertTrue(UnlaunchableAppActivity.createInQuietModeDialogIntent(TEST_USER_ID) |
| 245 | .filterEquals(mInterceptor.mIntent)); |
| 246 | } |
| 247 | |
| 248 | @Test |
Benjamin Franz | 563707b | 2017-06-29 15:06:13 +0100 | [diff] [blame] | 249 | public void testWorkChallenge() { |
| 250 | // GIVEN that the user the activity is starting as is currently locked |
Wale Ogunwale | 86b7446 | 2018-07-02 08:42:43 -0700 | [diff] [blame] | 251 | when(mAmInternal.shouldConfirmCredentials(TEST_USER_ID)).thenReturn(true); |
Benjamin Franz | 563707b | 2017-06-29 15:06:13 +0100 | [diff] [blame] | 252 | |
| 253 | // THEN calling intercept returns true |
| 254 | mInterceptor.intercept(null, null, mAInfo, null, null, 0, 0, null); |
| 255 | |
| 256 | // THEN the returned intent is the quiet mode intent |
| 257 | assertTrue(CONFIRM_CREDENTIALS_INTENT.filterEquals(mInterceptor.mIntent)); |
| 258 | } |
| 259 | |
| 260 | @Test |
Ben Gruver | 4982873 | 2018-03-07 14:20:37 -0800 | [diff] [blame] | 261 | public void testHarmfulAppWarning() { |
| 262 | // GIVEN the package we're about to launch has a harmful app warning set |
| 263 | when(mPackageManager.getHarmfulAppWarning(TEST_PACKAGE_NAME, TEST_USER_ID)) |
| 264 | .thenReturn("This app is bad"); |
| 265 | |
| 266 | // THEN calling intercept returns true |
| 267 | assertTrue(mInterceptor.intercept(null, null, mAInfo, null, null, 0, 0, null)); |
| 268 | |
| 269 | // THEN the returned intent is the harmful app warning intent |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 270 | assertEquals(HarmfulAppWarningActivity.class.getName(), |
| 271 | mInterceptor.mIntent.getComponent().getClassName()); |
Ben Gruver | 4982873 | 2018-03-07 14:20:37 -0800 | [diff] [blame] | 272 | } |
| 273 | |
| 274 | @Test |
Benjamin Franz | 563707b | 2017-06-29 15:06:13 +0100 | [diff] [blame] | 275 | public void testNoInterception() { |
| 276 | // GIVEN that none of the interception conditions are met |
| 277 | |
| 278 | // THEN calling intercept returns false |
| 279 | assertFalse(mInterceptor.intercept(null, null, mAInfo, null, null, 0, 0, null)); |
| 280 | } |
| 281 | } |