Get app info with correct user id.
- when querying app info from package manager, we should use the methods that takes the user id so that it will work properly with managed profile. Change-Id: Ifc84d3a29aaf7b2c1acfa096596a53f1715cc908 Fixes: 117222623 Test: make RunSettingsRoboTests
This commit is contained in:
@@ -34,6 +34,7 @@ import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.PackageManager.NameNotFoundException;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.content.res.Resources;
|
||||
import android.os.UserManager;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
@@ -130,6 +131,16 @@ public class DefaultBrowserPreferenceControllerTest {
|
||||
verify(mPackageManager).getDefaultBrowserPackageNameAsUser(anyInt());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getDefaultApp_shouldGetApplicationInfoAsUser() throws NameNotFoundException {
|
||||
final String PACKAGE_NAME = "com.test.package";
|
||||
when(mPackageManager.getDefaultBrowserPackageNameAsUser(anyInt())).thenReturn(PACKAGE_NAME);
|
||||
|
||||
mController.getDefaultAppInfo();
|
||||
|
||||
verify(mPackageManager).getApplicationInfoAsUser(eq(PACKAGE_NAME), anyInt(), anyInt());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isBrowserDefault_onlyApp_shouldReturnTrue() {
|
||||
when(mPackageManager.getDefaultBrowserPackageNameAsUser(anyInt())).thenReturn(null);
|
||||
@@ -173,6 +184,33 @@ public class DefaultBrowserPreferenceControllerTest {
|
||||
any(Intent.class), eq(0) /* flags */, eq(0) /* userId */);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getOnlyAppIcon_shouldGetApplicationInfoAsUser() throws NameNotFoundException {
|
||||
final List<ResolveInfo> resolveInfos = new ArrayList<>();
|
||||
final String PACKAGE_NAME = "com.test.package";
|
||||
resolveInfos.add(createResolveInfo(PACKAGE_NAME));
|
||||
when(mPackageManager.queryIntentActivitiesAsUser(any(Intent.class), anyInt(), anyInt()))
|
||||
.thenReturn(resolveInfos);
|
||||
when(mContext.getPackageManager()).thenReturn(mPackageManager);
|
||||
when(mContext.getSystemService(UserManager.class)).thenReturn(mUserManager);
|
||||
when(mContext.getResources()).thenReturn(mock(Resources.class));
|
||||
|
||||
mController.getOnlyAppIcon();
|
||||
|
||||
verify(mPackageManager).getApplicationInfoAsUser(
|
||||
eq(PACKAGE_NAME), eq(0) /* flags */, eq(0) /* userId */);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hasBrowserPreference_shouldQueryIntentActivitiesAsUser() {
|
||||
when(mContext.getPackageManager()).thenReturn(mPackageManager);
|
||||
|
||||
mController.hasBrowserPreference("com.test.package", mContext, 0 /* userId */);
|
||||
|
||||
verify(mPackageManager).queryIntentActivitiesAsUser(
|
||||
any(Intent.class), eq(0) /* flags */, eq(0) /* userId */);
|
||||
}
|
||||
|
||||
private ResolveInfo createResolveInfo(String packageName) {
|
||||
final ResolveInfo info = new ResolveInfo();
|
||||
info.handleAllWebDataURI = true;
|
||||
|
Reference in New Issue
Block a user