Expose lockdown button in settings

Test: manually verified toggle controls lockdown button visibility
Test: make RunSettingsRoboTests
Bug: 37221346
Change-Id: Ie59f9c6a1df1d877b18986c6a58492a5aa789d34
This commit is contained in:
Chad Brubaker
2018-01-11 11:09:31 -08:00
parent bd261ff8b1
commit 5f67c6491f
5 changed files with 171 additions and 0 deletions

View File

@@ -0,0 +1,61 @@
/*
* Copyright (C) 2018 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.os.UserHandle;
import android.provider.Settings;
import android.support.v7.preference.Preference;
import android.support.v7.preference.TwoStatePreference;
import com.android.internal.widget.LockPatternUtils;
import com.android.settings.core.BasePreferenceController;
import com.android.settings.core.TogglePreferenceController;
public class LockdownButtonPreferenceController extends TogglePreferenceController {
private static final String KEY_LOCKDOWN_ENALBED = "security_setting_lockdown_enabled";
private final LockPatternUtils mLockPatternUtils;
public LockdownButtonPreferenceController(Context context) {
super(context, KEY_LOCKDOWN_ENALBED);
mLockPatternUtils = new LockPatternUtils(context);
}
@Override
public int getAvailabilityStatus() {
if (mLockPatternUtils.isSecure(UserHandle.myUserId())) {
return BasePreferenceController.AVAILABLE;
} else {
return BasePreferenceController.DISABLED_FOR_USER;
}
}
@Override
public boolean isChecked() {
return Settings.Secure.getInt(mContext.getContentResolver(),
Settings.Secure.LOCKDOWN_IN_POWER_MENU, 0) != 0;
}
@Override
public boolean setChecked(boolean isChecked) {
Settings.Secure.putInt(mContext.getContentResolver(),
Settings.Secure.LOCKDOWN_IN_POWER_MENU, isChecked ? 1 : 0);
return true;
}
}

View File

@@ -93,6 +93,8 @@ public class LockscreenDashboardFragment extends DashboardFragment
mOwnerInfoPreferenceController =
new OwnerInfoPreferenceController(context, this, lifecycle);
controllers.add(mOwnerInfoPreferenceController);
controllers.add(new LockdownButtonPreferenceController(context));
return controllers;
}
@@ -122,6 +124,7 @@ public class LockscreenDashboardFragment extends DashboardFragment
KEY_ADD_USER_FROM_LOCK_SCREEN));
controllers.add(new OwnerInfoPreferenceController(
context, null /* fragment */, null /* lifecycle */));
controllers.add(new LockdownButtonPreferenceController(context));
return controllers;
}