Merge "Add page Settings->Security & lock screen->Lock screen preferences."
This commit is contained in:
committed by
Android (Google) Code Review
commit
4433c8ce3d
@@ -31,6 +31,7 @@ import android.widget.EditText;
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
import com.android.internal.widget.LockPatternUtils;
|
||||
import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
|
||||
import com.android.settings.security.OwnerInfoPreferenceController.OwnerInfoCallback;
|
||||
|
||||
public class OwnerInfoSettings extends InstrumentedDialogFragment implements OnClickListener {
|
||||
|
||||
@@ -76,8 +77,8 @@ public class OwnerInfoSettings extends InstrumentedDialogFragment implements OnC
|
||||
mLockPatternUtils.setOwnerInfoEnabled(!TextUtils.isEmpty(info), mUserId);
|
||||
mLockPatternUtils.setOwnerInfo(info, mUserId);
|
||||
|
||||
if (getTargetFragment() instanceof SecuritySettings.SecuritySubSettings) {
|
||||
((SecuritySettings.SecuritySubSettings) getTargetFragment()).updateOwnerInfo();
|
||||
if (getTargetFragment() instanceof OwnerInfoCallback) {
|
||||
((OwnerInfoCallback) getTargetFragment()).onOwnerInfoUpdated();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -16,7 +16,6 @@
|
||||
|
||||
package com.android.settings;
|
||||
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
@@ -67,6 +66,7 @@ import com.android.settings.search.BaseSearchIndexProvider;
|
||||
import com.android.settings.search.Indexable;
|
||||
import com.android.settings.search.SearchIndexableRaw;
|
||||
import com.android.settings.search2.SearchFeatureProvider;
|
||||
import com.android.settings.security.OwnerInfoPreferenceController;
|
||||
import com.android.settings.security.SecurityFeatureProvider;
|
||||
import com.android.settings.trustagent.TrustAgentManager;
|
||||
import com.android.settings.widget.GearPreference;
|
||||
@@ -917,11 +917,10 @@ public class SecuritySettings extends SettingsPreferenceFragment
|
||||
}
|
||||
|
||||
public static class SecuritySubSettings extends SettingsPreferenceFragment
|
||||
implements OnPreferenceChangeListener {
|
||||
implements OnPreferenceChangeListener, OwnerInfoPreferenceController.OwnerInfoCallback {
|
||||
|
||||
private static final String KEY_VISIBLE_PATTERN = "visiblepattern";
|
||||
private static final String KEY_LOCK_AFTER_TIMEOUT = "lock_after_timeout";
|
||||
private static final String KEY_OWNER_INFO_SETTINGS = "owner_info_settings";
|
||||
private static final String KEY_POWER_INSTANTLY_LOCKS = "power_button_instantly_locks";
|
||||
|
||||
// These switch preferences need special handling since they're not all stored in Settings.
|
||||
@@ -931,11 +930,11 @@ public class SecuritySettings extends SettingsPreferenceFragment
|
||||
private TimeoutListPreference mLockAfter;
|
||||
private SwitchPreference mVisiblePattern;
|
||||
private SwitchPreference mPowerButtonInstantlyLocks;
|
||||
private RestrictedPreference mOwnerInfoPref;
|
||||
|
||||
private TrustAgentManager mTrustAgentManager;
|
||||
private LockPatternUtils mLockPatternUtils;
|
||||
private DevicePolicyManager mDPM;
|
||||
private OwnerInfoPreferenceController mOwnerInfoPreferenceController;
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
@@ -950,6 +949,8 @@ public class SecuritySettings extends SettingsPreferenceFragment
|
||||
mTrustAgentManager = securityFeatureProvider.getTrustAgentManager();
|
||||
mLockPatternUtils = new LockPatternUtils(getContext());
|
||||
mDPM = getContext().getSystemService(DevicePolicyManager.class);
|
||||
mOwnerInfoPreferenceController =
|
||||
new OwnerInfoPreferenceController(getContext(), this, null /* lifecycle */);
|
||||
createPreferenceHierarchy();
|
||||
}
|
||||
|
||||
@@ -968,7 +969,7 @@ public class SecuritySettings extends SettingsPreferenceFragment
|
||||
mLockPatternUtils.getPowerButtonInstantlyLocks(MY_USER_ID));
|
||||
}
|
||||
|
||||
updateOwnerInfo();
|
||||
mOwnerInfoPreferenceController.updateSummary();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1010,26 +1011,8 @@ public class SecuritySettings extends SettingsPreferenceFragment
|
||||
trustAgentLabel));
|
||||
}
|
||||
|
||||
mOwnerInfoPref = (RestrictedPreference) findPreference(KEY_OWNER_INFO_SETTINGS);
|
||||
if (mOwnerInfoPref != null) {
|
||||
if (mLockPatternUtils.isDeviceOwnerInfoEnabled()) {
|
||||
EnforcedAdmin admin = RestrictedLockUtils.getDeviceOwner(getActivity());
|
||||
mOwnerInfoPref.setDisabledByAdmin(admin);
|
||||
} else {
|
||||
mOwnerInfoPref.setDisabledByAdmin(null);
|
||||
mOwnerInfoPref.setEnabled(!mLockPatternUtils.isLockScreenDisabled(MY_USER_ID));
|
||||
if (mOwnerInfoPref.isEnabled()) {
|
||||
mOwnerInfoPref.setOnPreferenceClickListener(
|
||||
new OnPreferenceClickListener() {
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
OwnerInfoSettings.show(SecuritySubSettings.this);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
mOwnerInfoPreferenceController.displayPreference(getPreferenceScreen());
|
||||
mOwnerInfoPreferenceController.updateEnableState();
|
||||
|
||||
for (int i = 0; i < SWITCH_PREFERENCE_KEYS.length; i++) {
|
||||
final Preference pref = findPreference(SWITCH_PREFERENCE_KEYS[i]);
|
||||
@@ -1093,17 +1076,9 @@ public class SecuritySettings extends SettingsPreferenceFragment
|
||||
mLockAfter.setSummary(summary);
|
||||
}
|
||||
|
||||
public void updateOwnerInfo() {
|
||||
if (mOwnerInfoPref != null) {
|
||||
if (mLockPatternUtils.isDeviceOwnerInfoEnabled()) {
|
||||
mOwnerInfoPref.setSummary(
|
||||
mLockPatternUtils.getDeviceOwnerInfo());
|
||||
} else {
|
||||
mOwnerInfoPref.setSummary(mLockPatternUtils.isOwnerInfoEnabled(MY_USER_ID)
|
||||
? mLockPatternUtils.getOwnerInfo(MY_USER_ID)
|
||||
: getString(R.string.owner_info_settings_summary));
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void onOwnerInfoUpdated() {
|
||||
mOwnerInfoPreferenceController.updateSummary();
|
||||
}
|
||||
|
||||
private static int getResIdForLockUnlockSubScreen(Context context,
|
||||
|
@@ -111,6 +111,7 @@ import com.android.settings.notification.ZenModeSettings;
|
||||
import com.android.settings.notification.ZenModeVisualInterruptionSettings;
|
||||
import com.android.settings.print.PrintJobSettingsFragment;
|
||||
import com.android.settings.print.PrintSettingsFragment;
|
||||
import com.android.settings.security.LockscreenDashboardFragment;
|
||||
import com.android.settings.sim.SimSettings;
|
||||
import com.android.settings.system.SystemDashboardFragment;
|
||||
import com.android.settings.tts.TextToSpeechSettings;
|
||||
@@ -242,6 +243,7 @@ public class SettingsGateway {
|
||||
UserAndAccountDashboardFragment.class.getName(),
|
||||
EnterprisePrivacySettings.class.getName(),
|
||||
WebViewAppPicker.class.getName(),
|
||||
LockscreenDashboardFragment.class.getName(),
|
||||
};
|
||||
|
||||
public static final String[] SETTINGS_FOR_RESTRICTED = {
|
||||
|
@@ -70,6 +70,7 @@ import com.android.settings.notification.ZenModePrioritySettings;
|
||||
import com.android.settings.notification.ZenModeSettings;
|
||||
import com.android.settings.notification.ZenModeVisualInterruptionSettings;
|
||||
import com.android.settings.print.PrintSettingsFragment;
|
||||
import com.android.settings.security.LockscreenDashboardFragment;
|
||||
import com.android.settings.sim.SimSettings;
|
||||
import com.android.settings.system.SystemDashboardFragment;
|
||||
import com.android.settings.tts.TtsEnginePreferenceFragment;
|
||||
@@ -170,6 +171,8 @@ public final class SearchIndexableResources {
|
||||
addIndex(PaymentSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_nfc_payment);
|
||||
addIndex(
|
||||
TtsEnginePreferenceFragment.class, NO_DATA_RES_ID, R.drawable.ic_settings_language);
|
||||
addIndex(LockscreenDashboardFragment.class, R.xml.security_lockscreen_settings,
|
||||
R.drawable.ic_settings_security);
|
||||
}
|
||||
|
||||
private SearchIndexableResources() {
|
||||
|
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
* 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.security;
|
||||
|
||||
import android.content.Context;
|
||||
import android.provider.SearchIndexableResource;
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.accounts.AddUserWhenLockedPreferenceController;
|
||||
import com.android.settings.core.PreferenceController;
|
||||
import com.android.settings.core.lifecycle.Lifecycle;
|
||||
import com.android.settings.dashboard.DashboardFragment;
|
||||
import com.android.settings.notification.LockScreenNotificationPreferenceController;
|
||||
import com.android.settings.search.BaseSearchIndexProvider;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Settings screen for lock screen preference
|
||||
*/
|
||||
public class LockscreenDashboardFragment extends DashboardFragment
|
||||
implements OwnerInfoPreferenceController.OwnerInfoCallback {
|
||||
|
||||
private static final String TAG = "LockscreenDashboardFragment";
|
||||
|
||||
private OwnerInfoPreferenceController mOwnerInfoPreferenceController;
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return MetricsEvent.SETTINGS_LOCK_SCREEN_PREFERENCES;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getLogTag() {
|
||||
return TAG;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getPreferenceScreenResId() {
|
||||
return R.xml.security_lockscreen_settings;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<PreferenceController> getPreferenceControllers(Context context) {
|
||||
final List<PreferenceController> controllers = new ArrayList<>();
|
||||
final Lifecycle lifecycle = getLifecycle();
|
||||
final LockScreenNotificationPreferenceController notificationController =
|
||||
new LockScreenNotificationPreferenceController(context);
|
||||
lifecycle.addObserver(notificationController);
|
||||
controllers.add(notificationController);
|
||||
final AddUserWhenLockedPreferenceController addUserWhenLockedController =
|
||||
new AddUserWhenLockedPreferenceController(context);
|
||||
lifecycle.addObserver(addUserWhenLockedController);
|
||||
controllers.add(addUserWhenLockedController);
|
||||
mOwnerInfoPreferenceController =
|
||||
new OwnerInfoPreferenceController(context, this, lifecycle);
|
||||
controllers.add(mOwnerInfoPreferenceController);
|
||||
return controllers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onOwnerInfoUpdated() {
|
||||
if (mOwnerInfoPreferenceController != null) {
|
||||
mOwnerInfoPreferenceController.updateSummary();
|
||||
}
|
||||
}
|
||||
|
||||
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.security_lockscreen_settings;
|
||||
return Arrays.asList(sir);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PreferenceController> getPreferenceControllers(Context context) {
|
||||
final List<PreferenceController> controllers = new ArrayList<>();
|
||||
controllers.add(new LockScreenNotificationPreferenceController(context));
|
||||
controllers.add(new AddUserWhenLockedPreferenceController(context));
|
||||
controllers.add(new OwnerInfoPreferenceController(
|
||||
context, null /* fragment */, null /* lifecycle */));
|
||||
return controllers;
|
||||
}
|
||||
};
|
||||
}
|
@@ -0,0 +1,142 @@
|
||||
/*
|
||||
* 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.security;
|
||||
|
||||
import android.app.Fragment;
|
||||
import android.content.Context;
|
||||
import android.os.UserHandle;
|
||||
import android.support.annotation.VisibleForTesting;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.Preference.OnPreferenceClickListener;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
import com.android.internal.widget.LockPatternUtils;
|
||||
import com.android.settings.OwnerInfoSettings;
|
||||
import com.android.settings.core.PreferenceController;
|
||||
import com.android.settings.core.lifecycle.Lifecycle;
|
||||
import com.android.settings.core.lifecycle.LifecycleObserver;
|
||||
import com.android.settings.core.lifecycle.events.OnResume;
|
||||
import com.android.settingslib.RestrictedLockUtils;
|
||||
import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
|
||||
import com.android.settingslib.RestrictedPreference;
|
||||
|
||||
public class OwnerInfoPreferenceController extends PreferenceController
|
||||
implements LifecycleObserver, OnResume {
|
||||
|
||||
private static final String KEY_OWNER_INFO = "owner_info_settings";
|
||||
private static final int MY_USER_ID = UserHandle.myUserId();
|
||||
|
||||
private final LockPatternUtils mLockPatternUtils;
|
||||
private final Fragment mParent;
|
||||
private RestrictedPreference mOwnerInfoPref;
|
||||
|
||||
// Container fragment should implement this in order to show the correct summary
|
||||
public interface OwnerInfoCallback {
|
||||
public void onOwnerInfoUpdated();
|
||||
}
|
||||
|
||||
public OwnerInfoPreferenceController(Context context, Fragment parent, Lifecycle lifecycle ) {
|
||||
super(context);
|
||||
mParent = parent;
|
||||
mLockPatternUtils = new LockPatternUtils(context);
|
||||
if (lifecycle != null) {
|
||||
lifecycle.addObserver(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayPreference(PreferenceScreen screen) {
|
||||
mOwnerInfoPref = (RestrictedPreference) screen.findPreference(KEY_OWNER_INFO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
updateEnableState();
|
||||
updateSummary();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreferenceKey() {
|
||||
return KEY_OWNER_INFO;
|
||||
}
|
||||
|
||||
public void updateEnableState() {
|
||||
if (mOwnerInfoPref == null) {
|
||||
return;
|
||||
}
|
||||
if (isDeviceOwnerInfoEnabled()) {
|
||||
EnforcedAdmin admin = getDeviceOwner();
|
||||
mOwnerInfoPref.setDisabledByAdmin(admin);
|
||||
} else {
|
||||
mOwnerInfoPref.setDisabledByAdmin(null);
|
||||
mOwnerInfoPref.setEnabled(!mLockPatternUtils.isLockScreenDisabled(MY_USER_ID));
|
||||
if (mOwnerInfoPref.isEnabled()) {
|
||||
mOwnerInfoPref.setOnPreferenceClickListener(
|
||||
new OnPreferenceClickListener() {
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
OwnerInfoSettings.show(mParent);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void updateSummary() {
|
||||
if (mOwnerInfoPref != null) {
|
||||
if (isDeviceOwnerInfoEnabled()) {
|
||||
mOwnerInfoPref.setSummary(
|
||||
getDeviceOwnerInfo());
|
||||
} else {
|
||||
mOwnerInfoPref.setSummary(isOwnerInfoEnabled()
|
||||
? getOwnerInfo()
|
||||
: mContext.getString(
|
||||
com.android.settings.R.string.owner_info_settings_summary));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Wrapper methods to allow testing
|
||||
@VisibleForTesting
|
||||
boolean isDeviceOwnerInfoEnabled() {
|
||||
return mLockPatternUtils.isDeviceOwnerInfoEnabled();
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
String getDeviceOwnerInfo() {
|
||||
return mLockPatternUtils.getDeviceOwnerInfo();
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
boolean isOwnerInfoEnabled() {
|
||||
return mLockPatternUtils.isOwnerInfoEnabled(MY_USER_ID);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
String getOwnerInfo() {
|
||||
return mLockPatternUtils.getOwnerInfo(MY_USER_ID);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
EnforcedAdmin getDeviceOwner() {
|
||||
return RestrictedLockUtils.getDeviceOwner(mContext);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user