Update strings and layout for enterprise privacy
This CL continues the finalization of UI layout and strings for the enterprise privacy page: * Turn footer into a header * Update strings * Dynamically generate summaries for entry points in security page Bug: 32692748 Test: m RunSettingsRoboTests Change-Id: Ibf248ac269380fb1b919b01f88f721130060b7f9
This commit is contained in:
@@ -1506,7 +1506,7 @@
|
|||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
<activity android:name="Settings$EnterprisePrivacySettingsActivity"
|
<activity android:name="Settings$EnterprisePrivacySettingsActivity"
|
||||||
android:label="@string/enterprise_privacy_settings_title"
|
android:label="@string/enterprise_privacy_settings"
|
||||||
android:taskAffinity="com.android.settings"
|
android:taskAffinity="com.android.settings"
|
||||||
android:parentActivityName="Settings$SecuritySettingsActivity">
|
android:parentActivityName="Settings$SecuritySettingsActivity">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
|
@@ -1304,10 +1304,13 @@
|
|||||||
<string name="device_admin_title">Device administration</string>
|
<string name="device_admin_title">Device administration</string>
|
||||||
|
|
||||||
<!-- Title of preference to manage device admins -->
|
<!-- Title of preference to manage device admins -->
|
||||||
<string name="manage_device_admin">Device administrators</string>
|
<string name="manage_device_admin">Device admin apps</string>
|
||||||
|
|
||||||
<!-- Summary of preference to manage device policies -->
|
<!-- Summary of preference to manage device administrators, informing the user how many device administrator apps are installed and active -->
|
||||||
<string name="manage_device_admin_summary">View or deactivate device administrators</string>
|
<plurals name="number_of_device_admins">
|
||||||
|
<item quantity="one"><xliff:g id="count">%d</xliff:g> active app</item>
|
||||||
|
<item quantity="other"><xliff:g id="count">%d</xliff:g> active apps</item>
|
||||||
|
</plurals>
|
||||||
|
|
||||||
<!-- Title of preference to manage trust agents -->
|
<!-- Title of preference to manage trust agents -->
|
||||||
<string name="manage_trust_agents">Trust agents</string>
|
<string name="manage_trust_agents">Trust agents</string>
|
||||||
@@ -8135,13 +8138,13 @@
|
|||||||
<!-- Enterprise Privacy --> <skip />
|
<!-- Enterprise Privacy --> <skip />
|
||||||
|
|
||||||
<!-- Title of setting on security settings screen. This will take the user to a screen with information about admin powers and their impact on the user's privacy on a managed device. Shown on enterprise-managed devices only. -->
|
<!-- Title of setting on security settings screen. This will take the user to a screen with information about admin powers and their impact on the user's privacy on a managed device. Shown on enterprise-managed devices only. -->
|
||||||
<string name="enterprise_privacy_settings">Device management</string>
|
<string name="enterprise_privacy_settings">Managed device details</string>
|
||||||
<!-- Summary for Enterprise Privacy settings, explaining what the user can expect to find under it [CHAR LIMIT=NONE]-->
|
<!-- Summary for Enterprise Privacy settings, explaining what the user can expect to find under it [CHAR LIMIT=NONE]-->
|
||||||
<string name="enterprise_privacy_settings_summary">View all settings applied by your admin</string>
|
<string name="enterprise_privacy_settings_summary_generic">Changes & settings managed by your organization</string>
|
||||||
<!-- Enterprise Privacy settings activity title -->
|
<!-- Summary for Enterprise Privacy settings, explaining what the user can expect to find under it [CHAR LIMIT=NONE]-->
|
||||||
<string name="enterprise_privacy_settings_title">Device management</string>
|
<string name="enterprise_privacy_settings_summary_with_name">Changes & settings managed by <xliff:g id="organization_name" example="Foo, Inc.">%s</xliff:g></string>
|
||||||
<!-- Enterprise Privacy settings activity footer, summarizing the powers that the admin has. [CHAR LIMIT=NONE] -->
|
<!-- Enterprise Privacy settings activity header, summarizing the powers that the admin has. [CHAR LIMIT=NONE] -->
|
||||||
<string name="enterprise_privacy_footer">To provide access to your work data, your organization may change settings and install software on your device. \n\nFor more details, contact your organization\'s admin.</string>
|
<string name="enterprise_privacy_header">To provide access to your work data, your organization may change settings and install software on your device.\n\nFor more details, contact your organization\'s admin.</string>
|
||||||
<!-- Title for the 'Types of information your organization can see' preference category. [CHAR LIMIT=60] -->
|
<!-- Title for the 'Types of information your organization can see' preference category. [CHAR LIMIT=60] -->
|
||||||
<string name="enterprise_privacy_exposure_category">Types of information your organization can see</string>
|
<string name="enterprise_privacy_exposure_category">Types of information your organization can see</string>
|
||||||
<!-- Title for the 'Changes made by your organization’s admin' preference category. [CHAR LIMIT=60] -->
|
<!-- Title for the 'Changes made by your organization’s admin' preference category. [CHAR LIMIT=60] -->
|
||||||
@@ -8201,8 +8204,8 @@
|
|||||||
</plurals>
|
</plurals>
|
||||||
<!-- Label explaining that the admin installed trusted CA certificates for the personal profile. [CHAR LIMIT=NONE] -->
|
<!-- Label explaining that the admin installed trusted CA certificates for the personal profile. [CHAR LIMIT=NONE] -->
|
||||||
<plurals name="enterprise_privacy_ca_certs_personal">
|
<plurals name="enterprise_privacy_ca_certs_personal">
|
||||||
<item quantity="one">Trusted CA Certificate installed in the personal profile</item>
|
<item quantity="one">Trusted CA Certificate installed in your personal profile</item>
|
||||||
<item quantity="other">Trusted CA Certificates installed in the personal profile</item>
|
<item quantity="other">Trusted CA Certificates installed in your personal profile</item>
|
||||||
</plurals>
|
</plurals>
|
||||||
<!-- Summary indicating the number of trusted CA certificates installed by the admin. [CHAR LIMIT=NONE] -->
|
<!-- Summary indicating the number of trusted CA certificates installed by the admin. [CHAR LIMIT=NONE] -->
|
||||||
<plurals name="enterprise_privacy_number_ca_certs">
|
<plurals name="enterprise_privacy_number_ca_certs">
|
||||||
@@ -8216,8 +8219,8 @@
|
|||||||
</plurals>
|
</plurals>
|
||||||
<!-- Label explaining that the admin installed trusted CA certificates for the work profile. [CHAR LIMIT=NONE] -->
|
<!-- Label explaining that the admin installed trusted CA certificates for the work profile. [CHAR LIMIT=NONE] -->
|
||||||
<plurals name="enterprise_privacy_ca_certs_work">
|
<plurals name="enterprise_privacy_ca_certs_work">
|
||||||
<item quantity="one">Trusted CA Certificate installed in the work profile</item>
|
<item quantity="one">Trusted CA Certificate installed in your work profile</item>
|
||||||
<item quantity="other">Trusted CA Certificates installed in the work profile</item>
|
<item quantity="other">Trusted CA Certificates installed in your work profile</item>
|
||||||
</plurals>
|
</plurals>
|
||||||
<!-- Label explaining that the admin can lock the device and change the user's password. [CHAR LIMIT=NONE] -->
|
<!-- Label explaining that the admin can lock the device and change the user's password. [CHAR LIMIT=NONE] -->
|
||||||
<string name="enterprise_privacy_lock_device">Admin can lock the device and reset password</string>
|
<string name="enterprise_privacy_lock_device">Admin can lock the device and reset password</string>
|
||||||
|
@@ -17,7 +17,13 @@
|
|||||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:settings="http://schemas.android.com/apk/res/com.android.settings"
|
xmlns:settings="http://schemas.android.com/apk/res/com.android.settings"
|
||||||
android:key="enterprise_privacy_settings"
|
android:key="enterprise_privacy_settings"
|
||||||
android:title="@string/enterprise_privacy_settings_title">
|
android:title="@string/enterprise_privacy_settings">
|
||||||
|
|
||||||
|
<!-- Header -->
|
||||||
|
<Preference
|
||||||
|
android:icon="@drawable/ic_info_outline_24dp"
|
||||||
|
android:summary="@string/enterprise_privacy_header"
|
||||||
|
android:selectable="false"/>
|
||||||
|
|
||||||
<PreferenceCategory android:title="@string/enterprise_privacy_exposure_category">
|
<PreferenceCategory android:title="@string/enterprise_privacy_exposure_category">
|
||||||
<com.android.settings.DividerPreference
|
<com.android.settings.DividerPreference
|
||||||
@@ -107,8 +113,4 @@
|
|||||||
android:key="failed_password_wipe_managed_profile"
|
android:key="failed_password_wipe_managed_profile"
|
||||||
settings:multiLine="true"/>
|
settings:multiLine="true"/>
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
|
|
||||||
<com.android.settings.widget.FooterPreference
|
|
||||||
android:title="@string/enterprise_privacy_footer"
|
|
||||||
android:selectable="false"/>
|
|
||||||
</PreferenceScreen>
|
</PreferenceScreen>
|
||||||
|
@@ -39,13 +39,11 @@
|
|||||||
|
|
||||||
<Preference android:key="manage_device_admin"
|
<Preference android:key="manage_device_admin"
|
||||||
android:title="@string/manage_device_admin"
|
android:title="@string/manage_device_admin"
|
||||||
android:summary="@string/manage_device_admin_summary"
|
|
||||||
android:persistent="false"
|
android:persistent="false"
|
||||||
android:fragment="com.android.settings.DeviceAdminSettings"/>
|
android:fragment="com.android.settings.DeviceAdminSettings"/>
|
||||||
|
|
||||||
<Preference android:key="enterprise_privacy"
|
<Preference android:key="enterprise_privacy"
|
||||||
android:title="@string/enterprise_privacy_settings"
|
android:title="@string/enterprise_privacy_settings"
|
||||||
android:summary="@string/enterprise_privacy_settings_summary"
|
|
||||||
android:persistent="false"
|
android:persistent="false"
|
||||||
android:fragment="com.android.settings.enterprise.EnterprisePrivacySettings"/>
|
android:fragment="com.android.settings.enterprise.EnterprisePrivacySettings"/>
|
||||||
|
|
||||||
|
@@ -58,6 +58,8 @@ import com.android.settings.TrustAgentUtils.TrustAgentComponentInfo;
|
|||||||
import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
|
import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
|
||||||
import com.android.settings.dashboard.DashboardFeatureProvider;
|
import com.android.settings.dashboard.DashboardFeatureProvider;
|
||||||
import com.android.settings.dashboard.SummaryLoader;
|
import com.android.settings.dashboard.SummaryLoader;
|
||||||
|
import com.android.settings.enterprise.EnterprisePrivacyPreferenceController;
|
||||||
|
import com.android.settings.enterprise.ManageDeviceAdminPreferenceController;
|
||||||
import com.android.settings.fingerprint.FingerprintSettings;
|
import com.android.settings.fingerprint.FingerprintSettings;
|
||||||
import com.android.settings.location.LocationPreferenceController;
|
import com.android.settings.location.LocationPreferenceController;
|
||||||
import com.android.settings.overlay.FeatureFactory;
|
import com.android.settings.overlay.FeatureFactory;
|
||||||
@@ -128,6 +130,10 @@ public class SecuritySettings extends SettingsPreferenceFragment
|
|||||||
static final String KEY_PACKAGE_VERIFIER_STATUS = "security_status_package_verifier";
|
static final String KEY_PACKAGE_VERIFIER_STATUS = "security_status_package_verifier";
|
||||||
private static final int PACKAGE_VERIFIER_STATE_ENABLED = 1;
|
private static final int PACKAGE_VERIFIER_STATE_ENABLED = 1;
|
||||||
|
|
||||||
|
// Device management settings
|
||||||
|
private static final String KEY_ENTERPRISE_PRIVACY = "enterprise_privacy";
|
||||||
|
private static final String KEY_MANAGE_DEVICE_ADMIN = "manage_device_admin";
|
||||||
|
|
||||||
// These switch preferences need special handling since they're not all stored in Settings.
|
// These switch preferences need special handling since they're not all stored in Settings.
|
||||||
private static final String SWITCH_PREFERENCE_KEYS[] = {
|
private static final String SWITCH_PREFERENCE_KEYS[] = {
|
||||||
KEY_SHOW_PASSWORD, KEY_UNIFICATION, KEY_VISIBLE_PATTERN_PROFILE
|
KEY_SHOW_PASSWORD, KEY_UNIFICATION, KEY_VISIBLE_PATTERN_PROFILE
|
||||||
@@ -164,6 +170,8 @@ public class SecuritySettings extends SettingsPreferenceFragment
|
|||||||
private String mCurrentProfilePassword;
|
private String mCurrentProfilePassword;
|
||||||
|
|
||||||
private LocationPreferenceController mLocationcontroller;
|
private LocationPreferenceController mLocationcontroller;
|
||||||
|
private ManageDeviceAdminPreferenceController mManageDeviceAdminPreferenceController;
|
||||||
|
private EnterprisePrivacyPreferenceController mEnterprisePrivacyPreferenceController;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getMetricsCategory() {
|
public int getMetricsCategory() {
|
||||||
@@ -201,6 +209,10 @@ public class SecuritySettings extends SettingsPreferenceFragment
|
|||||||
}
|
}
|
||||||
|
|
||||||
mLocationcontroller = new LocationPreferenceController(activity);
|
mLocationcontroller = new LocationPreferenceController(activity);
|
||||||
|
mManageDeviceAdminPreferenceController
|
||||||
|
= new ManageDeviceAdminPreferenceController(activity);
|
||||||
|
mEnterprisePrivacyPreferenceController
|
||||||
|
= new EnterprisePrivacyPreferenceController(activity, null /* lifecycle */);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int getResIdForLockUnlockScreen(Context context,
|
private static int getResIdForLockUnlockScreen(Context context,
|
||||||
@@ -394,6 +406,11 @@ public class SecuritySettings extends SettingsPreferenceFragment
|
|||||||
}
|
}
|
||||||
|
|
||||||
mLocationcontroller.displayPreference(root);
|
mLocationcontroller.displayPreference(root);
|
||||||
|
mManageDeviceAdminPreferenceController.updateState(
|
||||||
|
root.findPreference(KEY_MANAGE_DEVICE_ADMIN));
|
||||||
|
mEnterprisePrivacyPreferenceController.displayPreference(root);
|
||||||
|
mEnterprisePrivacyPreferenceController.onResume();
|
||||||
|
|
||||||
return root;
|
return root;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -895,6 +912,11 @@ public class SecuritySettings extends SettingsPreferenceFragment
|
|||||||
keys.add(KEY_MANAGE_TRUST_AGENTS);
|
keys.add(KEY_MANAGE_TRUST_AGENTS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!(new EnterprisePrivacyPreferenceController(context, null /* lifecycle */))
|
||||||
|
.isAvailable()) {
|
||||||
|
keys.add(KEY_ENTERPRISE_PRIVACY);
|
||||||
|
}
|
||||||
|
|
||||||
return keys;
|
return keys;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -30,6 +30,13 @@ import java.util.List;
|
|||||||
* newer than the API version supported by Robolectric.
|
* newer than the API version supported by Robolectric.
|
||||||
*/
|
*/
|
||||||
public interface DevicePolicyManagerWrapper {
|
public interface DevicePolicyManagerWrapper {
|
||||||
|
/**
|
||||||
|
* Calls {@code DevicePolicyManager.getActiveAdminsAsUser()}.
|
||||||
|
*
|
||||||
|
* @see android.app.admin.DevicePolicyManager#getActiveAdminsAsUser
|
||||||
|
*/
|
||||||
|
public @Nullable List<ComponentName> getActiveAdminsAsUser(int userId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calls {@code DevicePolicyManager.getMaximumFailedPasswordsForWipe()}.
|
* Calls {@code DevicePolicyManager.getMaximumFailedPasswordsForWipe()}.
|
||||||
*
|
*
|
||||||
|
@@ -31,6 +31,11 @@ public class DevicePolicyManagerWrapperImpl implements DevicePolicyManagerWrappe
|
|||||||
mDpm = dpm;
|
mDpm = dpm;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @Nullable List<ComponentName> getActiveAdminsAsUser(int userId) {
|
||||||
|
return mDpm.getActiveAdminsAsUser(userId);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin, int userHandle) {
|
public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin, int userHandle) {
|
||||||
return mDpm.getMaximumFailedPasswordsForWipe(admin, userHandle);
|
return mDpm.getMaximumFailedPasswordsForWipe(admin, userHandle);
|
||||||
|
@@ -31,6 +31,13 @@ public interface EnterprisePrivacyFeatureProvider {
|
|||||||
*/
|
*/
|
||||||
boolean isInCompMode();
|
boolean isInCompMode();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the name of the organization managing the device via a Device Owner app. If the device
|
||||||
|
* is not managed by a Device Owner app or the name of the managing organization was not set,
|
||||||
|
* returns {@code null}.
|
||||||
|
*/
|
||||||
|
String getDeviceOwnerOrganizationName();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a message informing the user that the device is managed by a Device Owner app. The
|
* Returns a message informing the user that the device is managed by a Device Owner app. The
|
||||||
* message includes a Learn More link that takes the user to the enterprise privacy section of
|
* message includes a Learn More link that takes the user to the enterprise privacy section of
|
||||||
@@ -100,4 +107,10 @@ public interface EnterprisePrivacyFeatureProvider {
|
|||||||
* managed profile (if any).
|
* managed profile (if any).
|
||||||
*/
|
*/
|
||||||
int getNumberOfOwnerInstalledCaCertsInManagedProfile();
|
int getNumberOfOwnerInstalledCaCertsInManagedProfile();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the number of Device Admin apps active in the current user and the user's managed
|
||||||
|
* profile (if any).
|
||||||
|
*/
|
||||||
|
int getNumberOfActiveDeviceAdminsForCurrentUserAndManagedProfile();
|
||||||
}
|
}
|
||||||
|
@@ -83,6 +83,16 @@ public class EnterprisePrivacyFeatureProviderImpl implements EnterprisePrivacyFe
|
|||||||
return hasDeviceOwner() && getManagedProfileUserId() != UserHandle.USER_NULL;
|
return hasDeviceOwner() && getManagedProfileUserId() != UserHandle.USER_NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDeviceOwnerOrganizationName() {
|
||||||
|
final CharSequence organizationName = mDpm.getDeviceOwnerOrganizationName();
|
||||||
|
if (organizationName == null) {
|
||||||
|
return null;
|
||||||
|
} else {
|
||||||
|
return organizationName.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CharSequence getDeviceOwnerDisclosure() {
|
public CharSequence getDeviceOwnerDisclosure() {
|
||||||
if (!hasDeviceOwner()) {
|
if (!hasDeviceOwner()) {
|
||||||
@@ -194,6 +204,19 @@ public class EnterprisePrivacyFeatureProviderImpl implements EnterprisePrivacyFe
|
|||||||
return certs != null ? certs.size() : 0;
|
return certs != null ? certs.size() : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getNumberOfActiveDeviceAdminsForCurrentUserAndManagedProfile() {
|
||||||
|
int activeAdmins = 0;
|
||||||
|
for (final UserInfo userInfo : mUm.getProfiles(MY_USER_ID)) {
|
||||||
|
final List<ComponentName> activeAdminsForUser
|
||||||
|
= mDpm.getActiveAdminsAsUser(userInfo.id);
|
||||||
|
if (activeAdminsForUser != null) {
|
||||||
|
activeAdmins += activeAdminsForUser.size();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return activeAdmins;
|
||||||
|
}
|
||||||
|
|
||||||
protected static class EnterprisePrivacySpan extends ClickableSpan {
|
protected static class EnterprisePrivacySpan extends ClickableSpan {
|
||||||
private final Context mContext;
|
private final Context mContext;
|
||||||
|
|
||||||
|
@@ -0,0 +1,56 @@
|
|||||||
|
/*
|
||||||
|
* 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.res.Resources;
|
||||||
|
import android.support.v7.preference.Preference;
|
||||||
|
|
||||||
|
import com.android.settings.R;
|
||||||
|
import com.android.settings.core.DynamicAvailabilityPreferenceController;
|
||||||
|
import com.android.settings.core.lifecycle.Lifecycle;
|
||||||
|
import com.android.settings.overlay.FeatureFactory;
|
||||||
|
|
||||||
|
public class EnterprisePrivacyPreferenceController extends DynamicAvailabilityPreferenceController {
|
||||||
|
|
||||||
|
private static final String KEY_ENTERPRISE_PRIVACY = "enterprise_privacy";
|
||||||
|
private final EnterprisePrivacyFeatureProvider mFeatureProvider;
|
||||||
|
|
||||||
|
public EnterprisePrivacyPreferenceController(Context context, Lifecycle lifecycle) {
|
||||||
|
super(context, lifecycle);
|
||||||
|
mFeatureProvider = FeatureFactory.getFactory(context)
|
||||||
|
.getEnterprisePrivacyFeatureProvider(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateState(Preference preference) {
|
||||||
|
final String organizationName = mFeatureProvider.getDeviceOwnerOrganizationName();
|
||||||
|
if (organizationName == null) {
|
||||||
|
preference.setSummary(R.string.enterprise_privacy_settings_summary_generic);
|
||||||
|
} else {
|
||||||
|
preference.setSummary(mContext.getResources().getString(
|
||||||
|
R.string.enterprise_privacy_settings_summary_with_name, organizationName));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isAvailable() {
|
||||||
|
return mFeatureProvider.hasDeviceOwner();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPreferenceKey() {
|
||||||
|
return KEY_ENTERPRISE_PRIVACY;
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,52 @@
|
|||||||
|
/*
|
||||||
|
* 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.res.Resources;
|
||||||
|
import android.support.v7.preference.Preference;
|
||||||
|
|
||||||
|
import com.android.settings.R;
|
||||||
|
import com.android.settings.core.PreferenceController;
|
||||||
|
import com.android.settings.overlay.FeatureFactory;
|
||||||
|
|
||||||
|
public class ManageDeviceAdminPreferenceController extends PreferenceController {
|
||||||
|
|
||||||
|
private static final String KEY_MANAGE_DEVICE_ADMIN = "manage_device_admin";
|
||||||
|
private final EnterprisePrivacyFeatureProvider mFeatureProvider;
|
||||||
|
|
||||||
|
public ManageDeviceAdminPreferenceController(Context context) {
|
||||||
|
super(context);
|
||||||
|
mFeatureProvider = FeatureFactory.getFactory(context)
|
||||||
|
.getEnterprisePrivacyFeatureProvider(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateState(Preference preference) {
|
||||||
|
final int activeAdmins
|
||||||
|
= mFeatureProvider.getNumberOfActiveDeviceAdminsForCurrentUserAndManagedProfile();
|
||||||
|
preference.setSummary(mContext.getResources().getQuantityString(
|
||||||
|
R.plurals.number_of_device_admins, activeAdmins, activeAdmins));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isAvailable() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPreferenceKey() {
|
||||||
|
return KEY_MANAGE_DEVICE_ADMIN;
|
||||||
|
}
|
||||||
|
}
|
@@ -172,6 +172,7 @@ public final class Ranking {
|
|||||||
sRankMap.put(SecuritySettings.class.getName(), RANK_SECURITY);
|
sRankMap.put(SecuritySettings.class.getName(), RANK_SECURITY);
|
||||||
sRankMap.put(ChooseLockGeneric.ChooseLockGenericFragment.class.getName(), RANK_SECURITY);
|
sRankMap.put(ChooseLockGeneric.ChooseLockGenericFragment.class.getName(), RANK_SECURITY);
|
||||||
sRankMap.put(ScreenPinningSettings.class.getName(), RANK_SECURITY);
|
sRankMap.put(ScreenPinningSettings.class.getName(), RANK_SECURITY);
|
||||||
|
sRankMap.put(EnterprisePrivacySettings.class.getName(), RANK_SECURITY);
|
||||||
|
|
||||||
// Accounts
|
// Accounts
|
||||||
sRankMap.put(UserAndAccountDashboardFragment.class.getName(), RANK_ACCOUNT);
|
sRankMap.put(UserAndAccountDashboardFragment.class.getName(), RANK_ACCOUNT);
|
||||||
@@ -181,7 +182,6 @@ public final class Ranking {
|
|||||||
|
|
||||||
// Privacy
|
// Privacy
|
||||||
sRankMap.put(PrivacySettings.class.getName(), RANK_PRIVACY);
|
sRankMap.put(PrivacySettings.class.getName(), RANK_PRIVACY);
|
||||||
sRankMap.put(EnterprisePrivacySettings.class.getName(), RANK_PRIVACY);
|
|
||||||
|
|
||||||
// Date / Time
|
// Date / Time
|
||||||
sRankMap.put(DateTimeSettings.class.getName(), RANK_DATE_TIME);
|
sRankMap.put(DateTimeSettings.class.getName(), RANK_DATE_TIME);
|
||||||
|
@@ -60,6 +60,8 @@ import static org.mockito.Mockito.when;
|
|||||||
public final class EnterprisePrivacyFeatureProviderImplTest {
|
public final class EnterprisePrivacyFeatureProviderImplTest {
|
||||||
|
|
||||||
private final ComponentName OWNER = new ComponentName("dummy", "component");
|
private final ComponentName OWNER = new ComponentName("dummy", "component");
|
||||||
|
private final ComponentName ADMIN_1 = new ComponentName("dummy", "admin1");
|
||||||
|
private final ComponentName ADMIN_2 = new ComponentName("dummy", "admin2");
|
||||||
private final String OWNER_ORGANIZATION = new String("ACME");
|
private final String OWNER_ORGANIZATION = new String("ACME");
|
||||||
private final Date TIMESTAMP = new Date(2011, 11, 11);
|
private final Date TIMESTAMP = new Date(2011, 11, 11);
|
||||||
private final int MY_USER_ID = UserHandle.myUserId();
|
private final int MY_USER_ID = UserHandle.myUserId();
|
||||||
@@ -113,6 +115,15 @@ public final class EnterprisePrivacyFeatureProviderImplTest {
|
|||||||
assertThat(mProvider.isInCompMode()).isTrue();
|
assertThat(mProvider.isInCompMode()).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetDeviceOwnerOrganizationName() {
|
||||||
|
when(mDevicePolicyManager.getDeviceOwnerOrganizationName()).thenReturn(null);
|
||||||
|
assertThat(mProvider.getDeviceOwnerOrganizationName()).isNull();
|
||||||
|
|
||||||
|
when(mDevicePolicyManager.getDeviceOwnerOrganizationName()).thenReturn(OWNER_ORGANIZATION);
|
||||||
|
assertThat(mProvider.getDeviceOwnerOrganizationName()).isEqualTo(OWNER_ORGANIZATION);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetDeviceOwnerDisclosure() {
|
public void testGetDeviceOwnerDisclosure() {
|
||||||
when(mDevicePolicyManager.getDeviceOwnerComponentOnAnyUser()).thenReturn(null);
|
when(mDevicePolicyManager.getDeviceOwnerComponentOnAnyUser()).thenReturn(null);
|
||||||
@@ -292,6 +303,21 @@ public final class EnterprisePrivacyFeatureProviderImplTest {
|
|||||||
assertThat(mProvider.getNumberOfOwnerInstalledCaCertsInManagedProfile()).isEqualTo(0);
|
assertThat(mProvider.getNumberOfOwnerInstalledCaCertsInManagedProfile()).isEqualTo(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetNumberOfActiveDeviceAdminsForCurrentUserAndManagedProfile() {
|
||||||
|
when(mDevicePolicyManager.getActiveAdminsAsUser(MY_USER_ID))
|
||||||
|
.thenReturn(Arrays.asList(new ComponentName[] {ADMIN_1, ADMIN_2}));
|
||||||
|
when(mDevicePolicyManager.getActiveAdminsAsUser(MANAGED_PROFILE_USER_ID))
|
||||||
|
.thenReturn(Arrays.asList(new ComponentName[] {ADMIN_1}));
|
||||||
|
|
||||||
|
assertThat(mProvider.getNumberOfActiveDeviceAdminsForCurrentUserAndManagedProfile())
|
||||||
|
.isEqualTo(2);
|
||||||
|
|
||||||
|
mProfiles.add(new UserInfo(MANAGED_PROFILE_USER_ID, "", "", UserInfo.FLAG_MANAGED_PROFILE));
|
||||||
|
assertThat(mProvider.getNumberOfActiveDeviceAdminsForCurrentUserAndManagedProfile())
|
||||||
|
.isEqualTo(3);
|
||||||
|
}
|
||||||
|
|
||||||
private void resetAndInitializePackageManagerWrapper() {
|
private void resetAndInitializePackageManagerWrapper() {
|
||||||
reset(mPackageManagerWrapper);
|
reset(mPackageManagerWrapper);
|
||||||
when(mPackageManagerWrapper.hasSystemFeature(PackageManager.FEATURE_DEVICE_ADMIN))
|
when(mPackageManagerWrapper.hasSystemFeature(PackageManager.FEATURE_DEVICE_ADMIN))
|
||||||
|
@@ -0,0 +1,104 @@
|
|||||||
|
/*
|
||||||
|
* 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.res.Resources;
|
||||||
|
import android.support.v7.preference.Preference;
|
||||||
|
|
||||||
|
import com.android.settings.R;
|
||||||
|
import com.android.settings.SettingsRobolectricTestRunner;
|
||||||
|
import com.android.settings.TestConfig;
|
||||||
|
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.robolectric.annotation.Config;
|
||||||
|
|
||||||
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests for {@link EnterprisePrivacyPreferenceController}.
|
||||||
|
*/
|
||||||
|
@RunWith(SettingsRobolectricTestRunner.class)
|
||||||
|
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||||
|
public final class EnterprisePrivacyPreferenceControllerTest {
|
||||||
|
|
||||||
|
private final String MANAGED_GENERIC = "managed by organization";
|
||||||
|
private final String MANAGED_WITH_NAME = "managed by Foo, Inc.";
|
||||||
|
private final String MANAGING_ORGANIZATION = "Foo, Inc.";
|
||||||
|
|
||||||
|
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||||
|
private Context mContext;
|
||||||
|
private FakeFeatureFactory mFeatureFactory;
|
||||||
|
|
||||||
|
private EnterprisePrivacyPreferenceController mController;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
MockitoAnnotations.initMocks(this);
|
||||||
|
FakeFeatureFactory.setupForTest(mContext);
|
||||||
|
mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
|
||||||
|
mController = new EnterprisePrivacyPreferenceController(mContext, null /* lifecycle */);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUpdateState() {
|
||||||
|
final Preference preference = new Preference(mContext, null, 0, 0);
|
||||||
|
|
||||||
|
when(mContext.getString(R.string.enterprise_privacy_settings_summary_generic))
|
||||||
|
.thenReturn(MANAGED_GENERIC);
|
||||||
|
when(mFeatureFactory.enterprisePrivacyFeatureProvider.getDeviceOwnerOrganizationName())
|
||||||
|
.thenReturn(null);
|
||||||
|
mController.updateState(preference);
|
||||||
|
assertThat(preference.getSummary()).isEqualTo(MANAGED_GENERIC);
|
||||||
|
|
||||||
|
when(mContext.getResources().getString(
|
||||||
|
R.string.enterprise_privacy_settings_summary_with_name, MANAGING_ORGANIZATION))
|
||||||
|
.thenReturn(MANAGED_WITH_NAME);
|
||||||
|
when(mFeatureFactory.enterprisePrivacyFeatureProvider.getDeviceOwnerOrganizationName())
|
||||||
|
.thenReturn(MANAGING_ORGANIZATION);
|
||||||
|
mController.updateState(preference);
|
||||||
|
assertThat(preference.getSummary()).isEqualTo(MANAGED_WITH_NAME);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testIsAvailable() {
|
||||||
|
when(mFeatureFactory.enterprisePrivacyFeatureProvider.hasDeviceOwner()).thenReturn(false);
|
||||||
|
assertThat(mController.isAvailable()).isFalse();
|
||||||
|
|
||||||
|
when(mFeatureFactory.enterprisePrivacyFeatureProvider.hasDeviceOwner()).thenReturn(true);
|
||||||
|
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("enterprise_privacy");
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,87 @@
|
|||||||
|
/*
|
||||||
|
* 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.res.Resources;
|
||||||
|
import android.support.v7.preference.Preference;
|
||||||
|
|
||||||
|
import com.android.settings.R;
|
||||||
|
import com.android.settings.SettingsRobolectricTestRunner;
|
||||||
|
import com.android.settings.TestConfig;
|
||||||
|
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.robolectric.annotation.Config;
|
||||||
|
|
||||||
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests for {@link ManageDeviceAdminPreferenceController}.
|
||||||
|
*/
|
||||||
|
@RunWith(SettingsRobolectricTestRunner.class)
|
||||||
|
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||||
|
public final class ManageDeviceAdminPreferenceControllerTest {
|
||||||
|
|
||||||
|
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||||
|
private Context mContext;
|
||||||
|
private FakeFeatureFactory mFeatureFactory;
|
||||||
|
|
||||||
|
private ManageDeviceAdminPreferenceController mController;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
MockitoAnnotations.initMocks(this);
|
||||||
|
FakeFeatureFactory.setupForTest(mContext);
|
||||||
|
mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
|
||||||
|
mController = new ManageDeviceAdminPreferenceController(mContext);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUpdateState() {
|
||||||
|
final Preference preference = new Preference(mContext, null, 0, 0);
|
||||||
|
|
||||||
|
when(mFeatureFactory.enterprisePrivacyFeatureProvider
|
||||||
|
.getNumberOfActiveDeviceAdminsForCurrentUserAndManagedProfile()).thenReturn(5);
|
||||||
|
when(mContext.getResources().getQuantityString(R.plurals.number_of_device_admins, 5, 5))
|
||||||
|
.thenReturn("5 active apps");
|
||||||
|
mController.updateState(preference);
|
||||||
|
assertThat(preference.getSummary()).isEqualTo("5 active apps");
|
||||||
|
}
|
||||||
|
|
||||||
|
@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("manage_device_admin");
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user