Skip to content

Commit 207c673

Browse files
Jim MillerAndroid (Google) Code Review
authored andcommitted
Merge "Fix 5444675: Fix vibrate regression on Pattern and PIN unlock screens." into ics-mr0
2 parents cc21cc0 + aef555b commit 207c673

File tree

3 files changed

+30
-44
lines changed

3 files changed

+30
-44
lines changed

core/java/com/android/internal/widget/LockPatternView.java

Lines changed: 10 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@
3232
import android.os.Parcel;
3333
import android.os.Parcelable;
3434
import android.os.SystemClock;
35-
import android.os.Vibrator;
3635
import android.util.AttributeSet;
3736
import android.util.Log;
37+
import android.view.HapticFeedbackConstants;
3838
import android.view.MotionEvent;
3939
import android.view.View;
4040
import android.view.accessibility.AccessibilityEvent;
@@ -59,9 +59,6 @@ public class LockPatternView extends View {
5959
private static final int ASPECT_LOCK_WIDTH = 1; // Fixed width; height will be minimum of (w,h)
6060
private static final int ASPECT_LOCK_HEIGHT = 2; // Fixed height; width will be minimum of (w,h)
6161

62-
// Vibrator pattern for creating a tactile bump
63-
private static final long[] DEFAULT_VIBE_PATTERN = {0, 1, 40, 41};
64-
6562
private static final boolean PROFILE_DRAWING = false;
6663
private boolean mDrawingProfilingStarted = false;
6764

@@ -102,7 +99,7 @@ public class LockPatternView extends View {
10299
private DisplayMode mPatternDisplayMode = DisplayMode.Correct;
103100
private boolean mInputEnabled = true;
104101
private boolean mInStealthMode = false;
105-
private boolean mTactileFeedbackEnabled = true;
102+
private boolean mEnableHapticFeedback = true;
106103
private boolean mPatternInProgress = false;
107104

108105
private float mDiameterFactor = 0.10f; // TODO: move to attrs
@@ -127,11 +124,6 @@ public class LockPatternView extends View {
127124
private int mBitmapWidth;
128125
private int mBitmapHeight;
129126

130-
131-
private Vibrator vibe; // Vibrator for creating tactile feedback
132-
133-
private long[] mVibePattern;
134-
135127
private int mAspect;
136128
private final Matrix mArrowMatrix = new Matrix();
137129
private final Matrix mCircleMatrix = new Matrix();
@@ -250,7 +242,6 @@ public LockPatternView(Context context) {
250242

251243
public LockPatternView(Context context, AttributeSet attrs) {
252244
super(context, attrs);
253-
vibe = new Vibrator();
254245

255246
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.LockPatternView);
256247

@@ -295,26 +286,6 @@ public LockPatternView(Context context, AttributeSet attrs) {
295286
mBitmapHeight = Math.max(mBitmapHeight, bitmap.getHeight());
296287
}
297288

298-
// allow vibration pattern to be customized
299-
mVibePattern = loadVibratePattern(com.android.internal.R.array.config_virtualKeyVibePattern);
300-
}
301-
302-
private long[] loadVibratePattern(int id) {
303-
int[] pattern = null;
304-
try {
305-
pattern = getResources().getIntArray(id);
306-
} catch (Resources.NotFoundException e) {
307-
Log.e(TAG, "Vibrate pattern missing, using default", e);
308-
}
309-
if (pattern == null) {
310-
return DEFAULT_VIBE_PATTERN;
311-
}
312-
313-
long[] tmpPattern = new long[pattern.length];
314-
for (int i = 0; i < pattern.length; i++) {
315-
tmpPattern[i] = pattern[i];
316-
}
317-
return tmpPattern;
318289
}
319290

320291
private Bitmap getBitmapFor(int resId) {
@@ -332,7 +303,7 @@ public boolean isInStealthMode() {
332303
* @return Whether the view has tactile feedback enabled.
333304
*/
334305
public boolean isTactileFeedbackEnabled() {
335-
return mTactileFeedbackEnabled;
306+
return mEnableHapticFeedback;
336307
}
337308

338309
/**
@@ -352,7 +323,7 @@ public void setInStealthMode(boolean inStealthMode) {
352323
* @param tactileFeedbackEnabled Whether tactile feedback is enabled
353324
*/
354325
public void setTactileFeedbackEnabled(boolean tactileFeedbackEnabled) {
355-
mTactileFeedbackEnabled = tactileFeedbackEnabled;
326+
mEnableHapticFeedback = tactileFeedbackEnabled;
356327
}
357328

358329
/**
@@ -573,8 +544,10 @@ private Cell detectAndAddHit(float x, float y) {
573544
addCellToPattern(fillInGapCell);
574545
}
575546
addCellToPattern(cell);
576-
if (mTactileFeedbackEnabled){
577-
vibe.vibrate(mVibePattern, -1); // Generate tactile feedback
547+
if (mEnableHapticFeedback) {
548+
performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY,
549+
HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING
550+
| HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING);
578551
}
579552
return cell;
580553
}
@@ -1114,7 +1087,7 @@ protected Parcelable onSaveInstanceState() {
11141087
return new SavedState(superState,
11151088
LockPatternUtils.patternToString(mPattern),
11161089
mPatternDisplayMode.ordinal(),
1117-
mInputEnabled, mInStealthMode, mTactileFeedbackEnabled);
1090+
mInputEnabled, mInStealthMode, mEnableHapticFeedback);
11181091
}
11191092

11201093
@Override
@@ -1127,7 +1100,7 @@ protected void onRestoreInstanceState(Parcelable state) {
11271100
mPatternDisplayMode = DisplayMode.values()[ss.getDisplayMode()];
11281101
mInputEnabled = ss.isInputEnabled();
11291102
mInStealthMode = ss.isInStealthMode();
1130-
mTactileFeedbackEnabled = ss.isTactileFeedbackEnabled();
1103+
mEnableHapticFeedback = ss.isTactileFeedbackEnabled();
11311104
}
11321105

11331106
/**

core/java/com/android/internal/widget/PasswordEntryKeyboardHelper.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import android.os.Vibrator;
2727
import android.provider.Settings;
2828
import android.util.Log;
29+
import android.view.HapticFeedbackConstants;
2930
import android.view.KeyCharacterMap;
3031
import android.view.KeyEvent;
3132
import android.view.View;
@@ -52,7 +53,7 @@ public class PasswordEntryKeyboardHelper implements OnKeyboardActionListener {
5253
private final View mTargetView;
5354
private final KeyboardView mKeyboardView;
5455
private long[] mVibratePattern;
55-
private final Vibrator mVibrator;
56+
private boolean mEnableHaptics = false;
5657

5758
public PasswordEntryKeyboardHelper(Context context, KeyboardView keyboardView, View targetView) {
5859
this(context, keyboardView, targetView, true);
@@ -71,7 +72,10 @@ public PasswordEntryKeyboardHelper(Context context, KeyboardView keyboardView, V
7172
mKeyboardView.getLayoutParams().height);
7273
}
7374
mKeyboardView.setOnKeyboardActionListener(this);
74-
mVibrator = new Vibrator();
75+
}
76+
77+
public void setEnableHaptics(boolean enabled) {
78+
mEnableHaptics = enabled;
7579
}
7680

7781
public boolean isAlpha() {
@@ -230,6 +234,7 @@ private void handleModeChange() {
230234

231235
public void handleBackspace() {
232236
sendDownUpKeyEvents(KeyEvent.KEYCODE_DEL);
237+
performHapticFeedback();
233238
}
234239

235240
private void handleShift() {
@@ -272,8 +277,14 @@ private void handleClose() {
272277
}
273278

274279
public void onPress(int primaryCode) {
275-
if (mVibratePattern != null) {
276-
mVibrator.vibrate(mVibratePattern, -1);
280+
performHapticFeedback();
281+
}
282+
283+
private void performHapticFeedback() {
284+
if (mEnableHaptics) {
285+
mKeyboardView.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY,
286+
HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING
287+
| HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING);
277288
}
278289
}
279290

policy/src/com/android/internal/policy/impl/PasswordUnlockScreen.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
import android.os.CountDownTimer;
3030
import android.os.SystemClock;
31+
import android.provider.Settings;
3132
import android.security.KeyStore;
3233
import android.text.Editable;
3334
import android.text.InputType;
@@ -109,6 +110,10 @@ public PasswordUnlockScreen(Context context, Configuration configuration,
109110
mPasswordEntry.setOnEditorActionListener(this);
110111

111112
mKeyboardHelper = new PasswordEntryKeyboardHelper(context, mKeyboardView, this, false);
113+
mKeyboardHelper.setEnableHaptics(
114+
Settings.Secure.getInt(mContext.getContentResolver(),
115+
Settings.Secure.LOCK_PATTERN_TACTILE_FEEDBACK_ENABLED, 0)
116+
!= 0);
112117
if (mIsAlpha) {
113118
// We always use the system IME for alpha keyboard, so hide lockscreen's soft keyboard
114119
mKeyboardHelper.setKeyboardMode(PasswordEntryKeyboardHelper.KEYBOARD_MODE_ALPHA);
@@ -150,9 +155,6 @@ public void onClick(View v) {
150155
//KeyguardStatusViewManager.LOCK_ICON);
151156
}
152157

153-
mKeyboardHelper.setVibratePattern(mLockPatternUtils.isTactileFeedbackEnabled() ?
154-
com.android.internal.R.array.config_virtualKeyVibePattern : 0);
155-
156158
// Poke the wakelock any time the text is selected or modified
157159
mPasswordEntry.setOnClickListener(new OnClickListener() {
158160
public void onClick(View v) {

0 commit comments

Comments
 (0)