Populate Enterprise Privacy Settings page - batch 1
This CL adds the first batch of items to the Privacy Settings page. These are all the items that fall into the "What types of information can your organization see?" category and do not require deeper Framework changes. Further batches are to come in separate CLs. Test: make RunSettingsRoboTests Bug: 32692748 Change-Id: I460093bc45ed0e5baab2a5cdf9833e654d436cc9
This commit is contained in:
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
* Copyright (C) 2016 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 android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.UserInfo;
|
||||
import android.os.UserManager;
|
||||
|
||||
import com.android.settings.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.testutils.ApplicationTestUtils;
|
||||
import com.android.settings.testutils.shadow.ShadowUserManager;
|
||||
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.Arrays;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Mockito.when;
|
||||
import org.robolectric.shadows.ShadowApplication;
|
||||
/**
|
||||
* Tests for {@link ApplicationFeatureProviderImpl}.
|
||||
*/
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION,
|
||||
shadows = {ShadowUserManager.class})
|
||||
public final class ApplicationFeatureProviderImplTest {
|
||||
|
||||
private final int MAIN_USER_ID = 0;
|
||||
private final int MANAGED_PROFILE_ID = 10;
|
||||
|
||||
private @Mock UserManager mUserManager;
|
||||
private @Mock Context mContext;
|
||||
private @Mock PackageManagerWrapper mPackageManager;
|
||||
|
||||
private ApplicationFeatureProvider mProvider;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
|
||||
when(mContext.getApplicationContext()).thenReturn(mContext);
|
||||
when(mContext.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager);
|
||||
|
||||
mProvider = new ApplicationFeatureProviderImpl(mContext, mPackageManager);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCalculateNumberOfInstalledApps() {
|
||||
final Integer[] numberOfInstalledApps = new Integer[1];
|
||||
numberOfInstalledApps[0] = null;
|
||||
|
||||
when(mUserManager.getUsers(true)).thenReturn(Arrays.asList(
|
||||
new UserInfo(MAIN_USER_ID, "main", UserInfo.FLAG_ADMIN),
|
||||
new UserInfo(MANAGED_PROFILE_ID, "managed profile", 0)));
|
||||
|
||||
when(mPackageManager.getInstalledApplicationsAsUser(PackageManager.GET_DISABLED_COMPONENTS
|
||||
| PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS
|
||||
| PackageManager.GET_UNINSTALLED_PACKAGES,
|
||||
MAIN_USER_ID)).thenReturn(Arrays.asList(
|
||||
ApplicationTestUtils.buildInfo(MAIN_USER_ID, "app1", 0 /* flags */)));
|
||||
|
||||
when(mPackageManager.getInstalledApplicationsAsUser(PackageManager.GET_DISABLED_COMPONENTS
|
||||
| PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS,
|
||||
MANAGED_PROFILE_ID)).thenReturn(Arrays.asList(
|
||||
ApplicationTestUtils.buildInfo(MANAGED_PROFILE_ID, "app2", 0 /* flags */)));
|
||||
|
||||
mProvider.calculateNumberOfInstalledApps(
|
||||
new ApplicationFeatureProvider.NumberOfInstalledAppsCallback() {
|
||||
@Override
|
||||
public void onNumberOfInstalledAppsResult(int num) {
|
||||
numberOfInstalledApps[0] = num;
|
||||
}
|
||||
});
|
||||
ShadowApplication.runBackgroundTasks();
|
||||
|
||||
assertThat(numberOfInstalledApps[0]).isEqualTo(2);
|
||||
}
|
||||
}
|
@@ -22,6 +22,7 @@ import android.content.pm.PackageManager;
|
||||
|
||||
import com.android.settings.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.applications.PackageManagerWrapper;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -41,9 +42,8 @@ public final class EnterprisePrivacyFeatureProviderImplTest {
|
||||
|
||||
private final ComponentName DEVICE_OWNER = new ComponentName("dummy", "component");
|
||||
|
||||
private @Mock PackageManager mPackageManager;
|
||||
private @Mock Context mContext;
|
||||
private @Mock DevicePolicyManagerWrapper mDevicePolicyManager;
|
||||
private @Mock PackageManagerWrapper mPackageManager;
|
||||
|
||||
private EnterprisePrivacyFeatureProvider mProvider;
|
||||
|
||||
@@ -51,12 +51,10 @@ public final class EnterprisePrivacyFeatureProviderImplTest {
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
|
||||
when(mContext.getApplicationContext()).thenReturn(mContext);
|
||||
when(mContext.getPackageManager()).thenReturn(mPackageManager);
|
||||
when(mPackageManager.hasSystemFeature(PackageManager.FEATURE_DEVICE_ADMIN))
|
||||
.thenReturn(true);
|
||||
|
||||
mProvider = new EnterprisePrivacyFeatureProviderImpl(mContext, mDevicePolicyManager);
|
||||
mProvider = new EnterprisePrivacyFeatureProviderImpl(mDevicePolicyManager, mPackageManager);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@@ -20,6 +20,8 @@ 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;
|
||||
@@ -28,6 +30,8 @@ import org.robolectric.shadows.ShadowApplication;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Tests for {@link EnterprisePrivacySettings}.
|
||||
*/
|
||||
@@ -66,7 +70,10 @@ public final class EnterprisePrivacySettingsTest {
|
||||
|
||||
@Test
|
||||
public void getPreferenceControllers() {
|
||||
assertThat(mSettings.getPreferenceControllers(
|
||||
ShadowApplication.getInstance().getApplicationContext())).isNull();
|
||||
final List<PreferenceController> controllers = mSettings.getPreferenceControllers(
|
||||
ShadowApplication.getInstance().getApplicationContext());
|
||||
assertThat(controllers).isNotNull();
|
||||
assertThat(controllers.size()).isEqualTo(1);
|
||||
assertThat(controllers.get(0)).isInstanceOf(InstalledPackagesPreferenceController.class);
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
* Copyright (C) 2016 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.res.Resources;
|
||||
import android.support.v7.preference.Preference;
|
||||
|
||||
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.applications.ApplicationFeatureProvider;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Answers;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.stubbing.Answer;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Mockito.anyObject;
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* Tests for {@link InstalledPackagesPreferenceController}.
|
||||
*/
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public final class InstalledPackagesPreferenceControllerTest {
|
||||
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private Context mContext;
|
||||
private FakeFeatureFactory mFeatureFactory;
|
||||
|
||||
private InstalledPackagesPreferenceController mController;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
FakeFeatureFactory.setupForTest(mContext);
|
||||
mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
|
||||
mController = new InstalledPackagesPreferenceController(mContext);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateState() {
|
||||
final Preference preference = new Preference(mContext, null, 0, 0);
|
||||
doAnswer(new Answer() {
|
||||
public Object answer(InvocationOnMock invocation) {
|
||||
((ApplicationFeatureProvider.NumberOfInstalledAppsCallback)
|
||||
invocation.getArguments()[0]).onNumberOfInstalledAppsResult(20);
|
||||
return null;
|
||||
}}).when(mFeatureFactory.applicationFeatureProvider)
|
||||
.calculateNumberOfInstalledApps(anyObject());
|
||||
when(mContext.getResources().getQuantityString(R.plurals.number_installed_packages, 20, 20))
|
||||
.thenReturn("20 packages");
|
||||
mController.updateState(preference);
|
||||
assertThat(preference.getTitle()).isEqualTo("20 packages");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsAvailable() {
|
||||
assertThat(mController.isAvailable()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHandlePreferenceTreeClick() {
|
||||
assertThat(mController.handlePreferenceTreeClick(new Preference(mContext, null, 0, 0)))
|
||||
.isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetPreferenceKey() {
|
||||
assertThat(mController.getPreferenceKey()).isEqualTo("number_installed_packages");
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user