Bring screen lock setting back to screen pinning
The material design of the request has removed this option from the dialog, and now needs to be in settings. When screen pinning is off it shows a description of how to use the feature, however when on it shows a switch to control whether it locks the device on exit. This setting defaults to on if there is a lock pin/pattern. Bug: 16957435 Change-Id: I59e0d64964cee4302e6ecff59e622cfe11422807
This commit is contained in:
@@ -5903,6 +5903,14 @@
|
|||||||
<string name="screen_pinning_title">Screen pinning</string>
|
<string name="screen_pinning_title">Screen pinning</string>
|
||||||
<!-- [CHAR LIMIT=300] Screen pinning description -->
|
<!-- [CHAR LIMIT=300] Screen pinning description -->
|
||||||
<string name="screen_pinning_description">When turned on, you can use screen pinning to keep the current screen in view until you unpin.\n\nTo use screen pinning:\n\n1. Make sure screen pinning is turned on.\n\n2. Open the screen you want to pin.\n\n3. Touch Overview.\n\n4. Touch the pin icon.</string>
|
<string name="screen_pinning_description">When turned on, you can use screen pinning to keep the current screen in view until you unpin.\n\nTo use screen pinning:\n\n1. Make sure screen pinning is turned on.\n\n2. Open the screen you want to pin.\n\n3. Touch Overview.\n\n4. Touch the pin icon.</string>
|
||||||
|
<!-- [CHAR LIMIT=60] Unlock setting for screen pinning -->
|
||||||
|
<string name="screen_pinning_unlock_pattern">Ask for unlock pattern before unpinning</string>
|
||||||
|
<!-- [CHAR LIMIT=60] Unlock setting for screen pinning -->
|
||||||
|
<string name="screen_pinning_unlock_pin">Ask for PIN before unpinning</string>
|
||||||
|
<!-- [CHAR LIMIT=60] Unlock setting for screen pinning -->
|
||||||
|
<string name="screen_pinning_unlock_password">Ask for password before unpinning</string>
|
||||||
|
<!-- [CHAR LIMIT=60] Unlock setting for screen pinning -->
|
||||||
|
<string name="screen_pinning_unlock_none">Lock device when unpinning</string>
|
||||||
|
|
||||||
<!-- Title for a work profile. [CHAR LIMIT=25] -->
|
<!-- Title for a work profile. [CHAR LIMIT=25] -->
|
||||||
<string name="managed_user_title">Work profile</string>
|
<string name="managed_user_title">Work profile</string>
|
||||||
|
25
res/xml/screen_pinning_settings.xml
Normal file
25
res/xml/screen_pinning_settings.xml
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- Copyright (C) 2014 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"
|
||||||
|
android:title="@string/screen_pinning_title">
|
||||||
|
|
||||||
|
<SwitchPreference
|
||||||
|
android:key="use_screen_lock"
|
||||||
|
android:title="@string/screen_pinning_unlock_none"
|
||||||
|
android:persistent="false" />
|
||||||
|
|
||||||
|
</PreferenceScreen>
|
@@ -15,42 +15,59 @@
|
|||||||
*/
|
*/
|
||||||
package com.android.settings;
|
package com.android.settings;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import android.app.admin.DevicePolicyManager;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.preference.Preference;
|
||||||
|
import android.preference.Preference.OnPreferenceChangeListener;
|
||||||
|
import android.preference.PreferenceScreen;
|
||||||
|
import android.preference.SwitchPreference;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.provider.Settings.SettingNotFoundException;
|
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.Switch;
|
import android.widget.Switch;
|
||||||
|
|
||||||
|
import com.android.internal.widget.LockPatternUtils;
|
||||||
import com.android.settings.search.BaseSearchIndexProvider;
|
import com.android.settings.search.BaseSearchIndexProvider;
|
||||||
import com.android.settings.search.Indexable;
|
import com.android.settings.search.Indexable;
|
||||||
import com.android.settings.search.SearchIndexableRaw;
|
import com.android.settings.search.SearchIndexableRaw;
|
||||||
import com.android.settings.widget.SwitchBar;
|
import com.android.settings.widget.SwitchBar;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Screen pinning settings.
|
* Screen pinning settings.
|
||||||
*/
|
*/
|
||||||
public class ScreenPinningSettings extends SettingsPreferenceFragment
|
public class ScreenPinningSettings extends SettingsPreferenceFragment
|
||||||
implements SwitchBar.OnSwitchChangeListener, Indexable {
|
implements SwitchBar.OnSwitchChangeListener, Indexable {
|
||||||
|
|
||||||
|
private static final CharSequence KEY_USE_SCREEN_LOCK = "use_screen_lock";
|
||||||
|
private static final int CHANGE_LOCK_METHOD_REQUEST = 43;
|
||||||
|
|
||||||
private SwitchBar mSwitchBar;
|
private SwitchBar mSwitchBar;
|
||||||
|
private SwitchPreference mUseScreenLock;
|
||||||
|
private LockPatternUtils mLockPatternUtils;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onActivityCreated(Bundle savedInstanceState) {
|
public void onActivityCreated(Bundle savedInstanceState) {
|
||||||
super.onActivityCreated(savedInstanceState);
|
super.onActivityCreated(savedInstanceState);
|
||||||
|
|
||||||
final SettingsActivity activity = (SettingsActivity) getActivity();
|
final SettingsActivity activity = (SettingsActivity) getActivity();
|
||||||
|
mLockPatternUtils = new LockPatternUtils(activity);
|
||||||
|
|
||||||
|
View emptyView = LayoutInflater.from(activity)
|
||||||
|
.inflate(R.layout.screen_pinning_instructions, null);
|
||||||
|
((ViewGroup) getListView().getParent()).addView(emptyView);
|
||||||
|
getListView().setEmptyView(emptyView);
|
||||||
|
|
||||||
mSwitchBar = activity.getSwitchBar();
|
mSwitchBar = activity.getSwitchBar();
|
||||||
mSwitchBar.addOnSwitchChangeListener(this);
|
mSwitchBar.addOnSwitchChangeListener(this);
|
||||||
mSwitchBar.show();
|
mSwitchBar.show();
|
||||||
mSwitchBar.setChecked(isLockToAppEnabled());
|
mSwitchBar.setChecked(isLockToAppEnabled(getActivity()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -61,19 +78,9 @@ public class ScreenPinningSettings extends SettingsPreferenceFragment
|
|||||||
mSwitchBar.hide();
|
mSwitchBar.hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private static boolean isLockToAppEnabled(Context context) {
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
return Settings.System.getInt(context.getContentResolver(),
|
||||||
Bundle savedInstanceState) {
|
Settings.System.LOCK_TO_APP_ENABLED, 0) != 0;
|
||||||
return inflater.inflate(R.layout.screen_pinning_instructions, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isLockToAppEnabled() {
|
|
||||||
try {
|
|
||||||
return Settings.System.getInt(getContentResolver(), Settings.System.LOCK_TO_APP_ENABLED)
|
|
||||||
!= 0;
|
|
||||||
} catch (SettingNotFoundException e) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setLockToAppEnabled(boolean isEnabled) {
|
private void setLockToAppEnabled(boolean isEnabled) {
|
||||||
@@ -81,12 +88,89 @@ public class ScreenPinningSettings extends SettingsPreferenceFragment
|
|||||||
isEnabled ? 1 : 0);
|
isEnabled ? 1 : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isScreenLockUsed() {
|
||||||
|
int def = getCurrentSecurityTitle() != R.string.screen_pinning_unlock_none ? 1 : 0;
|
||||||
|
return Settings.Secure.getInt(getContentResolver(),
|
||||||
|
Settings.Secure.LOCK_TO_APP_EXIT_LOCKED, def) != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean setScreenLockUsed(boolean isEnabled) {
|
||||||
|
if (isEnabled) {
|
||||||
|
LockPatternUtils lockPatternUtils = new LockPatternUtils(getActivity());
|
||||||
|
if (lockPatternUtils.getKeyguardStoredPasswordQuality()
|
||||||
|
== DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED) {
|
||||||
|
Intent chooseLockIntent = new Intent(DevicePolicyManager.ACTION_SET_NEW_PASSWORD);
|
||||||
|
chooseLockIntent.putExtra(
|
||||||
|
ChooseLockGeneric.ChooseLockGenericFragment.MINIMUM_QUALITY_KEY,
|
||||||
|
DevicePolicyManager.PASSWORD_QUALITY_SOMETHING);
|
||||||
|
startActivityForResult(chooseLockIntent, CHANGE_LOCK_METHOD_REQUEST);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Settings.Secure.putInt(getContentResolver(), Settings.Secure.LOCK_TO_APP_EXIT_LOCKED,
|
||||||
|
isEnabled ? 1 : 0);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
|
super.onActivityResult(requestCode, resultCode, data);
|
||||||
|
if (requestCode == CHANGE_LOCK_METHOD_REQUEST) {
|
||||||
|
LockPatternUtils lockPatternUtils = new LockPatternUtils(getActivity());
|
||||||
|
boolean validPassQuality = lockPatternUtils.getKeyguardStoredPasswordQuality()
|
||||||
|
!= DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED;
|
||||||
|
setScreenLockUsed(validPassQuality);
|
||||||
|
// Make sure the screen updates.
|
||||||
|
mUseScreenLock.setChecked(validPassQuality);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private int getCurrentSecurityTitle() {
|
||||||
|
int quality = mLockPatternUtils.getKeyguardStoredPasswordQuality();
|
||||||
|
switch (quality) {
|
||||||
|
case DevicePolicyManager.PASSWORD_QUALITY_NUMERIC:
|
||||||
|
case DevicePolicyManager.PASSWORD_QUALITY_NUMERIC_COMPLEX:
|
||||||
|
return R.string.screen_pinning_unlock_pin;
|
||||||
|
case DevicePolicyManager.PASSWORD_QUALITY_ALPHABETIC:
|
||||||
|
case DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC:
|
||||||
|
case DevicePolicyManager.PASSWORD_QUALITY_COMPLEX:
|
||||||
|
return R.string.screen_pinning_unlock_password;
|
||||||
|
case DevicePolicyManager.PASSWORD_QUALITY_SOMETHING:
|
||||||
|
if (mLockPatternUtils.isLockPatternEnabled()) {
|
||||||
|
return R.string.screen_pinning_unlock_pattern;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return R.string.screen_pinning_unlock_none;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Listens to the state change of the lock-to-app master switch.
|
* Listens to the state change of the lock-to-app master switch.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onSwitchChanged(Switch switchView, boolean isChecked) {
|
public void onSwitchChanged(Switch switchView, boolean isChecked) {
|
||||||
setLockToAppEnabled(isChecked);
|
setLockToAppEnabled(isChecked);
|
||||||
|
updateDisplay();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateDisplay() {
|
||||||
|
PreferenceScreen root = getPreferenceScreen();
|
||||||
|
if (root != null) {
|
||||||
|
root.removeAll();
|
||||||
|
}
|
||||||
|
if (isLockToAppEnabled(getActivity())) {
|
||||||
|
addPreferencesFromResource(R.xml.screen_pinning_settings);
|
||||||
|
root = getPreferenceScreen();
|
||||||
|
|
||||||
|
mUseScreenLock = (SwitchPreference) root.findPreference(KEY_USE_SCREEN_LOCK);
|
||||||
|
mUseScreenLock.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
|
||||||
|
@Override
|
||||||
|
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||||
|
return setScreenLockUsed((boolean) newValue);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
mUseScreenLock.setChecked(isScreenLockUsed());
|
||||||
|
mUseScreenLock.setTitle(getCurrentSecurityTitle());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -106,11 +190,19 @@ public class ScreenPinningSettings extends SettingsPreferenceFragment
|
|||||||
data.screenTitle = res.getString(R.string.screen_pinning_title);
|
data.screenTitle = res.getString(R.string.screen_pinning_title);
|
||||||
result.add(data);
|
result.add(data);
|
||||||
|
|
||||||
// Screen pinning description.
|
if (isLockToAppEnabled(context)) {
|
||||||
data = new SearchIndexableRaw(context);
|
// Screen lock option
|
||||||
data.title = res.getString(R.string.screen_pinning_description);
|
data = new SearchIndexableRaw(context);
|
||||||
data.screenTitle = res.getString(R.string.screen_pinning_title);
|
data.title = res.getString(R.string.screen_pinning_unlock_none);
|
||||||
result.add(data);
|
data.screenTitle = res.getString(R.string.screen_pinning_title);
|
||||||
|
result.add(data);
|
||||||
|
} else {
|
||||||
|
// Screen pinning description.
|
||||||
|
data = new SearchIndexableRaw(context);
|
||||||
|
data.title = res.getString(R.string.screen_pinning_description);
|
||||||
|
data.screenTitle = res.getString(R.string.screen_pinning_title);
|
||||||
|
result.add(data);
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user