Skip to content

Commit 27230f0

Browse files
Jim MillerAndroid (Google) Code Review
authored andcommitted
Merge "Better flow for SIM PIN/ SIM PUK screens in keyguard." into jb-mr1-dev
2 parents 9ca26e4 + 4b09dd3 commit 27230f0

7 files changed

Lines changed: 155 additions & 67 deletions

File tree

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!-- Copyright (C) 2012 The Android Open Source Project
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
-->
16+
17+
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
18+
android:interpolator="@interpolator/decelerate_quad"
19+
android:fromAlpha="0.0" android:toAlpha="1.0"
20+
android:duration="@integer/kg_security_fade_duration" />
21+
22+
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!-- Copyright (C) 2012 The Android Open Source Project
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
-->
16+
<alpha xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@interpolator/accelerate_quad"
17+
android:fromAlpha="1.0"
18+
android:toAlpha="0.0"
19+
android:duration="@integer/kg_security_fade_duration"
20+
/>

core/res/res/values/integers.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@
1818
-->
1919
<resources>
2020
<integer name="kg_security_flip_duration">150</integer>
21+
<integer name="kg_security_fade_duration">150</integer>
2122
</resources>

core/res/res/values/public.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1214,6 +1214,8 @@
12141214
<java-symbol type="anim" name="dock_right_exit" />
12151215
<java-symbol type="anim" name="keyguard_security_animate_in" />
12161216
<java-symbol type="anim" name="keyguard_security_animate_out" />
1217+
<java-symbol type="anim" name="keyguard_security_fade_in" />
1218+
<java-symbol type="anim" name="keyguard_security_fade_out" />
12171219
<java-symbol type="array" name="config_keyboardTapVibePattern" />
12181220
<java-symbol type="array" name="config_longPressVibePattern" />
12191221
<java-symbol type="array" name="config_safeModeDisabledVibePattern" />

policy/src/com/android/internal/policy/impl/keyguard/KeyguardHostView.java

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,6 @@ protected void onFinishInflate() {
130130

131131
// View Flipper
132132
mViewFlipper = (ViewFlipper) findViewById(R.id.view_flipper);
133-
mViewFlipper.setInAnimation(AnimationUtils.loadAnimation(mContext,
134-
R.anim.keyguard_security_animate_in));
135-
mViewFlipper.setOutAnimation(AnimationUtils.loadAnimation(mContext,
136-
R.anim.keyguard_security_animate_out));
137133

138134
// Initialize all security views
139135
for (int i = 0; i < mViewIds.length; i++) {
@@ -381,11 +377,28 @@ private void showNextSecurityScreenOrFinish(boolean authenticated) {
381377
showSecurityScreen(realSecurityId); // switch to the "real" security view
382378
}
383379
} else if (authenticated) {
384-
if (mCurrentSecurityId == SECURITY_PATTERN_ID
385-
|| mCurrentSecurityId == SECURITY_PASSWORD_ID
386-
|| mCurrentSecurityId == SECURITY_ACCOUNT_ID
387-
|| mCurrentSecurityId == SECURITY_BIOMETRIC_ID) {
388-
finish = true;
380+
switch (mCurrentSecurityId) {
381+
case SECURITY_PATTERN_ID:
382+
case SECURITY_PASSWORD_ID:
383+
case SECURITY_ACCOUNT_ID:
384+
case SECURITY_BIOMETRIC_ID:
385+
finish = true;
386+
break;
387+
388+
case SECURITY_SIM_PIN_ID:
389+
case SECURITY_SIM_PUK_ID:
390+
// Shortcut for SIM PIN/PUK to go to directly to user's security screen or home
391+
SecurityMode securityMode = mSecurityModel.getSecurityMode();
392+
if (securityMode != SecurityMode.None) {
393+
showSecurityScreen(getSecurityViewIdForMode(securityMode));
394+
} else {
395+
finish = true;
396+
}
397+
break;
398+
399+
default:
400+
showSecurityScreen(SECURITY_SELECTOR_ID);
401+
break;
389402
}
390403
} else {
391404
// Not authenticated but we were asked to dismiss so go back to selector screen.
@@ -480,10 +493,20 @@ private void showSecurityScreen(int securityViewId) {
480493
newView.onResume();
481494

482495
mViewMediatorCallback.setNeedsInput(newView.needsInput());
483-
mCurrentSecurityId = securityViewId;
484496

485497
// Find and show this child.
486498
final int childCount = mViewFlipper.getChildCount();
499+
500+
// If we're go to/from the selector view, do flip animation, otherwise use fade animation.
501+
final boolean doFlip = mCurrentSecurityId == SECURITY_SELECTOR_ID
502+
|| securityViewId == SECURITY_SELECTOR_ID;
503+
final int inAnimation = doFlip ? R.anim.keyguard_security_animate_in
504+
: R.anim.keyguard_security_fade_in;
505+
final int outAnimation = doFlip ? R.anim.keyguard_security_animate_out
506+
: R.anim.keyguard_security_fade_out;
507+
508+
mViewFlipper.setInAnimation(AnimationUtils.loadAnimation(mContext, inAnimation));
509+
mViewFlipper.setOutAnimation(AnimationUtils.loadAnimation(mContext, outAnimation));
487510
for (int i = 0; i < childCount; i++) {
488511
if (securityViewId == mViewFlipper.getChildAt(i).getId()) {
489512
mViewFlipper.setDisplayedChild(i);
@@ -495,6 +518,8 @@ private void showSecurityScreen(int securityViewId) {
495518
if (securityViewId == SECURITY_SELECTOR_ID) {
496519
setOnDismissRunnable(null);
497520
}
521+
522+
mCurrentSecurityId = securityViewId;
498523
}
499524

500525
@Override

policy/src/com/android/internal/policy/impl/keyguard/KeyguardSimPinView.java

Lines changed: 34 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
import android.util.AttributeSet;
3434
import android.view.KeyEvent;
35+
import android.view.MotionEvent;
3536
import android.view.View;
3637
import android.view.WindowManager;
3738
import android.view.inputmethod.EditorInfo;
@@ -56,6 +57,8 @@ public class KeyguardSimPinView extends LinearLayout
5657
private LockPatternUtils mLockPatternUtils;
5758
private KeyguardNavigationManager mNavigationManager;
5859

60+
private volatile boolean mSimCheckInProgress;
61+
5962
public KeyguardSimPinView(Context context) {
6063
this(context, null);
6164
}
@@ -129,7 +132,7 @@ protected CheckSimPin(String pin) {
129132
mPin = pin;
130133
}
131134

132-
abstract void onSimLockChangedResponse(boolean success);
135+
abstract void onSimCheckResponse(boolean success);
133136

134137
@Override
135138
public void run() {
@@ -138,13 +141,13 @@ public void run() {
138141
.checkService("phone")).supplyPin(mPin);
139142
post(new Runnable() {
140143
public void run() {
141-
onSimLockChangedResponse(result);
144+
onSimCheckResponse(result);
142145
}
143146
});
144147
} catch (RemoteException e) {
145148
post(new Runnable() {
146149
public void run() {
147-
onSimLockChangedResponse(false);
150+
onSimCheckResponse(false);
148151
}
149152
});
150153
}
@@ -154,8 +157,10 @@ public void run() {
154157
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
155158
// Check if this was the result of hitting the enter key
156159
mCallback.userActivity(DIGIT_PRESS_WAKE_MILLIS);
157-
if (actionId == EditorInfo.IME_NULL || actionId == EditorInfo.IME_ACTION_DONE
158-
|| actionId == EditorInfo.IME_ACTION_NEXT) {
160+
if (event.getAction() == MotionEvent.ACTION_DOWN && (
161+
actionId == EditorInfo.IME_NULL
162+
|| actionId == EditorInfo.IME_ACTION_DONE
163+
|| actionId == EditorInfo.IME_ACTION_NEXT)) {
159164
checkPin();
160165
return true;
161166
}
@@ -188,27 +193,31 @@ private void checkPin() {
188193

189194
getSimUnlockProgressDialog().show();
190195

191-
new CheckSimPin(mPinEntry.getText().toString()) {
192-
void onSimLockChangedResponse(final boolean success) {
193-
post(new Runnable() {
194-
public void run() {
195-
if (mSimUnlockProgressDialog != null) {
196-
mSimUnlockProgressDialog.hide();
196+
if (!mSimCheckInProgress) {
197+
mSimCheckInProgress = true; // there should be only one
198+
new CheckSimPin(mPinEntry.getText().toString()) {
199+
void onSimCheckResponse(final boolean success) {
200+
post(new Runnable() {
201+
public void run() {
202+
if (mSimUnlockProgressDialog != null) {
203+
mSimUnlockProgressDialog.hide();
204+
}
205+
if (success) {
206+
// before closing the keyguard, report back that the sim is unlocked
207+
// so it knows right away.
208+
KeyguardUpdateMonitor.getInstance(getContext()).reportSimUnlocked();
209+
mCallback.dismiss(true);
210+
} else {
211+
mNavigationManager.setMessage(R.string.kg_password_wrong_pin_code);
212+
mPinEntry.setText("");
213+
}
214+
mCallback.userActivity(0);
215+
mSimCheckInProgress = false;
197216
}
198-
if (success) {
199-
// before closing the keyguard, report back that the sim is unlocked
200-
// so it knows right away.
201-
KeyguardUpdateMonitor.getInstance(getContext()).reportSimUnlocked();
202-
mCallback.dismiss(false); //
203-
} else {
204-
mNavigationManager.setMessage(R.string.kg_password_wrong_pin_code);
205-
mPinEntry.setText("");
206-
}
207-
mCallback.userActivity(0);
208-
}
209-
});
210-
}
211-
}.start();
217+
});
218+
}
219+
}.start();
220+
}
212221
}
213222

214223
public void setLockPatternUtils(LockPatternUtils utils) {

policy/src/com/android/internal/policy/impl/keyguard/KeyguardSimPukView.java

Lines changed: 41 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import android.util.AttributeSet;
2828
import android.util.Log;
2929
import android.view.KeyEvent;
30+
import android.view.MotionEvent;
3031
import android.view.View;
3132
import android.view.WindowManager;
3233
import android.view.inputmethod.EditorInfo;
@@ -63,6 +64,8 @@ public class KeyguardSimPukView extends LinearLayout implements View.OnClickList
6364

6465
private LockPatternUtils mLockPatternUtils;
6566

67+
private volatile boolean mCheckInProgress;
68+
6669
public KeyguardSimPukView(Context context) {
6770
this(context, null);
6871
}
@@ -233,48 +236,54 @@ private void checkPuk() {
233236

234237
getSimUnlockProgressDialog().show();
235238

236-
new CheckSimPuk(mPukText.getText().toString(),
237-
mPinText.getText().toString()) {
238-
void onSimLockChangedResponse(final boolean success) {
239-
mPinText.post(new Runnable() {
240-
public void run() {
241-
if (mSimUnlockProgressDialog != null) {
242-
mSimUnlockProgressDialog.hide();
243-
}
244-
if (success) {
245-
mCallback.dismiss(true);
246-
} else {
247-
mNavigationManager.setMessage(R.string.kg_invalid_puk);
248-
mPukText.setText("");
249-
mPinText.setText("");
239+
if (!mCheckInProgress) {
240+
mCheckInProgress = true;
241+
new CheckSimPuk(mPukText.getText().toString(),
242+
mPinText.getText().toString()) {
243+
void onSimLockChangedResponse(final boolean success) {
244+
mPinText.post(new Runnable() {
245+
public void run() {
246+
if (mSimUnlockProgressDialog != null) {
247+
mSimUnlockProgressDialog.hide();
248+
}
249+
if (success) {
250+
mCallback.dismiss(true);
251+
} else {
252+
mNavigationManager.setMessage(R.string.kg_invalid_puk);
253+
mPukText.setText("");
254+
mPinText.setText("");
255+
}
256+
mCheckInProgress = false;
250257
}
251-
}
252-
});
253-
}
254-
}.start();
258+
});
259+
}
260+
}.start();
261+
}
255262
}
256263

257264
@Override
258265
public boolean onEditorAction(TextView view, int actionId, KeyEvent event) {
259266
// Check if this was the result of hitting the enter key
260267
mCallback.userActivity(DIGIT_PRESS_WAKE_MILLIS);
261-
if (actionId == EditorInfo.IME_NULL
268+
if (event.getAction() == MotionEvent.ACTION_DOWN) {
269+
if (actionId == EditorInfo.IME_NULL
262270
|| actionId == EditorInfo.IME_ACTION_DONE
263271
|| actionId == EditorInfo.IME_ACTION_NEXT) {
264-
if (view == mPukText && mPukText.getText().length() < 8) {
265-
mNavigationManager.setMessage(R.string.kg_invalid_sim_puk_hint);
266-
mPukText.setText("");
267-
mPukText.requestFocus();
268-
return true;
269-
} else if (view == mPinText) {
270-
if (mPinText.getText().length() < 4 || mPinText.getText().length() > 8) {
271-
mNavigationManager.setMessage(R.string.kg_invalid_sim_pin_hint);
272-
mPinText.setText("");
273-
mPinText.requestFocus();
274-
} else {
275-
checkPuk();
272+
if (view == mPukText && mPukText.getText().length() < 8) {
273+
mNavigationManager.setMessage(R.string.kg_invalid_sim_puk_hint);
274+
mPukText.setText("");
275+
mPukText.requestFocus();
276+
return true;
277+
} else if (view == mPinText) {
278+
if (mPinText.getText().length() < 4 || mPinText.getText().length() > 8) {
279+
mNavigationManager.setMessage(R.string.kg_invalid_sim_pin_hint);
280+
mPinText.setText("");
281+
mPinText.requestFocus();
282+
} else {
283+
checkPuk();
284+
}
285+
return true;
276286
}
277-
return true;
278287
}
279288
}
280289
return false;

0 commit comments

Comments
 (0)