Handling configuration changes at runtime instead of killing the process
Change-Id: I0c7f7e58ddb690f371c257b6142a4e918e9acb7f
diff --git a/src/com/android/launcher3/LauncherAppState.java b/src/com/android/launcher3/LauncherAppState.java
index 6bf5812..338c20b 100644
--- a/src/com/android/launcher3/LauncherAppState.java
+++ b/src/com/android/launcher3/LauncherAppState.java
@@ -17,6 +17,7 @@
package com.android.launcher3;
import static com.android.launcher3.util.SecureSettingsObserver.newNotificationSettingsObserver;
+import static com.android.launcher3.InvariantDeviceProfile.CHANGE_FLAG_ICON_SIZE;
import android.content.ComponentName;
import android.content.ContentProviderClient;
@@ -30,6 +31,7 @@
import com.android.launcher3.compat.UserManagerCompat;
import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.icons.IconCache;
+import com.android.launcher3.icons.LauncherIcons;
import com.android.launcher3.notification.NotificationListener;
import com.android.launcher3.util.MainThreadInitializedObject;
import com.android.launcher3.util.Preconditions;
@@ -94,6 +96,7 @@
mContext.registerReceiver(mModel, filter);
UserManagerCompat.getInstance(mContext).enableAndResetCache();
+ mInvariantDeviceProfile.addOnChangeListener(this::onIdpChanged);
if (!mContext.getResources().getBoolean(R.bool.notification_badging_enabled)) {
mNotificationBadgingObserver = null;
@@ -113,6 +116,19 @@
}
}
+ private void onIdpChanged(int changeFlags, InvariantDeviceProfile idp) {
+ if (changeFlags == 0) {
+ return;
+ }
+
+ if ((changeFlags & CHANGE_FLAG_ICON_SIZE) != 0) {
+ LauncherIcons.clearPool();
+ mIconCache.updateIconParams(idp.fillResIconDpi, idp.iconBitmapSize);
+ }
+
+ mModel.forceReload();
+ }
+
/**
* Call from Application.onTerminate(), which is not guaranteed to ever be called.
*/