Skip to content

Commit bb5c941

Browse files
author
John Spurlock
committed
Disable security handle when swiping into camera widget.
Bug:7444313 Change-Id: I3eb268a41bc8b8a4323e55577a775c5ab3cef10d
1 parent dd8ac78 commit bb5c941

File tree

7 files changed

+76
-47
lines changed

7 files changed

+76
-47
lines changed

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

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,14 @@ interface Callbacks {
5353
private final Callbacks mCallbacks;
5454
private final WindowManager mWindowManager;
5555
private final Point mRenderedSize = new Point();
56+
private final int[] mScreenLocation = new int[2];
5657

5758
private View mWidgetView;
5859
private long mLaunchCameraStart;
5960
private boolean mActive;
60-
private boolean mChallengeActive;
6161
private boolean mTransitioning;
6262
private boolean mDown;
63+
private boolean mWindowFocused;
6364

6465
private final Runnable mLaunchCameraRunnable = new Runnable() {
6566
@Override
@@ -186,7 +187,7 @@ public void render() {
186187
}
187188

188189
private void transitionToCamera() {
189-
if (mTransitioning || mChallengeActive || mDown) return;
190+
if (mTransitioning || mDown) return;
190191

191192
mTransitioning = true;
192193

@@ -233,7 +234,7 @@ private void transitionToCamera() {
233234
public void onClick(View v) {
234235
if (DEBUG) Log.d(TAG, "clicked");
235236
if (mTransitioning) return;
236-
if (mActive && !mChallengeActive) {
237+
if (mActive) {
237238
cancelTransitionToCamera();
238239
transitionToCamera();
239240
}
@@ -242,6 +243,7 @@ public void onClick(View v) {
242243
@Override
243244
public void onWindowFocusChanged(boolean hasWindowFocus) {
244245
super.onWindowFocusChanged(hasWindowFocus);
246+
mWindowFocused = hasWindowFocus;
245247
if (DEBUG) Log.d(TAG, "onWindowFocusChanged: " + hasWindowFocus);
246248
if (!hasWindowFocus) {
247249
mTransitioning = false;
@@ -265,13 +267,29 @@ public void onActive(boolean isActive) {
265267
}
266268

267269
@Override
268-
public boolean onUserInteraction(int action) {
269-
if (mTransitioning) return true;
270-
if (DEBUG) Log.d(TAG, "onUserInteraction " + action);
270+
public boolean onUserInteraction(MotionEvent event) {
271+
if (!mWindowFocused) {
272+
if (DEBUG) Log.d(TAG, "onUserInteraction eaten: !mWindowFocused");
273+
return true;
274+
}
275+
if (mTransitioning) {
276+
if (DEBUG) Log.d(TAG, "onUserInteraction eaten: mTransitioning");
277+
return true;
278+
}
279+
280+
getLocationOnScreen(mScreenLocation);
281+
int rawBottom = mScreenLocation[1] + getHeight();
282+
if (event.getRawY() > rawBottom) {
283+
if (DEBUG) Log.d(TAG, "onUserInteraction eaten: below widget");
284+
return true;
285+
}
286+
287+
int action = event.getAction();
271288
mDown = action == MotionEvent.ACTION_DOWN || action == MotionEvent.ACTION_MOVE;
272-
if (mActive && !mChallengeActive) {
289+
if (mActive) {
273290
rescheduleTransitionToCamera();
274291
}
292+
if (DEBUG) Log.d(TAG, "onUserInteraction observed, not eaten");
275293
return false;
276294
}
277295

@@ -282,20 +300,6 @@ protected void onFocusLost() {
282300
super.onFocusLost();
283301
}
284302

285-
@Override
286-
public void onChallengeActive(boolean challengeActive) {
287-
if (DEBUG) Log.d(TAG, "onChallengeActive: " + challengeActive);
288-
mChallengeActive = challengeActive;
289-
if (mTransitioning) return;
290-
if (mActive) {
291-
if (mChallengeActive) {
292-
cancelTransitionToCamera();
293-
} else {
294-
rescheduleTransitionToCamera();
295-
}
296-
}
297-
}
298-
299303
public void onScreenTurnedOff() {
300304
if (DEBUG) Log.d(TAG, "onScreenTurnedOff");
301305
reset();
@@ -321,7 +325,6 @@ private void reset() {
321325
if (DEBUG) Log.d(TAG, "reset");
322326
mLaunchCameraStart = 0;
323327
mTransitioning = false;
324-
mChallengeActive = false;
325328
mDown = false;
326329
cancelTransitionToCamera();
327330
animate().cancel();
@@ -347,6 +350,7 @@ private void enableWindowExitAnimation(boolean isEnabled) {
347350
WindowManager.LayoutParams wlp = (WindowManager.LayoutParams) lp;
348351
int newWindowAnimations = isEnabled ? com.android.internal.R.style.Animation_LockScreen : 0;
349352
if (newWindowAnimations != wlp.windowAnimations) {
353+
if (DEBUG) Log.d(TAG, "setting windowAnimations to: " + newWindowAnimations);
350354
wlp.windowAnimations = newWindowAnimations;
351355
mWindowManager.updateViewLayout(root, wlp);
352356
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -837,6 +837,10 @@ public void onCameraLaunched() {
837837
if (isCameraPage(mAppWidgetContainer.getCurrentPage())) {
838838
mAppWidgetContainer.scrollLeft();
839839
}
840+
SlidingChallengeLayout slider = locateSlider();
841+
if (slider != null) {
842+
slider.setHandleAlpha(1);
843+
}
840844
mShowSecurityWhenReturn = true;
841845
}
842846

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,14 @@ public void fadeInSecurity(int duration) {
101101
((View) mKeyguardSecurityContainer).animate().alpha(1f).setDuration(duration);
102102
}
103103

104-
public void onPageSwitch(View newPage, int newPageIndex) {
104+
public void onPageSwitching(View newPage, int newPageIndex) {
105+
if (mPagedView != null && mChallengeLayout instanceof SlidingChallengeLayout) {
106+
boolean isCameraPage = newPage instanceof CameraWidgetFrame;
107+
((SlidingChallengeLayout) mChallengeLayout).setChallengeInteractive(!isCameraPage);
108+
}
109+
}
110+
111+
public void onPageSwitched(View newPage, int newPageIndex) {
105112
// Reset the previous page size and ensure the current page is sized appropriately.
106113
// We only modify the page state if it is not currently under control by the slider.
107114
// This prevents conflicts.
@@ -166,7 +173,6 @@ public void onScrollStateChanged(int scrollState) {
166173
if (!challengeOverlapping) {
167174
frame.resetSize();
168175
}
169-
frame.onChallengeActive(mChallengeLayout.isChallengeShowing());
170176
frame.hideFrame(this);
171177

172178
if (challengeOverlapping) {
@@ -200,8 +206,6 @@ public void onScrollStateChanged(int scrollState) {
200206
}
201207
// View is on the move. Pause the security view until it completes.
202208
mKeyguardSecurityContainer.onPause();
203-
204-
frame.onChallengeActive(true);
205209
}
206210
mLastScrollState = scrollState;
207211
}

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -418,12 +418,8 @@ public void onActive(boolean isActive) {
418418
// hook for subclasses
419419
}
420420

421-
public boolean onUserInteraction(int action) {
421+
public boolean onUserInteraction(MotionEvent event) {
422422
// hook for subclasses
423423
return false;
424424
}
425-
426-
public void onChallengeActive(boolean challengeActive) {
427-
// hook for subclasses
428-
}
429425
}

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,14 @@ public void setLockPatternUtils(LockPatternUtils l) {
119119
}
120120

121121
@Override
122-
public void onPageSwitch(View newPage, int newPageIndex) {
122+
public void onPageSwitching(View newPage, int newPageIndex) {
123+
if (mViewStateManager != null) {
124+
mViewStateManager.onPageSwitching(newPage, newPageIndex);
125+
}
126+
}
127+
128+
@Override
129+
public void onPageSwitched(View newPage, int newPageIndex) {
123130
boolean showingStatusWidget = false;
124131
if (newPage instanceof ViewGroup) {
125132
ViewGroup vg = (ViewGroup) newPage;
@@ -158,7 +165,7 @@ public void onPageSwitch(View newPage, int newPageIndex) {
158165
}
159166
}
160167
if (mViewStateManager != null) {
161-
mViewStateManager.onPageSwitch(newPage, newPageIndex);
168+
mViewStateManager.onPageSwitched(newPage, newPageIndex);
162169
}
163170
}
164171

@@ -179,7 +186,7 @@ private void userActivity() {
179186
@Override
180187
public boolean onTouchEvent(MotionEvent ev) {
181188
KeyguardWidgetFrame currentWidgetPage = getWidgetPageAt(getCurrentPage());
182-
if (currentWidgetPage != null && currentWidgetPage.onUserInteraction(ev.getAction())) {
189+
if (currentWidgetPage != null && currentWidgetPage.onUserInteraction(ev)) {
183190
return true;
184191
}
185192
return super.onTouchEvent(ev);

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

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,8 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc
239239
private boolean mIsFlingingToDelete = false;
240240

241241
public interface PageSwitchListener {
242-
void onPageSwitch(View newPage, int newPageIndex);
242+
void onPageSwitching(View newPage, int newPageIndex);
243+
void onPageSwitched(View newPage, int newPageIndex);
243244
}
244245

245246
public PagedView(Context context) {
@@ -356,7 +357,7 @@ int getViewportOffsetY() {
356357
public void setPageSwitchListener(PageSwitchListener pageSwitchListener) {
357358
mPageSwitchListener = pageSwitchListener;
358359
if (mPageSwitchListener != null) {
359-
mPageSwitchListener.onPageSwitch(getPageAt(mCurrentPage), mCurrentPage);
360+
mPageSwitchListener.onPageSwitched(getPageAt(mCurrentPage), mCurrentPage);
360361
}
361362
}
362363

@@ -415,6 +416,7 @@ protected void updateCurrentPageScroll() {
415416
* Sets the current page.
416417
*/
417418
void setCurrentPage(int currentPage) {
419+
notifyPageSwitching(currentPage);
418420
if (!mScroller.isFinished()) {
419421
mScroller.abortAnimation();
420422
}
@@ -428,17 +430,23 @@ void setCurrentPage(int currentPage) {
428430
mCurrentPage = Math.max(0, Math.min(currentPage, getPageCount() - 1));
429431
updateCurrentPageScroll();
430432
updateScrollingIndicator();
431-
notifyPageSwitchListener();
433+
notifyPageSwitched();
432434
invalidate();
433435
}
434436

435437
public void setOnlyAllowEdgeSwipes(boolean enable) {
436438
mOnlyAllowEdgeSwipes = enable;
437439
}
438440

439-
protected void notifyPageSwitchListener() {
441+
protected void notifyPageSwitching(int whichPage) {
440442
if (mPageSwitchListener != null) {
441-
mPageSwitchListener.onPageSwitch(getPageAt(mCurrentPage), mCurrentPage);
443+
mPageSwitchListener.onPageSwitching(getPageAt(whichPage), whichPage);
444+
}
445+
}
446+
447+
protected void notifyPageSwitched() {
448+
if (mPageSwitchListener != null) {
449+
mPageSwitchListener.onPageSwitched(getPageAt(mCurrentPage), mCurrentPage);
442450
}
443451
}
444452

@@ -532,7 +540,7 @@ protected boolean computeScrollHelper() {
532540
} else if (mNextPage != INVALID_PAGE) {
533541
mCurrentPage = Math.max(0, Math.min(mNextPage, getPageCount() - 1));
534542
mNextPage = INVALID_PAGE;
535-
notifyPageSwitchListener();
543+
notifyPageSwitched();
536544

537545
// We don't want to trigger a page end moving unless the page has settled
538546
// and the user has stopped scrolling
@@ -1743,7 +1751,7 @@ protected void snapToPage(int whichPage, int delta, int duration) {
17431751
}
17441752
protected void snapToPage(int whichPage, int delta, int duration, boolean immediate) {
17451753
mNextPage = whichPage;
1746-
1754+
notifyPageSwitching(whichPage);
17471755
View focusedChild = getFocusedChild();
17481756
if (focusedChild != null && whichPage != mCurrentPage &&
17491757
focusedChild == getPageAt(mCurrentPage)) {
@@ -1761,7 +1769,7 @@ protected void snapToPage(int whichPage, int delta, int duration, boolean immedi
17611769
if (!mScroller.isFinished()) mScroller.abortAnimation();
17621770
mScroller.startScroll(mUnboundedScrollX, 0, delta, 0, duration);
17631771

1764-
notifyPageSwitchListener();
1772+
notifyPageSwitched();
17651773

17661774
// Trigger a compute() to finish switching pages if necessary
17671775
if (immediate) {

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ public class SlidingChallengeLayout extends ViewGroup implements ChallengeLayout
122122
private final Rect mTempRect = new Rect();
123123

124124
private boolean mHasGlowpad;
125+
private boolean mChallengeInteractive = true;
125126

126127
static final Property<SlidingChallengeLayout, Float> HANDLE_ALPHA =
127128
new FloatProperty<SlidingChallengeLayout>("handleAlpha") {
@@ -186,7 +187,7 @@ public void onClick(View v) {
186187
private final OnClickListener mExpandChallengeClickListener = new OnClickListener() {
187188
@Override
188189
public void onClick(View v) {
189-
if (!isChallengeShowing()) {
190+
if (!isChallengeShowing() && mChallengeInteractive) {
190191
showChallenge(true);
191192
}
192193
}
@@ -275,6 +276,10 @@ public void setHandleAlpha(float alpha) {
275276
}
276277
}
277278

279+
public void setChallengeInteractive(boolean interactive) {
280+
mChallengeInteractive = interactive;
281+
}
282+
278283
void animateHandle(boolean visible) {
279284
if (mHandleAnimation != null) {
280285
mHandleAnimation.cancel();
@@ -579,7 +584,7 @@ public boolean onInterceptTouchEvent(MotionEvent ev) {
579584
for (int i = 0; i < count; i++) {
580585
final float x = ev.getX(i);
581586
final float y = ev.getY(i);
582-
if (!mIsBouncing && mActivePointerId == INVALID_POINTER
587+
if (!mIsBouncing && mChallengeInteractive && mActivePointerId == INVALID_POINTER
583588
&& (crossedDragHandle(x, y, mGestureStartY)
584589
|| (isInChallengeView(x, y) &&
585590
mScrollState == SCROLL_STATE_SETTLING))) {
@@ -627,7 +632,7 @@ public boolean onTouchEvent(MotionEvent ev) {
627632
break;
628633

629634
case MotionEvent.ACTION_CANCEL:
630-
if (mDragging) {
635+
if (mDragging && mChallengeInteractive) {
631636
showChallenge(0);
632637
}
633638
resetTouch();
@@ -638,7 +643,7 @@ public boolean onTouchEvent(MotionEvent ev) {
638643
break;
639644
}
640645
case MotionEvent.ACTION_UP:
641-
if (mDragging) {
646+
if (mDragging && mChallengeInteractive) {
642647
mVelocityTracker.computeCurrentVelocity(1000, mMaxVelocity);
643648
showChallenge((int) mVelocityTracker.getYVelocity(mActivePointerId));
644649
}
@@ -654,7 +659,8 @@ public boolean onTouchEvent(MotionEvent ev) {
654659

655660
if ((isInDragHandle(x, y) || crossedDragHandle(x, y, mGestureStartY) ||
656661
(isInChallengeView(x, y) && mScrollState == SCROLL_STATE_SETTLING))
657-
&& mActivePointerId == INVALID_POINTER) {
662+
&& mActivePointerId == INVALID_POINTER
663+
&& mChallengeInteractive) {
658664
mGestureStartX = x;
659665
mGestureStartY = y;
660666
mActivePointerId = ev.getPointerId(i);

0 commit comments

Comments
 (0)