diff options
Diffstat (limited to 'src')
8 files changed, 179 insertions, 1 deletions
diff --git a/src/com/android/settings/SecuritySettings.java b/src/com/android/settings/SecuritySettings.java index fb590cc0f9..53fab730e4 100644 --- a/src/com/android/settings/SecuritySettings.java +++ b/src/com/android/settings/SecuritySettings.java @@ -58,6 +58,8 @@ import com.android.settings.TrustAgentUtils.TrustAgentComponentInfo; import com.android.settings.core.instrumentation.InstrumentedDialogFragment; import com.android.settings.dashboard.DashboardFeatureProvider; 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.location.LocationPreferenceController; 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"; 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. private static final String SWITCH_PREFERENCE_KEYS[] = { KEY_SHOW_PASSWORD, KEY_UNIFICATION, KEY_VISIBLE_PATTERN_PROFILE @@ -164,6 +170,8 @@ public class SecuritySettings extends SettingsPreferenceFragment private String mCurrentProfilePassword; private LocationPreferenceController mLocationcontroller; + private ManageDeviceAdminPreferenceController mManageDeviceAdminPreferenceController; + private EnterprisePrivacyPreferenceController mEnterprisePrivacyPreferenceController; @Override public int getMetricsCategory() { @@ -201,6 +209,10 @@ public class SecuritySettings extends SettingsPreferenceFragment } mLocationcontroller = new LocationPreferenceController(activity); + mManageDeviceAdminPreferenceController + = new ManageDeviceAdminPreferenceController(activity); + mEnterprisePrivacyPreferenceController + = new EnterprisePrivacyPreferenceController(activity, null /* lifecycle */); } private static int getResIdForLockUnlockScreen(Context context, @@ -394,6 +406,11 @@ public class SecuritySettings extends SettingsPreferenceFragment } mLocationcontroller.displayPreference(root); + mManageDeviceAdminPreferenceController.updateState( + root.findPreference(KEY_MANAGE_DEVICE_ADMIN)); + mEnterprisePrivacyPreferenceController.displayPreference(root); + mEnterprisePrivacyPreferenceController.onResume(); + return root; } @@ -895,6 +912,11 @@ public class SecuritySettings extends SettingsPreferenceFragment keys.add(KEY_MANAGE_TRUST_AGENTS); } + if (!(new EnterprisePrivacyPreferenceController(context, null /* lifecycle */)) + .isAvailable()) { + keys.add(KEY_ENTERPRISE_PRIVACY); + } + return keys; } } diff --git a/src/com/android/settings/enterprise/DevicePolicyManagerWrapper.java b/src/com/android/settings/enterprise/DevicePolicyManagerWrapper.java index 7fae8bb7e9..ed9dd94707 100644 --- a/src/com/android/settings/enterprise/DevicePolicyManagerWrapper.java +++ b/src/com/android/settings/enterprise/DevicePolicyManagerWrapper.java @@ -31,6 +31,13 @@ import java.util.List; */ public interface DevicePolicyManagerWrapper { /** + * Calls {@code DevicePolicyManager.getActiveAdminsAsUser()}. + * + * @see android.app.admin.DevicePolicyManager#getActiveAdminsAsUser + */ + public @Nullable List<ComponentName> getActiveAdminsAsUser(int userId); + + /** * Calls {@code DevicePolicyManager.getMaximumFailedPasswordsForWipe()}. * * @see android.app.admin.DevicePolicyManager#getMaximumFailedPasswordsForWipe diff --git a/src/com/android/settings/enterprise/DevicePolicyManagerWrapperImpl.java b/src/com/android/settings/enterprise/DevicePolicyManagerWrapperImpl.java index 76264b4c44..647b4a75b5 100644 --- a/src/com/android/settings/enterprise/DevicePolicyManagerWrapperImpl.java +++ b/src/com/android/settings/enterprise/DevicePolicyManagerWrapperImpl.java @@ -32,6 +32,11 @@ public class DevicePolicyManagerWrapperImpl implements DevicePolicyManagerWrappe } @Override + public @Nullable List<ComponentName> getActiveAdminsAsUser(int userId) { + return mDpm.getActiveAdminsAsUser(userId); + } + + @Override public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin, int userHandle) { return mDpm.getMaximumFailedPasswordsForWipe(admin, userHandle); } diff --git a/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProvider.java b/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProvider.java index 792c3acc7b..2270efac8d 100644 --- a/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProvider.java +++ b/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProvider.java @@ -32,6 +32,13 @@ public interface EnterprisePrivacyFeatureProvider { 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 * message includes a Learn More link that takes the user to the enterprise privacy section of * Settings. If the device is not managed by a Device Owner app, returns {@code null}. @@ -100,4 +107,10 @@ public interface EnterprisePrivacyFeatureProvider { * managed profile (if any). */ int getNumberOfOwnerInstalledCaCertsInManagedProfile(); + + /** + * Returns the number of Device Admin apps active in the current user and the user's managed + * profile (if any). + */ + int getNumberOfActiveDeviceAdminsForCurrentUserAndManagedProfile(); } diff --git a/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProviderImpl.java b/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProviderImpl.java index 3b8251cb83..6cff807de9 100644 --- a/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProviderImpl.java +++ b/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProviderImpl.java @@ -84,6 +84,16 @@ public class EnterprisePrivacyFeatureProviderImpl implements EnterprisePrivacyFe } @Override + public String getDeviceOwnerOrganizationName() { + final CharSequence organizationName = mDpm.getDeviceOwnerOrganizationName(); + if (organizationName == null) { + return null; + } else { + return organizationName.toString(); + } + } + + @Override public CharSequence getDeviceOwnerDisclosure() { if (!hasDeviceOwner()) { return null; @@ -194,6 +204,19 @@ public class EnterprisePrivacyFeatureProviderImpl implements EnterprisePrivacyFe 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 { private final Context mContext; diff --git a/src/com/android/settings/enterprise/EnterprisePrivacyPreferenceController.java b/src/com/android/settings/enterprise/EnterprisePrivacyPreferenceController.java new file mode 100644 index 0000000000..254940e020 --- /dev/null +++ b/src/com/android/settings/enterprise/EnterprisePrivacyPreferenceController.java @@ -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; + } +} diff --git a/src/com/android/settings/enterprise/ManageDeviceAdminPreferenceController.java b/src/com/android/settings/enterprise/ManageDeviceAdminPreferenceController.java new file mode 100644 index 0000000000..55937ecebb --- /dev/null +++ b/src/com/android/settings/enterprise/ManageDeviceAdminPreferenceController.java @@ -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; + } +} diff --git a/src/com/android/settings/search/Ranking.java b/src/com/android/settings/search/Ranking.java index e0fb876dda..20f578b8f1 100644 --- a/src/com/android/settings/search/Ranking.java +++ b/src/com/android/settings/search/Ranking.java @@ -172,6 +172,7 @@ public final class Ranking { sRankMap.put(SecuritySettings.class.getName(), RANK_SECURITY); sRankMap.put(ChooseLockGeneric.ChooseLockGenericFragment.class.getName(), RANK_SECURITY); sRankMap.put(ScreenPinningSettings.class.getName(), RANK_SECURITY); + sRankMap.put(EnterprisePrivacySettings.class.getName(), RANK_SECURITY); // Accounts sRankMap.put(UserAndAccountDashboardFragment.class.getName(), RANK_ACCOUNT); @@ -181,7 +182,6 @@ 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); |