blob: fec94fe8d757f09f02a0ce72e00623dfdf7028cf [file] [log] [blame]
Sunny Goyal27835952017-01-13 12:15:53 -08001/*
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
17package com.android.launcher3;
18
Mike Schneidera79d4602023-03-03 15:58:06 +010019import static com.android.launcher3.util.FlagDebugUtils.appendFlag;
20import static com.android.launcher3.util.FlagDebugUtils.formatFlagChange;
Tony Wickhamb4821882021-04-23 14:26:45 -070021import static com.android.launcher3.util.SystemUiController.UI_STATE_FULLSCREEN_TASK;
Sunny Goyal8c48d8b2019-01-25 15:10:18 -080022
Sunny Goyal7eff40f2018-04-11 15:30:46 -070023import static java.lang.annotation.RetentionPolicy.SOURCE;
24
Sunny Goyal27835952017-01-13 12:15:53 -080025import android.app.Activity;
26import android.content.Context;
27import android.content.ContextWrapper;
Sunny Goyal64a75aa2017-07-03 13:50:52 -070028import android.content.Intent;
Winson Chung1a77c3d2018-04-11 12:47:47 -070029import android.content.res.Configuration;
Yein Jo18446d02022-09-19 22:18:09 +000030import android.os.Bundle;
Mike Schneidera79d4602023-03-03 15:58:06 +010031import android.util.Log;
Yein Jo18446d02022-09-19 22:18:09 +000032import android.window.OnBackInvokedDispatcher;
Sunny Goyal27835952017-01-13 12:15:53 -080033
Winson Chungef528762019-09-06 12:05:52 -070034import androidx.annotation.IntDef;
35
Sunny Goyalfde55052018-02-01 14:46:13 -080036import com.android.launcher3.DeviceProfile.OnDeviceProfileChangeListener;
Hyunyoung Songfc007472018-10-25 14:09:50 -070037import com.android.launcher3.logging.StatsLogManager;
Yein Jo18446d02022-09-19 22:18:09 +000038import com.android.launcher3.testing.TestLogging;
39import com.android.launcher3.testing.shared.TestProtocol;
Sunny Goyale82a20a2023-10-19 13:52:49 -070040import com.android.launcher3.util.RunnableList;
Sunny Goyal8392c822017-06-20 10:03:56 -070041import com.android.launcher3.util.SystemUiController;
Sunny Goyal56863332019-05-22 14:13:53 -070042import com.android.launcher3.util.ViewCache;
Sunny Goyal54fa1102022-12-07 22:48:37 -080043import com.android.launcher3.views.ActivityContext;
Tony Wickhamb4821882021-04-23 14:26:45 -070044import com.android.launcher3.views.ScrimView;
Sunny Goyala535ae42017-02-27 10:07:13 -080045
Sunny Goyale43d00d2018-05-14 14:23:18 -070046import java.io.PrintWriter;
Sunny Goyal7eff40f2018-04-11 15:30:46 -070047import java.lang.annotation.Retention;
Sunny Goyalfde55052018-02-01 14:46:13 -080048import java.util.ArrayList;
Brian Isganitis099945b2022-01-31 18:15:00 -050049import java.util.List;
Mike Schneidera79d4602023-03-03 15:58:06 +010050import java.util.StringJoiner;
Sunny Goyalfde55052018-02-01 14:46:13 -080051
Samuel Fufaa579ddc2020-02-27 16:59:19 -080052/**
53 * Launcher BaseActivity
54 */
Sunny Goyal54fa1102022-12-07 22:48:37 -080055public abstract class BaseActivity extends Activity implements ActivityContext {
Sunny Goyal27835952017-01-13 12:15:53 -080056
Sunny Goyalfa395362019-12-11 10:00:47 -080057 private static final String TAG = "BaseActivity";
Mike Schneidera79d4602023-03-03 15:58:06 +010058 static final boolean DEBUG = false;
Sunny Goyalfa395362019-12-11 10:00:47 -080059
Sunny Goyal7eff40f2018-04-11 15:30:46 -070060 public static final int INVISIBLE_BY_STATE_HANDLER = 1 << 0;
61 public static final int INVISIBLE_BY_APP_TRANSITIONS = 1 << 1;
Sunny Goyal1c63c722018-06-05 16:00:34 -070062 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 Goyal7eff40f2018-04-11 15:30:46 -070073 public static final int INVISIBLE_ALL =
Sunny Goyal1c63c722018-06-05 16:00:34 -070074 INVISIBLE_FLAGS | PENDING_INVISIBLE_BY_WALLPAPER_ANIMATION;
Sunny Goyal7eff40f2018-04-11 15:30:46 -070075
76 @Retention(SOURCE)
77 @IntDef(
78 flag = true,
Sunny Goyal1c63c722018-06-05 16:00:34 -070079 value = {INVISIBLE_BY_STATE_HANDLER, INVISIBLE_BY_APP_TRANSITIONS,
80 INVISIBLE_BY_PENDING_FLAGS, PENDING_INVISIBLE_BY_WALLPAPER_ANIMATION})
Mike Schneidera79d4602023-03-03 15:58:06 +010081 public @interface InvisibilityFlags {
82 }
Sunny Goyal7eff40f2018-04-11 15:30:46 -070083
Sunny Goyalfde55052018-02-01 14:46:13 -080084 private final ArrayList<OnDeviceProfileChangeListener> mDPChangeListeners = new ArrayList<>();
Winson Chung1a77c3d2018-04-11 12:47:47 -070085 private final ArrayList<MultiWindowModeChangedListener> mMultiWindowModeChangedListeners =
86 new ArrayList<>();
Sunny Goyalfde55052018-02-01 14:46:13 -080087
Sunny Goyal27835952017-01-13 12:15:53 -080088 protected DeviceProfile mDeviceProfile;
Sunny Goyal8392c822017-06-20 10:03:56 -070089 protected SystemUiController mSystemUiController;
Sunny Goyal977838b2022-06-27 13:15:41 -070090 private StatsLogManager mStatsLogManager;
Sunny Goyal27835952017-01-13 12:15:53 -080091
Sunny Goyal210e1742019-10-17 12:05:38 -070092
93 public static final int ACTIVITY_STATE_STARTED = 1 << 0;
94 public static final int ACTIVITY_STATE_RESUMED = 1 << 1;
95
Sunny Goyal3483c522018-04-12 11:23:33 -070096 /**
Sunny Goyal210e1742019-10-17 12:05:38 -070097 * 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 Goyal3483c522018-04-12 11:23:33 -0700106 * of user action.
Mike Schneidera79d4602023-03-03 15:58:06 +0100107 *
Sunny Goyal3483c522018-04-12 11:23:33 -0700108 * @see #isUserActive()
109 */
Sunny Goyal210e1742019-10-17 12:05:38 -0700110 public static final int ACTIVITY_STATE_USER_ACTIVE = 1 << 4;
111
112 /**
113 * State flag indicating that a state transition is in progress
114 */
Winson Chung034ce6f2020-05-14 10:49:30 -0700115 public static final int ACTIVITY_STATE_TRANSITION_ACTIVE = 1 << 6;
Sunny Goyal3483c522018-04-12 11:23:33 -0700116
117 @Retention(SOURCE)
118 @IntDef(
119 flag = true,
Sunny Goyal210e1742019-10-17 12:05:38 -0700120 value = {ACTIVITY_STATE_STARTED,
121 ACTIVITY_STATE_RESUMED,
122 ACTIVITY_STATE_DEFERRED_RESUMED,
123 ACTIVITY_STATE_WINDOW_FOCUSED,
124 ACTIVITY_STATE_USER_ACTIVE,
125 ACTIVITY_STATE_TRANSITION_ACTIVE})
Mike Schneidera79d4602023-03-03 15:58:06 +0100126 public @interface ActivityFlags {
127 }
128
129 /** Returns a human-readable string for the specified {@link ActivityFlags}. */
130 public static String getActivityStateString(@ActivityFlags int flags) {
131 StringJoiner result = new StringJoiner("|");
132 appendFlag(result, flags, ACTIVITY_STATE_STARTED, "state_started");
133 appendFlag(result, flags, ACTIVITY_STATE_RESUMED, "state_resumed");
134 appendFlag(result, flags, ACTIVITY_STATE_DEFERRED_RESUMED, "state_deferred_resumed");
135 appendFlag(result, flags, ACTIVITY_STATE_WINDOW_FOCUSED, "state_window_focused");
136 appendFlag(result, flags, ACTIVITY_STATE_USER_ACTIVE, "state_user_active");
137 appendFlag(result, flags, ACTIVITY_STATE_TRANSITION_ACTIVE, "state_transition_active");
138 return result.toString();
139 }
Sunny Goyal3483c522018-04-12 11:23:33 -0700140
141 @ActivityFlags
142 private int mActivityFlags;
Sunny Goyal7eff40f2018-04-11 15:30:46 -0700143
Winson Chung9800e732018-04-04 13:33:23 -0700144 // When the recents animation is running, the visibility of the Launcher is managed by the
145 // animation
Mike Schneidera79d4602023-03-03 15:58:06 +0100146 @InvisibilityFlags
147 private int mForceInvisible;
Sunny Goyalcc96aa12018-01-11 09:56:07 -0800148
Sunny Goyal56863332019-05-22 14:13:53 -0700149 private final ViewCache mViewCache = new ViewCache();
150
Sunny Goyale82a20a2023-10-19 13:52:49 -0700151 @Retention(SOURCE)
152 @IntDef({EVENT_STARTED, EVENT_RESUMED, EVENT_STOPPED, EVENT_DESTROYED})
153 public @interface ActivityEvent { }
154 public static final int EVENT_STARTED = 0;
155 public static final int EVENT_RESUMED = 1;
156 public static final int EVENT_STOPPED = 2;
157 public static final int EVENT_DESTROYED = 3;
158
159 // Callback array that corresponds to events defined in @ActivityEvent
160 private final RunnableList[] mEventCallbacks =
161 {new RunnableList(), new RunnableList(), new RunnableList(), new RunnableList()};
162
Sunny Goyal59969372021-05-06 12:11:44 -0700163 @Override
Sunny Goyal56863332019-05-22 14:13:53 -0700164 public ViewCache getViewCache() {
165 return mViewCache;
166 }
167
Sunny Goyalfe8e4a92018-11-13 19:43:57 -0800168 @Override
Sunny Goyal27835952017-01-13 12:15:53 -0800169 public DeviceProfile getDeviceProfile() {
170 return mDeviceProfile;
171 }
172
Brian Isganitis099945b2022-01-31 18:15:00 -0500173 @Override
174 public List<OnDeviceProfileChangeListener> getOnDeviceProfileChangeListeners() {
175 return mDPChangeListeners;
176 }
177
thiruramc96873c2021-02-11 15:13:47 -0800178 /**
179 * Returns {@link StatsLogManager} for user event logging.
180 */
Sunny Goyal177785e2021-07-29 15:48:24 -0700181 @Override
thiruramc96873c2021-02-11 15:13:47 -0800182 public StatsLogManager getStatsLogManager() {
Hyunyoung Songfc007472018-10-25 14:09:50 -0700183 if (mStatsLogManager == null) {
Hyunyoung Song801f81f2020-06-19 02:58:53 -0700184 mStatsLogManager = StatsLogManager.newInstance(this);
Hyunyoung Songfc007472018-10-25 14:09:50 -0700185 }
186 return mStatsLogManager;
187 }
188
Sunny Goyal8392c822017-06-20 10:03:56 -0700189 public SystemUiController getSystemUiController() {
190 if (mSystemUiController == null) {
191 mSystemUiController = new SystemUiController(getWindow());
192 }
193 return mSystemUiController;
194 }
Sunny Goyal64a75aa2017-07-03 13:50:52 -0700195
Tony Wickhamb4821882021-04-23 14:26:45 -0700196 public ScrimView getScrimView() {
197 return null;
198 }
199
Sunny Goyal64a75aa2017-07-03 13:50:52 -0700200 @Override
201 public void onActivityResult(int requestCode, int resultCode, Intent data) {
202 super.onActivityResult(requestCode, resultCode, data);
203 }
Sunny Goyalcc96aa12018-01-11 09:56:07 -0800204
205 @Override
Yein Jo18446d02022-09-19 22:18:09 +0000206 protected void onCreate(Bundle savedInstanceState) {
207 super.onCreate(savedInstanceState);
Fengjiang Lie884c2c2022-12-19 14:42:14 -0800208 registerBackDispatcher();
Yein Jo18446d02022-09-19 22:18:09 +0000209 }
210
211 @Override
Sunny Goyalcc96aa12018-01-11 09:56:07 -0800212 protected void onStart() {
Sunny Goyal210e1742019-10-17 12:05:38 -0700213 addActivityFlags(ACTIVITY_STATE_STARTED);
Sunny Goyalcc96aa12018-01-11 09:56:07 -0800214 super.onStart();
Sunny Goyale82a20a2023-10-19 13:52:49 -0700215 mEventCallbacks[EVENT_STARTED].executeAllAndClear();
Sunny Goyalcc96aa12018-01-11 09:56:07 -0800216 }
217
218 @Override
Tracy Zhoua706f002018-03-28 13:55:19 -0700219 protected void onResume() {
Mady Mellor9a90c2d2022-09-14 15:17:21 -0700220 setResumed();
Tracy Zhoua706f002018-03-28 13:55:19 -0700221 super.onResume();
Sunny Goyale82a20a2023-10-19 13:52:49 -0700222 mEventCallbacks[EVENT_RESUMED].executeAllAndClear();
Tracy Zhoua706f002018-03-28 13:55:19 -0700223 }
224
225 @Override
226 protected void onUserLeaveHint() {
Sunny Goyal210e1742019-10-17 12:05:38 -0700227 removeActivityFlags(ACTIVITY_STATE_USER_ACTIVE);
Tracy Zhoua706f002018-03-28 13:55:19 -0700228 super.onUserLeaveHint();
229 }
230
231 @Override
Winson Chung1a77c3d2018-04-11 12:47:47 -0700232 public void onMultiWindowModeChanged(boolean isInMultiWindowMode, Configuration newConfig) {
233 super.onMultiWindowModeChanged(isInMultiWindowMode, newConfig);
234 for (int i = mMultiWindowModeChangedListeners.size() - 1; i >= 0; i--) {
235 mMultiWindowModeChangedListeners.get(i).onMultiWindowModeChanged(isInMultiWindowMode);
236 }
237 }
238
239 @Override
Sunny Goyalcc96aa12018-01-11 09:56:07 -0800240 protected void onStop() {
Sunny Goyal210e1742019-10-17 12:05:38 -0700241 removeActivityFlags(ACTIVITY_STATE_STARTED | ACTIVITY_STATE_USER_ACTIVE);
Sunny Goyal7eff40f2018-04-11 15:30:46 -0700242 mForceInvisible = 0;
Sunny Goyalcc96aa12018-01-11 09:56:07 -0800243 super.onStop();
Sunny Goyale82a20a2023-10-19 13:52:49 -0700244 mEventCallbacks[EVENT_STOPPED].executeAllAndClear();
245
Winson Chunga36c8002019-06-11 16:15:54 -0700246
247 // Reset the overridden sysui flags used for the task-swipe launch animation, this is a
248 // catch all for if we do not get resumed (and therefore not paused below)
Tony Wickhamb4821882021-04-23 14:26:45 -0700249 getSystemUiController().updateUiState(UI_STATE_FULLSCREEN_TASK, 0);
Sunny Goyalcc96aa12018-01-11 09:56:07 -0800250 }
251
Sunny Goyal3483c522018-04-12 11:23:33 -0700252 @Override
Sunny Goyale82a20a2023-10-19 13:52:49 -0700253 protected void onDestroy() {
254 super.onDestroy();
255 mEventCallbacks[EVENT_DESTROYED].executeAllAndClear();
256 }
257
258 @Override
Sunny Goyal3483c522018-04-12 11:23:33 -0700259 protected void onPause() {
Mady Mellor9a90c2d2022-09-14 15:17:21 -0700260 setPaused();
Sunny Goyal3483c522018-04-12 11:23:33 -0700261 super.onPause();
Winson Chunga0f09f92018-05-11 21:55:21 +0000262
263 // Reset the overridden sysui flags used for the task-swipe launch animation, we do this
264 // here instead of at the end of the animation because the start of the new activity does
265 // not happen immediately, which would cause us to reset to launcher's sysui flags and then
266 // back to the new app (causing a flash)
Tony Wickhamb4821882021-04-23 14:26:45 -0700267 getSystemUiController().updateUiState(UI_STATE_FULLSCREEN_TASK, 0);
Sunny Goyal3483c522018-04-12 11:23:33 -0700268 }
269
Sunny Goyal210e1742019-10-17 12:05:38 -0700270 @Override
271 public void onWindowFocusChanged(boolean hasFocus) {
272 super.onWindowFocusChanged(hasFocus);
273 if (hasFocus) {
274 addActivityFlags(ACTIVITY_STATE_WINDOW_FOCUSED);
275 } else {
276 removeActivityFlags(ACTIVITY_STATE_WINDOW_FOCUSED);
277 }
Sunny Goyal210e1742019-10-17 12:05:38 -0700278 }
279
Fengjiang Lie884c2c2022-12-19 14:42:14 -0800280 protected void registerBackDispatcher() {
281 if (Utilities.ATLEAST_T) {
282 getOnBackInvokedDispatcher().registerOnBackInvokedCallback(
283 OnBackInvokedDispatcher.PRIORITY_DEFAULT,
284 () -> {
285 onBackPressed();
286 TestLogging.recordEvent(TestProtocol.SEQUENCE_MAIN, "onBackInvoked");
287 });
288 }
289 }
290
Sunny Goyalcc96aa12018-01-11 09:56:07 -0800291 public boolean isStarted() {
Sunny Goyal3483c522018-04-12 11:23:33 -0700292 return (mActivityFlags & ACTIVITY_STATE_STARTED) != 0;
293 }
294
295 /**
296 * isResumed in already defined as a hidden final method in Activity.java
297 */
298 public boolean hasBeenResumed() {
299 return (mActivityFlags & ACTIVITY_STATE_RESUMED) != 0;
Sunny Goyalcc96aa12018-01-11 09:56:07 -0800300 }
Sunny Goyalfde55052018-02-01 14:46:13 -0800301
Mady Mellor9a90c2d2022-09-14 15:17:21 -0700302 /**
303 * Sets the activity to appear as paused.
304 */
305 public void setPaused() {
306 removeActivityFlags(ACTIVITY_STATE_RESUMED | ACTIVITY_STATE_DEFERRED_RESUMED);
307 }
308
309 /**
310 * Sets the activity to appear as resumed.
311 */
312 public void setResumed() {
313 addActivityFlags(ACTIVITY_STATE_RESUMED | ACTIVITY_STATE_USER_ACTIVE);
Mady Mellor9a90c2d2022-09-14 15:17:21 -0700314 }
315
Tracy Zhoua706f002018-03-28 13:55:19 -0700316 public boolean isUserActive() {
Sunny Goyal3483c522018-04-12 11:23:33 -0700317 return (mActivityFlags & ACTIVITY_STATE_USER_ACTIVE) != 0;
Tracy Zhoua706f002018-03-28 13:55:19 -0700318 }
319
Sunny Goyal210e1742019-10-17 12:05:38 -0700320 public int getActivityFlags() {
321 return mActivityFlags;
322 }
323
Mike Schneidera79d4602023-03-03 15:58:06 +0100324 protected void addActivityFlags(int toAdd) {
325 final int oldFlags = mActivityFlags;
326 mActivityFlags |= toAdd;
327 if (DEBUG) {
328 Log.d(TAG, "Launcher flags updated: " + formatFlagChange(mActivityFlags, oldFlags,
329 BaseActivity::getActivityStateString));
330 }
331 onActivityFlagsChanged(toAdd);
Sunny Goyal210e1742019-10-17 12:05:38 -0700332 }
333
Mike Schneidera79d4602023-03-03 15:58:06 +0100334 protected void removeActivityFlags(int toRemove) {
335 final int oldFlags = mActivityFlags;
336 mActivityFlags &= ~toRemove;
337 if (DEBUG) {
338 Log.d(TAG, "Launcher flags updated: " + formatFlagChange(mActivityFlags, oldFlags,
339 BaseActivity::getActivityStateString));
340 }
341
342 onActivityFlagsChanged(toRemove);
Sunny Goyal210e1742019-10-17 12:05:38 -0700343 }
344
Mike Schneidera79d4602023-03-03 15:58:06 +0100345 protected void onActivityFlagsChanged(int changeBits) {
346 }
Sunny Goyal210e1742019-10-17 12:05:38 -0700347
Winson Chung1a77c3d2018-04-11 12:47:47 -0700348 public void addMultiWindowModeChangedListener(MultiWindowModeChangedListener listener) {
349 mMultiWindowModeChangedListeners.add(listener);
350 }
351
352 public void removeMultiWindowModeChangedListener(MultiWindowModeChangedListener listener) {
353 mMultiWindowModeChangedListeners.remove(listener);
354 }
355
Sunny Goyalf633ef52018-03-13 09:57:05 -0700356 /**
Winson Chung9800e732018-04-04 13:33:23 -0700357 * Used to set the override visibility state, used only to handle the transition home with the
358 * recents animation.
Mike Schneidera79d4602023-03-03 15:58:06 +0100359 *
Sunny Goyalb65d7662021-03-07 15:09:11 -0800360 * @see QuickstepTransitionManager#createWallpaperOpenRunner
Winson Chung9800e732018-04-04 13:33:23 -0700361 */
Sunny Goyal7eff40f2018-04-11 15:30:46 -0700362 public void addForceInvisibleFlag(@InvisibilityFlags int flag) {
363 mForceInvisible |= flag;
Winson Chung9800e732018-04-04 13:33:23 -0700364 }
365
Sunny Goyal7eff40f2018-04-11 15:30:46 -0700366 public void clearForceInvisibleFlag(@InvisibilityFlags int flag) {
367 mForceInvisible &= ~flag;
368 }
369
Winson Chung9800e732018-04-04 13:33:23 -0700370 /**
371 * @return Wether this activity should be considered invisible regardless of actual visibility.
372 */
373 public boolean isForceInvisible() {
Sunny Goyal1c63c722018-06-05 16:00:34 -0700374 return hasSomeInvisibleFlag(INVISIBLE_FLAGS);
375 }
376
377 public boolean hasSomeInvisibleFlag(int mask) {
378 return (mForceInvisible & mask) != 0;
Winson Chung9800e732018-04-04 13:33:23 -0700379 }
380
Jon Mirandacb582592023-04-19 15:40:04 -0700381 /**
Sunny Goyale82a20a2023-10-19 13:52:49 -0700382 * Adds a callback for the provided activity event
Jon Mirandacb582592023-04-19 15:40:04 -0700383 */
Sunny Goyale82a20a2023-10-19 13:52:49 -0700384 public void addEventCallback(@ActivityEvent int event, Runnable callback) {
385 mEventCallbacks[event].add(callback);
386 }
387
388 /** Removes a previously added callback */
389 public void removeEventCallback(@ActivityEvent int event, Runnable callback) {
390 mEventCallbacks[event].remove(callback);
Jon Mirandacb582592023-04-19 15:40:04 -0700391 }
392
Winson Chung1a77c3d2018-04-11 12:47:47 -0700393 public interface MultiWindowModeChangedListener {
394 void onMultiWindowModeChanged(boolean isInMultiWindowMode);
395 }
Sunny Goyale43d00d2018-05-14 14:23:18 -0700396
Winson Chungef528762019-09-06 12:05:52 -0700397 protected void dumpMisc(String prefix, PrintWriter writer) {
398 writer.println(prefix + "deviceProfile isTransposed="
399 + getDeviceProfile().isVerticalBarLayout());
400 writer.println(prefix + "orientation=" + getResources().getConfiguration().orientation);
401 writer.println(prefix + "mSystemUiController: " + mSystemUiController);
Mike Schneidera79d4602023-03-03 15:58:06 +0100402 writer.println(prefix + "mActivityFlags: " + getActivityStateString(mActivityFlags));
Winson Chungef528762019-09-06 12:05:52 -0700403 writer.println(prefix + "mForceInvisible: " + mForceInvisible);
Sunny Goyale43d00d2018-05-14 14:23:18 -0700404 }
Sunny Goyal87b5eb62018-07-03 15:53:39 -0700405
406 public static <T extends BaseActivity> T fromContext(Context context) {
407 if (context instanceof BaseActivity) {
408 return (T) context;
Fengjiang Lib2d08452024-04-25 15:51:09 -0700409 } else if (context instanceof ActivityContextDelegate) {
410 return (T) ((ActivityContextDelegate) context).mDelegate;
Tony Wickham1906cc32021-02-11 11:55:24 -0800411 } else if (context instanceof ContextWrapper) {
Sunny Goyal87b5eb62018-07-03 15:53:39 -0700412 return fromContext(((ContextWrapper) context).getBaseContext());
413 } else {
414 throw new IllegalArgumentException("Cannot find BaseActivity in parent tree");
415 }
416 }
Sunny Goyal27835952017-01-13 12:15:53 -0800417}