Daniel Sandler | cc8befa | 2013-06-11 14:45:48 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.launcher3; |
| 18 | |
kholoud mohamed | d5a4d60 | 2022-04-28 15:55:40 +0100 | [diff] [blame] | 19 | import static android.app.admin.DevicePolicyManager.ACTION_DEVICE_POLICY_RESOURCE_UPDATED; |
Sunny Goyal | b02dafc | 2023-06-22 11:17:29 -0700 | [diff] [blame] | 20 | import static android.content.Context.RECEIVER_EXPORTED; |
kholoud mohamed | d5a4d60 | 2022-04-28 15:55:40 +0100 | [diff] [blame] | 21 | |
fbaron | 9d08e0f | 2024-04-24 11:26:01 -0700 | [diff] [blame] | 22 | import static com.android.launcher3.Flags.enableSmartspaceRemovalToggle; |
Charlie Anderson | bad2be4 | 2024-12-06 16:32:03 -0500 | [diff] [blame] | 23 | import static com.android.launcher3.InvariantDeviceProfile.GRID_NAME_PREFS_KEY; |
| 24 | import static com.android.launcher3.LauncherPrefs.DB_FILE; |
| 25 | import static com.android.launcher3.LauncherPrefs.GRID_NAME; |
Stefan Andonian | d1b33b3 | 2022-12-16 21:22:27 +0000 | [diff] [blame] | 26 | import static com.android.launcher3.LauncherPrefs.ICON_STATE; |
| 27 | import static com.android.launcher3.LauncherPrefs.THEMED_ICONS; |
Charlie Anderson | bad2be4 | 2024-12-06 16:32:03 -0500 | [diff] [blame] | 28 | import static com.android.launcher3.model.DeviceGridState.KEY_DB_FILE; |
fbaron | c0e687b | 2023-10-04 12:11:20 -0700 | [diff] [blame] | 29 | import static com.android.launcher3.model.LoaderTask.SMARTSPACE_ON_HOME_SCREEN; |
Sunny Goyal | 045b4fa | 2019-09-20 12:51:37 -0700 | [diff] [blame] | 30 | import static com.android.launcher3.util.Executors.MODEL_EXECUTOR; |
Fengjiang Li | b87ad6f | 2024-07-09 10:15:43 -0700 | [diff] [blame] | 31 | import static com.android.launcher3.util.Executors.UI_HELPER_EXECUTOR; |
Jon Miranda | ec1277e | 2021-03-25 10:41:54 -0400 | [diff] [blame] | 32 | import static com.android.launcher3.util.SettingsCache.NOTIFICATION_BADGING_URI; |
Himanshu Gupta | 739b3c9 | 2023-11-06 17:47:29 +0000 | [diff] [blame] | 33 | import static com.android.launcher3.util.SettingsCache.PRIVATE_SPACE_HIDE_WHEN_LOCKED_URI; |
Sunny Goyal | d0e360a | 2018-06-29 14:40:18 -0700 | [diff] [blame] | 34 | |
Tony | d48710c | 2017-07-27 23:23:58 -0700 | [diff] [blame] | 35 | import android.content.ComponentName; |
Sunny Goyal | e755d46 | 2014-07-22 13:48:29 -0700 | [diff] [blame] | 36 | import android.content.Context; |
Sunny Goyal | 01c32a6 | 2021-05-17 13:23:08 -0700 | [diff] [blame] | 37 | import android.content.SharedPreferences; |
| 38 | import android.content.SharedPreferences.OnSharedPreferenceChangeListener; |
Sunny Goyal | e7b0012 | 2019-10-02 16:13:34 -0700 | [diff] [blame] | 39 | import android.content.pm.LauncherApps; |
Jakob Schneider | 94b5f17 | 2024-01-31 19:17:10 +0000 | [diff] [blame] | 40 | import android.content.pm.LauncherApps.ArchiveCompatibilityParams; |
Sunny Goyal | b47172b | 2021-05-03 19:59:51 -0700 | [diff] [blame] | 41 | import android.os.UserHandle; |
Daniel Sandler | b9eb286 | 2013-06-14 20:17:30 -0400 | [diff] [blame] | 42 | import android.util.Log; |
Sunny Goyal | 71b5c0b | 2015-01-08 16:59:04 -0800 | [diff] [blame] | 43 | |
Tracy Zhou | be13d10 | 2020-01-12 01:07:59 -0800 | [diff] [blame] | 44 | import androidx.annotation.Nullable; |
Anton Vayvod | ee38224 | 2024-05-28 21:26:25 -0400 | [diff] [blame] | 45 | import androidx.core.os.BuildCompat; |
Tracy Zhou | be13d10 | 2020-01-12 01:07:59 -0800 | [diff] [blame] | 46 | |
Sunny Goyal | b47172b | 2021-05-03 19:59:51 -0700 | [diff] [blame] | 47 | import com.android.launcher3.graphics.IconShape; |
Sunny Goyal | f840f10 | 2018-09-21 14:41:05 -0700 | [diff] [blame] | 48 | import com.android.launcher3.icons.IconCache; |
Sunny Goyal | 1416843 | 2019-10-24 15:59:49 -0700 | [diff] [blame] | 49 | import com.android.launcher3.icons.IconProvider; |
Sunny Goyal | 68af549 | 2021-12-24 01:08:31 +0530 | [diff] [blame] | 50 | import com.android.launcher3.icons.LauncherIconProvider; |
Sunny Goyal | 87dc48b | 2018-10-12 11:42:33 -0700 | [diff] [blame] | 51 | import com.android.launcher3.icons.LauncherIcons; |
Charlie Anderson | bad2be4 | 2024-12-06 16:32:03 -0500 | [diff] [blame] | 52 | import com.android.launcher3.logging.FileLog; |
Sunny Goyal | 6449a21 | 2024-01-12 09:40:43 -0800 | [diff] [blame] | 53 | import com.android.launcher3.model.ModelLauncherCallbacks; |
Shamali P | ea078cb | 2024-11-04 21:35:38 +0000 | [diff] [blame] | 54 | import com.android.launcher3.model.WidgetsFilterDataProvider; |
Tony | d48710c | 2017-07-27 23:23:58 -0700 | [diff] [blame] | 55 | import com.android.launcher3.notification.NotificationListener; |
Sunny Goyal | 73b5a27 | 2019-12-09 14:55:56 -0800 | [diff] [blame] | 56 | import com.android.launcher3.pm.InstallSessionHelper; |
Sunny Goyal | 045b4fa | 2019-09-20 12:51:37 -0700 | [diff] [blame] | 57 | import com.android.launcher3.pm.InstallSessionTracker; |
Sunny Goyal | 337c81f | 2019-12-10 12:19:13 -0800 | [diff] [blame] | 58 | import com.android.launcher3.pm.UserCache; |
Stefan Andonian | 5bd9a22 | 2023-02-23 00:58:33 +0000 | [diff] [blame] | 59 | import com.android.launcher3.util.LockedUserState; |
Sunny Goyal | d0e360a | 2018-06-29 14:40:18 -0700 | [diff] [blame] | 60 | import com.android.launcher3.util.MainThreadInitializedObject; |
Winson Chung | 94e8ad0 | 2024-05-08 21:14:57 +0000 | [diff] [blame] | 61 | import com.android.launcher3.util.PackageManagerHelper; |
Sunny Goyal | fdbef27 | 2017-02-01 12:52:54 -0800 | [diff] [blame] | 62 | import com.android.launcher3.util.Preconditions; |
Sunny Goyal | b47172b | 2021-05-03 19:59:51 -0700 | [diff] [blame] | 63 | import com.android.launcher3.util.RunnableList; |
Sunny Goyal | 1416843 | 2019-10-24 15:59:49 -0700 | [diff] [blame] | 64 | import com.android.launcher3.util.SafeCloseable; |
Jon Miranda | ec1277e | 2021-03-25 10:41:54 -0400 | [diff] [blame] | 65 | import com.android.launcher3.util.SettingsCache; |
Sunny Goyal | e7b0012 | 2019-10-02 16:13:34 -0700 | [diff] [blame] | 66 | import com.android.launcher3.util.SimpleBroadcastReceiver; |
Sunny Goyal | 01c32a6 | 2021-05-17 13:23:08 -0700 | [diff] [blame] | 67 | import com.android.launcher3.util.Themes; |
Sunny Goyal | 31e27ed | 2024-01-09 15:45:14 -0800 | [diff] [blame] | 68 | import com.android.launcher3.util.TraceHelper; |
Pinyao Ting | c7a6c29 | 2019-08-26 14:36:02 -0700 | [diff] [blame] | 69 | import com.android.launcher3.widget.custom.CustomWidgetManager; |
Sunny Goyal | 71b5c0b | 2015-01-08 16:59:04 -0800 | [diff] [blame] | 70 | |
Sunny Goyal | 777d490 | 2021-08-27 21:22:17 +0000 | [diff] [blame] | 71 | public class LauncherAppState implements SafeCloseable { |
Chris Wren | aeff7ea | 2014-02-14 16:59:24 -0500 | [diff] [blame] | 72 | |
Charlie Anderson | bad2be4 | 2024-12-06 16:32:03 -0500 | [diff] [blame] | 73 | public static final String TAG = "LauncherAppState"; |
Sunny Goyal | 29947f0 | 2017-12-18 13:49:44 -0800 | [diff] [blame] | 74 | public static final String ACTION_FORCE_ROLOAD = "force-reload-launcher"; |
| 75 | |
Sunny Goyal | fdbef27 | 2017-02-01 12:52:54 -0800 | [diff] [blame] | 76 | // We do not need any synchronization for this variable as its only written on UI thread. |
Sunny Goyal | cf845f0 | 2019-09-25 09:08:16 -0700 | [diff] [blame] | 77 | public static final MainThreadInitializedObject<LauncherAppState> INSTANCE = |
Sunny Goyal | e529a86 | 2019-08-06 09:48:36 -0700 | [diff] [blame] | 78 | new MainThreadInitializedObject<>(LauncherAppState::new); |
Daniel Sandler | cc8befa | 2013-06-11 14:45:48 -0400 | [diff] [blame] | 79 | |
Sunny Goyal | fdbef27 | 2017-02-01 12:52:54 -0800 | [diff] [blame] | 80 | private final Context mContext; |
| 81 | private final LauncherModel mModel; |
Sunny Goyal | 68af549 | 2021-12-24 01:08:31 +0530 | [diff] [blame] | 82 | private final LauncherIconProvider mIconProvider; |
Sunny Goyal | fdbef27 | 2017-02-01 12:52:54 -0800 | [diff] [blame] | 83 | private final IconCache mIconCache; |
Sunny Goyal | fdbef27 | 2017-02-01 12:52:54 -0800 | [diff] [blame] | 84 | private final InvariantDeviceProfile mInvariantDeviceProfile; |
Sunny Goyal | 31e27ed | 2024-01-09 15:45:14 -0800 | [diff] [blame] | 85 | private boolean mIsSafeModeEnabled; |
| 86 | |
Sunny Goyal | b47172b | 2021-05-03 19:59:51 -0700 | [diff] [blame] | 87 | private final RunnableList mOnTerminateCallback = new RunnableList(); |
Sunny Goyal | 045b4fa | 2019-09-20 12:51:37 -0700 | [diff] [blame] | 88 | |
Sunny Goyal | 10fa016 | 2024-04-21 00:13:35 -0700 | [diff] [blame] | 89 | public static LauncherAppState getInstance(Context context) { |
Sunny Goyal | d0e360a | 2018-06-29 14:40:18 -0700 | [diff] [blame] | 90 | return INSTANCE.get(context); |
Daniel Sandler | cc8befa | 2013-06-11 14:45:48 -0400 | [diff] [blame] | 91 | } |
| 92 | |
Daniel Sandler | cc8befa | 2013-06-11 14:45:48 -0400 | [diff] [blame] | 93 | public Context getContext() { |
Sunny Goyal | fdbef27 | 2017-02-01 12:52:54 -0800 | [diff] [blame] | 94 | return mContext; |
Daniel Sandler | cc8befa | 2013-06-11 14:45:48 -0400 | [diff] [blame] | 95 | } |
| 96 | |
Jakob Schneider | 2f609d0 | 2024-01-10 18:03:35 +0000 | [diff] [blame] | 97 | @SuppressWarnings("NewApi") |
Tracy Zhou | be13d10 | 2020-01-12 01:07:59 -0800 | [diff] [blame] | 98 | public LauncherAppState(Context context) { |
| 99 | this(context, LauncherFiles.APP_ICONS_DB); |
Sunny Goyal | df4241c | 2021-05-19 19:42:14 -0700 | [diff] [blame] | 100 | Log.v(Launcher.TAG, "LauncherAppState initiated"); |
| 101 | Preconditions.assertUIThread(); |
Sunny Goyal | 2759579 | 2015-03-19 13:18:44 -0700 | [diff] [blame] | 102 | |
Sunny Goyal | 31e27ed | 2024-01-09 15:45:14 -0800 | [diff] [blame] | 103 | mIsSafeModeEnabled = TraceHelper.allowIpcs("isSafeMode", |
| 104 | () -> context.getPackageManager().isSafeMode()); |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 105 | mInvariantDeviceProfile.addOnChangeListener(modelPropertiesChanged -> { |
| 106 | if (modelPropertiesChanged) { |
| 107 | refreshAndReloadLauncher(); |
| 108 | } |
| 109 | }); |
Daniel Sandler | cc8befa | 2013-06-11 14:45:48 -0400 | [diff] [blame] | 110 | |
Sunny Goyal | 6449a21 | 2024-01-12 09:40:43 -0800 | [diff] [blame] | 111 | ModelLauncherCallbacks callbacks = mModel.newModelCallbacks(); |
Jakob Schneider | 2f609d0 | 2024-01-10 18:03:35 +0000 | [diff] [blame] | 112 | LauncherApps launcherApps = mContext.getSystemService(LauncherApps.class); |
| 113 | launcherApps.registerCallback(callbacks); |
Sunny Goyal | e274d97 | 2023-05-01 16:55:59 -0700 | [diff] [blame] | 114 | mOnTerminateCallback.add(() -> |
Sunny Goyal | 6449a21 | 2024-01-12 09:40:43 -0800 | [diff] [blame] | 115 | mContext.getSystemService(LauncherApps.class).unregisterCallback(callbacks)); |
Jakob Schneider | 328c322 | 2024-02-01 15:39:11 +0000 | [diff] [blame] | 116 | |
Anton Vayvod | ee38224 | 2024-05-28 21:26:25 -0400 | [diff] [blame] | 117 | if (BuildCompat.isAtLeastV() && Flags.enableSupportForArchiving()) { |
Jakob Schneider | 94b5f17 | 2024-01-31 19:17:10 +0000 | [diff] [blame] | 118 | ArchiveCompatibilityParams params = new ArchiveCompatibilityParams(); |
| 119 | params.setEnableUnarchivalConfirmation(false); |
Charlie Anderson | 6b8e362 | 2024-08-01 15:19:27 -0400 | [diff] [blame] | 120 | params.setEnableIconOverlay(!Flags.useNewIconForArchivedApps()); |
Jakob Schneider | 94b5f17 | 2024-01-31 19:17:10 +0000 | [diff] [blame] | 121 | launcherApps.setArchiveCompatibility(params); |
Jakob Schneider | 2f609d0 | 2024-01-10 18:03:35 +0000 | [diff] [blame] | 122 | } |
Sunny Goyal | b47172b | 2021-05-03 19:59:51 -0700 | [diff] [blame] | 123 | |
| 124 | SimpleBroadcastReceiver modelChangeReceiver = |
Fengjiang Li | b87ad6f | 2024-07-09 10:15:43 -0700 | [diff] [blame] | 125 | new SimpleBroadcastReceiver(UI_HELPER_EXECUTOR, mModel::onBroadcastIntent); |
Fengjiang Li | b87ad6f | 2024-07-09 10:15:43 -0700 | [diff] [blame] | 126 | modelChangeReceiver.register( |
| 127 | mContext, |
kholoud mohamed | d5a4d60 | 2022-04-28 15:55:40 +0100 | [diff] [blame] | 128 | ACTION_DEVICE_POLICY_RESOURCE_UPDATED); |
Sunny Goyal | b02dafc | 2023-06-22 11:17:29 -0700 | [diff] [blame] | 129 | if (BuildConfig.IS_STUDIO_BUILD) { |
Sunny Goyal | e79d453 | 2024-12-31 00:10:20 -0800 | [diff] [blame] | 130 | modelChangeReceiver.register(mContext, RECEIVER_EXPORTED, ACTION_FORCE_ROLOAD); |
Sunny Goyal | 29947f0 | 2017-12-18 13:49:44 -0800 | [diff] [blame] | 131 | } |
Fengjiang Li | b87ad6f | 2024-07-09 10:15:43 -0700 | [diff] [blame] | 132 | mOnTerminateCallback.add(() -> modelChangeReceiver.unregisterReceiverSafely(mContext)); |
Sunny Goyal | 1416843 | 2019-10-24 15:59:49 -0700 | [diff] [blame] | 133 | |
Sunny Goyal | b47172b | 2021-05-03 19:59:51 -0700 | [diff] [blame] | 134 | SafeCloseable userChangeListener = UserCache.INSTANCE.get(mContext) |
Sunny Goyal | c80e60d | 2023-06-07 12:52:30 -0700 | [diff] [blame] | 135 | .addUserEventListener(mModel::onUserEvent); |
Sunny Goyal | b47172b | 2021-05-03 19:59:51 -0700 | [diff] [blame] | 136 | mOnTerminateCallback.add(userChangeListener::close); |
Sunny Goyal | 337c81f | 2019-12-10 12:19:13 -0800 | [diff] [blame] | 137 | |
fbaron | 9d08e0f | 2024-04-24 11:26:01 -0700 | [diff] [blame] | 138 | if (enableSmartspaceRemovalToggle()) { |
fbaron | c0e687b | 2023-10-04 12:11:20 -0700 | [diff] [blame] | 139 | OnSharedPreferenceChangeListener firstPagePinnedItemListener = |
| 140 | new OnSharedPreferenceChangeListener() { |
| 141 | @Override |
| 142 | public void onSharedPreferenceChanged( |
| 143 | SharedPreferences sharedPreferences, String key) { |
| 144 | if (SMARTSPACE_ON_HOME_SCREEN.equals(key)) { |
| 145 | mModel.forceReload(); |
| 146 | } |
| 147 | } |
| 148 | }; |
| 149 | LauncherPrefs.getPrefs(mContext).registerOnSharedPreferenceChangeListener( |
| 150 | firstPagePinnedItemListener); |
| 151 | mOnTerminateCallback.add(() -> LauncherPrefs.getPrefs(mContext) |
| 152 | .unregisterOnSharedPreferenceChangeListener(firstPagePinnedItemListener)); |
| 153 | } |
| 154 | |
Stefan Andonian | 5bd9a22 | 2023-02-23 00:58:33 +0000 | [diff] [blame] | 155 | LockedUserState.get(context).runOnUserUnlocked(() -> { |
Sunny Goyal | e274d97 | 2023-05-01 16:55:59 -0700 | [diff] [blame] | 156 | CustomWidgetManager cwm = CustomWidgetManager.INSTANCE.get(mContext); |
Sunny Goyal | 6bbd805 | 2024-10-24 12:38:33 -0700 | [diff] [blame] | 157 | mOnTerminateCallback.add(cwm.addWidgetRefreshCallback(mModel::rebindCallbacks)::close); |
Tony Wickham | 827cef2 | 2016-03-17 15:39:39 -0700 | [diff] [blame] | 158 | |
Stefan Andonian | 5bd9a22 | 2023-02-23 00:58:33 +0000 | [diff] [blame] | 159 | IconObserver observer = new IconObserver(); |
| 160 | SafeCloseable iconChangeTracker = mIconProvider.registerIconChangeListener( |
| 161 | observer, MODEL_EXECUTOR.getHandler()); |
| 162 | mOnTerminateCallback.add(iconChangeTracker::close); |
| 163 | MODEL_EXECUTOR.execute(observer::verifyIconChanged); |
| 164 | LauncherPrefs.get(context).addListener(observer, THEMED_ICONS); |
| 165 | mOnTerminateCallback.add( |
| 166 | () -> LauncherPrefs.get(mContext).removeListener(observer, THEMED_ICONS)); |
| 167 | |
| 168 | InstallSessionTracker installSessionTracker = |
Sunny Goyal | c363295 | 2024-10-09 15:15:42 -0700 | [diff] [blame] | 169 | InstallSessionHelper.INSTANCE.get(context).registerInstallTracker(callbacks); |
Stefan Andonian | 5bd9a22 | 2023-02-23 00:58:33 +0000 | [diff] [blame] | 170 | mOnTerminateCallback.add(installSessionTracker::unregister); |
| 171 | }); |
Sunny Goyal | 045b4fa | 2019-09-20 12:51:37 -0700 | [diff] [blame] | 172 | |
Sunny Goyal | eaf7a95 | 2020-07-29 16:54:20 -0700 | [diff] [blame] | 173 | // Register an observer to rebind the notification listener when dots are re-enabled. |
Sunny Goyal | b47172b | 2021-05-03 19:59:51 -0700 | [diff] [blame] | 174 | SettingsCache settingsCache = SettingsCache.INSTANCE.get(mContext); |
| 175 | SettingsCache.OnChangeListener notificationLister = this::onNotificationSettingsChanged; |
| 176 | settingsCache.register(NOTIFICATION_BADGING_URI, notificationLister); |
| 177 | onNotificationSettingsChanged(settingsCache.getValue(NOTIFICATION_BADGING_URI)); |
| 178 | mOnTerminateCallback.add(() -> |
| 179 | settingsCache.unregister(NOTIFICATION_BADGING_URI, notificationLister)); |
Himanshu Gupta | 739b3c9 | 2023-11-06 17:47:29 +0000 | [diff] [blame] | 180 | // Register an observer to notify Launcher about Private Space settings toggle. |
Pechetty Sravani (xWF) | 41743bd | 2024-11-14 06:11:08 +0000 | [diff] [blame] | 181 | registerPrivateSpaceHideWhenLockListener(settingsCache); |
Sunny Goyal | 420d545 | 2018-10-17 10:25:14 -0700 | [diff] [blame] | 182 | } |
| 183 | |
Tracy Zhou | be13d10 | 2020-01-12 01:07:59 -0800 | [diff] [blame] | 184 | public LauncherAppState(Context context, @Nullable String iconCacheFileName) { |
Tracy Zhou | be13d10 | 2020-01-12 01:07:59 -0800 | [diff] [blame] | 185 | mContext = context; |
| 186 | |
| 187 | mInvariantDeviceProfile = InvariantDeviceProfile.INSTANCE.get(context); |
Sunny Goyal | 68af549 | 2021-12-24 01:08:31 +0530 | [diff] [blame] | 188 | mIconProvider = new LauncherIconProvider(context); |
Sunny Goyal | b47172b | 2021-05-03 19:59:51 -0700 | [diff] [blame] | 189 | mIconCache = new IconCache(mContext, mInvariantDeviceProfile, |
| 190 | iconCacheFileName, mIconProvider); |
Shamali P | ea078cb | 2024-11-04 21:35:38 +0000 | [diff] [blame] | 191 | mModel = new LauncherModel(context, this, mIconCache, |
| 192 | WidgetsFilterDataProvider.Companion.newInstance(context), new AppFilter(mContext), |
Winson Chung | 94e8ad0 | 2024-05-08 21:14:57 +0000 | [diff] [blame] | 193 | PackageManagerHelper.INSTANCE.get(context), iconCacheFileName != null); |
Sunny Goyal | df4241c | 2021-05-19 19:42:14 -0700 | [diff] [blame] | 194 | mOnTerminateCallback.add(mIconCache::close); |
Sunny Goyal | e274d97 | 2023-05-01 16:55:59 -0700 | [diff] [blame] | 195 | mOnTerminateCallback.add(mModel::destroy); |
Tracy Zhou | be13d10 | 2020-01-12 01:07:59 -0800 | [diff] [blame] | 196 | } |
| 197 | |
Sunny Goyal | b47172b | 2021-05-03 19:59:51 -0700 | [diff] [blame] | 198 | private void onNotificationSettingsChanged(boolean areNotificationDotsEnabled) { |
Tony Wickham | f34bee8 | 2018-12-03 18:11:39 -0800 | [diff] [blame] | 199 | if (areNotificationDotsEnabled) { |
Sunny Goyal | 420d545 | 2018-10-17 10:25:14 -0700 | [diff] [blame] | 200 | NotificationListener.requestRebind(new ComponentName( |
| 201 | mContext, NotificationListener.class)); |
Tony | d48710c | 2017-07-27 23:23:58 -0700 | [diff] [blame] | 202 | } |
Daniel Sandler | cc8befa | 2013-06-11 14:45:48 -0400 | [diff] [blame] | 203 | } |
Kenny Guy | 1317e2d | 2014-05-08 18:52:50 +0100 | [diff] [blame] | 204 | |
Himanshu Gupta | 739b3c9 | 2023-11-06 17:47:29 +0000 | [diff] [blame] | 205 | private void registerPrivateSpaceHideWhenLockListener(SettingsCache settingsCache) { |
| 206 | SettingsCache.OnChangeListener psHideWhenLockChangedListener = |
| 207 | this::onPrivateSpaceHideWhenLockChanged; |
| 208 | settingsCache.register(PRIVATE_SPACE_HIDE_WHEN_LOCKED_URI, psHideWhenLockChangedListener); |
| 209 | mOnTerminateCallback.add(() -> settingsCache.unregister(PRIVATE_SPACE_HIDE_WHEN_LOCKED_URI, |
| 210 | psHideWhenLockChangedListener)); |
| 211 | } |
| 212 | |
| 213 | private void onPrivateSpaceHideWhenLockChanged(boolean isPrivateSpaceHideOnLockEnabled) { |
| 214 | mModel.forceReload(); |
| 215 | } |
| 216 | |
Sunny Goyal | b47172b | 2021-05-03 19:59:51 -0700 | [diff] [blame] | 217 | private void refreshAndReloadLauncher() { |
Sunny Goyal | bf3efe8 | 2024-05-07 10:19:57 -0700 | [diff] [blame] | 218 | LauncherIcons.clearPool(mContext); |
Sunny Goyal | b47172b | 2021-05-03 19:59:51 -0700 | [diff] [blame] | 219 | mIconCache.updateIconParams( |
| 220 | mInvariantDeviceProfile.fillResIconDpi, mInvariantDeviceProfile.iconBitmapSize); |
Sunny Goyal | 87dc48b | 2018-10-12 11:42:33 -0700 | [diff] [blame] | 221 | mModel.forceReload(); |
| 222 | } |
| 223 | |
Daniel Sandler | cc8befa | 2013-06-11 14:45:48 -0400 | [diff] [blame] | 224 | /** |
| 225 | * Call from Application.onTerminate(), which is not guaranteed to ever be called. |
| 226 | */ |
Sunny Goyal | 777d490 | 2021-08-27 21:22:17 +0000 | [diff] [blame] | 227 | @Override |
| 228 | public void close() { |
Sunny Goyal | b47172b | 2021-05-03 19:59:51 -0700 | [diff] [blame] | 229 | mOnTerminateCallback.executeAllAndDestroy(); |
| 230 | } |
Sunny Goyal | 01615a6 | 2019-09-20 12:00:07 -0700 | [diff] [blame] | 231 | |
Sunny Goyal | b47172b | 2021-05-03 19:59:51 -0700 | [diff] [blame] | 232 | public IconProvider getIconProvider() { |
| 233 | return mIconProvider; |
Daniel Sandler | cc8befa | 2013-06-11 14:45:48 -0400 | [diff] [blame] | 234 | } |
| 235 | |
Sunny Goyal | 3494262 | 2014-08-29 17:20:55 -0700 | [diff] [blame] | 236 | public IconCache getIconCache() { |
Daniel Sandler | cc8befa | 2013-06-11 14:45:48 -0400 | [diff] [blame] | 237 | return mIconCache; |
| 238 | } |
| 239 | |
Sunny Goyal | 18bf8e2 | 2015-04-08 18:13:46 -0700 | [diff] [blame] | 240 | public LauncherModel getModel() { |
Daniel Sandler | cc8befa | 2013-06-11 14:45:48 -0400 | [diff] [blame] | 241 | return mModel; |
| 242 | } |
| 243 | |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 244 | public InvariantDeviceProfile getInvariantDeviceProfile() { |
| 245 | return mInvariantDeviceProfile; |
| 246 | } |
Sunny Goyal | 87f784c | 2017-01-11 10:48:34 -0800 | [diff] [blame] | 247 | |
Sunny Goyal | 31e27ed | 2024-01-09 15:45:14 -0800 | [diff] [blame] | 248 | public boolean isSafeModeEnabled() { |
| 249 | return mIsSafeModeEnabled; |
| 250 | } |
| 251 | |
Sunny Goyal | 87f784c | 2017-01-11 10:48:34 -0800 | [diff] [blame] | 252 | /** |
| 253 | * Shorthand for {@link #getInvariantDeviceProfile()} |
| 254 | */ |
| 255 | public static InvariantDeviceProfile getIDP(Context context) { |
Sunny Goyal | d0e360a | 2018-06-29 14:40:18 -0700 | [diff] [blame] | 256 | return InvariantDeviceProfile.INSTANCE.get(context); |
Sunny Goyal | 87f784c | 2017-01-11 10:48:34 -0800 | [diff] [blame] | 257 | } |
Sunny Goyal | b47172b | 2021-05-03 19:59:51 -0700 | [diff] [blame] | 258 | |
Sunny Goyal | 01c32a6 | 2021-05-17 13:23:08 -0700 | [diff] [blame] | 259 | private class IconObserver |
Brian Isganitis | 9cbc478 | 2024-10-08 14:47:17 -0400 | [diff] [blame] | 260 | implements IconProvider.IconChangeListener, LauncherPrefChangeListener { |
Sunny Goyal | b47172b | 2021-05-03 19:59:51 -0700 | [diff] [blame] | 261 | |
| 262 | @Override |
| 263 | public void onAppIconChanged(String packageName, UserHandle user) { |
| 264 | mModel.onAppIconChanged(packageName, user); |
| 265 | } |
| 266 | |
| 267 | @Override |
| 268 | public void onSystemIconStateChanged(String iconState) { |
Sunny Goyal | 638a687 | 2024-04-25 15:55:11 -0700 | [diff] [blame] | 269 | IconShape.INSTANCE.get(mContext).pickBestShape(mContext); |
Sunny Goyal | b47172b | 2021-05-03 19:59:51 -0700 | [diff] [blame] | 270 | refreshAndReloadLauncher(); |
Stefan Andonian | d1b33b3 | 2022-12-16 21:22:27 +0000 | [diff] [blame] | 271 | LauncherPrefs.get(mContext).put(ICON_STATE, iconState); |
Sunny Goyal | b47172b | 2021-05-03 19:59:51 -0700 | [diff] [blame] | 272 | } |
| 273 | |
| 274 | void verifyIconChanged() { |
| 275 | String iconState = mIconProvider.getSystemIconState(); |
Stefan Andonian | d1b33b3 | 2022-12-16 21:22:27 +0000 | [diff] [blame] | 276 | if (!iconState.equals(LauncherPrefs.get(mContext).get(ICON_STATE))) { |
Sunny Goyal | b47172b | 2021-05-03 19:59:51 -0700 | [diff] [blame] | 277 | onSystemIconStateChanged(iconState); |
| 278 | } |
| 279 | } |
Sunny Goyal | 01c32a6 | 2021-05-17 13:23:08 -0700 | [diff] [blame] | 280 | |
| 281 | @Override |
Brian Isganitis | 9cbc478 | 2024-10-08 14:47:17 -0400 | [diff] [blame] | 282 | public void onPrefChanged(String key) { |
Sunny Goyal | 01c32a6 | 2021-05-17 13:23:08 -0700 | [diff] [blame] | 283 | if (Themes.KEY_THEMED_ICONS.equals(key)) { |
| 284 | mIconProvider.setIconThemeSupported(Themes.isThemedIconEnabled(mContext)); |
| 285 | verifyIconChanged(); |
Charlie Anderson | bad2be4 | 2024-12-06 16:32:03 -0500 | [diff] [blame] | 286 | } else if (GRID_NAME_PREFS_KEY.equals(key)) { |
| 287 | FileLog.d(TAG, "onPrefChanged GRID_NAME changed: " |
| 288 | + LauncherPrefs.get(mContext).get(GRID_NAME)); |
| 289 | } else if (KEY_DB_FILE.equals(key)) { |
| 290 | FileLog.d(TAG, "onPrefChanged DB_FILE changed: " |
| 291 | + LauncherPrefs.get(mContext).get(DB_FILE)); |
Sunny Goyal | 01c32a6 | 2021-05-17 13:23:08 -0700 | [diff] [blame] | 292 | } |
| 293 | } |
Sunny Goyal | b47172b | 2021-05-03 19:59:51 -0700 | [diff] [blame] | 294 | } |
Daniel Sandler | cc8befa | 2013-06-11 14:45:48 -0400 | [diff] [blame] | 295 | } |