Sunny Goyal | 2783595 | 2017-01-13 12:15:53 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 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 | |
Mike Schneider | a79d460 | 2023-03-03 15:58:06 +0100 | [diff] [blame] | 19 | import static com.android.launcher3.util.FlagDebugUtils.appendFlag; |
| 20 | import static com.android.launcher3.util.FlagDebugUtils.formatFlagChange; |
Tony Wickham | b482188 | 2021-04-23 14:26:45 -0700 | [diff] [blame] | 21 | import static com.android.launcher3.util.SystemUiController.UI_STATE_FULLSCREEN_TASK; |
Sunny Goyal | 8c48d8b | 2019-01-25 15:10:18 -0800 | [diff] [blame] | 22 | |
Sunny Goyal | 7eff40f | 2018-04-11 15:30:46 -0700 | [diff] [blame] | 23 | import static java.lang.annotation.RetentionPolicy.SOURCE; |
| 24 | |
Sunny Goyal | 2783595 | 2017-01-13 12:15:53 -0800 | [diff] [blame] | 25 | import android.app.Activity; |
| 26 | import android.content.Context; |
| 27 | import android.content.ContextWrapper; |
Sunny Goyal | 64a75aa | 2017-07-03 13:50:52 -0700 | [diff] [blame] | 28 | import android.content.Intent; |
Winson Chung | 1a77c3d | 2018-04-11 12:47:47 -0700 | [diff] [blame] | 29 | import android.content.res.Configuration; |
Yein Jo | 18446d0 | 2022-09-19 22:18:09 +0000 | [diff] [blame] | 30 | import android.os.Bundle; |
Mike Schneider | a79d460 | 2023-03-03 15:58:06 +0100 | [diff] [blame] | 31 | import android.util.Log; |
Jon Miranda | cb58259 | 2023-04-19 15:40:04 -0700 | [diff] [blame^] | 32 | import android.view.View; |
Yein Jo | 18446d0 | 2022-09-19 22:18:09 +0000 | [diff] [blame] | 33 | import android.window.OnBackInvokedDispatcher; |
Sunny Goyal | 2783595 | 2017-01-13 12:15:53 -0800 | [diff] [blame] | 34 | |
Winson Chung | ef52876 | 2019-09-06 12:05:52 -0700 | [diff] [blame] | 35 | import androidx.annotation.IntDef; |
| 36 | |
Sunny Goyal | fde5505 | 2018-02-01 14:46:13 -0800 | [diff] [blame] | 37 | import com.android.launcher3.DeviceProfile.OnDeviceProfileChangeListener; |
Hyunyoung Song | fc00747 | 2018-10-25 14:09:50 -0700 | [diff] [blame] | 38 | import com.android.launcher3.logging.StatsLogManager; |
Yein Jo | 18446d0 | 2022-09-19 22:18:09 +0000 | [diff] [blame] | 39 | import com.android.launcher3.testing.TestLogging; |
| 40 | import com.android.launcher3.testing.shared.TestProtocol; |
Sunny Goyal | 8392c82 | 2017-06-20 10:03:56 -0700 | [diff] [blame] | 41 | import com.android.launcher3.util.SystemUiController; |
Sunny Goyal | 5686333 | 2019-05-22 14:13:53 -0700 | [diff] [blame] | 42 | import com.android.launcher3.util.ViewCache; |
Sunny Goyal | 54fa110 | 2022-12-07 22:48:37 -0800 | [diff] [blame] | 43 | import com.android.launcher3.views.ActivityContext; |
Tony Wickham | b482188 | 2021-04-23 14:26:45 -0700 | [diff] [blame] | 44 | import com.android.launcher3.views.ScrimView; |
Sunny Goyal | a535ae4 | 2017-02-27 10:07:13 -0800 | [diff] [blame] | 45 | |
Sunny Goyal | e43d00d | 2018-05-14 14:23:18 -0700 | [diff] [blame] | 46 | import java.io.PrintWriter; |
Sunny Goyal | 7eff40f | 2018-04-11 15:30:46 -0700 | [diff] [blame] | 47 | import java.lang.annotation.Retention; |
Sunny Goyal | fde5505 | 2018-02-01 14:46:13 -0800 | [diff] [blame] | 48 | import java.util.ArrayList; |
Brian Isganitis | 099945b | 2022-01-31 18:15:00 -0500 | [diff] [blame] | 49 | import java.util.List; |
Mike Schneider | a79d460 | 2023-03-03 15:58:06 +0100 | [diff] [blame] | 50 | import java.util.StringJoiner; |
Sunny Goyal | fde5505 | 2018-02-01 14:46:13 -0800 | [diff] [blame] | 51 | |
Samuel Fufa | a579ddc | 2020-02-27 16:59:19 -0800 | [diff] [blame] | 52 | /** |
| 53 | * Launcher BaseActivity |
| 54 | */ |
Sunny Goyal | 54fa110 | 2022-12-07 22:48:37 -0800 | [diff] [blame] | 55 | public abstract class BaseActivity extends Activity implements ActivityContext { |
Sunny Goyal | 2783595 | 2017-01-13 12:15:53 -0800 | [diff] [blame] | 56 | |
Sunny Goyal | fa39536 | 2019-12-11 10:00:47 -0800 | [diff] [blame] | 57 | private static final String TAG = "BaseActivity"; |
Mike Schneider | a79d460 | 2023-03-03 15:58:06 +0100 | [diff] [blame] | 58 | static final boolean DEBUG = false; |
Sunny Goyal | fa39536 | 2019-12-11 10:00:47 -0800 | [diff] [blame] | 59 | |
Sunny Goyal | 7eff40f | 2018-04-11 15:30:46 -0700 | [diff] [blame] | 60 | public static final int INVISIBLE_BY_STATE_HANDLER = 1 << 0; |
| 61 | public static final int INVISIBLE_BY_APP_TRANSITIONS = 1 << 1; |
Sunny Goyal | 1c63c72 | 2018-06-05 16:00:34 -0700 | [diff] [blame] | 62 | public static final int INVISIBLE_BY_PENDING_FLAGS = 1 << 2; |
| 63 | |
| 64 | // This is not treated as invisibility flag, but adds as a hint for an incomplete transition. |
| 65 | // When the wallpaper animation runs, it replaces this flag with a proper invisibility |
| 66 | // flag, INVISIBLE_BY_PENDING_FLAGS only for the duration of that animation. |
| 67 | public static final int PENDING_INVISIBLE_BY_WALLPAPER_ANIMATION = 1 << 3; |
| 68 | |
| 69 | private static final int INVISIBLE_FLAGS = |
| 70 | INVISIBLE_BY_STATE_HANDLER | INVISIBLE_BY_APP_TRANSITIONS | INVISIBLE_BY_PENDING_FLAGS; |
| 71 | public static final int STATE_HANDLER_INVISIBILITY_FLAGS = |
| 72 | INVISIBLE_BY_STATE_HANDLER | PENDING_INVISIBLE_BY_WALLPAPER_ANIMATION; |
Sunny Goyal | 7eff40f | 2018-04-11 15:30:46 -0700 | [diff] [blame] | 73 | public static final int INVISIBLE_ALL = |
Sunny Goyal | 1c63c72 | 2018-06-05 16:00:34 -0700 | [diff] [blame] | 74 | INVISIBLE_FLAGS | PENDING_INVISIBLE_BY_WALLPAPER_ANIMATION; |
Sunny Goyal | 7eff40f | 2018-04-11 15:30:46 -0700 | [diff] [blame] | 75 | |
| 76 | @Retention(SOURCE) |
| 77 | @IntDef( |
| 78 | flag = true, |
Sunny Goyal | 1c63c72 | 2018-06-05 16:00:34 -0700 | [diff] [blame] | 79 | value = {INVISIBLE_BY_STATE_HANDLER, INVISIBLE_BY_APP_TRANSITIONS, |
| 80 | INVISIBLE_BY_PENDING_FLAGS, PENDING_INVISIBLE_BY_WALLPAPER_ANIMATION}) |
Mike Schneider | a79d460 | 2023-03-03 15:58:06 +0100 | [diff] [blame] | 81 | public @interface InvisibilityFlags { |
| 82 | } |
Sunny Goyal | 7eff40f | 2018-04-11 15:30:46 -0700 | [diff] [blame] | 83 | |
Sunny Goyal | fde5505 | 2018-02-01 14:46:13 -0800 | [diff] [blame] | 84 | private final ArrayList<OnDeviceProfileChangeListener> mDPChangeListeners = new ArrayList<>(); |
Winson Chung | 1a77c3d | 2018-04-11 12:47:47 -0700 | [diff] [blame] | 85 | private final ArrayList<MultiWindowModeChangedListener> mMultiWindowModeChangedListeners = |
| 86 | new ArrayList<>(); |
Sunny Goyal | fde5505 | 2018-02-01 14:46:13 -0800 | [diff] [blame] | 87 | |
Sunny Goyal | 2783595 | 2017-01-13 12:15:53 -0800 | [diff] [blame] | 88 | protected DeviceProfile mDeviceProfile; |
Sunny Goyal | 8392c82 | 2017-06-20 10:03:56 -0700 | [diff] [blame] | 89 | protected SystemUiController mSystemUiController; |
Sunny Goyal | 977838b | 2022-06-27 13:15:41 -0700 | [diff] [blame] | 90 | private StatsLogManager mStatsLogManager; |
Sunny Goyal | 2783595 | 2017-01-13 12:15:53 -0800 | [diff] [blame] | 91 | |
Sunny Goyal | 210e174 | 2019-10-17 12:05:38 -0700 | [diff] [blame] | 92 | |
| 93 | public static final int ACTIVITY_STATE_STARTED = 1 << 0; |
| 94 | public static final int ACTIVITY_STATE_RESUMED = 1 << 1; |
| 95 | |
Sunny Goyal | 3483c52 | 2018-04-12 11:23:33 -0700 | [diff] [blame] | 96 | /** |
Sunny Goyal | 210e174 | 2019-10-17 12:05:38 -0700 | [diff] [blame] | 97 | * State flags indicating that the activity has received one frame after resume, and was |
| 98 | * not immediately paused. |
| 99 | */ |
| 100 | public static final int ACTIVITY_STATE_DEFERRED_RESUMED = 1 << 2; |
| 101 | |
| 102 | public static final int ACTIVITY_STATE_WINDOW_FOCUSED = 1 << 3; |
| 103 | |
| 104 | /** |
| 105 | * State flag indicating if the user is active or the activity when to background as a result |
Sunny Goyal | 3483c52 | 2018-04-12 11:23:33 -0700 | [diff] [blame] | 106 | * of user action. |
Mike Schneider | a79d460 | 2023-03-03 15:58:06 +0100 | [diff] [blame] | 107 | * |
Sunny Goyal | 3483c52 | 2018-04-12 11:23:33 -0700 | [diff] [blame] | 108 | * @see #isUserActive() |
| 109 | */ |
Sunny Goyal | 210e174 | 2019-10-17 12:05:38 -0700 | [diff] [blame] | 110 | public static final int ACTIVITY_STATE_USER_ACTIVE = 1 << 4; |
| 111 | |
| 112 | /** |
Winson Chung | 034ce6f | 2020-05-14 10:49:30 -0700 | [diff] [blame] | 113 | * State flag indicating if the user will be active shortly. |
| 114 | */ |
| 115 | public static final int ACTIVITY_STATE_USER_WILL_BE_ACTIVE = 1 << 5; |
| 116 | |
| 117 | /** |
Sunny Goyal | 210e174 | 2019-10-17 12:05:38 -0700 | [diff] [blame] | 118 | * State flag indicating that a state transition is in progress |
| 119 | */ |
Winson Chung | 034ce6f | 2020-05-14 10:49:30 -0700 | [diff] [blame] | 120 | public static final int ACTIVITY_STATE_TRANSITION_ACTIVE = 1 << 6; |
Sunny Goyal | 3483c52 | 2018-04-12 11:23:33 -0700 | [diff] [blame] | 121 | |
| 122 | @Retention(SOURCE) |
| 123 | @IntDef( |
| 124 | flag = true, |
Sunny Goyal | 210e174 | 2019-10-17 12:05:38 -0700 | [diff] [blame] | 125 | value = {ACTIVITY_STATE_STARTED, |
| 126 | ACTIVITY_STATE_RESUMED, |
| 127 | ACTIVITY_STATE_DEFERRED_RESUMED, |
| 128 | ACTIVITY_STATE_WINDOW_FOCUSED, |
| 129 | ACTIVITY_STATE_USER_ACTIVE, |
| 130 | ACTIVITY_STATE_TRANSITION_ACTIVE}) |
Mike Schneider | a79d460 | 2023-03-03 15:58:06 +0100 | [diff] [blame] | 131 | public @interface ActivityFlags { |
| 132 | } |
| 133 | |
| 134 | /** Returns a human-readable string for the specified {@link ActivityFlags}. */ |
| 135 | public static String getActivityStateString(@ActivityFlags int flags) { |
| 136 | StringJoiner result = new StringJoiner("|"); |
| 137 | appendFlag(result, flags, ACTIVITY_STATE_STARTED, "state_started"); |
| 138 | appendFlag(result, flags, ACTIVITY_STATE_RESUMED, "state_resumed"); |
| 139 | appendFlag(result, flags, ACTIVITY_STATE_DEFERRED_RESUMED, "state_deferred_resumed"); |
| 140 | appendFlag(result, flags, ACTIVITY_STATE_WINDOW_FOCUSED, "state_window_focused"); |
| 141 | appendFlag(result, flags, ACTIVITY_STATE_USER_ACTIVE, "state_user_active"); |
| 142 | appendFlag(result, flags, ACTIVITY_STATE_TRANSITION_ACTIVE, "state_transition_active"); |
| 143 | return result.toString(); |
| 144 | } |
Sunny Goyal | 3483c52 | 2018-04-12 11:23:33 -0700 | [diff] [blame] | 145 | |
| 146 | @ActivityFlags |
| 147 | private int mActivityFlags; |
Sunny Goyal | 7eff40f | 2018-04-11 15:30:46 -0700 | [diff] [blame] | 148 | |
Winson Chung | 9800e73 | 2018-04-04 13:33:23 -0700 | [diff] [blame] | 149 | // When the recents animation is running, the visibility of the Launcher is managed by the |
| 150 | // animation |
Mike Schneider | a79d460 | 2023-03-03 15:58:06 +0100 | [diff] [blame] | 151 | @InvisibilityFlags |
| 152 | private int mForceInvisible; |
Sunny Goyal | cc96aa1 | 2018-01-11 09:56:07 -0800 | [diff] [blame] | 153 | |
Sunny Goyal | 5686333 | 2019-05-22 14:13:53 -0700 | [diff] [blame] | 154 | private final ViewCache mViewCache = new ViewCache(); |
| 155 | |
Sunny Goyal | 5996937 | 2021-05-06 12:11:44 -0700 | [diff] [blame] | 156 | @Override |
Sunny Goyal | 5686333 | 2019-05-22 14:13:53 -0700 | [diff] [blame] | 157 | public ViewCache getViewCache() { |
| 158 | return mViewCache; |
| 159 | } |
| 160 | |
Sunny Goyal | fe8e4a9 | 2018-11-13 19:43:57 -0800 | [diff] [blame] | 161 | @Override |
Sunny Goyal | 2783595 | 2017-01-13 12:15:53 -0800 | [diff] [blame] | 162 | public DeviceProfile getDeviceProfile() { |
| 163 | return mDeviceProfile; |
| 164 | } |
| 165 | |
Brian Isganitis | 099945b | 2022-01-31 18:15:00 -0500 | [diff] [blame] | 166 | @Override |
| 167 | public List<OnDeviceProfileChangeListener> getOnDeviceProfileChangeListeners() { |
| 168 | return mDPChangeListeners; |
| 169 | } |
| 170 | |
thiruram | c96873c | 2021-02-11 15:13:47 -0800 | [diff] [blame] | 171 | /** |
| 172 | * Returns {@link StatsLogManager} for user event logging. |
| 173 | */ |
Sunny Goyal | 177785e | 2021-07-29 15:48:24 -0700 | [diff] [blame] | 174 | @Override |
thiruram | c96873c | 2021-02-11 15:13:47 -0800 | [diff] [blame] | 175 | public StatsLogManager getStatsLogManager() { |
Hyunyoung Song | fc00747 | 2018-10-25 14:09:50 -0700 | [diff] [blame] | 176 | if (mStatsLogManager == null) { |
Hyunyoung Song | 801f81f | 2020-06-19 02:58:53 -0700 | [diff] [blame] | 177 | mStatsLogManager = StatsLogManager.newInstance(this); |
Hyunyoung Song | fc00747 | 2018-10-25 14:09:50 -0700 | [diff] [blame] | 178 | } |
| 179 | return mStatsLogManager; |
| 180 | } |
| 181 | |
Sunny Goyal | 8392c82 | 2017-06-20 10:03:56 -0700 | [diff] [blame] | 182 | public SystemUiController getSystemUiController() { |
| 183 | if (mSystemUiController == null) { |
| 184 | mSystemUiController = new SystemUiController(getWindow()); |
| 185 | } |
| 186 | return mSystemUiController; |
| 187 | } |
Sunny Goyal | 64a75aa | 2017-07-03 13:50:52 -0700 | [diff] [blame] | 188 | |
Tony Wickham | b482188 | 2021-04-23 14:26:45 -0700 | [diff] [blame] | 189 | public ScrimView getScrimView() { |
| 190 | return null; |
| 191 | } |
| 192 | |
Sunny Goyal | 64a75aa | 2017-07-03 13:50:52 -0700 | [diff] [blame] | 193 | @Override |
| 194 | public void onActivityResult(int requestCode, int resultCode, Intent data) { |
| 195 | super.onActivityResult(requestCode, resultCode, data); |
| 196 | } |
Sunny Goyal | cc96aa1 | 2018-01-11 09:56:07 -0800 | [diff] [blame] | 197 | |
| 198 | @Override |
Yein Jo | 18446d0 | 2022-09-19 22:18:09 +0000 | [diff] [blame] | 199 | protected void onCreate(Bundle savedInstanceState) { |
| 200 | super.onCreate(savedInstanceState); |
Fengjiang Li | e884c2c | 2022-12-19 14:42:14 -0800 | [diff] [blame] | 201 | registerBackDispatcher(); |
Yein Jo | 18446d0 | 2022-09-19 22:18:09 +0000 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | @Override |
Sunny Goyal | cc96aa1 | 2018-01-11 09:56:07 -0800 | [diff] [blame] | 205 | protected void onStart() { |
Sunny Goyal | 210e174 | 2019-10-17 12:05:38 -0700 | [diff] [blame] | 206 | addActivityFlags(ACTIVITY_STATE_STARTED); |
Sunny Goyal | cc96aa1 | 2018-01-11 09:56:07 -0800 | [diff] [blame] | 207 | super.onStart(); |
| 208 | } |
| 209 | |
| 210 | @Override |
Tracy Zhou | a706f00 | 2018-03-28 13:55:19 -0700 | [diff] [blame] | 211 | protected void onResume() { |
Mady Mellor | 9a90c2d | 2022-09-14 15:17:21 -0700 | [diff] [blame] | 212 | setResumed(); |
Tracy Zhou | a706f00 | 2018-03-28 13:55:19 -0700 | [diff] [blame] | 213 | super.onResume(); |
| 214 | } |
| 215 | |
| 216 | @Override |
| 217 | protected void onUserLeaveHint() { |
Sunny Goyal | 210e174 | 2019-10-17 12:05:38 -0700 | [diff] [blame] | 218 | removeActivityFlags(ACTIVITY_STATE_USER_ACTIVE); |
Tracy Zhou | a706f00 | 2018-03-28 13:55:19 -0700 | [diff] [blame] | 219 | super.onUserLeaveHint(); |
| 220 | } |
| 221 | |
| 222 | @Override |
Winson Chung | 1a77c3d | 2018-04-11 12:47:47 -0700 | [diff] [blame] | 223 | public void onMultiWindowModeChanged(boolean isInMultiWindowMode, Configuration newConfig) { |
| 224 | super.onMultiWindowModeChanged(isInMultiWindowMode, newConfig); |
| 225 | for (int i = mMultiWindowModeChangedListeners.size() - 1; i >= 0; i--) { |
| 226 | mMultiWindowModeChangedListeners.get(i).onMultiWindowModeChanged(isInMultiWindowMode); |
| 227 | } |
| 228 | } |
| 229 | |
| 230 | @Override |
Sunny Goyal | cc96aa1 | 2018-01-11 09:56:07 -0800 | [diff] [blame] | 231 | protected void onStop() { |
Sunny Goyal | 210e174 | 2019-10-17 12:05:38 -0700 | [diff] [blame] | 232 | removeActivityFlags(ACTIVITY_STATE_STARTED | ACTIVITY_STATE_USER_ACTIVE); |
Sunny Goyal | 7eff40f | 2018-04-11 15:30:46 -0700 | [diff] [blame] | 233 | mForceInvisible = 0; |
Sunny Goyal | cc96aa1 | 2018-01-11 09:56:07 -0800 | [diff] [blame] | 234 | super.onStop(); |
Winson Chung | a36c800 | 2019-06-11 16:15:54 -0700 | [diff] [blame] | 235 | |
| 236 | // Reset the overridden sysui flags used for the task-swipe launch animation, this is a |
| 237 | // catch all for if we do not get resumed (and therefore not paused below) |
Tony Wickham | b482188 | 2021-04-23 14:26:45 -0700 | [diff] [blame] | 238 | getSystemUiController().updateUiState(UI_STATE_FULLSCREEN_TASK, 0); |
Sunny Goyal | cc96aa1 | 2018-01-11 09:56:07 -0800 | [diff] [blame] | 239 | } |
| 240 | |
Sunny Goyal | 3483c52 | 2018-04-12 11:23:33 -0700 | [diff] [blame] | 241 | @Override |
| 242 | protected void onPause() { |
Mady Mellor | 9a90c2d | 2022-09-14 15:17:21 -0700 | [diff] [blame] | 243 | setPaused(); |
Sunny Goyal | 3483c52 | 2018-04-12 11:23:33 -0700 | [diff] [blame] | 244 | super.onPause(); |
Winson Chung | a0f09f9 | 2018-05-11 21:55:21 +0000 | [diff] [blame] | 245 | |
| 246 | // Reset the overridden sysui flags used for the task-swipe launch animation, we do this |
| 247 | // here instead of at the end of the animation because the start of the new activity does |
| 248 | // not happen immediately, which would cause us to reset to launcher's sysui flags and then |
| 249 | // back to the new app (causing a flash) |
Tony Wickham | b482188 | 2021-04-23 14:26:45 -0700 | [diff] [blame] | 250 | getSystemUiController().updateUiState(UI_STATE_FULLSCREEN_TASK, 0); |
Sunny Goyal | 3483c52 | 2018-04-12 11:23:33 -0700 | [diff] [blame] | 251 | } |
| 252 | |
Sunny Goyal | 210e174 | 2019-10-17 12:05:38 -0700 | [diff] [blame] | 253 | @Override |
| 254 | public void onWindowFocusChanged(boolean hasFocus) { |
| 255 | super.onWindowFocusChanged(hasFocus); |
| 256 | if (hasFocus) { |
| 257 | addActivityFlags(ACTIVITY_STATE_WINDOW_FOCUSED); |
| 258 | } else { |
| 259 | removeActivityFlags(ACTIVITY_STATE_WINDOW_FOCUSED); |
| 260 | } |
| 261 | |
| 262 | } |
| 263 | |
Fengjiang Li | e884c2c | 2022-12-19 14:42:14 -0800 | [diff] [blame] | 264 | protected void registerBackDispatcher() { |
| 265 | if (Utilities.ATLEAST_T) { |
| 266 | getOnBackInvokedDispatcher().registerOnBackInvokedCallback( |
| 267 | OnBackInvokedDispatcher.PRIORITY_DEFAULT, |
| 268 | () -> { |
| 269 | onBackPressed(); |
| 270 | TestLogging.recordEvent(TestProtocol.SEQUENCE_MAIN, "onBackInvoked"); |
| 271 | }); |
| 272 | } |
| 273 | } |
| 274 | |
Sunny Goyal | cc96aa1 | 2018-01-11 09:56:07 -0800 | [diff] [blame] | 275 | public boolean isStarted() { |
Sunny Goyal | 3483c52 | 2018-04-12 11:23:33 -0700 | [diff] [blame] | 276 | return (mActivityFlags & ACTIVITY_STATE_STARTED) != 0; |
| 277 | } |
| 278 | |
| 279 | /** |
| 280 | * isResumed in already defined as a hidden final method in Activity.java |
| 281 | */ |
| 282 | public boolean hasBeenResumed() { |
| 283 | return (mActivityFlags & ACTIVITY_STATE_RESUMED) != 0; |
Sunny Goyal | cc96aa1 | 2018-01-11 09:56:07 -0800 | [diff] [blame] | 284 | } |
Sunny Goyal | fde5505 | 2018-02-01 14:46:13 -0800 | [diff] [blame] | 285 | |
Mady Mellor | 9a90c2d | 2022-09-14 15:17:21 -0700 | [diff] [blame] | 286 | /** |
| 287 | * Sets the activity to appear as paused. |
| 288 | */ |
| 289 | public void setPaused() { |
| 290 | removeActivityFlags(ACTIVITY_STATE_RESUMED | ACTIVITY_STATE_DEFERRED_RESUMED); |
| 291 | } |
| 292 | |
| 293 | /** |
| 294 | * Sets the activity to appear as resumed. |
| 295 | */ |
| 296 | public void setResumed() { |
| 297 | addActivityFlags(ACTIVITY_STATE_RESUMED | ACTIVITY_STATE_USER_ACTIVE); |
| 298 | removeActivityFlags(ACTIVITY_STATE_USER_WILL_BE_ACTIVE); |
| 299 | } |
| 300 | |
Tracy Zhou | a706f00 | 2018-03-28 13:55:19 -0700 | [diff] [blame] | 301 | public boolean isUserActive() { |
Sunny Goyal | 3483c52 | 2018-04-12 11:23:33 -0700 | [diff] [blame] | 302 | return (mActivityFlags & ACTIVITY_STATE_USER_ACTIVE) != 0; |
Tracy Zhou | a706f00 | 2018-03-28 13:55:19 -0700 | [diff] [blame] | 303 | } |
| 304 | |
Sunny Goyal | 210e174 | 2019-10-17 12:05:38 -0700 | [diff] [blame] | 305 | public int getActivityFlags() { |
| 306 | return mActivityFlags; |
| 307 | } |
| 308 | |
Mike Schneider | a79d460 | 2023-03-03 15:58:06 +0100 | [diff] [blame] | 309 | protected void addActivityFlags(int toAdd) { |
| 310 | final int oldFlags = mActivityFlags; |
| 311 | mActivityFlags |= toAdd; |
| 312 | if (DEBUG) { |
| 313 | Log.d(TAG, "Launcher flags updated: " + formatFlagChange(mActivityFlags, oldFlags, |
| 314 | BaseActivity::getActivityStateString)); |
| 315 | } |
| 316 | onActivityFlagsChanged(toAdd); |
Sunny Goyal | 210e174 | 2019-10-17 12:05:38 -0700 | [diff] [blame] | 317 | } |
| 318 | |
Mike Schneider | a79d460 | 2023-03-03 15:58:06 +0100 | [diff] [blame] | 319 | protected void removeActivityFlags(int toRemove) { |
| 320 | final int oldFlags = mActivityFlags; |
| 321 | mActivityFlags &= ~toRemove; |
| 322 | if (DEBUG) { |
| 323 | Log.d(TAG, "Launcher flags updated: " + formatFlagChange(mActivityFlags, oldFlags, |
| 324 | BaseActivity::getActivityStateString)); |
| 325 | } |
| 326 | |
| 327 | onActivityFlagsChanged(toRemove); |
Sunny Goyal | 210e174 | 2019-10-17 12:05:38 -0700 | [diff] [blame] | 328 | } |
| 329 | |
Mike Schneider | a79d460 | 2023-03-03 15:58:06 +0100 | [diff] [blame] | 330 | protected void onActivityFlagsChanged(int changeBits) { |
| 331 | } |
Sunny Goyal | 210e174 | 2019-10-17 12:05:38 -0700 | [diff] [blame] | 332 | |
Winson Chung | 1a77c3d | 2018-04-11 12:47:47 -0700 | [diff] [blame] | 333 | public void addMultiWindowModeChangedListener(MultiWindowModeChangedListener listener) { |
| 334 | mMultiWindowModeChangedListeners.add(listener); |
| 335 | } |
| 336 | |
| 337 | public void removeMultiWindowModeChangedListener(MultiWindowModeChangedListener listener) { |
| 338 | mMultiWindowModeChangedListeners.remove(listener); |
| 339 | } |
| 340 | |
Sunny Goyal | f633ef5 | 2018-03-13 09:57:05 -0700 | [diff] [blame] | 341 | /** |
Winson Chung | 9800e73 | 2018-04-04 13:33:23 -0700 | [diff] [blame] | 342 | * Used to set the override visibility state, used only to handle the transition home with the |
| 343 | * recents animation. |
Mike Schneider | a79d460 | 2023-03-03 15:58:06 +0100 | [diff] [blame] | 344 | * |
Sunny Goyal | b65d766 | 2021-03-07 15:09:11 -0800 | [diff] [blame] | 345 | * @see QuickstepTransitionManager#createWallpaperOpenRunner |
Winson Chung | 9800e73 | 2018-04-04 13:33:23 -0700 | [diff] [blame] | 346 | */ |
Sunny Goyal | 7eff40f | 2018-04-11 15:30:46 -0700 | [diff] [blame] | 347 | public void addForceInvisibleFlag(@InvisibilityFlags int flag) { |
| 348 | mForceInvisible |= flag; |
Winson Chung | 9800e73 | 2018-04-04 13:33:23 -0700 | [diff] [blame] | 349 | } |
| 350 | |
Sunny Goyal | 7eff40f | 2018-04-11 15:30:46 -0700 | [diff] [blame] | 351 | public void clearForceInvisibleFlag(@InvisibilityFlags int flag) { |
| 352 | mForceInvisible &= ~flag; |
| 353 | } |
| 354 | |
Winson Chung | 9800e73 | 2018-04-04 13:33:23 -0700 | [diff] [blame] | 355 | /** |
| 356 | * @return Wether this activity should be considered invisible regardless of actual visibility. |
| 357 | */ |
| 358 | public boolean isForceInvisible() { |
Sunny Goyal | 1c63c72 | 2018-06-05 16:00:34 -0700 | [diff] [blame] | 359 | return hasSomeInvisibleFlag(INVISIBLE_FLAGS); |
| 360 | } |
| 361 | |
| 362 | public boolean hasSomeInvisibleFlag(int mask) { |
| 363 | return (mForceInvisible & mask) != 0; |
Winson Chung | 9800e73 | 2018-04-04 13:33:23 -0700 | [diff] [blame] | 364 | } |
| 365 | |
Jon Miranda | cb58259 | 2023-04-19 15:40:04 -0700 | [diff] [blame^] | 366 | /** |
| 367 | * Attempts to clear accessibility focus on {@param view}. |
| 368 | */ |
| 369 | public void tryClearAccessibilityFocus(View view) { |
| 370 | } |
| 371 | |
Winson Chung | 1a77c3d | 2018-04-11 12:47:47 -0700 | [diff] [blame] | 372 | public interface MultiWindowModeChangedListener { |
| 373 | void onMultiWindowModeChanged(boolean isInMultiWindowMode); |
| 374 | } |
Sunny Goyal | e43d00d | 2018-05-14 14:23:18 -0700 | [diff] [blame] | 375 | |
Winson Chung | ef52876 | 2019-09-06 12:05:52 -0700 | [diff] [blame] | 376 | protected void dumpMisc(String prefix, PrintWriter writer) { |
| 377 | writer.println(prefix + "deviceProfile isTransposed=" |
| 378 | + getDeviceProfile().isVerticalBarLayout()); |
| 379 | writer.println(prefix + "orientation=" + getResources().getConfiguration().orientation); |
| 380 | writer.println(prefix + "mSystemUiController: " + mSystemUiController); |
Mike Schneider | a79d460 | 2023-03-03 15:58:06 +0100 | [diff] [blame] | 381 | writer.println(prefix + "mActivityFlags: " + getActivityStateString(mActivityFlags)); |
Winson Chung | ef52876 | 2019-09-06 12:05:52 -0700 | [diff] [blame] | 382 | writer.println(prefix + "mForceInvisible: " + mForceInvisible); |
Sunny Goyal | e43d00d | 2018-05-14 14:23:18 -0700 | [diff] [blame] | 383 | } |
Sunny Goyal | 87b5eb6 | 2018-07-03 15:53:39 -0700 | [diff] [blame] | 384 | |
| 385 | public static <T extends BaseActivity> T fromContext(Context context) { |
| 386 | if (context instanceof BaseActivity) { |
| 387 | return (T) context; |
Tony Wickham | 1906cc3 | 2021-02-11 11:55:24 -0800 | [diff] [blame] | 388 | } else if (context instanceof ContextWrapper) { |
Sunny Goyal | 87b5eb6 | 2018-07-03 15:53:39 -0700 | [diff] [blame] | 389 | return fromContext(((ContextWrapper) context).getBaseContext()); |
| 390 | } else { |
| 391 | throw new IllegalArgumentException("Cannot find BaseActivity in parent tree"); |
| 392 | } |
| 393 | } |
Sunny Goyal | 2783595 | 2017-01-13 12:15:53 -0800 | [diff] [blame] | 394 | } |