Skip to content

Commit c7505bc

Browse files
author
Jeff Brown
committed
Increase lock screen timeout when on custom widget page.
Bug: 7290676 Change-Id: I93c48fb24adb24d16ec278a4fdd51a13a85a96c3
1 parent 5217773 commit c7505bc

File tree

5 files changed

+114
-14
lines changed

5 files changed

+114
-14
lines changed

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

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ public class KeyguardHostView extends KeyguardViewBase {
6565
private static final String KEYGUARD_WIDGET_PREFS = "keyguard_widget_prefs";
6666

6767
private AppWidgetHost mAppWidgetHost;
68+
private KeyguardWidgetRegion mAppWidgetRegion;
6869
private KeyguardWidgetPager mAppWidgetContainer;
6970
private ViewFlipper mSecurityViewContainer;
7071
private KeyguardSelectorView mKeyguardSelectorView;
@@ -142,9 +143,11 @@ private int getWidgetPosition(int id) {
142143

143144
@Override
144145
protected void onFinishInflate() {
146+
mAppWidgetRegion = (KeyguardWidgetRegion) findViewById(R.id.kg_widget_region);
147+
mAppWidgetRegion.setVisibility(VISIBLE);
148+
mAppWidgetRegion.setCallbacks(mWidgetCallbacks);
149+
145150
mAppWidgetContainer = (KeyguardWidgetPager) findViewById(R.id.app_widget_container);
146-
KeyguardWidgetRegion kgwr = (KeyguardWidgetRegion) findViewById(R.id.kg_widget_region);
147-
kgwr.setVisibility(VISIBLE);
148151
mSecurityViewContainer = (ViewFlipper) findViewById(R.id.view_flipper);
149152
mKeyguardSelectorView = (KeyguardSelectorView) findViewById(R.id.keyguard_selector_view);
150153

@@ -209,6 +212,33 @@ void addWidget(AppWidgetHostView view) {
209212
mAppWidgetContainer.addWidget(view);
210213
}
211214

215+
private KeyguardWidgetRegion.Callbacks mWidgetCallbacks
216+
= new KeyguardWidgetRegion.Callbacks() {
217+
@Override
218+
public void userActivity() {
219+
if (mViewMediatorCallback != null) {
220+
mViewMediatorCallback.userActivity();
221+
}
222+
}
223+
224+
@Override
225+
public void onUserActivityTimeoutChanged() {
226+
if (mViewMediatorCallback != null) {
227+
mViewMediatorCallback.onUserActivityTimeoutChanged();
228+
}
229+
}
230+
};
231+
232+
@Override
233+
public long getUserActivityTimeout() {
234+
// Currently only considering user activity timeouts needed by widgets.
235+
// Could also take into account longer timeouts for certain security views.
236+
if (mAppWidgetRegion != null) {
237+
return mAppWidgetRegion.getUserActivityTimeout();
238+
}
239+
return -1;
240+
}
241+
212242
private KeyguardSecurityCallback mCallback = new KeyguardSecurityCallback() {
213243

214244
public void userActivity(long timeout) {

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,12 @@ public void resetBackground() {
137137
*/
138138
abstract public void cleanUp();
139139

140+
/**
141+
* Gets the desired user activity timeout in milliseconds, or -1 if the
142+
* default should be used.
143+
*/
144+
abstract public long getUserActivityTimeout();
145+
140146
@Override
141147
public boolean dispatchKeyEvent(KeyEvent event) {
142148
if (interceptMediaKey(event)) {
@@ -250,5 +256,4 @@ public void setViewMediatorCallback(
250256
KeyguardViewMediator.ViewMediatorCallback viewMediatorCallback) {
251257
mViewMediatorCallback = viewMediatorCallback;
252258
}
253-
254259
}

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

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,12 +184,13 @@ private void maybeCreateKeyguardLocked(boolean enableScreenRotation, Bundle opti
184184
lp.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
185185
}
186186
lp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_DISABLE_USER_ACTIVITY;
187-
lp.userActivityTimeout = KeyguardViewMediator.AWAKE_INTERVAL_DEFAULT_MS;
188187
lp.setTitle(isActivity ? "KeyguardMock" : "Keyguard");
189188
mWindowLayoutParams = lp;
190189
mViewManager.addView(mKeyguardHost, lp);
191190
}
191+
192192
inflateKeyguardView(options);
193+
updateUserActivityTimeoutInWindowLayoutParams();
193194
mViewManager.updateViewLayout(mKeyguardHost, mWindowLayoutParams);
194195

195196
mKeyguardHost.restoreHierarchyState(mStateContainer);
@@ -224,6 +225,25 @@ private void inflateKeyguardView(Bundle options) {
224225
}
225226
}
226227

228+
public void updateUserActivityTimeout() {
229+
updateUserActivityTimeoutInWindowLayoutParams();
230+
mViewManager.updateViewLayout(mKeyguardHost, mWindowLayoutParams);
231+
}
232+
233+
private void updateUserActivityTimeoutInWindowLayoutParams() {
234+
// Use the user activity timeout requested by the keyguard view, if any.
235+
if (mKeyguardView != null) {
236+
long timeout = mKeyguardView.getUserActivityTimeout();
237+
if (timeout >= 0) {
238+
mWindowLayoutParams.userActivityTimeout = timeout;
239+
return;
240+
}
241+
}
242+
243+
// Otherwise, use the default timeout.
244+
mWindowLayoutParams.userActivityTimeout = KeyguardViewMediator.AWAKE_INTERVAL_DEFAULT_MS;
245+
}
246+
227247
private void maybeEnableScreenRotation(boolean enableScreenRotation) {
228248
// TODO: move this outside
229249
if (enableScreenRotation) {

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

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -259,9 +259,14 @@ public interface ViewMediatorCallback {
259259
void wakeUp();
260260

261261
/**
262-
* Reports user activity and requests that the screen stay on for the specified
263-
* amount of time.
264-
* @param millis The amount of time in millis.
262+
* Reports user activity and requests that the screen stay on.
263+
*/
264+
void userActivity();
265+
266+
/**
267+
* Reports user activity and requests that the screen stay on for at least
268+
* the specified amount of time.
269+
* @param millis The amount of time in millis. This value is currently ignored.
265270
*/
266271
void userActivity(long millis);
267272

@@ -284,6 +289,12 @@ public interface ViewMediatorCallback {
284289
* @param needsInput
285290
*/
286291
void setNeedsInput(boolean needsInput);
292+
293+
/**
294+
* Tell view mediator that the keyguard view's desired user activity timeout
295+
* has changed and needs to be reapplied to the window.
296+
*/
297+
void onUserActivityTimeoutChanged();
287298
}
288299

289300
KeyguardUpdateMonitorCallback mUpdateCallback = new KeyguardUpdateMonitorCallback() {
@@ -400,6 +411,10 @@ public void wakeUp() {
400411
KeyguardViewMediator.this.wakeUp();
401412
}
402413

414+
public void userActivity() {
415+
KeyguardViewMediator.this.userActivity();
416+
}
417+
403418
public void userActivity(long holdMs) {
404419
KeyguardViewMediator.this.userActivity(holdMs);
405420
}
@@ -416,6 +431,11 @@ public void keyguardDoneDrawing() {
416431
public void setNeedsInput(boolean needsInput) {
417432
mKeyguardViewManager.setNeedsInput(needsInput);
418433
}
434+
435+
@Override
436+
public void onUserActivityTimeoutChanged() {
437+
mKeyguardViewManager.updateUserActivityTimeout();
438+
}
419439
};
420440

421441
public void wakeUp() {

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

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
package com.android.internal.policy.impl.keyguard;
1717

1818
import android.content.Context;
19-
import android.os.PowerManager;
20-
import android.os.SystemClock;
2119
import android.util.AttributeSet;
2220
import android.view.View;
2321
import android.view.ViewGroup;
@@ -31,7 +29,9 @@ public class KeyguardWidgetRegion extends LinearLayout implements PageSwitchList
3129
KeyguardGlowStripView mRightStrip;
3230
KeyguardWidgetPager mPager;
3331
private int mPage = 0;
34-
private PowerManager mPowerManager;
32+
private Callbacks mCallbacks;
33+
34+
private static final long CUSTOM_WIDGET_USER_ACTIVITY_TIMEOUT = 30000;
3535

3636
public KeyguardWidgetRegion(Context context) {
3737
this(context, null, 0);
@@ -43,7 +43,6 @@ public KeyguardWidgetRegion(Context context, AttributeSet attrs) {
4343

4444
public KeyguardWidgetRegion(Context context, AttributeSet attrs, int defStyle) {
4545
super(context, attrs, defStyle);
46-
mPowerManager = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
4746
}
4847

4948
@Override
@@ -75,9 +74,10 @@ public void showPagingFeedback() {
7574
@Override
7675
public void onPageSwitch(View newPage, int newPageIndex) {
7776
boolean showingStatusWidget = false;
78-
if ((newPage instanceof ViewGroup)) {
77+
if (newPage instanceof ViewGroup) {
7978
ViewGroup vg = (ViewGroup) newPage;
80-
if (vg.getChildAt(0) instanceof KeyguardStatusView) {
79+
View view = vg.getChildAt(0);
80+
if (view instanceof KeyguardStatusView) {
8181
showingStatusWidget = true;
8282
}
8383
}
@@ -91,8 +91,33 @@ public void onPageSwitch(View newPage, int newPageIndex) {
9191

9292
// Extend the display timeout if the user switches pages
9393
if (mPage != newPageIndex) {
94-
mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
9594
mPage = newPageIndex;
95+
if (mCallbacks != null) {
96+
mCallbacks.onUserActivityTimeoutChanged();
97+
mCallbacks.userActivity();
98+
}
99+
}
100+
}
101+
102+
public long getUserActivityTimeout() {
103+
View page = mPager.getPageAt(mPage);
104+
if (page instanceof ViewGroup) {
105+
ViewGroup vg = (ViewGroup) page;
106+
View view = vg.getChildAt(0);
107+
if (!(view instanceof KeyguardStatusView)
108+
&& !(view instanceof KeyguardMultiUserSelectorView)) {
109+
return CUSTOM_WIDGET_USER_ACTIVITY_TIMEOUT;
110+
}
96111
}
112+
return -1;
113+
}
114+
115+
public void setCallbacks(Callbacks callbacks) {
116+
mCallbacks = callbacks;
117+
}
118+
119+
public interface Callbacks {
120+
public void userActivity();
121+
public void onUserActivityTimeoutChanged();
97122
}
98123
}

0 commit comments

Comments
 (0)