Merge "Have UserManagerService clear the restrictions and unblock apps"
This commit is contained in:
committed by
Android (Google) Code Review
commit
7e81dd274f
@ -49,4 +49,5 @@ interface IUserManager {
|
||||
boolean changeRestrictionsPin(in String newPin);
|
||||
int checkRestrictionsPin(in String pin);
|
||||
boolean hasRestrictionsPin();
|
||||
void removeRestrictions();
|
||||
}
|
||||
|
@ -678,4 +678,13 @@ public class UserManager {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/** @hide */
|
||||
public void removeRestrictions() {
|
||||
try {
|
||||
mService.removeRestrictions();
|
||||
} catch (RemoteException re) {
|
||||
Log.w(TAG, "Could not change restrictions pin");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -26,6 +26,7 @@ import android.text.TextWatcher;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
import android.widget.TextView.OnEditorActionListener;
|
||||
@ -39,17 +40,24 @@ import com.android.internal.R;
|
||||
public class RestrictionsPinActivity extends AlertActivity
|
||||
implements DialogInterface.OnClickListener, TextWatcher, OnEditorActionListener {
|
||||
|
||||
private UserManager mUserManager;
|
||||
protected UserManager mUserManager;
|
||||
protected boolean mHasRestrictionsPin;
|
||||
|
||||
private EditText mPin1Text;
|
||||
private EditText mPin2Text;
|
||||
private TextView mPinErrorMessage;
|
||||
private TextView mPinMessage;
|
||||
protected EditText mPinText;
|
||||
protected TextView mPinErrorMessage;
|
||||
protected TextView mPinMessage;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle icicle) {
|
||||
super.onCreate(icicle);
|
||||
|
||||
mUserManager = (UserManager) getSystemService(Context.USER_SERVICE);
|
||||
mHasRestrictionsPin = mUserManager.hasRestrictionsPin();
|
||||
initUi();
|
||||
setupAlert();
|
||||
}
|
||||
|
||||
protected void initUi() {
|
||||
AlertController.AlertParams ap = mAlertParams;
|
||||
ap.mTitle = getString(R.string.restr_pin_enter_pin);
|
||||
ap.mPositiveButtonText = getString(R.string.ok);
|
||||
@ -58,18 +66,12 @@ public class RestrictionsPinActivity extends AlertActivity
|
||||
ap.mNegativeButtonListener = this;
|
||||
LayoutInflater inflater =
|
||||
(LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
ap.mView = inflater.inflate(R.layout.pin_challenge, null);
|
||||
ap.mView = inflater.inflate(R.layout.restrictions_pin_challenge, null);
|
||||
|
||||
mPinMessage = (TextView) ap.mView.findViewById(R.id.pin_message);
|
||||
mPin1Text = (EditText) ap.mView.findViewById(R.id.pin1_text);
|
||||
mPin2Text = (EditText) ap.mView.findViewById(R.id.pin2_text);
|
||||
mPinText = (EditText) ap.mView.findViewById(R.id.pin_text);
|
||||
mPinErrorMessage = (TextView) ap.mView.findViewById(R.id.pin_error_message);
|
||||
mPin1Text.addTextChangedListener(this);
|
||||
mPin2Text.addTextChangedListener(this);
|
||||
|
||||
mUserManager = (UserManager) getSystemService(Context.USER_SERVICE);
|
||||
|
||||
setupAlert();
|
||||
mPinText.addTextChangedListener(this);
|
||||
}
|
||||
|
||||
protected boolean verifyingPin() {
|
||||
@ -81,19 +83,12 @@ public class RestrictionsPinActivity extends AlertActivity
|
||||
|
||||
setPositiveButtonState(false);
|
||||
boolean hasPin = mUserManager.hasRestrictionsPin();
|
||||
if (verifyingPin()) {
|
||||
if (hasPin) {
|
||||
mPinMessage.setVisibility(View.GONE);
|
||||
mPinErrorMessage.setVisibility(View.GONE);
|
||||
mPin2Text.setVisibility(View.GONE);
|
||||
mPin1Text.setOnEditorActionListener(this);
|
||||
updatePinTimer(-1);
|
||||
} else {
|
||||
setResult(RESULT_OK);
|
||||
finish();
|
||||
}
|
||||
} else if (hasPin) {
|
||||
// Shouldn't really be in this state, exit
|
||||
if (hasPin) {
|
||||
mPinMessage.setVisibility(View.GONE);
|
||||
mPinErrorMessage.setVisibility(View.GONE);
|
||||
mPinText.setOnEditorActionListener(this);
|
||||
updatePinTimer(-1);
|
||||
} else if (verifyingPin()) {
|
||||
setResult(RESULT_OK);
|
||||
finish();
|
||||
}
|
||||
@ -114,14 +109,14 @@ public class RestrictionsPinActivity extends AlertActivity
|
||||
seconds);
|
||||
mPinErrorMessage.setText(String.format(formatString, seconds));
|
||||
mPinErrorMessage.setVisibility(View.VISIBLE);
|
||||
mPin1Text.setEnabled(false);
|
||||
mPin1Text.setText("");
|
||||
mPinText.setEnabled(false);
|
||||
mPinText.setText("");
|
||||
setPositiveButtonState(false);
|
||||
mPin1Text.postDelayed(mCountdownRunnable, Math.min(1000, pinTimerMs));
|
||||
mPinText.postDelayed(mCountdownRunnable, Math.min(1000, pinTimerMs));
|
||||
} else {
|
||||
mPinErrorMessage.setVisibility(View.INVISIBLE);
|
||||
mPin1Text.setEnabled(true);
|
||||
mPin1Text.setText("");
|
||||
mPinText.setEnabled(true);
|
||||
mPinText.setText("");
|
||||
}
|
||||
}
|
||||
|
||||
@ -134,20 +129,13 @@ public class RestrictionsPinActivity extends AlertActivity
|
||||
}
|
||||
}
|
||||
|
||||
private void performPositiveButtonAction() {
|
||||
if (verifyingPin()) {
|
||||
int result = mUserManager.checkRestrictionsPin(mPin1Text.getText().toString());
|
||||
if (result == UserManager.PIN_VERIFICATION_SUCCESS) {
|
||||
setResult(RESULT_OK);
|
||||
finish();
|
||||
} else if (result >= 0) {
|
||||
updatePinTimer(result);
|
||||
}
|
||||
} else {
|
||||
if (mUserManager.changeRestrictionsPin(mPin1Text.getText().toString())) {
|
||||
setResult(RESULT_OK);
|
||||
finish();
|
||||
}
|
||||
protected void performPositiveButtonAction() {
|
||||
int result = mUserManager.checkRestrictionsPin(mPinText.getText().toString());
|
||||
if (result == UserManager.PIN_VERIFICATION_SUCCESS) {
|
||||
setResult(RESULT_OK);
|
||||
finish();
|
||||
} else if (result >= 0) {
|
||||
updatePinTimer(result);
|
||||
}
|
||||
}
|
||||
|
||||
@ -157,16 +145,8 @@ public class RestrictionsPinActivity extends AlertActivity
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
CharSequence pin1 = mPin1Text.getText();
|
||||
if (!verifyingPin()) {
|
||||
CharSequence pin2 = mPin2Text.getText();
|
||||
boolean match = pin1 != null && pin2 != null && pin1.length() >= 4
|
||||
&& pin1.toString().equals(pin2.toString());
|
||||
setPositiveButtonState(match);
|
||||
mPinErrorMessage.setVisibility(match ? View.INVISIBLE : View.VISIBLE);
|
||||
} else {
|
||||
setPositiveButtonState(pin1 != null && pin1.length() >= 4);
|
||||
}
|
||||
CharSequence pin = mPinText.getText();
|
||||
setPositiveButtonState(pin != null && pin.length() >= 4);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -16,13 +16,115 @@
|
||||
|
||||
package com.android.internal.app;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.UserManager;
|
||||
import android.text.Editable;
|
||||
import android.text.TextUtils;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.android.internal.R;
|
||||
|
||||
/**
|
||||
* This activity is launched by Settings and other apps to either create a new PIN or
|
||||
* challenge for an existing PIN. The PIN is maintained by UserManager.
|
||||
* change an existing PIN. The PIN is maintained by UserManager.
|
||||
*/
|
||||
public class RestrictionsPinSetupActivity extends RestrictionsPinActivity {
|
||||
|
||||
private EditText mNewPinText;
|
||||
private EditText mConfirmPinText;
|
||||
|
||||
protected void initUi() {
|
||||
AlertController.AlertParams ap = mAlertParams;
|
||||
ap.mTitle = getString(R.string.restr_pin_enter_pin);
|
||||
ap.mPositiveButtonText = getString(R.string.ok);
|
||||
ap.mNegativeButtonText = getString(R.string.cancel);
|
||||
ap.mPositiveButtonListener = this;
|
||||
ap.mNegativeButtonListener = this;
|
||||
LayoutInflater inflater =
|
||||
(LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
ap.mView = inflater.inflate(R.layout.restrictions_pin_setup, null);
|
||||
|
||||
mPinText = (EditText) ap.mView.findViewById(R.id.pin_text);
|
||||
mPinMessage = (TextView) ap.mView.findViewById(R.id.pin_message);
|
||||
mNewPinText = (EditText) ap.mView.findViewById(R.id.pin_new_text);
|
||||
mConfirmPinText = (EditText) ap.mView.findViewById(R.id.pin_confirm_text);
|
||||
mPinErrorMessage = (TextView) ap.mView.findViewById(R.id.pin_error_message);
|
||||
mNewPinText.addTextChangedListener(this);
|
||||
mConfirmPinText.addTextChangedListener(this);
|
||||
|
||||
if (!mHasRestrictionsPin) {
|
||||
mPinText.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
setPositiveButtonState(false);
|
||||
}
|
||||
|
||||
protected boolean verifyingPin() {
|
||||
return false;
|
||||
}
|
||||
|
||||
private void setPositiveButtonState(boolean enabled) {
|
||||
mAlert.getButton(DialogInterface.BUTTON_POSITIVE).setEnabled(enabled);
|
||||
}
|
||||
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
setResult(RESULT_CANCELED);
|
||||
if (which == AlertDialog.BUTTON_POSITIVE) {
|
||||
performPositiveButtonAction();
|
||||
} else if (which == AlertDialog.BUTTON_NEGATIVE) {
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
protected void performPositiveButtonAction() {
|
||||
if (mHasRestrictionsPin) {
|
||||
int result = mUserManager.checkRestrictionsPin(mPinText.getText().toString());
|
||||
if (result != UserManager.PIN_VERIFICATION_SUCCESS) {
|
||||
// TODO: Set message that existing pin doesn't match
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (mUserManager.changeRestrictionsPin(mNewPinText.getText().toString())) {
|
||||
// TODO: Send message to PIN recovery agent about the recovery email address
|
||||
setResult(RESULT_OK);
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
CharSequence pin = mPinText.getText();
|
||||
CharSequence pin1 = mNewPinText.getText();
|
||||
CharSequence pin2 = mConfirmPinText.getText();
|
||||
boolean match = pin1 != null && pin2 != null && pin1.length() >= 4
|
||||
&& pin1.toString().equals(pin2.toString())
|
||||
&& (!mHasRestrictionsPin || (pin != null && pin.length() >= 4));
|
||||
boolean showError = !TextUtils.isEmpty(pin1) && !TextUtils.isEmpty(pin2);
|
||||
// TODO: Check recovery email address as well
|
||||
setPositiveButtonState(match);
|
||||
mPinErrorMessage.setVisibility((match || !showError) ? View.INVISIBLE : View.VISIBLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
|
||||
performPositiveButtonAction();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user