diff options
author | Kunhung Li <kunhungli@google.com> | 2019-06-19 15:32:20 +0800 |
---|---|---|
committer | Kunhung Li <kunhungli@google.com> | 2019-06-25 07:02:11 +0000 |
commit | dbf9ada7d8c0241e1eac6b5a1541b7e7ee82cc07 (patch) | |
tree | 7a92f9128ce76b7ae36a5cee13e6328dd87f287b | |
parent | 3978e487dc88a321138eb7c79d0fda891135c2a4 (diff) | |
download | android_packages_wallpapers_LivePicker-dbf9ada7d8c0241e1eac6b5a1541b7e7ee82cc07.tar.gz android_packages_wallpapers_LivePicker-dbf9ada7d8c0241e1eac6b5a1541b7e7ee82cc07.tar.bz2 android_packages_wallpapers_LivePicker-dbf9ada7d8c0241e1eac6b5a1541b7e7ee82cc07.zip |
Let wallpaper connection follow activity life cycle
For some case framework will relaunch all exist activities but preserve
their windows, and framework will also unbind all binding service during
relaunch. So for those service which used to draw things, a safer way
should let they followed activity's life cycle.
Bug: 133820924
Bug: 135098604
Test: Reproduce by description of the problem. Also test on rotate
device.
Change-Id: I2ee01575ec995f4b7ca86f44d64542994488d4ac
-rw-r--r-- | src/com/android/wallpaper/livepicker/LiveWallpaperPreview.java | 72 |
1 files changed, 34 insertions, 38 deletions
diff --git a/src/com/android/wallpaper/livepicker/LiveWallpaperPreview.java b/src/com/android/wallpaper/livepicker/LiveWallpaperPreview.java index 65e0e6c..fbae006 100644 --- a/src/com/android/wallpaper/livepicker/LiveWallpaperPreview.java +++ b/src/com/android/wallpaper/livepicker/LiveWallpaperPreview.java @@ -154,6 +154,13 @@ public class LiveWallpaperPreview extends Activity { mWallpaperManager = WallpaperManager.getInstance(this); mWallpaperConnection = new WallpaperConnection(mWallpaperIntent); + getWindow().getDecorView().post(new Runnable() { + public void run() { + if (!mWallpaperConnection.connect()) { + mWallpaperConnection = null; + } + } + }); if (!TextUtils.isEmpty(deleteAction)) { mDeleteIntent = new Intent(deleteAction); @@ -517,48 +524,17 @@ public class LiveWallpaperPreview extends Activity { @Override public void onResume() { super.onResume(); - if (mWallpaperConnection != null && mWallpaperConnection.mEngine != null) { - try { - mWallpaperConnection.mEngine.setVisibility(true); - } catch (RemoteException e) { - // Ignore - } + if (mWallpaperConnection != null) { + mWallpaperConnection.setVisibility(true); } } @Override public void onPause() { super.onPause(); - if (mWallpaperConnection != null && mWallpaperConnection.mEngine != null) { - try { - mWallpaperConnection.mEngine.setVisibility(false); - } catch (RemoteException e) { - // Ignore - } - } - } - - @Override - public void onAttachedToWindow() { - super.onAttachedToWindow(); - - getWindow().getDecorView().post(new Runnable() { - public void run() { - if (!mWallpaperConnection.connect()) { - mWallpaperConnection = null; - } - } - }); - } - - @Override - public void onDetachedFromWindow() { - super.onDetachedFromWindow(); - if (mWallpaperConnection != null) { - mWallpaperConnection.disconnect(); + mWallpaperConnection.setVisibility(false); } - mWallpaperConnection = null; } @Override @@ -567,6 +543,10 @@ public class LiveWallpaperPreview extends Activity { mLiveDataSettings.removeObserver(mSliceViewSettings); mLiveDataSettings = null; } + if (mWallpaperConnection != null) { + mWallpaperConnection.disconnect(); + } + mWallpaperConnection = null; super.onDestroy(); } @@ -610,6 +590,8 @@ public class LiveWallpaperPreview extends Activity { IWallpaperService mService; IWallpaperEngine mEngine; boolean mConnected; + boolean mIsVisible; + boolean mIsEngineVisible; WallpaperConnection(Intent intent) { mIntent = intent; @@ -675,10 +657,8 @@ public class LiveWallpaperPreview extends Activity { synchronized (this) { if (mConnected) { mEngine = engine; - try { - engine.setVisibility(true); - } catch (RemoteException e) { - // Ignore + if (mIsVisible) { + setEngineVisibility(true); } } else { try { @@ -712,6 +692,22 @@ public class LiveWallpaperPreview extends Activity { .withEndAction(() -> mLoading.setVisibility(View.INVISIBLE)); }); } + + public void setVisibility(boolean visible) { + mIsVisible = visible; + setEngineVisibility(visible); + } + + private void setEngineVisibility(boolean visible) { + if (mEngine != null && visible != mIsEngineVisible) { + try { + mEngine.setVisibility(visible); + mIsEngineVisible = visible; + } catch (RemoteException e) { + Log.w(LOG_TAG, "Failure setting wallpaper visibility ", e); + } + } + } } private static class WallpaperTargetAdapter extends ArrayAdapter<CharSequence> { |