Fixing potential ANR when fetching for wallpaper info

Bug: 214581894
Test: Manual
Change-Id: I616b34b0ce6c96ed360073b2e8ff4eed81190add
This commit is contained in:
Sunny Goyal
2022-04-11 13:20:34 -07:00
parent 9ef75227c0
commit ba7cf0dc7d
@@ -14,6 +14,8 @@ import android.os.SystemClock;
import android.util.Log;
import android.view.animation.Interpolator;
import androidx.annotation.AnyThread;
import com.android.launcher3.Utilities;
import com.android.launcher3.Workspace;
import com.android.launcher3.anim.Interpolators;
@@ -182,6 +184,7 @@ public class WallpaperOffsetInterpolator extends BroadcastReceiver {
}
}
@AnyThread
private void updateOffset() {
Message.obtain(mHandler, MSG_SET_NUM_PARALLAX, getNumPagesForWallpaperParallax(), 0,
mWindowToken).sendToTarget();
@@ -206,9 +209,12 @@ public class WallpaperOffsetInterpolator extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
mWallpaperIsLiveWallpaper =
WallpaperManager.getInstance(mWorkspace.getContext()).getWallpaperInfo() != null;
updateOffset();
UI_HELPER_EXECUTOR.execute(() -> {
// Updating the boolean on a background thread is fine as the assignments are atomic
mWallpaperIsLiveWallpaper =
WallpaperManager.getInstance(context).getWallpaperInfo() != null;
updateOffset();
});
}
private static final int MSG_START_ANIMATION = 1;