Skip to content

Commit 835579e

Browse files
mikejurkaAndroid (Google) Code Review
authored andcommitted
Merge "Removing sticky widgets in lockscreen" into jb-mr1-lockscreen-dev
2 parents ad9f594 + 76017ca commit 835579e

File tree

4 files changed

+41
-73
lines changed

4 files changed

+41
-73
lines changed

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

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,11 @@ public class LockPatternUtils {
110110
*/
111111
public static final String KEYGUARD_SHOW_SECURITY_CHALLENGE = "showsecuritychallenge";
112112

113+
/**
114+
* Tells the keyguard to show the widget with the specified id when the keyguard is created.
115+
*/
116+
public static final String KEYGUARD_SHOW_APPWIDGET = "showappwidget";
117+
113118
/**
114119
* Options used to lock the device upon user switch.
115120
*/
@@ -1183,21 +1188,6 @@ public boolean removeAppWidget(int widgetId) {
11831188
return true;
11841189
}
11851190

1186-
public int getStickyAppWidgetIndex() {
1187-
return Settings.Secure.getIntForUser(
1188-
mContentResolver,
1189-
Settings.Secure.LOCK_SCREEN_STICKY_APPWIDGET,
1190-
-1,
1191-
UserHandle.USER_CURRENT);
1192-
}
1193-
1194-
public void setStickyAppWidgetIndex(int value) {
1195-
Settings.Secure.putIntForUser(mContentResolver,
1196-
Settings.Secure.LOCK_SCREEN_STICKY_APPWIDGET,
1197-
value,
1198-
UserHandle.USER_CURRENT);
1199-
}
1200-
12011191
private long getLong(String secureSettingKey, long defaultValue) {
12021192
try {
12031193
return getLockSettings().getLong(secureSettingKey, defaultValue,

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

Lines changed: 30 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@
3737
import android.os.Parcel;
3838
import android.os.Parcelable;
3939
import android.os.SystemClock;
40-
import android.os.SystemProperties;
41-
import android.os.UserHandle;
4240
import android.os.UserManager;
4341
import android.util.AttributeSet;
4442
import android.util.Log;
@@ -75,6 +73,7 @@ public class KeyguardHostView extends KeyguardViewBase {
7573
private boolean mIsVerifyUnlockOnly;
7674
private boolean mEnableFallback; // TODO: This should get the value from KeyguardPatternView
7775
private SecurityMode mCurrentSecuritySelection = SecurityMode.Invalid;
76+
private int mAppWidgetToShow;
7877

7978
protected Runnable mLaunchRunnable;
8079

@@ -84,7 +83,6 @@ public class KeyguardHostView extends KeyguardViewBase {
8483
private KeyguardSecurityModel mSecurityModel;
8584
private KeyguardViewStateManager mViewStateManager;
8685

87-
int mLocalStickyWidget = -1;
8886
boolean mPersitentStickyWidgetLoaded = false;
8987

9088
private Rect mTempRect = new Rect();
@@ -768,7 +766,6 @@ public void onScreenTurnedOff() {
768766
// Once the screen turns off, we no longer consider this to be first boot and we want the
769767
// biometric unlock to start next time keyguard is shown.
770768
KeyguardUpdateMonitor.getInstance(mContext).setAlternateUnlockEnabled(true);
771-
saveStickyWidgetIndex();
772769
checkAppWidgetConsistency();
773770
showPrimarySecurityScreen(true);
774771
getSecurityView(mCurrentSecuritySelection).onPause();
@@ -967,7 +964,7 @@ public void onClick(View v) {
967964
initializeTransportControl();
968965
}
969966

970-
private void removeTransportFromWidgetPager() {
967+
private boolean removeTransportFromWidgetPager() {
971968
int page = getWidgetPosition(R.id.keyguard_transport_control);
972969
if (page != -1) {
973970
mAppWidgetContainer.removeWidget(mTransportControl);
@@ -976,8 +973,9 @@ private void removeTransportFromWidgetPager() {
976973
KeyguardHostView.this.addView(mTransportControl);
977974
mTransportControl.setVisibility(View.GONE);
978975
mViewStateManager.setTransportState(KeyguardViewStateManager.TRANSPORT_GONE);
979-
mTransportControl.post(mSwitchPageRunnable);
976+
return true;
980977
}
978+
return false;
981979
}
982980

983981
private void addTransportToWidgetPager() {
@@ -1006,8 +1004,9 @@ private void initializeTransportControl() {
10061004
mTransportControl.setKeyguardCallback(new TransportCallback() {
10071005
@Override
10081006
public void onListenerDetached() {
1009-
removeTransportFromWidgetPager();
1010-
mTransportControl.post(mSwitchPageRunnable);
1007+
if (removeTransportFromWidgetPager()) {
1008+
mTransportControl.post(mSwitchPageRunnable);
1009+
}
10111010
}
10121011

10131012
@Override
@@ -1183,7 +1182,6 @@ public SavedState[] newArray(int size) {
11831182
@Override
11841183
public Parcelable onSaveInstanceState() {
11851184
if (DEBUG) Log.d(TAG, "onSaveInstanceState");
1186-
saveStickyWidgetIndex();
11871185
Parcelable superState = super.onSaveInstanceState();
11881186
SavedState ss = new SavedState(superState);
11891187
ss.transportState = mViewStateManager.getTransportState();
@@ -1207,9 +1205,7 @@ public void onRestoreInstanceState(Parcelable state) {
12071205
public void onWindowFocusChanged(boolean hasWindowFocus) {
12081206
super.onWindowFocusChanged(hasWindowFocus);
12091207
if (DEBUG) Log.d(TAG, "Window is " + (hasWindowFocus ? "focused" : "unfocused"));
1210-
if (!hasWindowFocus) {
1211-
saveStickyWidgetIndex();
1212-
} else if (mShowSecurityWhenReturn) {
1208+
if (hasWindowFocus && mShowSecurityWhenReturn) {
12131209
SlidingChallengeLayout slider =
12141210
(SlidingChallengeLayout) findViewById(R.id.sliding_layout);
12151211
if (slider != null) {
@@ -1243,31 +1239,13 @@ private CameraWidgetFrame findCameraPage() {
12431239
return null;
12441240
}
12451241

1246-
private int getStickyWidget() {
1247-
// The first time we query the persistent state. From that point, we use a locally updated
1248-
// notion of the sticky widget page.
1249-
if (!mPersitentStickyWidgetLoaded) {
1250-
mLocalStickyWidget = mLockPatternUtils.getStickyAppWidgetIndex();
1251-
mPersitentStickyWidgetLoaded = true;
1252-
}
1253-
return mLocalStickyWidget;
1254-
}
1255-
1256-
public void updateStickyWidget(int index) {
1257-
if (index < 0 || index >= mAppWidgetContainer.getChildCount()) {
1258-
return;
1259-
}
1260-
if (mAppWidgetContainer.isAddPage(index)) {
1261-
return;
1262-
}
1263-
if (mAppWidgetContainer.isCameraPage(index)) {
1264-
return;
1265-
}
1266-
if (isMusicPage(index)) {
1267-
return;
1242+
private boolean isWidgetPage(int pageIndex) {
1243+
View v = mAppWidgetContainer.getChildAt(pageIndex);
1244+
if (v != null && v instanceof KeyguardWidgetFrame) {
1245+
KeyguardWidgetFrame kwf = (KeyguardWidgetFrame) v;
1246+
return kwf.getContentAppWidgetId() != AppWidgetManager.INVALID_APPWIDGET_ID;
12681247
}
1269-
1270-
mLocalStickyWidget = index;
1248+
return false;
12711249
}
12721250

12731251
boolean isMusicPage(int pageIndex) {
@@ -1276,23 +1254,23 @@ boolean isMusicPage(int pageIndex) {
12761254

12771255
private int getAppropriateWidgetPage(boolean isMusicPlaying) {
12781256
// assumes at least one widget (besides camera + add)
1279-
1257+
if (mAppWidgetToShow != AppWidgetManager.INVALID_APPWIDGET_ID) {
1258+
final int childCount = mAppWidgetContainer.getChildCount();
1259+
for (int i = 0; i < childCount; i++) {
1260+
if (mAppWidgetContainer.getWidgetPageAt(i).getContentAppWidgetId()
1261+
== mAppWidgetToShow) {
1262+
mAppWidgetToShow = AppWidgetManager.INVALID_APPWIDGET_ID;
1263+
return i;
1264+
}
1265+
}
1266+
mAppWidgetToShow = AppWidgetManager.INVALID_APPWIDGET_ID;
1267+
}
12801268
// if music playing, show transport
12811269
if (isMusicPlaying) {
12821270
if (DEBUG) Log.d(TAG, "Music playing, show transport");
12831271
return mAppWidgetContainer.getWidgetPageIndex(mTransportControl);
12841272
}
12851273

1286-
// if we have a valid sticky widget, show it
1287-
int stickyWidgetIndex = getStickyWidget();
1288-
if (stickyWidgetIndex > -1
1289-
&& stickyWidgetIndex < mAppWidgetContainer.getChildCount()
1290-
&& !mAppWidgetContainer.isAddPage(stickyWidgetIndex)
1291-
&& !mAppWidgetContainer.isCameraPage(stickyWidgetIndex)) {
1292-
if (DEBUG) Log.d(TAG, "Valid sticky widget found, show page " + stickyWidgetIndex);
1293-
return stickyWidgetIndex;
1294-
}
1295-
12961274
// else show the right-most widget (except for camera)
12971275
int rightMost = mAppWidgetContainer.getChildCount() - 1;
12981276
if (mAppWidgetContainer.isCameraPage(rightMost)) {
@@ -1302,13 +1280,6 @@ private int getAppropriateWidgetPage(boolean isMusicPlaying) {
13021280
return rightMost;
13031281
}
13041282

1305-
private void saveStickyWidgetIndex() {
1306-
if (DEBUG) Log.d(TAG, "saveStickyWidgetIndex: " + mLocalStickyWidget);
1307-
if (mPersitentStickyWidgetLoaded && mLocalStickyWidget >= 0) {
1308-
mLockPatternUtils.setStickyAppWidgetIndex(mLocalStickyWidget);
1309-
}
1310-
}
1311-
13121283
private void enableUserSelectorIfNecessary() {
13131284
if (!UserManager.supportsMultipleUsers()) {
13141285
return; // device doesn't support multi-user mode
@@ -1380,6 +1351,11 @@ public void goToUserSwitcher() {
13801351
mAppWidgetContainer.setCurrentPage(getWidgetPosition(R.id.keyguard_multi_user_selector));
13811352
}
13821353

1354+
public void goToWidget(int appWidgetId) {
1355+
mAppWidgetToShow = appWidgetId;
1356+
mSwitchPageRunnable.run();
1357+
}
1358+
13831359
public boolean handleMenuKey() {
13841360
// The following enables the MENU key to work for testing automation
13851361
if (shouldEnableMenuKey()) {

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import android.app.Activity;
2020
import android.app.ActivityManager;
21+
import android.appwidget.AppWidgetManager;
2122
import android.content.Context;
2223
import android.content.pm.ActivityInfo;
2324
import android.content.res.Configuration;
@@ -240,6 +241,11 @@ private void inflateKeyguardView(Bundle options) {
240241
if (options.getBoolean(LockPatternUtils.KEYGUARD_SHOW_SECURITY_CHALLENGE)) {
241242
mKeyguardView.showNextSecurityScreenIfPresent();
242243
}
244+
int widgetToShow = options.getInt(LockPatternUtils.KEYGUARD_SHOW_APPWIDGET,
245+
AppWidgetManager.INVALID_APPWIDGET_ID);
246+
if (widgetToShow != AppWidgetManager.INVALID_APPWIDGET_ID) {
247+
mKeyguardView.goToWidget(widgetToShow);
248+
}
243249
}
244250
}
245251

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,6 @@ public void onPageSwitched(View newPage, int newPageIndex) {
147147
// We only modify the page state if it is not currently under control by the slider.
148148
// This prevents conflicts.
149149

150-
if (mKeyguardHostView != null) {
151-
mKeyguardHostView.updateStickyWidget(newPageIndex);
152-
}
153-
154150
// If the page hasn't switched, don't bother with any of this
155151
if (mCurrentPage == newPageIndex) return;
156152

0 commit comments

Comments
 (0)