- adding support for more intent actions
- use ApplicationsState in application settings, that's what other settings app use

Bug: 120040741

Test: verified on head unit
Change-Id: I5298d35f2c8efdd2c38b300e5e160ffd7d530f99
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index bfe09c4..14c8c7f 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -91,6 +91,11 @@
             </intent-filter>
 
             <intent-filter android:priority="1">
+                <action android:name="android.settings.NIGHT_DISPLAY_SETTINGS" />
+                <category android:name="android.intent.category.DEFAULT" />
+            </intent-filter>
+
+            <intent-filter android:priority="1">
                 <action android:name="android.settings.USER_SETTINGS" />
                 <category android:name="android.intent.category.DEFAULT" />
             </intent-filter>
@@ -101,6 +106,16 @@
             </intent-filter>
 
             <intent-filter android:priority="1">
+                <action android:name="android.settings.DEVICE_INFO_SETTINGS" />
+                <category android:name="android.intent.category.DEFAULT" />
+            </intent-filter>
+
+            <intent-filter android:priority="1">
+                <action android:name="android.settings.APPLICATION_DETAILS_SETTINGS" />
+                <category android:name="android.intent.category.DEFAULT" />
+            </intent-filter>
+
+            <intent-filter android:priority="1">
                 <action android:name="android.settings.DATE_SETTINGS" />
                 <category android:name="android.intent.category.DEFAULT" />
             </intent-filter>
diff --git a/src/com/android/car/settings/applications/ApplicationDetailsFragment.java b/src/com/android/car/settings/applications/ApplicationDetailsFragment.java
index 3ad17df..446563b 100644
--- a/src/com/android/car/settings/applications/ApplicationDetailsFragment.java
+++ b/src/com/android/car/settings/applications/ApplicationDetailsFragment.java
@@ -25,7 +25,6 @@
 import android.content.pm.ApplicationInfo;
 import android.content.pm.PackageInfo;
 import android.content.pm.PackageManager;
-import android.content.pm.ResolveInfo;
 import android.net.Uri;
 import android.os.Bundle;
 import android.os.UserHandle;
@@ -39,6 +38,7 @@
 import com.android.car.settings.common.Logger;
 import com.android.car.settings.common.SettingsFragment;
 import com.android.settingslib.Utils;
+import com.android.settingslib.applications.ApplicationsState;
 
 import java.text.MessageFormat;
 
@@ -48,20 +48,20 @@
  */
 public class ApplicationDetailsFragment extends SettingsFragment {
     private static final Logger LOG = new Logger(ApplicationDetailsFragment.class);
-    public static final String EXTRA_RESOLVE_INFO = "extra_resolve_info";
+    public static final String EXTRA_PACKAGE_NAME = "extra_package_name";
 
-    private ResolveInfo mResolveInfo;
+    private String mPackageName;
     private PackageInfo mPackageInfo;
 
     private Button mDisableToggle;
     private Button mForceStopButton;
     private DevicePolicyManager mDpm;
 
-    /** Creates an instance of this fragment, passing resolveInfo as an argument. */
-    public static ApplicationDetailsFragment getInstance(ResolveInfo resolveInfo) {
+    /** Creates an instance of this fragment, passing packageName as an argument. */
+    public static ApplicationDetailsFragment getInstance(String packageName) {
         ApplicationDetailsFragment applicationDetailFragment = new ApplicationDetailsFragment();
         Bundle bundle = new Bundle();
-        bundle.putParcelable(EXTRA_RESOLVE_INFO, resolveInfo);
+        bundle.putString(EXTRA_PACKAGE_NAME, packageName);
         applicationDetailFragment.setArguments(bundle);
         return applicationDetailFragment;
     }
@@ -83,12 +83,18 @@
         super.onAttach(context);
 
         // These should be loaded before onCreate() so that the controller operates as expected.
-        mResolveInfo = getArguments().getParcelable(EXTRA_RESOLVE_INFO);
+        mPackageName = getArguments().getString(EXTRA_PACKAGE_NAME);
         mPackageInfo = getPackageInfo();
+        ApplicationsState applicationsState =
+                ApplicationsState.getInstance(getActivity().getApplication());
+        ApplicationsState.AppEntry appEntry =
+                applicationsState.getEntry(mPackageName, UserHandle.myUserId());
+
         use(ApplicationPreferenceController.class,
-                R.string.pk_application_details_app).setResolveInfo(mResolveInfo);
+                R.string.pk_application_details_app)
+                        .setAppEntry(appEntry).setAppState(applicationsState);
         use(PermissionsPreferenceController.class,
-                R.string.pk_application_details_permissions).setResolveInfo(mResolveInfo);
+                R.string.pk_application_details_permissions).setPackageName(mPackageName);
         use(VersionPreferenceController.class,
                 R.string.pk_application_details_version).setPackageInfo(mPackageInfo);
     }
@@ -96,7 +102,7 @@
     @Override
     public void onActivityCreated(Bundle savedInstanceState) {
         super.onActivityCreated(savedInstanceState);
-        if (mResolveInfo == null) {
+        if (mPackageName == null) {
             LOG.w("No application info set.");
             return;
         }
@@ -109,7 +115,7 @@
         mDpm = (DevicePolicyManager) getContext().getSystemService(Context.DEVICE_POLICY_SERVICE);
         updateForceStopButton();
         mForceStopButton.setOnClickListener(
-                v -> forceStopPackage(mResolveInfo.activityInfo.packageName));
+                v -> forceStopPackage(mPackageName));
     }
 
     @Override
@@ -122,20 +128,18 @@
     // fetch the latest ApplicationInfo instead of caching it so it reflects the current state.
     private ApplicationInfo getAppInfo() {
         try {
-            return getContext().getPackageManager().getApplicationInfo(
-                    mResolveInfo.activityInfo.packageName, 0 /* flag */);
+            return getContext().getPackageManager().getApplicationInfo(mPackageName, 0 /* flag */);
         } catch (PackageManager.NameNotFoundException e) {
-            LOG.e("incorrect packagename: " + mResolveInfo.activityInfo.packageName, e);
+            LOG.e("incorrect packagename: " + mPackageName, e);
             throw new IllegalArgumentException(e);
         }
     }
 
     private PackageInfo getPackageInfo() {
         try {
-            return getContext().getPackageManager().getPackageInfo(
-                    mResolveInfo.activityInfo.packageName, 0 /* flag */);
+            return getContext().getPackageManager().getPackageInfo(mPackageName, 0 /* flag */);
         } catch (PackageManager.NameNotFoundException e) {
-            LOG.e("incorrect packagename: " + mResolveInfo.activityInfo.packageName, e);
+            LOG.e("incorrect packagename: " + mPackageName, e);
             throw new IllegalArgumentException(e);
         }
     }
@@ -165,7 +169,7 @@
                 : PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER;
         mDisableToggle.setOnClickListener(v -> {
             getContext().getPackageManager().setApplicationEnabledSetting(
-                    mResolveInfo.activityInfo.packageName,
+                    mPackageName,
                     enableState,
                     0);
             updateDisableable();
@@ -191,7 +195,7 @@
     // - if there's a reason for the system to restart the application, that indicates the app
     //   can be force stopped.
     private void updateForceStopButton() {
-        if (mDpm.packageHasActiveAdmins(mResolveInfo.activityInfo.packageName)) {
+        if (mDpm.packageHasActiveAdmins(mPackageName)) {
             // User can't force stop device admin.
             LOG.d("Disabling button, user can't force stop device admin");
             mForceStopButton.setEnabled(false);
@@ -202,12 +206,11 @@
             mForceStopButton.setEnabled(true);
         } else {
             Intent intent = new Intent(Intent.ACTION_QUERY_PACKAGE_RESTART,
-                    Uri.fromParts("package", mResolveInfo.activityInfo.packageName, null));
+                    Uri.fromParts("package", mPackageName, null));
             intent.putExtra(Intent.EXTRA_PACKAGES, new String[]{
-                    mResolveInfo.activityInfo.packageName
+                    mPackageName
             });
-            LOG.d("Sending broadcast to query restart for "
-                    + mResolveInfo.activityInfo.packageName);
+            LOG.d("Sending broadcast to query restart for " + mPackageName);
             getActivity().sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT, null,
                     mCheckKillProcessesReceiver, null, Activity.RESULT_CANCELED, null, null);
         }
@@ -218,7 +221,7 @@
         public void onReceive(Context context, Intent intent) {
             final boolean enabled = getResultCode() != Activity.RESULT_CANCELED;
             LOG.d(MessageFormat.format("Got broadcast response: Restart status for {0} {1}",
-                    mResolveInfo.activityInfo.packageName, enabled));
+                    mPackageName, enabled));
             mForceStopButton.setEnabled(enabled);
         }
     };
diff --git a/src/com/android/car/settings/applications/ApplicationPreferenceController.java b/src/com/android/car/settings/applications/ApplicationPreferenceController.java
index 4507ea3..bd9dcf0 100644
--- a/src/com/android/car/settings/applications/ApplicationPreferenceController.java
+++ b/src/com/android/car/settings/applications/ApplicationPreferenceController.java
@@ -18,24 +18,24 @@
 
 import android.car.drivingstate.CarUxRestrictions;
 import android.content.Context;
-import android.content.pm.PackageManager;
-import android.content.pm.ResolveInfo;
+import android.graphics.drawable.Drawable;
 
 import androidx.preference.Preference;
 
 import com.android.car.settings.common.FragmentController;
 import com.android.car.settings.common.PreferenceController;
+import com.android.settingslib.applications.ApplicationsState;
+import com.android.settingslib.applications.ApplicationsState.AppEntry;
 
 /** Business logic for the Application field in the application details page. */
 public class ApplicationPreferenceController extends PreferenceController<Preference> {
 
-    private PackageManager mPackageManager;
-    private ResolveInfo mResolveInfo;
+    private AppEntry mAppEntry;
+    private ApplicationsState mApplicationsState;
 
     public ApplicationPreferenceController(Context context, String preferenceKey,
             FragmentController fragmentController, CarUxRestrictions uxRestrictions) {
         super(context, preferenceKey, fragmentController, uxRestrictions);
-        mPackageManager = context.getPackageManager();
     }
 
     @Override
@@ -43,22 +43,40 @@
         return Preference.class;
     }
 
-    /** Sets the resolve info which is used to load the app name and icon. */
-    public void setResolveInfo(ResolveInfo resolveInfo) {
-        mResolveInfo = resolveInfo;
+    /** Sets the {@link AppEntry} which is used to load the app name and icon. */
+    public ApplicationPreferenceController setAppEntry(AppEntry appEntry) {
+        mAppEntry = appEntry;
+        return this;
     }
 
+    /** Sets the {@link ApplicationsState} which is used to load the app name and icon. */
+    public ApplicationPreferenceController setAppState(ApplicationsState applicationsState) {
+        mApplicationsState = applicationsState;
+        return this;
+    }
+
+
     @Override
     protected void checkInitialized() {
-        if (mResolveInfo == null) {
+        if (mAppEntry == null || mApplicationsState == null) {
             throw new IllegalStateException(
-                    "ResolveInfo should be set before calling this function");
+                    "AppEntry and AppState should be set before calling this function");
         }
     }
 
     @Override
     protected void updateState(Preference preference) {
-        preference.setTitle(mResolveInfo.loadLabel(mPackageManager));
-        preference.setIcon(mResolveInfo.loadIcon(mPackageManager));
+        preference.setTitle(getAppName());
+        preference.setIcon(getAppIcon());
+    }
+
+    private String getAppName() {
+        mAppEntry.ensureLabel(getContext());
+        return mAppEntry.label;
+    }
+
+    private Drawable getAppIcon() {
+        mApplicationsState.ensureIcon(mAppEntry);
+        return mAppEntry.icon;
     }
 }
diff --git a/src/com/android/car/settings/applications/ApplicationsSettingsPreferenceController.java b/src/com/android/car/settings/applications/ApplicationsSettingsPreferenceController.java
index 6e166d1..76aa5eb 100644
--- a/src/com/android/car/settings/applications/ApplicationsSettingsPreferenceController.java
+++ b/src/com/android/car/settings/applications/ApplicationsSettingsPreferenceController.java
@@ -84,7 +84,7 @@
         preference.setIcon(resolveInfo.loadIcon(mPackageManager));
         preference.setOnPreferenceClickListener((p) -> {
             getFragmentController().launchFragment(
-                    ApplicationDetailsFragment.getInstance(resolveInfo));
+                    ApplicationDetailsFragment.getInstance(resolveInfo.activityInfo.packageName));
             return true;
         });
         return preference;
diff --git a/src/com/android/car/settings/applications/PermissionsPreferenceController.java b/src/com/android/car/settings/applications/PermissionsPreferenceController.java
index 246ae0d..8498f5c 100644
--- a/src/com/android/car/settings/applications/PermissionsPreferenceController.java
+++ b/src/com/android/car/settings/applications/PermissionsPreferenceController.java
@@ -20,7 +20,6 @@
 import android.content.ActivityNotFoundException;
 import android.content.Context;
 import android.content.Intent;
-import android.content.pm.ResolveInfo;
 import android.content.res.Resources;
 import android.icu.text.ListFormatter;
 import android.text.TextUtils;
@@ -41,7 +40,7 @@
 
     private static final Logger LOG = new Logger(PermissionsPreferenceController.class);
 
-    private ResolveInfo mResolveInfo;
+    private String mPackageName;
     private String mSummary;
 
     public PermissionsPreferenceController(Context context, String preferenceKey,
@@ -55,18 +54,18 @@
     }
 
     /**
-     * Set the resolve info, which is used to find the package name to open the permissions
+     * Set the packageName, which is used on the intent to open the permissions
      * selection screen.
      */
-    public void setResolveInfo(ResolveInfo resolveInfo) {
-        mResolveInfo = resolveInfo;
+    public void setPackageName(String packageName) {
+        mPackageName = packageName;
     }
 
     @Override
     protected void checkInitialized() {
-        if (mResolveInfo == null) {
+        if (mPackageName == null) {
             throw new IllegalStateException(
-                    "ResolveInfo should be set before calling this function");
+                    "PackageName should be set before calling this function");
         }
     }
 
@@ -74,15 +73,15 @@
     protected void updateState(Preference preference) {
         // This call needs to be here, not onCreate, so that the summary is updated every time
         // the preference is displayed.
-        PermissionsSummaryHelper.getPermissionSummary(getContext(),
-                mResolveInfo.activityInfo.packageName, mPermissionCallback);
+        PermissionsSummaryHelper.getPermissionSummary(
+                getContext(), mPackageName, mPermissionCallback);
         preference.setSummary(getSummary());
     }
 
     @Override
     protected boolean handlePreferenceClicked(Preference preference) {
         Intent intent = new Intent(Intent.ACTION_MANAGE_APP_PERMISSIONS);
-        intent.putExtra(Intent.EXTRA_PACKAGE_NAME, mResolveInfo.activityInfo.packageName);
+        intent.putExtra(Intent.EXTRA_PACKAGE_NAME, mPackageName);
         try {
             getContext().startActivity(intent);
         } catch (ActivityNotFoundException e) {
diff --git a/src/com/android/car/settings/common/CarSettingActivity.java b/src/com/android/car/settings/common/CarSettingActivity.java
index 50ff347..154e27d 100644
--- a/src/com/android/car/settings/common/CarSettingActivity.java
+++ b/src/com/android/car/settings/common/CarSettingActivity.java
@@ -85,7 +85,7 @@
     protected void onResume() {
         super.onResume();
         if (mHasNewIntent) {
-            Fragment fragment = FragmentResolver.getFragmentForAction(getIntent().getAction());
+            Fragment fragment = FragmentResolver.getFragmentForIntent(getIntent());
             launchIfDifferent(fragment);
             mHasNewIntent = false;
         }
diff --git a/src/com/android/car/settings/common/FragmentResolver.java b/src/com/android/car/settings/common/FragmentResolver.java
index 39d2b45..8148d94 100644
--- a/src/com/android/car/settings/common/FragmentResolver.java
+++ b/src/com/android/car/settings/common/FragmentResolver.java
@@ -15,6 +15,8 @@
  */
 package com.android.car.settings.common;
 
+import android.content.Intent;
+import android.net.Uri;
 import android.provider.Settings;
 
 import androidx.annotation.Nullable;
@@ -22,12 +24,15 @@
 
 import com.android.car.settings.accounts.AccountSettingsFragment;
 import com.android.car.settings.accounts.ChooseAccountFragment;
+import com.android.car.settings.applications.ApplicationDetailsFragment;
 import com.android.car.settings.applications.ApplicationsSettingsFragment;
 import com.android.car.settings.bluetooth.BluetoothSettingsFragment;
 import com.android.car.settings.datetime.DatetimeSettingsFragment;
 import com.android.car.settings.display.DisplaySettingsFragment;
 import com.android.car.settings.location.LocationSettingsFragment;
+import com.android.car.settings.quicksettings.QuickSettingFragment;
 import com.android.car.settings.sound.SoundSettingsFragment;
+import com.android.car.settings.system.AboutSettingsFragment;
 import com.android.car.settings.users.UsersListFragment;
 import com.android.car.settings.wifi.WifiSettingsFragment;
 
@@ -36,15 +41,22 @@
  * Maps an Action string to a {@link Fragment} that can handle this Action.
  */
 public class FragmentResolver {
+
+    private static final Logger LOG = new Logger(FragmentResolver.class);
+
     private FragmentResolver() {
     }
 
     /**
      * Returns a {@link Fragment} that can handle the given action, returns {@code null} if no
-     * {@link Fragment} that can handle this action can be found.
+     * {@link Fragment} that can handle this {@link Intent} can be found.
      */
     @Nullable
-    static Fragment getFragmentForAction(@Nullable String action) {
+    static Fragment getFragmentForIntent(@Nullable Intent intent) {
+        if (intent == null) {
+            return null;
+        }
+        String action = intent.getAction();
         if (action == null) {
             return null;
         }
@@ -57,8 +69,10 @@
             case Settings.ACTION_WIRELESS_SETTINGS:
                 return new WifiSettingsFragment();
 
+            case Settings.ACTION_NIGHT_DISPLAY_SETTINGS:
+                return new QuickSettingFragment();
+
             case Settings.ACTION_USER_SETTINGS:
-            case Settings.ACTION_SECURITY_SETTINGS:
                 return new UsersListFragment();
 
             case Settings.ACTION_BLUETOOTH_SETTINGS:
@@ -71,7 +85,6 @@
                 return new SoundSettingsFragment();
 
             case Settings.ACTION_DISPLAY_SETTINGS:
-            case Settings.ACTION_NIGHT_DISPLAY_SETTINGS:
                 return new DisplaySettingsFragment();
 
             case Settings.ACTION_APPLICATION_SETTINGS:
@@ -79,12 +92,23 @@
             case Settings.ACTION_MANAGE_ALL_APPLICATIONS_SETTINGS:
                 return new ApplicationsSettingsFragment();
 
+            case Settings.ACTION_APPLICATION_DETAILS_SETTINGS:
+                Uri uri = intent.getData();
+                if (uri == null) {
+                    LOG.w("No uri provided for application detailed intent");
+                    return null;
+                }
+                return ApplicationDetailsFragment.getInstance(uri.getSchemeSpecificPart());
+
             case Settings.ACTION_SYNC_SETTINGS:
                 return new AccountSettingsFragment();
 
             case Settings.ACTION_ADD_ACCOUNT:
                 return new ChooseAccountFragment();
 
+            case Settings.ACTION_DEVICE_INFO_SETTINGS:
+                return new AboutSettingsFragment();
+
             default:
                 return null;
         }
diff --git a/src/com/android/car/settings/location/RecentLocationRequestsPreferenceController.java b/src/com/android/car/settings/location/RecentLocationRequestsPreferenceController.java
index e6d86c9..bdc1ea5 100644
--- a/src/com/android/car/settings/location/RecentLocationRequestsPreferenceController.java
+++ b/src/com/android/car/settings/location/RecentLocationRequestsPreferenceController.java
@@ -100,7 +100,7 @@
                 PackageManager.MATCH_DEFAULT_ONLY);
         pref.setOnPreferenceClickListener(p -> {
             getFragmentController().launchFragment(
-                    ApplicationDetailsFragment.getInstance(resolveInfo));
+                    ApplicationDetailsFragment.getInstance(resolveInfo.activityInfo.packageName));
             return true;
         });
         return pref;
diff --git a/tests/robotests/src/com/android/car/settings/applications/ApplicationPreferenceControllerTest.java b/tests/robotests/src/com/android/car/settings/applications/ApplicationPreferenceControllerTest.java
index 5c9f917..ecfd20a 100644
--- a/tests/robotests/src/com/android/car/settings/applications/ApplicationPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/car/settings/applications/ApplicationPreferenceControllerTest.java
@@ -19,18 +19,16 @@
 import static com.google.common.truth.Truth.assertThat;
 
 import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.when;
 import static org.testng.Assert.assertThrows;
 
 import android.content.Context;
-import android.content.pm.PackageManager;
-import android.content.pm.ResolveInfo;
 
 import androidx.lifecycle.Lifecycle;
 import androidx.preference.Preference;
 
 import com.android.car.settings.CarSettingsRobolectricTestRunner;
 import com.android.car.settings.common.PreferenceControllerTestHelper;
+import com.android.settingslib.applications.ApplicationsState;
 
 import org.junit.Before;
 import org.junit.Test;
@@ -48,16 +46,15 @@
             mPreferenceControllerHelper;
     private ApplicationPreferenceController mController;
     @Mock
-    private ResolveInfo mResolveInfo;
+    private ApplicationsState mMockAppState;
     @Mock
-    private PackageManager mPackageManager;
+    private ApplicationsState.AppEntry mMockAppEntry;
 
     @Before
     public void setUp() {
         MockitoAnnotations.initMocks(this);
         Context context = spy(RuntimeEnvironment.application);
-        when(context.getPackageManager()).thenReturn(mPackageManager);
-        when(mResolveInfo.loadLabel(mPackageManager)).thenReturn(PACKAGE_NAME);
+        mMockAppEntry.label = PACKAGE_NAME;
 
         mPreference = new Preference(context);
         mPreferenceControllerHelper = new PreferenceControllerTestHelper<>(context,
@@ -66,14 +63,23 @@
     }
 
     @Test
-    public void testCheckInitialized_noResolveInfo_throwException() {
+    public void testCheckInitialized_noAppState_throwException() {
+        mController.setAppEntry(mMockAppEntry);
+        assertThrows(IllegalStateException.class,
+                () -> mPreferenceControllerHelper.setPreference(mPreference));
+    }
+
+    @Test
+    public void testCheckInitialized_noAppEntry_throwException() {
+        mController.setAppState(mMockAppState);
         assertThrows(IllegalStateException.class,
                 () -> mPreferenceControllerHelper.setPreference(mPreference));
     }
 
     @Test
     public void testRefreshUi_hasResolveInfo_setTitle() {
-        mController.setResolveInfo(mResolveInfo);
+        mController.setAppEntry(mMockAppEntry);
+        mController.setAppState(mMockAppState);
         mPreferenceControllerHelper.setPreference(mPreference);
         mPreferenceControllerHelper.sendLifecycleEvent(Lifecycle.Event.ON_CREATE);
         mController.refreshUi();
diff --git a/tests/robotests/src/com/android/car/settings/applications/ApplicationsSettingsPreferenceControllerTest.java b/tests/robotests/src/com/android/car/settings/applications/ApplicationsSettingsPreferenceControllerTest.java
index 5efc12f..772662e 100644
--- a/tests/robotests/src/com/android/car/settings/applications/ApplicationsSettingsPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/car/settings/applications/ApplicationsSettingsPreferenceControllerTest.java
@@ -26,6 +26,7 @@
 
 import android.content.Context;
 import android.content.Intent;
+import android.content.pm.ActivityInfo;
 import android.content.pm.PackageManager;
 import android.content.pm.ResolveInfo;
 
@@ -52,6 +53,8 @@
 
     private static final String APP_NAME_1 = "Some Application";
     private static final String APP_NAME_2 = "Other Application";
+    private static final String PKG_NAME_1 = "Some package";
+    private static final String PKG_NAME_2 = "Other package";
 
     private PreferenceGroup mPreferenceGroup;
     private PreferenceControllerTestHelper<ApplicationsSettingsPreferenceController>
@@ -61,9 +64,13 @@
     @Mock
     private PackageManager mPackageManager;
     @Mock
-    private ResolveInfo mResolveInfo1;
+    private ResolveInfo mMockResolveInfo1;
     @Mock
-    private ResolveInfo mResolveInfo2;
+    private ResolveInfo mMockResolveInfo2;
+    @Mock
+    private ActivityInfo mMockActivityInfo1;
+    @Mock
+    private ActivityInfo mMockActivityInfo2;
 
     @Before
     public void setUp() {
@@ -76,12 +83,16 @@
                 ApplicationsSettingsPreferenceController.class, mPreferenceGroup);
         mController = mPreferenceControllerHelper.getController();
 
-        when(mResolveInfo1.loadLabel(any(PackageManager.class))).thenReturn(APP_NAME_1);
-        when(mResolveInfo2.loadLabel(any(PackageManager.class))).thenReturn(APP_NAME_2);
+        when(mMockResolveInfo1.loadLabel(any(PackageManager.class))).thenReturn(APP_NAME_1);
+        when(mMockResolveInfo2.loadLabel(any(PackageManager.class))).thenReturn(APP_NAME_2);
+        mMockActivityInfo1.packageName = PKG_NAME_1;
+        mMockActivityInfo2.packageName = PKG_NAME_2;
+        mMockResolveInfo1.activityInfo = mMockActivityInfo1;
+        mMockResolveInfo2.activityInfo = mMockActivityInfo2;
 
         List<ResolveInfo> testList = new ArrayList<>();
-        testList.add(mResolveInfo1);
-        testList.add(mResolveInfo2);
+        testList.add(mMockResolveInfo1);
+        testList.add(mMockResolveInfo2);
 
         // Cannot use specific intent because it doesn't have a proper "equals" method.
         when(mPackageManager.queryIntentActivities(any(Intent.class),
diff --git a/tests/robotests/src/com/android/car/settings/applications/PermissionsPreferenceControllerTest.java b/tests/robotests/src/com/android/car/settings/applications/PermissionsPreferenceControllerTest.java
index d4b32e5..8741417 100644
--- a/tests/robotests/src/com/android/car/settings/applications/PermissionsPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/car/settings/applications/PermissionsPreferenceControllerTest.java
@@ -22,8 +22,6 @@
 
 import android.content.Context;
 import android.content.Intent;
-import android.content.pm.ActivityInfo;
-import android.content.pm.ResolveInfo;
 
 import androidx.lifecycle.Lifecycle;
 import androidx.preference.Preference;
@@ -47,7 +45,6 @@
     private PreferenceControllerTestHelper<PermissionsPreferenceController>
             mPreferenceControllerHelper;
     private PermissionsPreferenceController mController;
-    private ResolveInfo mResolveInfo;
 
     @Before
     public void setUp() {
@@ -57,11 +54,6 @@
                 PermissionsPreferenceController.class);
         mController = mPreferenceControllerHelper.getController();
         mPreference = new Preference(mContext);
-
-        mResolveInfo = new ResolveInfo();
-        mResolveInfo.resolvePackageName = PACKAGE_NAME;
-        mResolveInfo.activityInfo = new ActivityInfo();
-        mResolveInfo.activityInfo.packageName = PACKAGE_NAME;
     }
 
     @Test
@@ -73,7 +65,7 @@
     @Test
     public void testHandlePreferenceClicked_navigateToNextActivity() {
         // Setup so the controller knows about the preference.
-        mController.setResolveInfo(mResolveInfo);
+        mController.setPackageName(PACKAGE_NAME);
         mPreferenceControllerHelper.setPreference(mPreference);
         mPreferenceControllerHelper.sendLifecycleEvent(Lifecycle.Event.ON_CREATE);
         assertThat(mController.handlePreferenceClicked(mPreference)).isTrue();