Sunny Goyal | 0b0847b | 2018-03-14 12:30:11 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 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 | |
Hyunyoung Song | 7f7894e | 2020-04-27 01:12:01 -0700 | [diff] [blame] | 19 | import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_APP_LAUNCH_TAP; |
Sunny Goyal | fd58da6 | 2020-08-11 12:06:49 -0700 | [diff] [blame^] | 20 | import static com.android.launcher3.util.DisplayController.DisplayHolder.CHANGE_ROTATION; |
Sunny Goyal | 9f56a2f | 2020-02-03 14:22:09 -0800 | [diff] [blame] | 21 | |
Sunny Goyal | 0b0847b | 2018-03-14 12:30:11 -0700 | [diff] [blame] | 22 | import android.app.ActivityOptions; |
| 23 | import android.content.ActivityNotFoundException; |
Sunny Goyal | 0b0847b | 2018-03-14 12:30:11 -0700 | [diff] [blame] | 24 | import android.content.Intent; |
Sunny Goyal | e7b0012 | 2019-10-02 16:13:34 -0700 | [diff] [blame] | 25 | import android.content.pm.LauncherApps; |
Lucas Dupin | eca08a1 | 2018-08-11 15:53:40 -0700 | [diff] [blame] | 26 | import android.content.res.Configuration; |
Sunny Goyal | b46703d | 2020-05-27 17:52:03 -0700 | [diff] [blame] | 27 | import android.graphics.Insets; |
Sunny Goyal | 0addbf0 | 2020-04-28 14:17:35 -0700 | [diff] [blame] | 28 | import android.graphics.Point; |
Sunny Goyal | 0b0847b | 2018-03-14 12:30:11 -0700 | [diff] [blame] | 29 | import android.graphics.Rect; |
| 30 | import android.os.Bundle; |
| 31 | import android.os.Process; |
| 32 | import android.os.StrictMode; |
| 33 | import android.os.UserHandle; |
| 34 | import android.util.Log; |
| 35 | import android.view.ActionMode; |
Sunny Goyal | 0addbf0 | 2020-04-28 14:17:35 -0700 | [diff] [blame] | 36 | import android.view.Display; |
Sunny Goyal | 0b0847b | 2018-03-14 12:30:11 -0700 | [diff] [blame] | 37 | import android.view.View; |
Sunny Goyal | 9c2b960 | 2020-01-07 13:07:55 -0800 | [diff] [blame] | 38 | import android.view.View.OnClickListener; |
Sunny Goyal | b46703d | 2020-05-27 17:52:03 -0700 | [diff] [blame] | 39 | import android.view.WindowInsets.Type; |
| 40 | import android.view.WindowMetrics; |
Sunny Goyal | 0b0847b | 2018-03-14 12:30:11 -0700 | [diff] [blame] | 41 | import android.widget.Toast; |
| 42 | |
Winson Chung | 13c1c2c | 2019-09-06 11:46:19 -0700 | [diff] [blame] | 43 | import androidx.annotation.Nullable; |
| 44 | |
Winson Chung | 3f8d868 | 2020-08-04 14:01:27 -0700 | [diff] [blame] | 45 | import com.android.launcher3.Launcher.OnResumeCallback; |
Sunny Goyal | 0b0847b | 2018-03-14 12:30:11 -0700 | [diff] [blame] | 46 | import com.android.launcher3.LauncherSettings.Favorites; |
Samuel Fufa | e9c4f40 | 2020-06-14 22:39:51 -0700 | [diff] [blame] | 47 | import com.android.launcher3.logging.InstanceId; |
| 48 | import com.android.launcher3.logging.InstanceIdSequence; |
Sunny Goyal | e396abf | 2020-04-06 15:11:17 -0700 | [diff] [blame] | 49 | import com.android.launcher3.model.data.ItemInfo; |
| 50 | import com.android.launcher3.model.data.WorkspaceItemInfo; |
Sunny Goyal | 9c2b960 | 2020-01-07 13:07:55 -0800 | [diff] [blame] | 51 | import com.android.launcher3.touch.ItemClickHandler; |
Sunny Goyal | 18c699f | 2018-05-03 16:58:41 -0700 | [diff] [blame] | 52 | import com.android.launcher3.uioverrides.WallpaperColorInfo; |
Sunny Goyal | fd58da6 | 2020-08-11 12:06:49 -0700 | [diff] [blame^] | 53 | import com.android.launcher3.util.DisplayController; |
| 54 | import com.android.launcher3.util.DisplayController.DisplayInfoChangeListener; |
| 55 | import com.android.launcher3.util.DisplayController.Info; |
Sunny Goyal | 9dbb27c | 2019-07-17 15:12:56 -0700 | [diff] [blame] | 56 | import com.android.launcher3.util.PackageManagerHelper; |
Hyunyoung Song | fcd090d | 2019-05-01 13:15:29 -0700 | [diff] [blame] | 57 | import com.android.launcher3.util.Themes; |
Sunny Goyal | 17c72fb | 2019-10-14 14:06:38 -0700 | [diff] [blame] | 58 | import com.android.launcher3.util.TraceHelper; |
Sunny Goyal | b46703d | 2020-05-27 17:52:03 -0700 | [diff] [blame] | 59 | import com.android.launcher3.util.WindowBounds; |
Sunny Goyal | 0b0847b | 2018-03-14 12:30:11 -0700 | [diff] [blame] | 60 | |
| 61 | /** |
| 62 | * Extension of BaseActivity allowing support for drag-n-drop |
| 63 | */ |
Sunny Goyal | ab83773 | 2018-03-27 17:35:54 -0700 | [diff] [blame] | 64 | public abstract class BaseDraggingActivity extends BaseActivity |
Sunny Goyal | 9f56a2f | 2020-02-03 14:22:09 -0800 | [diff] [blame] | 65 | implements WallpaperColorInfo.OnChangeListener, DisplayInfoChangeListener { |
Sunny Goyal | 0b0847b | 2018-03-14 12:30:11 -0700 | [diff] [blame] | 66 | |
| 67 | private static final String TAG = "BaseDraggingActivity"; |
| 68 | |
Sunny Goyal | 0b0847b | 2018-03-14 12:30:11 -0700 | [diff] [blame] | 69 | // When starting an action mode, setting this tag will cause the action mode to be cancelled |
| 70 | // automatically when user interacts with the launcher. |
| 71 | public static final Object AUTO_CANCEL_ACTION_MODE = new Object(); |
| 72 | |
| 73 | private ActionMode mCurrentActionMode; |
| 74 | protected boolean mIsSafeModeEnabled; |
| 75 | |
Winson Chung | a19a2b7 | 2019-10-14 16:30:38 -0700 | [diff] [blame] | 76 | private Runnable mOnStartCallback; |
Sunny Goyal | 9d69c8d | 2018-03-19 13:41:31 -0700 | [diff] [blame] | 77 | |
Sunny Goyal | bd88f39 | 2018-06-07 15:42:57 -0700 | [diff] [blame] | 78 | private int mThemeRes = R.style.AppTheme; |
Sunny Goyal | ab83773 | 2018-03-27 17:35:54 -0700 | [diff] [blame] | 79 | |
Sunny Goyal | 0b0847b | 2018-03-14 12:30:11 -0700 | [diff] [blame] | 80 | @Override |
| 81 | protected void onCreate(Bundle savedInstanceState) { |
| 82 | super.onCreate(savedInstanceState); |
Sunny Goyal | 17c72fb | 2019-10-14 14:06:38 -0700 | [diff] [blame] | 83 | |
| 84 | |
Sunny Goyal | 5d09b2e | 2020-07-09 12:21:40 -0700 | [diff] [blame] | 85 | mIsSafeModeEnabled = TraceHelper.allowIpcs("isSafeMode", |
Sunny Goyal | 17c72fb | 2019-10-14 14:06:38 -0700 | [diff] [blame] | 86 | () -> getPackageManager().isSafeMode()); |
Sunny Goyal | fd58da6 | 2020-08-11 12:06:49 -0700 | [diff] [blame^] | 87 | DisplayController.getDefaultDisplay(this).addChangeListener(this); |
Sunny Goyal | ab83773 | 2018-03-27 17:35:54 -0700 | [diff] [blame] | 88 | |
| 89 | // Update theme |
Sunny Goyal | 73b5a27 | 2019-12-09 14:55:56 -0800 | [diff] [blame] | 90 | WallpaperColorInfo.INSTANCE.get(this).addOnChangeListener(this); |
Hyunyoung Song | fcd090d | 2019-05-01 13:15:29 -0700 | [diff] [blame] | 91 | int themeRes = Themes.getActivityThemeRes(this); |
Sunny Goyal | ab83773 | 2018-03-27 17:35:54 -0700 | [diff] [blame] | 92 | if (themeRes != mThemeRes) { |
| 93 | mThemeRes = themeRes; |
| 94 | setTheme(themeRes); |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | @Override |
| 99 | public void onExtractedColorsChanged(WallpaperColorInfo wallpaperColorInfo) { |
Lucas Dupin | eca08a1 | 2018-08-11 15:53:40 -0700 | [diff] [blame] | 100 | updateTheme(); |
| 101 | } |
| 102 | |
| 103 | @Override |
| 104 | public void onConfigurationChanged(Configuration newConfig) { |
| 105 | super.onConfigurationChanged(newConfig); |
| 106 | updateTheme(); |
| 107 | } |
| 108 | |
| 109 | private void updateTheme() { |
Hyunyoung Song | fcd090d | 2019-05-01 13:15:29 -0700 | [diff] [blame] | 110 | if (mThemeRes != Themes.getActivityThemeRes(this)) { |
Winson Chung | 3f8d868 | 2020-08-04 14:01:27 -0700 | [diff] [blame] | 111 | // Workaround (b/162812884): The system currently doesn't allow recreating an activity |
| 112 | // when it is not resumed, in such a case defer recreation until it is possible |
| 113 | if (hasBeenResumed()) { |
| 114 | recreate(); |
| 115 | } else { |
| 116 | addOnResumeCallback(this::recreate); |
| 117 | } |
Sunny Goyal | ab83773 | 2018-03-27 17:35:54 -0700 | [diff] [blame] | 118 | } |
| 119 | } |
| 120 | |
Winson Chung | 3f8d868 | 2020-08-04 14:01:27 -0700 | [diff] [blame] | 121 | protected void addOnResumeCallback(OnResumeCallback callback) { |
| 122 | // To be overridden |
| 123 | } |
| 124 | |
Sunny Goyal | 0b0847b | 2018-03-14 12:30:11 -0700 | [diff] [blame] | 125 | @Override |
| 126 | public void onActionModeStarted(ActionMode mode) { |
| 127 | super.onActionModeStarted(mode); |
| 128 | mCurrentActionMode = mode; |
| 129 | } |
| 130 | |
| 131 | @Override |
| 132 | public void onActionModeFinished(ActionMode mode) { |
| 133 | super.onActionModeFinished(mode); |
| 134 | mCurrentActionMode = null; |
| 135 | } |
| 136 | |
Sunny Goyal | 87b5eb6 | 2018-07-03 15:53:39 -0700 | [diff] [blame] | 137 | @Override |
Sunny Goyal | 0b0847b | 2018-03-14 12:30:11 -0700 | [diff] [blame] | 138 | public boolean finishAutoCancelActionMode() { |
| 139 | if (mCurrentActionMode != null && AUTO_CANCEL_ACTION_MODE == mCurrentActionMode.getTag()) { |
| 140 | mCurrentActionMode.finish(); |
| 141 | return true; |
| 142 | } |
| 143 | return false; |
| 144 | } |
| 145 | |
Sunny Goyal | 0b0847b | 2018-03-14 12:30:11 -0700 | [diff] [blame] | 146 | public abstract <T extends View> T getOverviewPanel(); |
| 147 | |
Sunny Goyal | 9d69c8d | 2018-03-19 13:41:31 -0700 | [diff] [blame] | 148 | public abstract View getRootView(); |
| 149 | |
Vinit Nayak | f9b585b | 2019-07-10 14:25:32 -0700 | [diff] [blame] | 150 | public void returnToHomescreen() { |
| 151 | // no-op |
| 152 | } |
| 153 | |
Sunny Goyal | 0b0847b | 2018-03-14 12:30:11 -0700 | [diff] [blame] | 154 | public Rect getViewBounds(View v) { |
| 155 | int[] pos = new int[2]; |
| 156 | v.getLocationOnScreen(pos); |
| 157 | return new Rect(pos[0], pos[1], pos[0] + v.getWidth(), pos[1] + v.getHeight()); |
| 158 | } |
| 159 | |
Jon Miranda | 73c27ec | 2018-05-16 18:06:23 -0700 | [diff] [blame] | 160 | public final Bundle getActivityLaunchOptionsAsBundle(View v) { |
| 161 | ActivityOptions activityOptions = getActivityLaunchOptions(v); |
Sunny Goyal | 0b0847b | 2018-03-14 12:30:11 -0700 | [diff] [blame] | 162 | return activityOptions == null ? null : activityOptions.toBundle(); |
| 163 | } |
| 164 | |
Jon Miranda | 73c27ec | 2018-05-16 18:06:23 -0700 | [diff] [blame] | 165 | public abstract ActivityOptions getActivityLaunchOptions(View v); |
Sunny Goyal | 0b0847b | 2018-03-14 12:30:11 -0700 | [diff] [blame] | 166 | |
Sunny Goyal | 852537f | 2020-07-15 17:02:16 -0700 | [diff] [blame] | 167 | public boolean startActivitySafely(View v, Intent intent, @Nullable ItemInfo item) { |
Sunny Goyal | 9dbb27c | 2019-07-17 15:12:56 -0700 | [diff] [blame] | 168 | if (mIsSafeModeEnabled && !PackageManagerHelper.isSystemApp(this, intent)) { |
Sunny Goyal | 0b0847b | 2018-03-14 12:30:11 -0700 | [diff] [blame] | 169 | Toast.makeText(this, R.string.safemode_shortcut_error, Toast.LENGTH_SHORT).show(); |
| 170 | return false; |
| 171 | } |
| 172 | |
Sunny Goyal | 9018627 | 2019-01-31 12:37:41 -0800 | [diff] [blame] | 173 | Bundle optsBundle = (v != null) ? getActivityLaunchOptionsAsBundle(v) : null; |
Sunny Goyal | 0b0847b | 2018-03-14 12:30:11 -0700 | [diff] [blame] | 174 | UserHandle user = item == null ? null : item.user; |
| 175 | |
| 176 | // Prepare intent |
| 177 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 178 | if (v != null) { |
| 179 | intent.setSourceBounds(getViewBounds(v)); |
| 180 | } |
| 181 | try { |
Sunny Goyal | 9589916 | 2019-03-27 16:03:06 -0700 | [diff] [blame] | 182 | boolean isShortcut = (item instanceof WorkspaceItemInfo) |
Sunny Goyal | 0b0847b | 2018-03-14 12:30:11 -0700 | [diff] [blame] | 183 | && (item.itemType == Favorites.ITEM_TYPE_SHORTCUT |
| 184 | || item.itemType == Favorites.ITEM_TYPE_DEEP_SHORTCUT) |
Sunny Goyal | 9589916 | 2019-03-27 16:03:06 -0700 | [diff] [blame] | 185 | && !((WorkspaceItemInfo) item).isPromise(); |
Sunny Goyal | 0b0847b | 2018-03-14 12:30:11 -0700 | [diff] [blame] | 186 | if (isShortcut) { |
| 187 | // Shortcuts need some special checks due to legacy reasons. |
Sunny Goyal | 852537f | 2020-07-15 17:02:16 -0700 | [diff] [blame] | 188 | startShortcutIntentSafely(intent, optsBundle, item); |
Sunny Goyal | 0b0847b | 2018-03-14 12:30:11 -0700 | [diff] [blame] | 189 | } else if (user == null || user.equals(Process.myUserHandle())) { |
| 190 | // Could be launching some bookkeeping activity |
| 191 | startActivity(intent, optsBundle); |
| 192 | } else { |
Sunny Goyal | e7b0012 | 2019-10-02 16:13:34 -0700 | [diff] [blame] | 193 | getSystemService(LauncherApps.class).startMainActivity( |
Sunny Goyal | 0b0847b | 2018-03-14 12:30:11 -0700 | [diff] [blame] | 194 | intent.getComponent(), user, intent.getSourceBounds(), optsBundle); |
| 195 | } |
Samuel Fufa | 78e7e5f | 2019-12-10 13:23:51 -0800 | [diff] [blame] | 196 | getUserEventDispatcher().logAppLaunch(v, intent, user); |
Hyunyoung Song | f26c793 | 2020-06-06 14:44:27 -0700 | [diff] [blame] | 197 | if (item != null) { |
Samuel Fufa | e9c4f40 | 2020-06-14 22:39:51 -0700 | [diff] [blame] | 198 | InstanceId instanceId = new InstanceIdSequence().newInstanceId(); |
| 199 | logAppLaunch(item, instanceId); |
Hyunyoung Song | f26c793 | 2020-06-06 14:44:27 -0700 | [diff] [blame] | 200 | } |
Sunny Goyal | 0b0847b | 2018-03-14 12:30:11 -0700 | [diff] [blame] | 201 | return true; |
Jon Miranda | 0121d46 | 2019-08-01 15:44:55 -0700 | [diff] [blame] | 202 | } catch (NullPointerException|ActivityNotFoundException|SecurityException e) { |
Sunny Goyal | 0b0847b | 2018-03-14 12:30:11 -0700 | [diff] [blame] | 203 | Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show(); |
| 204 | Log.e(TAG, "Unable to launch. tag=" + item + " intent=" + intent, e); |
| 205 | } |
| 206 | return false; |
| 207 | } |
| 208 | |
Samuel Fufa | e9c4f40 | 2020-06-14 22:39:51 -0700 | [diff] [blame] | 209 | protected void logAppLaunch(ItemInfo info, InstanceId instanceId) { |
thiruram | c6a38ba | 2020-06-16 18:58:13 -0700 | [diff] [blame] | 210 | getStatsLogManager().logger().withItemInfo(info).withInstanceId(instanceId) |
| 211 | .log(LAUNCHER_APP_LAUNCH_TAP); |
Samuel Fufa | e9c4f40 | 2020-06-14 22:39:51 -0700 | [diff] [blame] | 212 | } |
| 213 | |
Sunny Goyal | 852537f | 2020-07-15 17:02:16 -0700 | [diff] [blame] | 214 | private void startShortcutIntentSafely(Intent intent, Bundle optsBundle, ItemInfo info) { |
Sunny Goyal | 0b0847b | 2018-03-14 12:30:11 -0700 | [diff] [blame] | 215 | try { |
| 216 | StrictMode.VmPolicy oldPolicy = StrictMode.getVmPolicy(); |
| 217 | try { |
| 218 | // Temporarily disable deathPenalty on all default checks. For eg, shortcuts |
| 219 | // containing file Uri's would cause a crash as penaltyDeathOnFileUriExposure |
| 220 | // is enabled by default on NYC. |
| 221 | StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectAll() |
| 222 | .penaltyLog().build()); |
| 223 | |
| 224 | if (info.itemType == LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT) { |
Sunny Goyal | 9589916 | 2019-03-27 16:03:06 -0700 | [diff] [blame] | 225 | String id = ((WorkspaceItemInfo) info).getDeepShortcutId(); |
Sunny Goyal | 0b0847b | 2018-03-14 12:30:11 -0700 | [diff] [blame] | 226 | String packageName = intent.getPackage(); |
Sunny Goyal | fa39536 | 2019-12-11 10:00:47 -0800 | [diff] [blame] | 227 | startShortcut(packageName, id, intent.getSourceBounds(), optsBundle, info.user); |
Sunny Goyal | 0b0847b | 2018-03-14 12:30:11 -0700 | [diff] [blame] | 228 | } else { |
| 229 | // Could be launching some bookkeeping activity |
| 230 | startActivity(intent, optsBundle); |
| 231 | } |
| 232 | } finally { |
| 233 | StrictMode.setVmPolicy(oldPolicy); |
| 234 | } |
| 235 | } catch (SecurityException e) { |
| 236 | if (!onErrorStartingShortcut(intent, info)) { |
| 237 | throw e; |
| 238 | } |
| 239 | } |
| 240 | } |
| 241 | |
| 242 | protected boolean onErrorStartingShortcut(Intent intent, ItemInfo info) { |
| 243 | return false; |
| 244 | } |
Sunny Goyal | 9d69c8d | 2018-03-19 13:41:31 -0700 | [diff] [blame] | 245 | |
| 246 | @Override |
| 247 | protected void onStart() { |
| 248 | super.onStart(); |
| 249 | |
| 250 | if (mOnStartCallback != null) { |
Winson Chung | a19a2b7 | 2019-10-14 16:30:38 -0700 | [diff] [blame] | 251 | mOnStartCallback.run(); |
Sunny Goyal | 9d69c8d | 2018-03-19 13:41:31 -0700 | [diff] [blame] | 252 | mOnStartCallback = null; |
| 253 | } |
| 254 | } |
| 255 | |
Sunny Goyal | ab83773 | 2018-03-27 17:35:54 -0700 | [diff] [blame] | 256 | @Override |
| 257 | protected void onDestroy() { |
| 258 | super.onDestroy(); |
Sunny Goyal | 73b5a27 | 2019-12-09 14:55:56 -0800 | [diff] [blame] | 259 | WallpaperColorInfo.INSTANCE.get(this).removeOnChangeListener(this); |
Sunny Goyal | fd58da6 | 2020-08-11 12:06:49 -0700 | [diff] [blame^] | 260 | DisplayController.getDefaultDisplay(this).removeChangeListener(this); |
Sunny Goyal | ab83773 | 2018-03-27 17:35:54 -0700 | [diff] [blame] | 261 | } |
| 262 | |
Winson Chung | a19a2b7 | 2019-10-14 16:30:38 -0700 | [diff] [blame] | 263 | public void runOnceOnStart(Runnable action) { |
| 264 | mOnStartCallback = action; |
| 265 | } |
| 266 | |
| 267 | public void clearRunOnceOnStartCallback() { |
| 268 | mOnStartCallback = null; |
Sunny Goyal | 9d69c8d | 2018-03-19 13:41:31 -0700 | [diff] [blame] | 269 | } |
| 270 | |
Sunny Goyal | 59d086c | 2018-05-07 17:31:40 -0700 | [diff] [blame] | 271 | protected void onDeviceProfileInitiated() { |
| 272 | if (mDeviceProfile.isVerticalBarLayout()) { |
Winson Chung | 13c1c2c | 2019-09-06 11:46:19 -0700 | [diff] [blame] | 273 | mDeviceProfile.updateIsSeascape(this); |
Sunny Goyal | 59d086c | 2018-05-07 17:31:40 -0700 | [diff] [blame] | 274 | } |
| 275 | } |
| 276 | |
Sunny Goyal | 9f56a2f | 2020-02-03 14:22:09 -0800 | [diff] [blame] | 277 | @Override |
| 278 | public void onDisplayInfoChanged(Info info, int flags) { |
| 279 | if ((flags & CHANGE_ROTATION) != 0 && mDeviceProfile.updateIsSeascape(this)) { |
Sunny Goyal | 59d086c | 2018-05-07 17:31:40 -0700 | [diff] [blame] | 280 | reapplyUi(); |
| 281 | } |
| 282 | } |
| 283 | |
Sunny Goyal | 9c2b960 | 2020-01-07 13:07:55 -0800 | [diff] [blame] | 284 | public OnClickListener getItemOnClickListener() { |
| 285 | return ItemClickHandler.INSTANCE; |
| 286 | } |
| 287 | |
Sunny Goyal | 59d086c | 2018-05-07 17:31:40 -0700 | [diff] [blame] | 288 | protected abstract void reapplyUi(); |
Sunny Goyal | 0addbf0 | 2020-04-28 14:17:35 -0700 | [diff] [blame] | 289 | |
Sunny Goyal | b46703d | 2020-05-27 17:52:03 -0700 | [diff] [blame] | 290 | protected WindowBounds getMultiWindowDisplaySize() { |
Sunny Goyal | 0addbf0 | 2020-04-28 14:17:35 -0700 | [diff] [blame] | 291 | if (Utilities.ATLEAST_R) { |
Sunny Goyal | b46703d | 2020-05-27 17:52:03 -0700 | [diff] [blame] | 292 | WindowMetrics wm = getWindowManager().getCurrentWindowMetrics(); |
| 293 | |
| 294 | Insets insets = wm.getWindowInsets().getInsets(Type.systemBars()); |
| 295 | return new WindowBounds(wm.getBounds(), |
| 296 | new Rect(insets.left, insets.top, insets.right, insets.bottom)); |
Sunny Goyal | 0addbf0 | 2020-04-28 14:17:35 -0700 | [diff] [blame] | 297 | } |
| 298 | // Note: Calls to getSize() can't rely on our cached DefaultDisplay since it can return |
| 299 | // the app window size |
| 300 | Display display = getWindowManager().getDefaultDisplay(); |
| 301 | Point mwSize = new Point(); |
| 302 | display.getSize(mwSize); |
Sunny Goyal | b46703d | 2020-05-27 17:52:03 -0700 | [diff] [blame] | 303 | return new WindowBounds(new Rect(0, 0, mwSize.x, mwSize.y), new Rect()); |
Sunny Goyal | 0addbf0 | 2020-04-28 14:17:35 -0700 | [diff] [blame] | 304 | } |
Sunny Goyal | 0b0847b | 2018-03-14 12:30:11 -0700 | [diff] [blame] | 305 | } |