3737import android .os .Parcel ;
3838import android .os .Parcelable ;
3939import android .os .SystemClock ;
40- import android .os .SystemProperties ;
41- import android .os .UserHandle ;
4240import android .os .UserManager ;
4341import android .util .AttributeSet ;
4442import 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 ()) {
0 commit comments