Add Enterprise Privacy page to Settings
This adds a new page to Settings which tells the user about his/her privacy in light of enterprise management. The new page is only shown on devices that have a Device Owner app set. This CL adds a mostly blank page. Follow-up CLs will populate the page with information about specific admin actions/policies. The page's title ("Privacy"), icon and location in the Settings app are tentative. The page will move to its final location once the new IA redesign is finished. Test: make RunSettingsRoboTests BUG: 32692748 Change-Id: I5b5c08c0025207516b0779f54cf68234a4ba3fe4
This commit is contained in:
@@ -1580,6 +1580,20 @@
|
||||
android:value="true" />
|
||||
</activity>
|
||||
|
||||
<activity android:name="Settings$EnterprisePrivacySettingsActivity"
|
||||
android:label="@string/enterprise_privacy_settings_title"
|
||||
android:icon="@drawable/ic_settings_about"
|
||||
android:taskAffinity="com.android.settings"
|
||||
android:parentActivityName="Settings">
|
||||
<intent-filter android:priority="-1">
|
||||
<action android:name="com.android.settings.action.SETTINGS" />
|
||||
</intent-filter>
|
||||
<meta-data android:name="com.android.settings.category"
|
||||
android:value="com.android.settings.category.device" />
|
||||
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
|
||||
android:value="com.android.settings.enterprise.EnterprisePrivacySettings" />
|
||||
</activity>
|
||||
|
||||
<!-- Second and third-level settings -->
|
||||
|
||||
<!-- Lock screen settings -->
|
||||
@@ -3435,6 +3449,18 @@
|
||||
android:value="true"/>
|
||||
</activity-alias>
|
||||
|
||||
<!-- Alias for enterprise privacy setting in new IA. Should merge into TargetActivity when launch -->
|
||||
<activity-alias android:name="EnterprisePrivacyDashboardAlias"
|
||||
android:targetActivity="Settings$EnterprisePrivacySettingsActivity">
|
||||
<intent-filter android:priority="-1">
|
||||
<action android:name="com.android.settings.action.SETTINGS" />
|
||||
</intent-filter>
|
||||
<meta-data android:name="com.android.settings.category"
|
||||
android:value="com.android.settings.category.ia.system" />
|
||||
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
|
||||
android:value="com.android.settings.enterprise.EnterprisePrivacySettings" />
|
||||
</activity-alias>
|
||||
|
||||
<!-- End of information architecture host activities -->
|
||||
|
||||
<service
|
||||
|
@@ -7974,4 +7974,12 @@
|
||||
<!-- Switch label to enable auto sync work account [CHAR LIMIT=30] -->
|
||||
<string name="auto_sync_work_account_title">Auto sync work account data</string>
|
||||
|
||||
<!-- Enterprise Privacy --> <skip />
|
||||
|
||||
<!-- Title of setting on main settings screen. This will take the user to a screen with information about his/her privacy on a managed device. Shown on enterprise-managed devices only. -->
|
||||
<string name="enterprise_privacy_settings">Privacy</string>
|
||||
<!-- Enterprise Privacy settings activity title -->
|
||||
<string name="enterprise_privacy_settings_title">Privacy</string>
|
||||
<!-- Enterprise Privacy settings activity header, summarizing the powers that the admin has. [CHAR LIMIT=NONE] -->
|
||||
<string name="enterprise_privacy_header">To provide access to your work data, your organization may change settings and install software on your device, which could cause some of your personal content to be visible to your admin. Contact your organization\'s admin for more details.</string>
|
||||
</resources>
|
||||
|
26
res/xml/enterprise_privacy_settings.xml
Normal file
26
res/xml/enterprise_privacy_settings.xml
Normal file
@@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- 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.
|
||||
-->
|
||||
|
||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:settings="http://schemas.android.com/apk/res/com.android.settings"
|
||||
android:key="enterprise_privacy_settings"
|
||||
android:title="@string/enterprise_privacy_settings_title">
|
||||
|
||||
<!-- Header -->
|
||||
<Preference android:key="enterprise_privacy_header"
|
||||
android:summary="@string/enterprise_privacy_header"
|
||||
android:selectable="false"/>
|
||||
</PreferenceScreen>
|
@@ -158,6 +158,7 @@ public class Settings extends SettingsActivity {
|
||||
public static class TestingSettingsActivity extends SettingsActivity { /* empty */ }
|
||||
public static class WifiAPITestActivity extends SettingsActivity { /* empty */ }
|
||||
public static class WifiInfoActivity extends SettingsActivity { /* empty */ }
|
||||
public static class EnterprisePrivacySettingsActivity extends SettingsActivity { /* empty */ }
|
||||
|
||||
// Categories.
|
||||
public static class WirelessSettings extends SettingsActivity { /* empty */ }
|
||||
|
@@ -94,6 +94,8 @@ import com.android.settings.deviceinfo.Status;
|
||||
import com.android.settings.deviceinfo.StorageDashboardFragment;
|
||||
import com.android.settings.deviceinfo.StorageSettings;
|
||||
import com.android.settings.display.NightDisplaySettings;
|
||||
import com.android.settings.enterprise.EnterprisePrivacyFeatureProvider;
|
||||
import com.android.settings.enterprise.EnterprisePrivacySettings;
|
||||
import com.android.settings.fuelgauge.BatterySaverSettings;
|
||||
import com.android.settings.fuelgauge.PowerUsageDetail;
|
||||
import com.android.settings.fuelgauge.PowerUsageSummary;
|
||||
@@ -277,6 +279,7 @@ public class SettingsActivity extends SettingsDrawerActivity
|
||||
Settings.AccessibilitySettingsActivity.class.getName(),
|
||||
Settings.PrintSettingsActivity.class.getName(),
|
||||
Settings.PaymentSettingsActivity.class.getName(),
|
||||
Settings.EnterprisePrivacySettingsActivity.class.getName(),
|
||||
|
||||
// New IA
|
||||
// Home page
|
||||
@@ -416,6 +419,7 @@ public class SettingsActivity extends SettingsDrawerActivity
|
||||
ConnectedDeviceDashboardFragment.class.getName(),
|
||||
AppAndNotificationDashboardFragment.class.getName(),
|
||||
UserAndAccountDashboardFragment.class.getName(),
|
||||
EnterprisePrivacySettings.class.getName(),
|
||||
};
|
||||
|
||||
|
||||
@@ -1219,6 +1223,11 @@ public class SettingsActivity extends SettingsDrawerActivity
|
||||
setTileEnabled(new ComponentName(packageName,
|
||||
BackupSettingsActivity.class.getName()), hasBackupActivity, isAdmin, pm);
|
||||
|
||||
setTileEnabled(new ComponentName(packageName,
|
||||
Settings.EnterprisePrivacySettingsActivity.class.getName()),
|
||||
FeatureFactory.getFactory(this).getEnterprisePrivacyFeatureProvider(this)
|
||||
.hasDeviceOwner(), isAdmin, pm);
|
||||
|
||||
}
|
||||
|
||||
private void setTileEnabled(ComponentName component, boolean enabled, boolean isAdmin,
|
||||
|
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* 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.ComponentName;
|
||||
|
||||
// This interface replicates a subset of the android.app.admin.DevicePolicyManager (DPM). The
|
||||
// interface exists so that we can use a thin wrapper around the DPM in production code and a mock
|
||||
// in tests. We cannot directly mock or shadow the DPM, because some of the methods we rely on are
|
||||
// newer than the API version supported by Robolectric.
|
||||
public interface DevicePolicyManagerWrapper {
|
||||
public ComponentName getDeviceOwnerComponentOnAnyUser();
|
||||
}
|
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* 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.app.admin.DevicePolicyManager;
|
||||
import android.content.ComponentName;
|
||||
|
||||
public class DevicePolicyManagerWrapperImpl implements DevicePolicyManagerWrapper {
|
||||
private final DevicePolicyManager mDpm;
|
||||
|
||||
public DevicePolicyManagerWrapperImpl(DevicePolicyManager dpm) {
|
||||
mDpm = dpm;
|
||||
}
|
||||
|
||||
public ComponentName getDeviceOwnerComponentOnAnyUser() {
|
||||
return mDpm.getDeviceOwnerComponentOnAnyUser();
|
||||
}
|
||||
}
|
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
public interface EnterprisePrivacyFeatureProvider {
|
||||
boolean hasDeviceOwner();
|
||||
}
|
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* 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.pm.PackageManager;
|
||||
import android.content.Context;
|
||||
|
||||
public class EnterprisePrivacyFeatureProviderImpl implements EnterprisePrivacyFeatureProvider {
|
||||
|
||||
private final Context mContext;
|
||||
private final DevicePolicyManagerWrapper mDpm;
|
||||
|
||||
public EnterprisePrivacyFeatureProviderImpl(Context context, DevicePolicyManagerWrapper dpm) {
|
||||
mContext = context.getApplicationContext();
|
||||
mDpm = dpm;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasDeviceOwner() {
|
||||
if (!mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_DEVICE_ADMIN)) {
|
||||
return false;
|
||||
}
|
||||
return mDpm.getDeviceOwnerComponentOnAnyUser() != null;
|
||||
}
|
||||
}
|
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* 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.os.Bundle;
|
||||
import android.provider.SearchIndexableResource;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.core.PreferenceController;
|
||||
import com.android.settings.dashboard.DashboardFragment;
|
||||
import com.android.settings.search.BaseSearchIndexProvider;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class EnterprisePrivacySettings extends DashboardFragment {
|
||||
|
||||
static final String TAG = "EnterprisePrivacySettings";
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return MetricsEvent.ENTERPRISE_PRIVACY_SETTINGS;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getCategoryKey() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getLogTag() {
|
||||
return TAG;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getPreferenceScreenResId() {
|
||||
return R.xml.enterprise_privacy_settings;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<PreferenceController> getPreferenceControllers(Context context) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
||||
new BaseSearchIndexProvider() {
|
||||
@Override
|
||||
public List<SearchIndexableResource> getXmlResourcesToIndex(
|
||||
Context context, boolean enabled) {
|
||||
final SearchIndexableResource sir = new SearchIndexableResource(context);
|
||||
sir.xmlResId = R.xml.enterprise_privacy_settings;
|
||||
return Arrays.asList(sir);
|
||||
}
|
||||
};
|
||||
}
|
@@ -24,6 +24,7 @@ import com.android.settings.R;
|
||||
import com.android.settings.applications.ApplicationFeatureProvider;
|
||||
import com.android.settings.core.instrumentation.MetricsFeatureProvider;
|
||||
import com.android.settings.dashboard.DashboardFeatureProvider;
|
||||
import com.android.settings.enterprise.EnterprisePrivacyFeatureProvider;
|
||||
import com.android.settings.fuelgauge.PowerUsageFeatureProvider;
|
||||
import com.android.settings.localepicker.LocaleFeatureProvider;
|
||||
|
||||
@@ -76,6 +77,8 @@ public abstract class FeatureFactory {
|
||||
|
||||
public abstract LocaleFeatureProvider getLocaleFeatureProvider();
|
||||
|
||||
public abstract EnterprisePrivacyFeatureProvider getEnterprisePrivacyFeatureProvider(
|
||||
Context context);
|
||||
|
||||
public static final class FactoryNotFoundException extends RuntimeException {
|
||||
public FactoryNotFoundException(Throwable throwable) {
|
||||
|
@@ -16,6 +16,7 @@
|
||||
|
||||
package com.android.settings.overlay;
|
||||
|
||||
import android.app.admin.DevicePolicyManager;
|
||||
import android.content.Context;
|
||||
import android.support.annotation.Keep;
|
||||
|
||||
@@ -25,6 +26,9 @@ import com.android.settings.core.instrumentation.MetricsFeatureProvider;
|
||||
import com.android.settings.core.instrumentation.MetricsFeatureProviderImpl;
|
||||
import com.android.settings.dashboard.DashboardFeatureProvider;
|
||||
import com.android.settings.dashboard.DashboardFeatureProviderImpl;
|
||||
import com.android.settings.enterprise.DevicePolicyManagerWrapperImpl;
|
||||
import com.android.settings.enterprise.EnterprisePrivacyFeatureProvider;
|
||||
import com.android.settings.enterprise.EnterprisePrivacyFeatureProviderImpl;
|
||||
import com.android.settings.fuelgauge.PowerUsageFeatureProvider;
|
||||
import com.android.settings.localepicker.LocaleFeatureProvider;
|
||||
import com.android.settings.localepicker.LocaleFeatureProviderImpl;
|
||||
@@ -39,6 +43,7 @@ public final class FeatureFactoryImpl extends FeatureFactory {
|
||||
private MetricsFeatureProvider mMetricsFeatureProvider;
|
||||
private DashboardFeatureProviderImpl mDashboardFeatureProvider;
|
||||
private LocaleFeatureProvider mLocaleFeatureProvider;
|
||||
private EnterprisePrivacyFeatureProvider mEnterprisePrivacyFeatureProvider;
|
||||
|
||||
@Override
|
||||
public SupportFeatureProvider getSupportFeatureProvider(Context context) {
|
||||
@@ -81,4 +86,14 @@ public final class FeatureFactoryImpl extends FeatureFactory {
|
||||
}
|
||||
return mLocaleFeatureProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnterprisePrivacyFeatureProvider getEnterprisePrivacyFeatureProvider(Context context) {
|
||||
if (mEnterprisePrivacyFeatureProvider == null) {
|
||||
mEnterprisePrivacyFeatureProvider = new EnterprisePrivacyFeatureProviderImpl(context,
|
||||
new DevicePolicyManagerWrapperImpl((DevicePolicyManager)context
|
||||
.getSystemService(Context.DEVICE_POLICY_SERVICE)));
|
||||
}
|
||||
return mEnterprisePrivacyFeatureProvider;
|
||||
}
|
||||
}
|
||||
|
@@ -37,6 +37,7 @@ import com.android.settings.datausage.DataUsageSummary;
|
||||
import com.android.settings.deviceinfo.StorageDashboardFragment;
|
||||
import com.android.settings.deviceinfo.StorageSettings;
|
||||
import com.android.settings.display.ScreenZoomSettings;
|
||||
import com.android.settings.enterprise.EnterprisePrivacySettings;
|
||||
import com.android.settings.fuelgauge.BatterySaverSettings;
|
||||
import com.android.settings.fuelgauge.PowerUsageSummary;
|
||||
import com.android.settings.gestures.GestureSettings;
|
||||
@@ -170,6 +171,7 @@ public final class Ranking {
|
||||
|
||||
// Privacy
|
||||
sRankMap.put(PrivacySettings.class.getName(), RANK_PRIVACY);
|
||||
sRankMap.put(EnterprisePrivacySettings.class.getName(), RANK_PRIVACY);
|
||||
|
||||
// Date / Time
|
||||
sRankMap.put(DateTimeSettings.class.getName(), RANK_DATE_TIME);
|
||||
|
@@ -38,6 +38,7 @@ import com.android.settings.datausage.DataUsageSummary;
|
||||
import com.android.settings.deviceinfo.StorageDashboardFragment;
|
||||
import com.android.settings.deviceinfo.StorageSettings;
|
||||
import com.android.settings.display.ScreenZoomSettings;
|
||||
import com.android.settings.enterprise.EnterprisePrivacySettings;
|
||||
import com.android.settings.fuelgauge.BatterySaverSettings;
|
||||
import com.android.settings.fuelgauge.PowerUsageSummary;
|
||||
import com.android.settings.gestures.GestureSettings;
|
||||
@@ -335,12 +336,20 @@ public final class SearchIndexableResources {
|
||||
NO_DATA_RES_ID,
|
||||
SystemDashboardFragment.class.getName(),
|
||||
R.drawable.ic_settings_about));
|
||||
|
||||
sResMap.put(StorageDashboardFragment.class.getName(),
|
||||
new SearchIndexableResource(
|
||||
Ranking.getRankForClassName(StorageDashboardFragment.class.getName()),
|
||||
NO_DATA_RES_ID,
|
||||
StorageDashboardFragment.class.getName(),
|
||||
R.drawable.ic_settings_storage));
|
||||
|
||||
sResMap.put(EnterprisePrivacySettings.class.getName(),
|
||||
new SearchIndexableResource(
|
||||
Ranking.getRankForClassName(EnterprisePrivacySettings.class.getName()),
|
||||
NO_DATA_RES_ID,
|
||||
EnterprisePrivacySettings.class.getName(),
|
||||
R.drawable.ic_settings_about));
|
||||
}
|
||||
|
||||
private SearchIndexableResources() {
|
||||
|
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* 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.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
|
||||
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 static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* Tests for {@link EnterprisePrivacyFeatureProviderImpl}.
|
||||
*/
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
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 EnterprisePrivacyFeatureProvider mProvider;
|
||||
|
||||
@Before
|
||||
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);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHasDeviceOwner() {
|
||||
when(mDevicePolicyManager.getDeviceOwnerComponentOnAnyUser()).thenReturn(null);
|
||||
assertThat(mProvider.hasDeviceOwner()).isFalse();
|
||||
|
||||
when(mDevicePolicyManager.getDeviceOwnerComponentOnAnyUser()).thenReturn(DEVICE_OWNER);
|
||||
assertThat(mProvider.hasDeviceOwner()).isTrue();
|
||||
}
|
||||
}
|
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* 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 com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.R;
|
||||
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.robolectric.annotation.Config;
|
||||
import org.robolectric.shadows.ShadowApplication;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link EnterprisePrivacySettings}.
|
||||
*/
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public final class EnterprisePrivacySettingsTest {
|
||||
|
||||
private EnterprisePrivacySettings mSettings;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mSettings = new EnterprisePrivacySettings();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetMetricsCategory() {
|
||||
assertThat(mSettings.getMetricsCategory())
|
||||
.isEqualTo(MetricsEvent.ENTERPRISE_PRIVACY_SETTINGS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetCategoryKey() {
|
||||
assertThat(mSettings.getCategoryKey()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetLogTag() {
|
||||
assertThat(mSettings.getLogTag()).isEqualTo("EnterprisePrivacySettings");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetPreferenceScreenResId() {
|
||||
assertThat(mSettings.getPreferenceScreenResId())
|
||||
.isEqualTo(R.xml.enterprise_privacy_settings);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getPreferenceControllers() {
|
||||
assertThat(mSettings.getPreferenceControllers(
|
||||
ShadowApplication.getInstance().getApplicationContext())).isNull();
|
||||
}
|
||||
}
|
@@ -20,6 +20,7 @@ import android.content.Context;
|
||||
import com.android.settings.applications.ApplicationFeatureProvider;
|
||||
import com.android.settings.core.instrumentation.MetricsFeatureProvider;
|
||||
import com.android.settings.dashboard.DashboardFeatureProvider;
|
||||
import com.android.settings.enterprise.EnterprisePrivacyFeatureProvider;
|
||||
import com.android.settings.fuelgauge.PowerUsageFeatureProvider;
|
||||
import com.android.settings.localepicker.LocaleFeatureProvider;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
@@ -41,6 +42,7 @@ public class FakeFeatureFactory extends FeatureFactory {
|
||||
public final DashboardFeatureProvider dashboardFeatureProvider;
|
||||
public final LocaleFeatureProvider localeFeatureProvider;
|
||||
public final ApplicationFeatureProvider applicationFeatureProvider;
|
||||
public final EnterprisePrivacyFeatureProvider enterprisePrivacyFeatureProvider;
|
||||
|
||||
/**
|
||||
* Call this in {@code @Before} method of the test class to use fake factory.
|
||||
@@ -69,6 +71,7 @@ public class FakeFeatureFactory extends FeatureFactory {
|
||||
dashboardFeatureProvider = mock(DashboardFeatureProvider.class);
|
||||
localeFeatureProvider = mock(LocaleFeatureProvider.class);
|
||||
applicationFeatureProvider = mock(ApplicationFeatureProvider.class);
|
||||
enterprisePrivacyFeatureProvider = mock(EnterprisePrivacyFeatureProvider.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -100,4 +103,9 @@ public class FakeFeatureFactory extends FeatureFactory {
|
||||
public LocaleFeatureProvider getLocaleFeatureProvider() {
|
||||
return localeFeatureProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnterprisePrivacyFeatureProvider getEnterprisePrivacyFeatureProvider(Context context) {
|
||||
return enterprisePrivacyFeatureProvider;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user