[Safer intents] Applications

To avoid implicit intents, make intents launch explicitly.

Test: build, robotest
Bug: 323061508
Change-Id: I9bf4eb102550f4afd8d14a6799940d37fc0ab9a7
This commit is contained in:
Jason Chiu
2024-03-27 11:49:33 +08:00
parent 9ab22c28fb
commit 071dfe8691
7 changed files with 22 additions and 3 deletions

View File

@@ -22,7 +22,9 @@ import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.nullable;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -30,6 +32,7 @@ import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import androidx.preference.Preference;
@@ -55,6 +58,7 @@ public class TimeSpentInAppPreferenceControllerTest {
private static final String TEST_KEY = "test_tey";
private static final Intent TEST_INTENT = new Intent(
TimeSpentInAppPreferenceController.SEE_TIME_IN_APP_TEMPLATE)
.setPackage("com.wellbeing")
.putExtra(EXTRA_PACKAGE_NAME, "com.android.settings");
@Mock
@@ -70,8 +74,11 @@ public class TimeSpentInAppPreferenceControllerTest {
public void setUp() {
MockitoAnnotations.initMocks(this);
mFeatureFactory = FakeFeatureFactory.setupForTest();
mContext = RuntimeEnvironment.application;
mPackageManager = Shadows.shadowOf(mContext.getPackageManager());
mContext = spy(RuntimeEnvironment.application);
PackageManager pm = spy(mContext.getPackageManager());
doReturn(pm).when(mContext).getPackageManager();
doReturn(TEST_INTENT.getPackage()).when(pm).getWellbeingPackageName();
mPackageManager = Shadows.shadowOf(pm);
mController = new TimeSpentInAppPreferenceController(mContext, TEST_KEY);
mPreference = new Preference(mContext);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);