DO Disclosures: detailed application lists
Add UI that lists enterprise set default apps for handling important intents
(opening browser, using camera, phone, etc).
Bug: 32692748
Test: m RunSettingsRoboTests
Merged-In: I75bb97d1b3728b1dcb90981b24d12edf510c4b04
Change-Id: I7d0041e4fada48bc56f6a6637614ac4471dba65a
(cherry picked from commit f0a61dd112
)
This commit is contained in:
@@ -20,13 +20,13 @@ import android.app.admin.DevicePolicyManager;
|
||||
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 android.content.pm.UserInfo;
|
||||
import android.os.Build;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
import android.util.ArraySet;
|
||||
|
||||
import com.android.settings.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
@@ -42,9 +42,9 @@ import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.shadows.ShadowApplication;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Mockito.when;
|
||||
@@ -200,8 +200,14 @@ public final class ApplicationFeatureProviderImplTest {
|
||||
|
||||
@Test
|
||||
public void testFindPersistentPreferredActivities() throws Exception {
|
||||
final UserInfo mainUser = new UserInfo(MAIN_USER_ID, "main", UserInfo.FLAG_ADMIN);
|
||||
final UserInfo managedUser = new UserInfo(MANAGED_PROFILE_ID, "managed",
|
||||
UserInfo.FLAG_MANAGED_PROFILE);
|
||||
|
||||
when(mUserManager.getUserProfiles()).thenReturn(Arrays.asList(new UserHandle(MAIN_USER_ID),
|
||||
new UserHandle(MANAGED_PROFILE_ID)));
|
||||
when(mUserManager.getUserInfo(MAIN_USER_ID)).thenReturn(mainUser);
|
||||
when(mUserManager.getUserInfo(MANAGED_PROFILE_ID)).thenReturn(managedUser);
|
||||
|
||||
final Intent viewIntent = new Intent(Intent.ACTION_VIEW);
|
||||
final Intent editIntent = new Intent(Intent.ACTION_EDIT);
|
||||
@@ -222,17 +228,21 @@ public final class ApplicationFeatureProviderImplTest {
|
||||
when(mPackageManagerService.findPersistentPreferredActivity(sendIntent, MANAGED_PROFILE_ID))
|
||||
.thenReturn(null);
|
||||
|
||||
final Set<ApplicationFeatureProvider.PersistentPreferredActivityInfo> expectedActivities
|
||||
= new ArraySet<>();
|
||||
expectedActivities.add(new ApplicationFeatureProvider.PersistentPreferredActivityInfo(APP_1,
|
||||
MAIN_USER_ID));
|
||||
expectedActivities.add(new ApplicationFeatureProvider.PersistentPreferredActivityInfo(APP_1,
|
||||
MANAGED_PROFILE_ID));
|
||||
expectedActivities.add(new ApplicationFeatureProvider.PersistentPreferredActivityInfo(APP_2,
|
||||
MANAGED_PROFILE_ID));
|
||||
final List<UserAppInfo> expectedMainUserActivities = new ArrayList<>();
|
||||
expectedMainUserActivities.add(new UserAppInfo(mainUser,
|
||||
new ApplicationInfo(app1.activityInfo.applicationInfo)));
|
||||
final List<UserAppInfo> expectedManagedUserActivities = new ArrayList<>();
|
||||
expectedManagedUserActivities.add(new UserAppInfo(managedUser,
|
||||
new ApplicationInfo(app1.activityInfo.applicationInfo)));
|
||||
expectedManagedUserActivities.add(new UserAppInfo(managedUser,
|
||||
new ApplicationInfo(app2.activityInfo.applicationInfo)));
|
||||
|
||||
assertThat(mProvider.findPersistentPreferredActivities(
|
||||
new Intent[] {viewIntent, editIntent, sendIntent})).isEqualTo(expectedActivities);
|
||||
assertThat(mProvider.findPersistentPreferredActivities(MAIN_USER_ID,
|
||||
new Intent[] {viewIntent, editIntent, sendIntent}))
|
||||
.isEqualTo(expectedMainUserActivities);
|
||||
assertThat(mProvider.findPersistentPreferredActivities(MANAGED_PROFILE_ID,
|
||||
new Intent[] {viewIntent, editIntent, sendIntent}))
|
||||
.isEqualTo(expectedManagedUserActivities);
|
||||
}
|
||||
|
||||
private void setUpUsersAndInstalledApps() {
|
||||
@@ -254,8 +264,11 @@ public final class ApplicationFeatureProviderImplTest {
|
||||
}
|
||||
|
||||
private ResolveInfo createResolveInfo(String packageName) {
|
||||
final ApplicationInfo applicationInfo = new ApplicationInfo();
|
||||
applicationInfo.packageName = packageName;
|
||||
final ActivityInfo activityInfo = new ActivityInfo();
|
||||
activityInfo.packageName = packageName;
|
||||
activityInfo.applicationInfo = applicationInfo;
|
||||
final ResolveInfo resolveInfo = new ResolveInfo();
|
||||
resolveInfo.activityInfo = activityInfo;
|
||||
return resolveInfo;
|
||||
|
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License
|
||||
*/
|
||||
|
||||
package com.android.settings.applications;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import static junit.framework.Assert.assertTrue;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class EnterpriseDefaultAppsTest {
|
||||
@Test
|
||||
public void testNumberOfIntentsCorrelateWithUI() throws Exception {
|
||||
final int concatenation_templates[] =
|
||||
new int[]{0 /* no need for single app name */,
|
||||
R.string.app_names_concatenation_template_2,
|
||||
R.string.app_names_concatenation_template_3};
|
||||
for (EnterpriseDefaultApps app : EnterpriseDefaultApps.values()) {
|
||||
assertTrue("Number of intents should be limited by number of apps the UI can show",
|
||||
app.getIntents().length <= concatenation_templates.length);
|
||||
}
|
||||
}
|
||||
}
|
@@ -70,12 +70,6 @@ public class ApplicationListFragmentTest {
|
||||
mFragment = new ApplicationListFragmentTestable(mPreferenceManager, mScreen);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getMetricsCategory() {
|
||||
assertThat(mFragment.getMetricsCategory())
|
||||
.isEqualTo(MetricsEvent.ENTERPRISE_PRIVACY_SETTINGS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getLogTag() {
|
||||
assertThat(mFragment.getLogTag())
|
||||
@@ -98,6 +92,17 @@ public class ApplicationListFragmentTest {
|
||||
ApplicationListPreferenceController.class);
|
||||
}
|
||||
|
||||
@Test public void getCategories() {
|
||||
assertThat(new ApplicationListFragment.AdminGrantedPermissionCamera().getMetricsCategory())
|
||||
.isEqualTo(MetricsEvent.ENTERPRISE_PRIVACY_PERMISSIONS);
|
||||
assertThat(new ApplicationListFragment.AdminGrantedPermissionLocation().
|
||||
getMetricsCategory()).isEqualTo(MetricsEvent.ENTERPRISE_PRIVACY_PERMISSIONS);
|
||||
assertThat(new ApplicationListFragment.AdminGrantedPermissionMicrophone().
|
||||
getMetricsCategory()).isEqualTo(MetricsEvent.ENTERPRISE_PRIVACY_PERMISSIONS);
|
||||
assertThat(new ApplicationListFragment.EnterpriseInstalledPackages().getMetricsCategory())
|
||||
.isEqualTo(MetricsEvent.ENTERPRISE_PRIVACY_INSTALLED_APPS);
|
||||
}
|
||||
|
||||
private static class ApplicationListFragmentTestable extends ApplicationListFragment {
|
||||
|
||||
private final PreferenceManager mPreferenceManager;
|
||||
@@ -127,5 +132,10 @@ public class ApplicationListFragmentTest {
|
||||
public PreferenceScreen getPreferenceScreen() {
|
||||
return mPreferenceScreen;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return MetricsEvent.VIEW_UNKNOWN;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,111 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License
|
||||
*/
|
||||
|
||||
package com.android.settings.enterprise;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.v7.preference.PreferenceManager;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.core.PreferenceController;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.shadows.ShadowApplication;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Answers.RETURNS_DEEP_STUBS;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class EnterpriseSetDefaultAppsListFragmentTest {
|
||||
@Mock(answer = RETURNS_DEEP_STUBS)
|
||||
private PreferenceScreen mScreen;
|
||||
@Mock(answer = RETURNS_DEEP_STUBS)
|
||||
private PreferenceManager mPreferenceManager;
|
||||
|
||||
private EnterpriseSetDefaultAppsListFragment mFragment;
|
||||
private Context mContext;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = ShadowApplication.getInstance().getApplicationContext();
|
||||
when(mPreferenceManager.getContext()).thenReturn(mContext);
|
||||
when(mScreen.getPreferenceManager()).thenReturn(mPreferenceManager);
|
||||
mFragment = new EnterpriseSetDefaultAppsListFragmentTestable(mPreferenceManager, mScreen);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getMetricsCategory() {
|
||||
assertThat(mFragment.getMetricsCategory())
|
||||
.isEqualTo(MetricsEvent.ENTERPRISE_PRIVACY_DEFAULT_APPS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getLogTag() {
|
||||
assertThat(mFragment.getLogTag()).isEqualTo("EnterprisePrivacySettings");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getScreenResource() {
|
||||
assertThat(mFragment.getPreferenceScreenResId())
|
||||
.isEqualTo(R.xml.enterprise_set_default_apps_settings);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getPreferenceControllers() {
|
||||
final List<PreferenceController> controllers = mFragment.getPreferenceControllers(mContext);
|
||||
assertThat(controllers).isNotNull();
|
||||
assertThat(controllers.size()).isEqualTo(1);
|
||||
int position = 0;
|
||||
assertThat(controllers.get(position++)).isInstanceOf(
|
||||
EnterpriseSetDefaultAppsListPreferenceController.class);
|
||||
}
|
||||
|
||||
private static class EnterpriseSetDefaultAppsListFragmentTestable extends
|
||||
EnterpriseSetDefaultAppsListFragment {
|
||||
|
||||
private final PreferenceManager mPreferenceManager;
|
||||
private final PreferenceScreen mPreferenceScreen;
|
||||
|
||||
public EnterpriseSetDefaultAppsListFragmentTestable(PreferenceManager preferenceManager,
|
||||
PreferenceScreen screen) {
|
||||
this.mPreferenceManager = preferenceManager;
|
||||
this.mPreferenceScreen = screen;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PreferenceManager getPreferenceManager() {
|
||||
return mPreferenceManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PreferenceScreen getPreferenceScreen() {
|
||||
return mPreferenceScreen;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,167 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License
|
||||
*/
|
||||
|
||||
package com.android.settings.enterprise;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.UserInfo;
|
||||
import android.content.res.Resources;
|
||||
import android.os.UserHandle;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceManager;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsPreferenceFragment;
|
||||
import com.android.settings.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.applications.EnterpriseDefaultApps;
|
||||
import com.android.settings.applications.UserAppInfo;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settings.testutils.ApplicationTestUtils;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.shadows.ShadowApplication;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Answers.RETURNS_DEEP_STUBS;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyInt;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class EnterpriseSetDefaultAppsListPreferenceControllerTest {
|
||||
private static final int USER_ID = 0;
|
||||
private static final int APP_UID = 0;
|
||||
|
||||
private static final String APP_1 = "APP_1";
|
||||
private static final String APP_2 = "APP_2";
|
||||
private static final String BROWSER_TITLE = "Browser app";
|
||||
private static final String PHONE_TITLE = "Phone apps";
|
||||
|
||||
@Mock(answer = RETURNS_DEEP_STUBS)
|
||||
private PreferenceScreen mScreen;
|
||||
@Mock(answer = RETURNS_DEEP_STUBS)
|
||||
private PreferenceManager mPrefenceManager;
|
||||
@Mock(answer = RETURNS_DEEP_STUBS)
|
||||
private PackageManager mPackageManager;
|
||||
@Mock(answer = RETURNS_DEEP_STUBS)
|
||||
private SettingsPreferenceFragment mFragment;
|
||||
|
||||
private Context mContext;
|
||||
private FakeFeatureFactory mFeatureFactory;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
ShadowApplication shadowContext = ShadowApplication.getInstance();
|
||||
mContext = spy(shadowContext.getApplicationContext());
|
||||
FakeFeatureFactory.setupForTest(mContext);
|
||||
mFeatureFactory = (FakeFeatureFactory) FeatureFactory.getFactory(mContext);
|
||||
when(mFragment.getPreferenceScreen()).thenReturn(mScreen);
|
||||
when(mPrefenceManager.getContext()).thenReturn(mContext);
|
||||
when(mFragment.getPreferenceManager()).thenReturn(mPrefenceManager);
|
||||
|
||||
when(mContext.getString(R.string.default_browser_title)).thenReturn(BROWSER_TITLE);
|
||||
Resources resources = spy(mContext.getResources());
|
||||
when(mContext.getResources()).thenReturn(resources);
|
||||
when(resources.getQuantityString(R.plurals.default_phone_app_title, 2))
|
||||
.thenReturn(PHONE_TITLE);
|
||||
when(mContext.getString(R.string.app_names_concatenation_template_2))
|
||||
.thenReturn("%1$s, %2$s");
|
||||
|
||||
when(mPackageManager.getText(eq(APP_1), anyInt(), any())).thenReturn(APP_1);
|
||||
when(mPackageManager.getText(eq(APP_2), anyInt(), any())).thenReturn(APP_2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultipleAppsForOneTypeOfDefault() {
|
||||
final UserInfo user = new UserInfo(USER_ID, "main", UserInfo.FLAG_ADMIN);
|
||||
final ApplicationInfo appInfo1 = ApplicationTestUtils.buildInfo(APP_UID, APP_1, 0, 0);
|
||||
final ApplicationInfo appInfo2 = ApplicationTestUtils.buildInfo(APP_UID, APP_2, 0, 0);
|
||||
|
||||
when(mFeatureFactory.userFeatureProvider.getUserProfiles())
|
||||
.thenReturn(Arrays.asList(new UserHandle(USER_ID)));
|
||||
when(mFeatureFactory.enterprisePrivacyFeatureProvider.isInCompMode()).thenReturn(false);
|
||||
when(mFeatureFactory.applicationFeatureProvider
|
||||
.findPersistentPreferredActivities(anyInt(), any()))
|
||||
.thenReturn(Collections.emptyList());
|
||||
when(mFeatureFactory.applicationFeatureProvider
|
||||
.findPersistentPreferredActivities(eq(USER_ID),
|
||||
eq(EnterpriseDefaultApps.BROWSER.getIntents())))
|
||||
.thenReturn(Arrays.asList(new UserAppInfo(user, appInfo1)));
|
||||
when(mFeatureFactory.applicationFeatureProvider
|
||||
.findPersistentPreferredActivities(eq(USER_ID),
|
||||
eq(EnterpriseDefaultApps.PHONE.getIntents()))).thenReturn(
|
||||
Arrays.asList(new UserAppInfo(user, appInfo1),
|
||||
new UserAppInfo(user, appInfo2)));
|
||||
|
||||
new EnterpriseSetDefaultAppsListPreferenceController(mContext, mFragment, mPackageManager);
|
||||
ShadowApplication.runBackgroundTasks();
|
||||
|
||||
ArgumentCaptor<Preference> apps = ArgumentCaptor.forClass(Preference.class);
|
||||
verify(mScreen, times(2)).addPreference(apps.capture());
|
||||
|
||||
assertThat(apps.getAllValues().get(0).getTitle()).isEqualTo(BROWSER_TITLE);
|
||||
assertThat(apps.getAllValues().get(0).getSummary()).isEqualTo(APP_1);
|
||||
|
||||
assertThat(apps.getAllValues().get(1).getTitle()).isEqualTo(PHONE_TITLE);
|
||||
assertThat(apps.getAllValues().get(1).getSummary()).isEqualTo(APP_1 + ", " + APP_2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable() {
|
||||
when(mFeatureFactory.userFeatureProvider.getUserProfiles())
|
||||
.thenReturn(Arrays.asList(new UserHandle(USER_ID)));
|
||||
when(mFeatureFactory.applicationFeatureProvider
|
||||
.findPersistentPreferredActivities(anyInt(), any()))
|
||||
.thenReturn(Collections.emptyList());
|
||||
final EnterpriseSetDefaultAppsListPreferenceController controller =
|
||||
new EnterpriseSetDefaultAppsListPreferenceController(mContext, mFragment,
|
||||
mPackageManager);
|
||||
assertThat(controller.isAvailable()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getPreferenceKey() {
|
||||
when(mFeatureFactory.userFeatureProvider.getUserProfiles())
|
||||
.thenReturn(Arrays.asList(new UserHandle(USER_ID)));
|
||||
when(mFeatureFactory.applicationFeatureProvider
|
||||
.findPersistentPreferredActivities(anyInt(), any()))
|
||||
.thenReturn(Collections.emptyList());
|
||||
final EnterpriseSetDefaultAppsListPreferenceController controller =
|
||||
new EnterpriseSetDefaultAppsListPreferenceController(mContext, mFragment,
|
||||
mPackageManager);
|
||||
assertThat(controller.getPreferenceKey()).isNull();
|
||||
}
|
||||
}
|
@@ -18,32 +18,35 @@ package com.android.settings.enterprise;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.res.Resources;
|
||||
import android.net.Uri;
|
||||
import android.provider.ContactsContract;
|
||||
import android.provider.MediaStore;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.UserInfo;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.util.ArraySet;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.applications.ApplicationFeatureProvider;
|
||||
import com.android.settings.applications.EnterpriseDefaultApps;
|
||||
import com.android.settings.applications.UserAppInfo;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentMatcher;
|
||||
import org.mockito.Answers;
|
||||
import org.mockito.ArgumentMatcher;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Matchers.anyInt;
|
||||
import static org.mockito.Matchers.argThat;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.anyObject;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@@ -56,6 +59,8 @@ public final class EnterpriseSetDefaultAppsPreferenceControllerTest {
|
||||
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private Context mContext;
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private UserManager mUm;
|
||||
private FakeFeatureFactory mFeatureFactory;
|
||||
|
||||
private EnterpriseSetDefaultAppsPreferenceController mController;
|
||||
@@ -69,50 +74,40 @@ public final class EnterpriseSetDefaultAppsPreferenceControllerTest {
|
||||
null /* lifecycle */);
|
||||
}
|
||||
|
||||
private static Intent buildIntent(String action, String category, String protocol,
|
||||
String type) {
|
||||
final Intent intent = new Intent(action);
|
||||
if (category != null) {
|
||||
intent.addCategory(category);
|
||||
private void setEnterpriseSetDefaultApps(Intent[] intents, int number) {
|
||||
final ApplicationInfo appInfo = new ApplicationInfo();
|
||||
appInfo.packageName = "app";
|
||||
for (int i = 0; i < number; i++) {
|
||||
final List<UserAppInfo> apps = new ArrayList<>(number);
|
||||
apps.add(new UserAppInfo(new UserInfo(i, "user." + i, UserInfo.FLAG_ADMIN), appInfo));
|
||||
when(mFeatureFactory.applicationFeatureProvider.findPersistentPreferredActivities(eq(i),
|
||||
argThat(new MatchesIntents(intents)))).thenReturn(apps);
|
||||
}
|
||||
if (protocol != null) {
|
||||
intent.setData(Uri.parse(protocol));
|
||||
}
|
||||
if (type != null) {
|
||||
intent.setType(type);
|
||||
}
|
||||
return intent;
|
||||
}
|
||||
|
||||
private void setEnterpriseSetDefaultApps(Intent[] intents, int number) {
|
||||
final Set<ApplicationFeatureProvider.PersistentPreferredActivityInfo> apps
|
||||
= new ArraySet<>(number);
|
||||
for (int i = 0; i < number; i++) {
|
||||
apps.add(new ApplicationFeatureProvider.PersistentPreferredActivityInfo("app", i));
|
||||
private void configureUsers(int number) {
|
||||
final List<UserHandle> users = new ArrayList<>(number);
|
||||
for (int i = 0; i < 64; i++) {
|
||||
users.add(new UserHandle(i));
|
||||
}
|
||||
when(mFeatureFactory.applicationFeatureProvider.findPersistentPreferredActivities(
|
||||
argThat(new MatchesIntents(intents)))).thenReturn(apps);
|
||||
when(mFeatureFactory.userFeatureProvider.getUserProfiles()).thenReturn(users);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateState() {
|
||||
setEnterpriseSetDefaultApps(new Intent[] {buildIntent(Intent.ACTION_VIEW,
|
||||
Intent.CATEGORY_BROWSABLE, "http:", null)}, 1);
|
||||
setEnterpriseSetDefaultApps(new Intent[] {new Intent(MediaStore.ACTION_IMAGE_CAPTURE),
|
||||
new Intent(MediaStore.ACTION_VIDEO_CAPTURE)}, 2);
|
||||
setEnterpriseSetDefaultApps(new Intent[] {buildIntent(Intent.ACTION_VIEW, null, "geo:",
|
||||
null)}, 4);
|
||||
setEnterpriseSetDefaultApps(new Intent[] {new Intent(Intent.ACTION_SENDTO),
|
||||
new Intent(Intent.ACTION_SEND), new Intent(Intent.ACTION_SEND_MULTIPLE)}, 8);
|
||||
setEnterpriseSetDefaultApps(new Intent[] {buildIntent(Intent.ACTION_INSERT, null, null,
|
||||
"vnd.android.cursor.dir/event")}, 16);
|
||||
setEnterpriseSetDefaultApps(new Intent[] {buildIntent(Intent.ACTION_PICK, null, null,
|
||||
ContactsContract.Contacts.CONTENT_TYPE)}, 32);
|
||||
setEnterpriseSetDefaultApps(new Intent[] {new Intent(Intent.ACTION_DIAL),
|
||||
new Intent(Intent.ACTION_CALL)}, 64);
|
||||
setEnterpriseSetDefaultApps(EnterpriseDefaultApps.BROWSER.getIntents(), 1);
|
||||
setEnterpriseSetDefaultApps(EnterpriseDefaultApps.CAMERA.getIntents(), 2);
|
||||
setEnterpriseSetDefaultApps(EnterpriseDefaultApps.MAP.getIntents(), 4);
|
||||
setEnterpriseSetDefaultApps(EnterpriseDefaultApps.EMAIL.getIntents(), 8);
|
||||
setEnterpriseSetDefaultApps(EnterpriseDefaultApps.CALENDAR.getIntents(), 16);
|
||||
setEnterpriseSetDefaultApps(EnterpriseDefaultApps.CONTACTS.getIntents(), 32);
|
||||
setEnterpriseSetDefaultApps(EnterpriseDefaultApps.PHONE.getIntents(), 64);
|
||||
when(mContext.getResources().getQuantityString(R.plurals.enterprise_privacy_number_packages,
|
||||
127, 127)).thenReturn("127 apps");
|
||||
|
||||
// As setEnterpriseSetDefaultApps uses fake Users, we need to list them via UserManager.
|
||||
configureUsers(64);
|
||||
|
||||
final Preference preference = new Preference(mContext, null, 0, 0);
|
||||
mController.updateState(preference);
|
||||
assertThat(preference.getSummary()).isEqualTo("127 apps");
|
||||
@@ -120,13 +115,12 @@ public final class EnterpriseSetDefaultAppsPreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void testIsAvailable() {
|
||||
when(mFeatureFactory.applicationFeatureProvider.findPersistentPreferredActivities(
|
||||
anyObject())).thenReturn(
|
||||
new ArraySet<ApplicationFeatureProvider.PersistentPreferredActivityInfo>());
|
||||
when(mFeatureFactory.applicationFeatureProvider.findPersistentPreferredActivities(anyInt(),
|
||||
anyObject())).thenReturn(new ArrayList<UserAppInfo>());
|
||||
assertThat(mController.isAvailable()).isFalse();
|
||||
|
||||
setEnterpriseSetDefaultApps(new Intent[] {buildIntent(Intent.ACTION_VIEW,
|
||||
Intent.CATEGORY_BROWSABLE, "http:", null)}, 1);
|
||||
setEnterpriseSetDefaultApps(EnterpriseDefaultApps.BROWSER.getIntents(), 1);
|
||||
configureUsers(1);
|
||||
assertThat(mController.isAvailable()).isTrue();
|
||||
}
|
||||
|
||||
|
@@ -30,6 +30,7 @@ import com.android.settings.overlay.SupportFeatureProvider;
|
||||
import com.android.settings.security.SecurityFeatureProvider;
|
||||
import com.android.settings.search2.SearchFeatureProvider;
|
||||
import com.android.settings.overlay.SurveyFeatureProvider;
|
||||
import com.android.settings.users.UserFeatureProvider;
|
||||
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Mockito.mock;
|
||||
@@ -52,6 +53,7 @@ public class FakeFeatureFactory extends FeatureFactory {
|
||||
public final SurveyFeatureProvider surveyFeatureProvider;
|
||||
public final SecurityFeatureProvider securityFeatureProvider;
|
||||
public final SuggestionFeatureProvider suggestionsFeatureProvider;
|
||||
public final UserFeatureProvider userFeatureProvider;
|
||||
public final AssistGestureFeatureProvider assistGestureFeatureProvider;
|
||||
|
||||
/**
|
||||
@@ -86,6 +88,7 @@ public class FakeFeatureFactory extends FeatureFactory {
|
||||
surveyFeatureProvider = mock(SurveyFeatureProvider.class);
|
||||
securityFeatureProvider = mock(SecurityFeatureProvider.class);
|
||||
suggestionsFeatureProvider = mock(SuggestionFeatureProvider.class);
|
||||
userFeatureProvider = mock(UserFeatureProvider.class);
|
||||
assistGestureFeatureProvider = mock(AssistGestureFeatureProvider.class);
|
||||
}
|
||||
|
||||
@@ -144,6 +147,11 @@ public class FakeFeatureFactory extends FeatureFactory {
|
||||
return securityFeatureProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserFeatureProvider getUserFeatureProvider(Context context) {
|
||||
return userFeatureProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AssistGestureFeatureProvider getAssistGestureFeatureProvider() {
|
||||
return assistGestureFeatureProvider;
|
||||
|
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License
|
||||
*/
|
||||
|
||||
package com.android.settings.users;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
|
||||
import com.android.settings.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class UserFeatureProviderImplTest {
|
||||
public static final int FIRST_USER_ID = 0;
|
||||
public static final int SECOND_USER_ID = 4;
|
||||
|
||||
@Mock
|
||||
private Context mContext;
|
||||
@Mock
|
||||
private UserManager mUserManager;
|
||||
|
||||
private UserFeatureProviderImpl mFeatureProvider;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
when(mContext.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager);
|
||||
mFeatureProvider = new UserFeatureProviderImpl(mContext);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getUserProfiles() {
|
||||
final List<UserHandle> expected =
|
||||
Arrays.asList(new UserHandle(FIRST_USER_ID), new UserHandle(SECOND_USER_ID));
|
||||
when(mUserManager.getUserProfiles()).thenReturn(expected);
|
||||
final List<UserHandle> userProfiles = mFeatureProvider.getUserProfiles();
|
||||
assertThat(userProfiles).isEqualTo(expected);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user