Merge "Get app info with correct user id."

This commit is contained in:
Doris Ling
2018-10-15 23:23:23 +00:00
committed by Android (Google) Code Review
12 changed files with 65 additions and 23 deletions

View File

@@ -43,12 +43,11 @@ import com.android.settingslib.applications.ApplicationsState.AppEntry;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;import android.net.INetworkStatsSession;
import org.mockito.Mock;
import android.util.FeatureFlagUtils;
import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.util.ReflectionHelpers;
import androidx.loader.app.LoaderManager;
import androidx.preference.Preference;

View File

@@ -18,8 +18,8 @@ package com.android.settings.applications.appinfo;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.argThat;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.argThat;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
@@ -66,8 +66,8 @@ public class DefaultBrowserShortcutPreferenceControllerTest {
public void hasAppCapability_hasBrowserCapability_shouldReturnTrue() {
List<ResolveInfo> resolveInfos = new ArrayList<>();
resolveInfos.add(new ResolveInfo());
when(mPackageManager.queryIntentActivities(argThat(intent-> intent != null
&& intent.getCategories().contains(Intent.CATEGORY_BROWSABLE)), anyInt()))
when(mPackageManager.queryIntentActivitiesAsUser(argThat(intent-> intent != null
&& intent.getCategories().contains(Intent.CATEGORY_BROWSABLE)), anyInt(), anyInt()))
.thenReturn(resolveInfos);
assertThat(mController.hasAppCapability()).isTrue();

View File

@@ -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;