Start hooking up password device policies
This introduces a new activity for changing the password, which takes care of launching the correct password activity based on the caller's request and active policy. The security settings activity now uses this, and it implements the API action for launching the password UI.
This commit is contained in:
@@ -423,31 +423,29 @@
|
|||||||
android:theme="@android:style/Theme.NoTitleBar">
|
android:theme="@android:style/Theme.NoTitleBar">
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
<activity android:name="ChooseLockPattern" android:label="@string/lockpattern_change_lock_pattern_label">
|
<activity android:name="ChooseLockGeneric"
|
||||||
|
android:theme="@android:style/Theme.NoDisplay">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.DEFAULT" />
|
<action android:name="android.app.action.SET_NEW_PASSWORD" />
|
||||||
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
<activity android:name="ChooseLockPassword" android:label="@string/lockpattern_change_lock_pin_label"
|
<activity android:name="ChooseLockPattern"
|
||||||
|
android:label="@string/lockpattern_change_lock_pattern_label">
|
||||||
|
</activity>
|
||||||
|
|
||||||
|
<activity android:name="ChooseLockPassword"
|
||||||
|
android:label="@string/lockpattern_change_lock_pin_label"
|
||||||
android:theme="@android:style/Theme.NoTitleBar">
|
android:theme="@android:style/Theme.NoTitleBar">
|
||||||
<intent-filter>
|
|
||||||
<action android:name="android.intent.action.DEFAULT" />
|
|
||||||
</intent-filter>
|
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
<activity android:name="ChooseLockPatternTutorial"
|
<activity android:name="ChooseLockPatternTutorial"
|
||||||
android:label="@string/lockpattern_change_lock_pattern_label">
|
android:label="@string/lockpattern_change_lock_pattern_label">
|
||||||
<intent-filter>
|
|
||||||
<action android:name="android.intent.action.DEFAULT" />
|
|
||||||
</intent-filter>
|
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
<activity android:name="ChooseLockPatternExample"
|
<activity android:name="ChooseLockPatternExample"
|
||||||
android:label="@string/lockpattern_change_lock_pattern_label">
|
android:label="@string/lockpattern_change_lock_pattern_label">
|
||||||
<intent-filter>
|
|
||||||
<action android:name="android.intent.action.DEFAULT" />
|
|
||||||
</intent-filter>
|
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
<activity android:name="ZoneList" android:label="@string/choose_timezone" />
|
<activity android:name="ZoneList" android:label="@string/choose_timezone" />
|
||||||
|
70
src/com/android/settings/ChooseLockGeneric.java
Normal file
70
src/com/android/settings/ChooseLockGeneric.java
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2010 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;
|
||||||
|
|
||||||
|
import com.android.internal.widget.LockPatternUtils;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.app.DevicePolicyManager;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.os.Bundle;
|
||||||
|
|
||||||
|
public class ChooseLockGeneric extends Activity {
|
||||||
|
private ChooseLockSettingsHelper mChooseLockSettingsHelper;
|
||||||
|
DevicePolicyManager mDPM;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
mDPM = (DevicePolicyManager)getSystemService(Context.DEVICE_POLICY_SERVICE);
|
||||||
|
mChooseLockSettingsHelper = new ChooseLockSettingsHelper(this);
|
||||||
|
|
||||||
|
final LockPatternUtils lockPatternUtils = mChooseLockSettingsHelper.utils();
|
||||||
|
|
||||||
|
int mode = getIntent().getIntExtra(LockPatternUtils.PASSWORD_TYPE_KEY, -1);
|
||||||
|
if (mode == -1) {
|
||||||
|
mode = lockPatternUtils.getPasswordMode();
|
||||||
|
}
|
||||||
|
int minMode = mDPM.getPasswordMode();
|
||||||
|
if (mode < minMode) {
|
||||||
|
mode = minMode;
|
||||||
|
}
|
||||||
|
if (mode >= DevicePolicyManager.PASSWORD_MODE_NUMERIC) {
|
||||||
|
int minLength = mDPM.getMinimumPasswordLength();
|
||||||
|
if (minLength < 4) {
|
||||||
|
minLength = 4;
|
||||||
|
}
|
||||||
|
final int maxLength = 16;
|
||||||
|
Intent intent = new Intent().setClass(this, ChooseLockPassword.class);
|
||||||
|
intent.putExtra(LockPatternUtils.PASSWORD_TYPE_KEY, mode);
|
||||||
|
intent.putExtra(ChooseLockPassword.PASSWORD_MIN_KEY, minLength);
|
||||||
|
intent.putExtra(ChooseLockPassword.PASSWORD_MAX_KEY, maxLength);
|
||||||
|
startActivity(intent);
|
||||||
|
} else {
|
||||||
|
boolean showTutorial = !lockPatternUtils.isPatternEverChosen();
|
||||||
|
Intent intent = new Intent();
|
||||||
|
intent.setClass(this, showTutorial
|
||||||
|
? ChooseLockPatternTutorial.class
|
||||||
|
: ChooseLockPattern.class);
|
||||||
|
intent.putExtra("key_lock_method", "pattern");
|
||||||
|
startActivity(intent);
|
||||||
|
}
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
}
|
@@ -79,15 +79,17 @@ public class ChooseLockPassword extends Activity implements OnClickListener {
|
|||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
mLockPatternUtils = new LockPatternUtils(this);
|
mLockPatternUtils = new LockPatternUtils(this);
|
||||||
if (mLockPatternUtils.isDevicePolicyActive()) {
|
mRequestedMode = getIntent().getIntExtra("password_mode", mRequestedMode);
|
||||||
mRequestedMode = mLockPatternUtils.getRequestedPasswordMode();
|
mPasswordMinLength = getIntent().getIntExtra("password_min_length", mPasswordMinLength);
|
||||||
mPasswordMinLength = mLockPatternUtils.getRequestedMinimumPasswordLength();
|
mPasswordMaxLength = getIntent().getIntExtra("password_max_length", mPasswordMaxLength);
|
||||||
} else {
|
int minMode = mLockPatternUtils.getRequestedPasswordMode();
|
||||||
mRequestedMode = getIntent().getIntExtra(LockPatternUtils.PASSWORD_TYPE_KEY,
|
if (mRequestedMode < minMode) {
|
||||||
mRequestedMode);
|
mRequestedMode = minMode;
|
||||||
mPasswordMinLength = getIntent().getIntExtra(PASSWORD_MIN_KEY, mPasswordMinLength);
|
}
|
||||||
|
int minLength = mLockPatternUtils.getRequestedMinimumPasswordLength();
|
||||||
|
if (mPasswordMinLength < minLength) {
|
||||||
|
mPasswordMinLength = minLength;
|
||||||
}
|
}
|
||||||
mPasswordMaxLength = getIntent().getIntExtra(PASSWORD_MAX_KEY, mPasswordMaxLength);
|
|
||||||
initViews();
|
initViews();
|
||||||
mChooseLockSettingsHelper = new ChooseLockSettingsHelper(this);
|
mChooseLockSettingsHelper = new ChooseLockSettingsHelper(this);
|
||||||
if (savedInstanceState == null) {
|
if (savedInstanceState == null) {
|
||||||
@@ -188,7 +190,7 @@ public class ChooseLockPassword extends Activity implements OnClickListener {
|
|||||||
// TODO: move these to LockPatternUtils
|
// TODO: move these to LockPatternUtils
|
||||||
mLockPatternUtils.setLockPatternEnabled(false);
|
mLockPatternUtils.setLockPatternEnabled(false);
|
||||||
mLockPatternUtils.saveLockPattern(null);
|
mLockPatternUtils.saveLockPattern(null);
|
||||||
mLockPatternUtils.saveLockPassword(pin);
|
mLockPatternUtils.saveLockPassword(pin, mRequestedMode);
|
||||||
finish();
|
finish();
|
||||||
} else {
|
} else {
|
||||||
int msg = R.string.lockpassword_confirm_passwords_dont_match;
|
int msg = R.string.lockpassword_confirm_passwords_dont_match;
|
||||||
|
@@ -36,7 +36,7 @@ public class ChooseLockPatternTutorial extends Activity implements View.OnClickL
|
|||||||
LockPatternUtils lockPatternUtils = new LockPatternUtils(this);
|
LockPatternUtils lockPatternUtils = new LockPatternUtils(this);
|
||||||
if (savedInstanceState == null && lockPatternUtils.isPatternEverChosen()) {
|
if (savedInstanceState == null && lockPatternUtils.isPatternEverChosen()) {
|
||||||
Intent intent = new Intent();
|
Intent intent = new Intent();
|
||||||
intent.setClassName("com.android.settings", "com.android.settings.ChooseLockPattern");
|
intent.setClass(this, ChooseLockPattern.class);
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
finish();
|
finish();
|
||||||
} else {
|
} else {
|
||||||
|
@@ -22,9 +22,11 @@ import java.util.Observer;
|
|||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
|
import android.app.DevicePolicyManager;
|
||||||
import android.app.Dialog;
|
import android.app.Dialog;
|
||||||
import android.content.ContentQueryMap;
|
import android.content.ContentQueryMap;
|
||||||
import android.content.ContentResolver;
|
import android.content.ContentResolver;
|
||||||
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
@@ -103,6 +105,8 @@ public class SecuritySettings extends PreferenceActivity {
|
|||||||
private CheckBoxPreference mGps;
|
private CheckBoxPreference mGps;
|
||||||
private CheckBoxPreference mAssistedGps;
|
private CheckBoxPreference mAssistedGps;
|
||||||
|
|
||||||
|
DevicePolicyManager mDPM;
|
||||||
|
|
||||||
// These provide support for receiving notification when Location Manager settings change.
|
// These provide support for receiving notification when Location Manager settings change.
|
||||||
// This is necessary because the Network Location Provider can change settings
|
// This is necessary because the Network Location Provider can change settings
|
||||||
// if the user does not confirm enabling the provider.
|
// if the user does not confirm enabling the provider.
|
||||||
@@ -120,6 +124,8 @@ public class SecuritySettings extends PreferenceActivity {
|
|||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
addPreferencesFromResource(R.xml.security_settings);
|
addPreferencesFromResource(R.xml.security_settings);
|
||||||
|
|
||||||
|
mDPM = (DevicePolicyManager)getSystemService(Context.DEVICE_POLICY_SERVICE);
|
||||||
|
|
||||||
mChooseLockSettingsHelper = new ChooseLockSettingsHelper(this);
|
mChooseLockSettingsHelper = new ChooseLockSettingsHelper(this);
|
||||||
|
|
||||||
createPreferenceHierarchy();
|
createPreferenceHierarchy();
|
||||||
@@ -217,23 +223,26 @@ public class SecuritySettings extends PreferenceActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void handleUpdateUnlockMethod(final String value) {
|
protected void handleUpdateUnlockMethod(final String value) {
|
||||||
final LockPatternUtils lockPatternUtils = mChooseLockSettingsHelper.utils();
|
|
||||||
if ("none".equals(value)) {
|
if ("none".equals(value)) {
|
||||||
mChooseLockSettingsHelper.launchConfirmationActivity(CONFIRM_EXISTING_REQUEST);
|
if (mDPM.getPasswordMode() == DevicePolicyManager.PASSWORD_MODE_UNSPECIFIED) {
|
||||||
} else if ("password".equals(value) || "pin".equals(value)) {
|
mChooseLockSettingsHelper.launchConfirmationActivity(CONFIRM_EXISTING_REQUEST);
|
||||||
final int mode = "password".equals(value)
|
}
|
||||||
? LockPatternUtils.MODE_PASSWORD : LockPatternUtils.MODE_PIN;
|
} else {
|
||||||
Intent intent = new Intent().setClassName(PACKAGE, CHOOSE_LOCK_PIN);
|
int reqMode;
|
||||||
intent.putExtra(LockPatternUtils.PASSWORD_TYPE_KEY, mode);
|
if ("password".equals(value)) {
|
||||||
intent.putExtra(ChooseLockPassword.PASSWORD_MIN_KEY, PASSWORD_MIN_LENGTH);
|
reqMode = LockPatternUtils.MODE_PASSWORD;
|
||||||
intent.putExtra(ChooseLockPassword.PASSWORD_MAX_KEY, PASSWORD_MAX_LENGTH);
|
} else if ( "pin".equals(value)) {
|
||||||
startActivityForResult(intent, UPDATE_PASSWORD_REQUEST);
|
reqMode = LockPatternUtils.MODE_PIN;
|
||||||
} else if ("pattern".equals(value)) {
|
} else {
|
||||||
boolean showTutorial = !lockPatternUtils.isPatternEverChosen();
|
reqMode = LockPatternUtils.MODE_PATTERN;
|
||||||
|
}
|
||||||
|
int minMode = mDPM.getPasswordMode();
|
||||||
|
if (reqMode < minMode) {
|
||||||
|
reqMode = minMode;
|
||||||
|
}
|
||||||
Intent intent = new Intent();
|
Intent intent = new Intent();
|
||||||
intent.setClassName(PACKAGE, showTutorial ?
|
intent.setClass(this, ChooseLockGeneric.class);
|
||||||
LOCK_PATTERN_TUTORIAL : CHOOSE_LOCK_PATTERN);
|
intent.putExtra(LockPatternUtils.PASSWORD_TYPE_KEY, reqMode);
|
||||||
intent.putExtra("key_lock_method", value);
|
|
||||||
startActivityForResult(intent, UPDATE_PASSWORD_REQUEST);
|
startActivityForResult(intent, UPDATE_PASSWORD_REQUEST);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -321,9 +330,7 @@ public class SecuritySettings extends PreferenceActivity {
|
|||||||
|
|
||||||
LockPatternUtils lockPatternUtils = mChooseLockSettingsHelper.utils();
|
LockPatternUtils lockPatternUtils = mChooseLockSettingsHelper.utils();
|
||||||
if ((requestCode == CONFIRM_EXISTING_REQUEST) && resultOk) {
|
if ((requestCode == CONFIRM_EXISTING_REQUEST) && resultOk) {
|
||||||
lockPatternUtils.saveLockPassword(null);
|
lockPatternUtils.clearLock();
|
||||||
lockPatternUtils.setLockPatternEnabled(false);
|
|
||||||
lockPatternUtils.saveLockPattern(null);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user