blob: 8066d383d1ac1ec3d7446693a1b4b96ca5f3f148 [file] [log] [blame]
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001/*
2 * Copyright (C) 2008 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
Daniel Sandler325dc232013-06-05 22:57:57 -040017package com.android.launcher3;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080018
Sunny Goyalf8d56fc2018-01-31 15:18:11 -080019import static android.content.pm.ActivityInfo.CONFIG_ORIENTATION;
20import static android.content.pm.ActivityInfo.CONFIG_SCREEN_SIZE;
vadimt00d42552018-12-11 17:59:36 -080021
Pinyao Tinga74b63a2019-07-17 23:26:06 -070022import static com.android.launcher3.AbstractFloatingView.TYPE_ALL;
23import static com.android.launcher3.AbstractFloatingView.TYPE_REBIND_SAFE;
Tony Wickham6a71a5b2018-08-21 11:40:23 -070024import static com.android.launcher3.AbstractFloatingView.TYPE_SNACKBAR;
Sunny Goyal4c7f2152017-10-17 17:17:16 -070025import static com.android.launcher3.LauncherAnimUtils.SPRING_LOADED_EXIT_DELAY;
Sunny Goyal3e3f44c2017-10-23 17:14:52 -070026import static com.android.launcher3.LauncherState.ALL_APPS;
27import static com.android.launcher3.LauncherState.NORMAL;
Govinda Wassermanc06e1512019-04-09 09:56:53 -040028import static com.android.launcher3.LauncherState.OVERVIEW;
29import static com.android.launcher3.LauncherState.OVERVIEW_PEEK;
Sunny Goyalb1d7de22019-09-06 10:36:54 -070030import static com.android.launcher3.Utilities.postAsyncCallback;
Sunny Goyal6001ea22018-05-10 16:31:00 -070031import static com.android.launcher3.dragndrop.DragLayer.ALPHA_INDEX_LAUNCHER_LOAD;
Sunny Goyalaeb16432017-10-16 11:46:41 -070032import static com.android.launcher3.logging.LoggerUtils.newContainerTarget;
Hyunyoung Song46d07f72018-05-22 15:41:25 -070033import static com.android.launcher3.logging.LoggerUtils.newTarget;
Sunny Goyal3a1eadd2019-10-23 17:44:27 -070034import static com.android.launcher3.popup.SystemShortcut.APP_INFO;
35import static com.android.launcher3.popup.SystemShortcut.DISMISS_PREDICTION;
36import static com.android.launcher3.popup.SystemShortcut.INSTALL;
37import static com.android.launcher3.popup.SystemShortcut.WIDGETS;
Sunny Goyalbe8c3402019-05-22 15:17:52 -070038import static com.android.launcher3.states.RotationHelper.REQUEST_NONE;
Sunny Goyal326403e2017-10-02 12:45:10 -070039
Gilles Debunnedd6c9922010-10-25 11:23:41 -070040import android.animation.Animator;
Sunny Goyal6001ea22018-05-10 16:31:00 -070041import android.animation.AnimatorListenerAdapter;
Gilles Debunnedd6c9922010-10-25 11:23:41 -070042import android.animation.AnimatorSet;
Sunny Goyal6001ea22018-05-10 16:31:00 -070043import android.animation.ObjectAnimator;
Gilles Debunnedd6c9922010-10-25 11:23:41 -070044import android.animation.ValueAnimator;
Adam Cohen0b395352014-06-09 22:54:36 +000045import android.annotation.TargetApi;
Tony Wickham005df0b2018-02-13 11:28:12 -080046import android.app.ActivityOptions;
Adam Cohen0cf2a7c2011-11-08 15:07:01 -080047import android.appwidget.AppWidgetHostView;
Michael Jurkaaf442092010-06-10 17:01:57 -070048import android.appwidget.AppWidgetManager;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080049import android.content.ActivityNotFoundException;
Joe Onorato2ca0ae72009-11-10 13:14:13 -080050import android.content.BroadcastReceiver;
Michael Jurkae326f182011-11-21 14:05:46 -080051import android.content.ComponentCallbacks2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080052import android.content.Context;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080053import android.content.Intent;
Winson Chungf0ea4d32011-06-06 14:27:16 -070054import android.content.IntentFilter;
Adam Cohen173f7112015-03-27 15:14:00 -070055import android.content.IntentSender;
Winson Chung82f55532011-08-09 14:14:23 -070056import android.content.SharedPreferences;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080057import android.content.pm.PackageManager;
Sunny Goyalf8d56fc2018-01-31 15:18:11 -080058import android.content.res.Configuration;
Adam Cohen3f9c9712014-10-31 11:48:25 -070059import android.database.sqlite.SQLiteDatabase;
Sunny Goyal59d086c2018-05-07 17:31:40 -070060import android.graphics.Point;
Sunny Goyalae6e3182019-04-30 12:04:37 -070061import android.graphics.Rect;
Adam Cohen0f668f32014-09-08 19:54:17 +020062import android.os.Build;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080063import android.os.Bundle;
Sunny Goyal210e1742019-10-17 12:05:38 -070064import android.os.CancellationSignal;
Hyunyoung Songbd6fba92018-05-16 15:54:31 -070065import android.os.Handler;
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -070066import android.os.Parcelable;
Sunny Goyal7c74e4a2016-12-15 15:53:17 -080067import android.os.Process;
Winson Chunga2413752012-04-03 14:22:34 -070068import android.os.StrictMode;
Michael Jurkaa33411c2012-06-14 16:18:21 -070069import android.text.TextUtils;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080070import android.text.method.TextKeyListener;
Joe Onorato7c312c12009-08-13 21:36:53 -070071import android.util.Log;
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -070072import android.util.SparseArray;
Sunny Goyal59d086c2018-05-07 17:31:40 -070073import android.view.Display;
Adam Cohen96d30a12013-07-16 18:13:21 -070074import android.view.KeyEvent;
Sunny Goyal66b24572016-09-21 15:57:55 -070075import android.view.KeyboardShortcutGroup;
76import android.view.KeyboardShortcutInfo;
Sunny Goyal9b29ca52017-02-17 10:39:44 -080077import android.view.LayoutInflater;
Adam Cohen96d30a12013-07-16 18:13:21 -070078import android.view.Menu;
Adam Cohen96d30a12013-07-16 18:13:21 -070079import android.view.View;
Adam Cohen96d30a12013-07-16 18:13:21 -070080import android.view.ViewGroup;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -080081import android.view.accessibility.AccessibilityEvent;
Sunny Goyal5a1f53b2015-05-27 10:24:24 -070082import android.view.animation.OvershootInterpolator;
Adam Cohen96d30a12013-07-16 18:13:21 -070083import android.widget.Toast;
Sunny Goyala1d1bf32015-06-26 13:24:53 -070084
Sunny Goyal11a50742019-08-07 09:24:26 -070085import androidx.annotation.Nullable;
Pinyao Tingc9074272019-11-11 11:51:44 -080086import androidx.annotation.StringRes;
Sunny Goyalb1d7de22019-09-06 10:36:54 -070087import androidx.annotation.VisibleForTesting;
Sunny Goyal11a50742019-08-07 09:24:26 -070088
Sunny Goyal651077b2014-06-30 14:15:31 -070089import com.android.launcher3.DropTarget.DragObject;
Sunny Goyal210e1742019-10-17 12:05:38 -070090import com.android.launcher3.LauncherState.ScaleAndTranslation;
91import com.android.launcher3.LauncherStateManager.StateHandler;
Sunny Goyalae502842016-06-17 08:43:56 -070092import com.android.launcher3.accessibility.LauncherAccessibilityDelegate;
Winson Chung5f4e0fd2015-05-22 11:12:27 -070093import com.android.launcher3.allapps.AllAppsContainerView;
vadimtd4c90e12019-06-04 13:59:43 -070094import com.android.launcher3.allapps.AllAppsStore;
Hyunyoung Song645764e2016-06-06 14:19:02 -070095import com.android.launcher3.allapps.AllAppsTransitionController;
Sunny Goyal7ede6112017-12-05 15:11:21 -080096import com.android.launcher3.allapps.DiscoveryBounce;
Sunny Goyalf0b6db72018-08-13 16:10:14 -070097import com.android.launcher3.anim.PropertyListBuilder;
Tony Wickhame0c33232016-02-08 11:37:04 -080098import com.android.launcher3.config.FeatureFlags;
vadimt00d42552018-12-11 17:59:36 -080099import com.android.launcher3.dot.DotInfo;
Vadim Tryshevfedca432015-08-19 17:55:02 -0700100import com.android.launcher3.dragndrop.DragController;
101import com.android.launcher3.dragndrop.DragLayer;
102import com.android.launcher3.dragndrop.DragView;
Sunny Goyal11a50742019-08-07 09:24:26 -0700103import com.android.launcher3.folder.FolderGridOrganizer;
Sunny Goyal26119432016-02-18 22:09:23 +0000104import com.android.launcher3.folder.FolderIcon;
Hyunyoung Song4c746202019-10-10 23:11:12 -0700105import com.android.launcher3.folder.FolderNameProvider;
Sunny Goyalae6e3182019-04-30 12:04:37 -0700106import com.android.launcher3.graphics.RotationMode;
Sunny Goyalf840f102018-09-21 14:41:05 -0700107import com.android.launcher3.icons.IconCache;
Sunny Goyal66b24572016-09-21 15:57:55 -0700108import com.android.launcher3.keyboard.CustomActionsPopup;
Sunny Goyal3333b0c2016-05-09 20:43:21 -0700109import com.android.launcher3.keyboard.ViewGroupFocusHelper;
Sunny Goyala7ce1662016-05-31 15:01:35 -0700110import com.android.launcher3.logging.FileLog;
Hyunyoung Songfc007472018-10-25 14:09:50 -0700111import com.android.launcher3.logging.StatsLogUtils;
Hyunyoung Songaa953652016-04-19 18:30:24 -0700112import com.android.launcher3.logging.UserEventDispatcher;
Hyunyoung Song46d07f72018-05-22 15:41:25 -0700113import com.android.launcher3.logging.UserEventDispatcher.UserEventDelegate;
Sunny Goyal369212a2019-03-26 15:03:57 -0700114import com.android.launcher3.model.AppLaunchTracker;
Sunny Goyal87dcde62019-07-17 20:35:56 -0700115import com.android.launcher3.model.BgDataModel.Callbacks;
Sunny Goyala535ae42017-02-27 10:07:13 -0800116import com.android.launcher3.model.ModelWriter;
Sunny Goyala535ae42017-02-27 10:07:13 -0800117import com.android.launcher3.notification.NotificationListener;
Sunny Goyale7b00122019-10-02 16:13:34 -0700118import com.android.launcher3.pm.PinRequestHelper;
Tony Wickham540913e2017-01-23 11:47:51 -0800119import com.android.launcher3.popup.PopupContainerWithArrow;
Sunny Goyala535ae42017-02-27 10:07:13 -0800120import com.android.launcher3.popup.PopupDataProvider;
Sunny Goyal3a1eadd2019-10-23 17:44:27 -0700121import com.android.launcher3.popup.SystemShortcut;
Samuel Fufaca37b8a2019-08-19 17:04:36 -0700122import com.android.launcher3.qsb.QsbContainerView;
Sunny Goyal623eddd2018-03-02 12:24:41 -0800123import com.android.launcher3.states.RotationHelper;
vadimtbc5d7e62019-12-09 13:53:05 -0800124import com.android.launcher3.testing.TestProtocol;
Sunny Goyal210e1742019-10-17 12:05:38 -0700125import com.android.launcher3.touch.AllAppsSwipeController;
Sunny Goyal8a2a63b2018-03-06 22:15:18 -0800126import com.android.launcher3.touch.ItemClickHandler;
Sunny Goyalb1d7de22019-09-06 10:36:54 -0700127import com.android.launcher3.uioverrides.plugins.PluginManagerWrapper;
Hyunyoung Song46d07f72018-05-22 15:41:25 -0700128import com.android.launcher3.userevent.nano.LauncherLogProto;
Sunny Goyal6c46a6d2016-11-23 02:24:32 +0530129import com.android.launcher3.userevent.nano.LauncherLogProto.Action;
130import com.android.launcher3.userevent.nano.LauncherLogProto.ContainerType;
Sunny Goyalaeb16432017-10-16 11:46:41 -0700131import com.android.launcher3.userevent.nano.LauncherLogProto.Target;
Sunny Goyal2100c782016-08-22 16:00:03 -0700132import com.android.launcher3.util.ActivityResultInfo;
Sunny Goyale84c5b82019-09-26 17:05:31 -0700133import com.android.launcher3.util.ActivityTracker;
Winson Chung6b1c73f2015-06-18 11:38:42 -0700134import com.android.launcher3.util.ComponentKey;
Sunny Goyalefb7e842018-10-04 15:11:00 -0700135import com.android.launcher3.util.IntArray;
Sunny Goyald3b87ef2016-07-28 12:11:54 -0700136import com.android.launcher3.util.ItemInfoMatcher;
Sunny Goyal6001ea22018-05-10 16:31:00 -0700137import com.android.launcher3.util.MultiValueAlpha;
138import com.android.launcher3.util.MultiValueAlpha.AlphaProperty;
Sunny Goyal04cc3a72016-05-17 10:32:43 -0700139import com.android.launcher3.util.PackageManagerHelper;
Tony Wickham010d2552017-01-20 08:15:28 -0800140import com.android.launcher3.util.PackageUserKey;
Sunny Goyal2100c782016-08-22 16:00:03 -0700141import com.android.launcher3.util.PendingRequestArgs;
Pinyao Ting49a3e692019-07-26 12:28:38 -0700142import com.android.launcher3.util.ShortcutUtil;
Sunny Goyal8392c822017-06-20 10:03:56 -0700143import com.android.launcher3.util.SystemUiController;
Mario Bertschlera6936942017-05-31 14:48:19 -0700144import com.android.launcher3.util.Themes;
Adam Cohen091440a2015-03-18 14:16:05 -0700145import com.android.launcher3.util.Thunk;
Sunny Goyal210e1742019-10-17 12:05:38 -0700146import com.android.launcher3.util.TouchController;
Sunny Goyalfca6bc92017-09-28 16:28:34 -0700147import com.android.launcher3.util.TraceHelper;
Sunny Goyal326403e2017-10-02 12:45:10 -0700148import com.android.launcher3.util.UiThreadHelper;
Sunny Goyal527c7d32015-08-28 15:19:36 -0700149import com.android.launcher3.util.ViewOnDrawExecutor;
Sunny Goyalab770a12018-11-14 15:17:26 -0800150import com.android.launcher3.views.ActivityContext;
Sunny Goyal7c7be8c2018-03-07 19:58:07 -0800151import com.android.launcher3.views.OptionsPopupView;
Govinda Wassermanc06e1512019-04-09 09:56:53 -0400152import com.android.launcher3.views.ScrimView;
Sunny Goyal29947f02017-12-18 13:49:44 -0800153import com.android.launcher3.widget.LauncherAppWidgetHostView;
Sunny Goyal782f0c92017-01-19 10:27:54 -0800154import com.android.launcher3.widget.PendingAddShortcutInfo;
Hyunyoung Song3f471442015-04-08 19:01:34 -0700155import com.android.launcher3.widget.PendingAddWidgetInfo;
Sunny Goyal29947f02017-12-18 13:49:44 -0800156import com.android.launcher3.widget.PendingAppWidgetHostView;
Sunny Goyal04a324a2017-01-20 21:08:59 -0800157import com.android.launcher3.widget.WidgetAddFlowHandler;
Hyunyoung Songb99ff3e2015-04-23 15:17:50 -0700158import com.android.launcher3.widget.WidgetHostViewLoader;
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -0700159import com.android.launcher3.widget.WidgetListRowEntry;
Sunny Goyal337c81f2019-12-10 12:19:13 -0800160import com.android.launcher3.widget.WidgetManagerHelper;
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -0700161import com.android.launcher3.widget.WidgetsFullSheet;
Pinyao Tingc7a6c292019-08-26 14:36:02 -0700162import com.android.launcher3.widget.custom.CustomWidgetManager;
Sunny Goyalb1d7de22019-09-06 10:36:54 -0700163import com.android.systemui.plugins.OverlayPlugin;
164import com.android.systemui.plugins.PluginListener;
165import com.android.systemui.plugins.shared.LauncherExterns;
166import com.android.systemui.plugins.shared.LauncherOverlayManager;
167import com.android.systemui.plugins.shared.LauncherOverlayManager.LauncherOverlay;
168import com.android.systemui.plugins.shared.LauncherOverlayManager.LauncherOverlayCallbacks;
Adam Cohen6c5891a2014-07-09 23:53:15 -0700169
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700170import java.io.FileDescriptor;
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700171import java.io.PrintWriter;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700172import java.util.ArrayList;
Winson Chungf0c6ae02012-03-21 16:10:31 -0700173import java.util.Collection;
Zak Cohen658c67a2018-10-19 14:21:05 -0700174import java.util.HashMap;
Sunny Goyal4390ace2014-10-13 11:33:11 -0700175import java.util.HashSet;
Michael Jurkad7c28052012-04-27 15:43:36 -0700176import java.util.List;
Sunny Goyalaae6fbb2019-01-31 16:05:58 -0800177import java.util.function.Predicate;
Sunny Goyalb1d7de22019-09-06 10:36:54 -0700178import java.util.function.Supplier;
Sunny Goyal3a1eadd2019-10-23 17:44:27 -0700179import java.util.stream.Stream;
Jon Mirandaf5197fc2019-09-04 16:55:41 -0700180
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800181/**
182 * Default launcher application.
183 */
Hyunyoung Song46d07f72018-05-22 15:41:25 -0700184public class Launcher extends BaseDraggingActivity implements LauncherExterns,
Sunny Goyal01615a62019-09-20 12:00:07 -0700185 Callbacks, UserEventDelegate,
Sunny Goyalb1d7de22019-09-06 10:36:54 -0700186 InvariantDeviceProfile.OnIDPChangeListener, PluginListener<OverlayPlugin> {
Vadim Tryshevfedca432015-08-19 17:55:02 -0700187 public static final String TAG = "Launcher";
Sunny Goyale84c5b82019-09-26 17:05:31 -0700188
189 public static final ActivityTracker<Launcher> ACTIVITY_TRACKER = new ActivityTracker<>();
190
Sunny Goyal2bba4c32015-05-18 15:42:48 -0700191 static final boolean LOGD = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800192
Winson Chunga2413752012-04-03 14:22:34 -0700193 static final boolean DEBUG_STRICT_MODE = false;
Romain Guy6fefcf12009-06-11 13:07:43 -0700194
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800195 private static final int REQUEST_CREATE_SHORTCUT = 1;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700196 private static final int REQUEST_CREATE_APPWIDGET = 5;
Jon Mirandac476d6e2017-05-04 16:30:01 -0700197
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700198 private static final int REQUEST_PICK_APPWIDGET = 9;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800199
Michael Jurka8b805b12012-04-18 14:23:14 -0700200 private static final int REQUEST_BIND_APPWIDGET = 11;
Sunny Goyal8a2a63b2018-03-06 22:15:18 -0800201 public static final int REQUEST_BIND_PENDING_APPWIDGET = 12;
202 public static final int REQUEST_RECONFIGURE_APPWIDGET = 13;
Michael Jurka8b805b12012-04-18 14:23:14 -0700203
Jon Mirandac476d6e2017-05-04 16:30:01 -0700204 private static final int REQUEST_PERMISSION_CALL_PHONE = 14;
Sunny Goyal28c6b962015-10-12 11:42:05 -0700205
Sunny Goyal5a1f53b2015-05-27 10:24:24 -0700206 private static final float BOUNCE_ANIMATION_TENSION = 1.3f;
207
Mathew Inwood876a8462013-06-14 14:12:41 +0100208 /**
209 * IntentStarter uses request codes starting with this. This must be greater than all activity
210 * request codes used internally.
211 */
212 protected static final int REQUEST_LAST = 100;
213
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800214 // Type: int
215 private static final String RUNTIME_STATE_CURRENT_SCREEN = "launcher.current_screen";
Michael Jurka883f55b2010-10-21 15:47:14 -0700216 // Type: int
217 private static final String RUNTIME_STATE = "launcher.state";
Sunny Goyal2100c782016-08-22 16:00:03 -0700218 // Type: PendingRequestArgs
219 private static final String RUNTIME_STATE_PENDING_REQUEST_ARGS = "launcher.request_args";
Sunny Goyaldedda052019-05-14 15:23:48 -0700220 // Type: int
221 private static final String RUNTIME_STATE_PENDING_REQUEST_CODE = "launcher.request_code";
Sunny Goyal2100c782016-08-22 16:00:03 -0700222 // Type: ActivityResultInfo
223 private static final String RUNTIME_STATE_PENDING_ACTIVITY_RESULT = "launcher.activity_result";
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -0700224 // Type: SparseArray<Parcelable>
225 private static final String RUNTIME_STATE_WIDGET_PANEL = "launcher.widget_panel";
Sunny Goyal17c72fb2019-10-14 14:06:38 -0700226
vadimt00d42552018-12-11 17:59:36 -0800227 public static final String ON_CREATE_EVT = "Launcher.onCreate";
Sunny Goyal17c72fb2019-10-14 14:06:38 -0700228 public static final String ON_START_EVT = "Launcher.onStart";
229 public static final String ON_RESUME_EVT = "Launcher.onResume";
230 public static final String ON_NEW_INTENT_EVT = "Launcher.onNewIntent";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800231
Sunny Goyal3e3f44c2017-10-23 17:14:52 -0700232 private LauncherStateManager mStateManager;
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700233
Adam Cohenad4e15c2013-10-17 16:21:35 -0700234 private static final int ON_ACTIVITY_RESULT_ANIMATION_DELAY = 500;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800235
Winson Chunga2413752012-04-03 14:22:34 -0700236 // How long to wait before the new-shortcut animation automatically pans the workspace
Jon Mirandaf5197fc2019-09-04 16:55:41 -0700237 @VisibleForTesting public static final int NEW_APPS_PAGE_MOVE_DELAY = 500;
Rajeev Kumar43c0f582017-06-23 15:34:55 -0700238 private static final int NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS = 5;
Jon Mirandaf5197fc2019-09-04 16:55:41 -0700239 @Thunk @VisibleForTesting public static final int NEW_APPS_ANIMATION_DELAY = 500;
Winson Chunga2413752012-04-03 14:22:34 -0700240
Govinda Wassermanc06e1512019-04-09 09:56:53 -0400241 private static final int APPS_VIEW_ALPHA_CHANNEL_INDEX = 1;
242 private static final int SCRIM_VIEW_ALPHA_CHANNEL_INDEX = 0;
243
Jon Miranda54441f52018-01-24 15:38:25 -0800244 private LauncherAppTransitionManager mAppTransitionManager;
Sunny Goyalf8d56fc2018-01-31 15:18:11 -0800245 private Configuration mOldConfig;
Jon Miranda54441f52018-01-24 15:38:25 -0800246
Samuel Fufaca37b8a2019-08-19 17:04:36 -0700247 @Thunk
248 Workspace mWorkspace;
Craig Mautner360310b2012-10-26 15:13:08 -0700249 private View mLauncherView;
Samuel Fufaca37b8a2019-08-19 17:04:36 -0700250 @Thunk
251 DragLayer mDragLayer;
Michael Jurkab737ee62011-11-15 15:57:22 -0800252 private DragController mDragController;
Sunny Goyal322d5562015-06-25 19:35:49 -0700253
Sunny Goyal337c81f2019-12-10 12:19:13 -0800254 private WidgetManagerHelper mAppWidgetManager;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700255 private LauncherAppWidgetHost mAppWidgetHost;
Romain Guycbb89e42009-06-08 15:52:54 -0700256
Rajeev Kumar43c0f582017-06-23 15:34:55 -0700257 private final int[] mTmpAddItemCellCoordinates = new int[2];
Michael Jurka0280c3b2010-09-17 15:00:07 -0700258
Samuel Fufaca37b8a2019-08-19 17:04:36 -0700259 @Thunk
260 Hotseat mHotseat;
Adam Cohenf358a4b2013-07-23 16:47:31 -0700261
Sunny Goyal47328fd2016-05-25 18:56:41 -0700262 private DropTargetBar mDropTargetBar;
Hyunyoung Song3f471442015-04-08 19:01:34 -0700263
264 // Main container view for the all apps screen.
Samuel Fufaca37b8a2019-08-19 17:04:36 -0700265 @Thunk
266 AllAppsContainerView mAppsView;
Hyunyoung Song645764e2016-06-06 14:19:02 -0700267 AllAppsTransitionController mAllAppsController;
Hyunyoung Song3f471442015-04-08 19:01:34 -0700268
Govinda Wassermanc06e1512019-04-09 09:56:53 -0400269 // Scrim view for the all apps and overview state.
Samuel Fufaca37b8a2019-08-19 17:04:36 -0700270 @Thunk
271 ScrimView mScrimView;
Govinda Wassermanc06e1512019-04-09 09:56:53 -0400272
Winson Chung8ae41982017-11-10 11:42:13 -0800273 // UI and state for the overview panel
Sunny Goyal7c7be8c2018-03-07 19:58:07 -0800274 private View mOverviewPanel;
Winson Chung8ae41982017-11-10 11:42:13 -0800275
Samuel Fufaca37b8a2019-08-19 17:04:36 -0700276 @Thunk
277 boolean mWorkspaceLoading = true;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400278
Winson Chung0b70cd42019-06-17 22:34:33 -0700279 private ArrayList<OnResumeCallback> mOnResumeCallbacks = new ArrayList<>();
Sunny Goyal3dce5f32017-10-05 11:40:05 -0700280
Winson Chungc9bf6d42019-10-04 15:33:18 -0700281 // Used to notify when an activity launch has been deferred because launcher is not yet resumed
282 // TODO: See if we can remove this later
283 private Runnable mOnDeferredActivityLaunchCallback;
284
Sunny Goyal527c7d32015-08-28 15:19:36 -0700285 private ViewOnDrawExecutor mPendingExecutor;
Michael Jurka7607c2f2013-04-03 14:33:19 -0700286
Joe Onorato9c1289c2009-08-17 11:03:03 -0400287 private LauncherModel mModel;
Sunny Goyal43bf11d2017-02-02 13:52:53 -0800288 private ModelWriter mModelWriter;
Joe Onorato0589f0f2010-02-08 13:44:00 -0800289 private IconCache mIconCache;
Sunny Goyalae502842016-06-17 08:43:56 -0700290 private LauncherAccessibilityDelegate mAccessibilityDelegate;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400291
Tony Wickham010d2552017-01-20 08:15:28 -0800292 private PopupDataProvider mPopupDataProvider;
Tony Wickhambfbf7f92016-05-19 11:19:39 -0700293
Sunny Goyalf4aceab2017-12-06 16:16:31 -0800294 private int mSynchronouslyBoundPage = PagedView.INVALID_PAGE;
Sunny Goyala7a5bf32020-01-05 15:35:29 +0530295 private int mPageToBindSynchronously = PagedView.INVALID_PAGE;
Adam Cohen1462de32012-07-24 22:34:36 -0700296
Winson Chung46353de2012-02-16 14:05:10 -0800297 // We only want to get the SharedPreferences once since it does an FS stat each time we get
298 // it from the context.
299 private SharedPreferences mSharedPrefs;
300
Sunny Goyal2100c782016-08-22 16:00:03 -0700301 // Activity result which needs to be processed after workspace has loaded.
302 private ActivityResultInfo mPendingActivityResult;
303 /**
304 * Holds extra information required to handle a result from an external call, like
305 * {@link #startActivityForResult(Intent, int)} or {@link #requestPermissions(String[], int)}
306 */
307 private PendingRequestArgs mPendingRequestArgs;
Sunny Goyaldedda052019-05-14 15:23:48 -0700308 // Request id for any pending activity result
Sunny Goyal210e1742019-10-17 12:05:38 -0700309 protected int mPendingActivityRequestCode = -1;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800310
Tracy Zhou4d7b2442019-12-09 13:42:57 -0800311 private ViewGroupFocusHelper mFocusHandler;
Hyunyoung Song7fb3ccc2017-10-17 15:39:46 -0700312
Sunny Goyal623eddd2018-03-02 12:24:41 -0800313 private RotationHelper mRotationHelper;
Sunny Goyal7779d622015-06-11 16:18:39 -0700314
Sunny Goyal2db53422019-03-01 16:06:12 -0800315 final Handler mHandler = new Handler();
Sunny Goyala002c6c2019-02-12 16:20:10 -0800316 private final Runnable mHandleDeferredResume = this::handleDeferredResume;
Sunny Goyale9c6f4c2019-05-30 11:35:25 -0700317 private boolean mDeferredResumePending;
Hyunyoung Songbd6fba92018-05-16 15:54:31 -0700318
Govinda Wassermanc06e1512019-04-09 09:56:53 -0400319 private float mCurrentAssistantVisibility = 0f;
320
Sunny Goyalae6e3182019-04-30 12:04:37 -0700321 private DeviceProfile mStableDeviceProfile;
322 private RotationMode mRotationMode = RotationMode.NORMAL;
323
Sunny Goyalb1d7de22019-09-06 10:36:54 -0700324 protected LauncherOverlayManager mOverlayManager;
325 // If true, overlay callbacks are deferred
326 private boolean mDeferOverlayCallbacks;
327 private final Runnable mDeferredOverlayCallbacks = this::checkIfOverlayStillDeferred;
328
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800329 @Override
330 protected void onCreate(Bundle savedInstanceState) {
Winson Chung5cc62c72019-10-16 11:32:41 -0700331 Object traceToken = TraceHelper.INSTANCE.beginSection(ON_CREATE_EVT,
332 TraceHelper.FLAG_UI_EVENT);
Winson Chunga2413752012-04-03 14:22:34 -0700333 if (DEBUG_STRICT_MODE) {
334 StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
335 .detectDiskReads()
336 .detectDiskWrites()
337 .detectNetwork() // or .detectAll() for all detectable problems
338 .penaltyLog()
339 .build());
340 StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
341 .detectLeakedSqlLiteObjects()
342 .detectLeakedClosableObjects()
343 .penaltyLog()
344 .penaltyDeath()
345 .build());
346 }
347
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800348 super.onCreate(savedInstanceState);
Daniel Sandlere060b0b2013-06-27 21:47:55 -0400349
Sunny Goyal87f784c2017-01-11 10:48:34 -0800350 LauncherAppState app = LauncherAppState.getInstance(this);
Sunny Goyalf8d56fc2018-01-31 15:18:11 -0800351 mOldConfig = new Configuration(getResources().getConfiguration());
Sunny Goyala7a5bf32020-01-05 15:35:29 +0530352 mModel = app.getModel();
Sunny Goyal41d51a02019-05-14 09:44:34 -0700353 mRotationHelper = new RotationHelper(this);
Hyunyoung Song31971a32019-01-27 12:31:12 -0800354 InvariantDeviceProfile idp = app.getInvariantDeviceProfile();
355 initDeviceProfile(idp);
356 idp.addOnChangeListener(this);
Sunny Goyalf7258242015-10-19 16:59:07 -0700357 mSharedPrefs = Utilities.getPrefs(this);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800358 mIconCache = app.getIconCache();
Sunny Goyalae502842016-06-17 08:43:56 -0700359 mAccessibilityDelegate = new LauncherAccessibilityDelegate(this);
Adam Cohen2e6da152015-05-06 11:42:25 -0700360
Joe Onorato41a12d22009-10-31 18:30:00 -0400361 mDragController = new DragController(this);
Hyunyoung Song645764e2016-06-06 14:19:02 -0700362 mAllAppsController = new AllAppsTransitionController(this);
Sunny Goyalc4fa8c32017-11-07 12:23:58 -0800363 mStateManager = new LauncherStateManager(this);
Romain Guycbb89e42009-06-08 15:52:54 -0700364
Sunny Goyal337c81f2019-12-10 12:19:13 -0800365 mAppWidgetManager = new WidgetManagerHelper(this);
Samuel Fufa44043ec2019-08-26 15:00:30 -0700366 mAppWidgetHost = new LauncherAppWidgetHost(this,
367 appWidgetId -> getWorkspace().removeWidget(appWidgetId));
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700368 mAppWidgetHost.startListening();
Romain Guycbb89e42009-06-08 15:52:54 -0700369
Sunny Goyal60820d72017-05-09 12:40:11 -0700370 mLauncherView = LayoutInflater.from(this).inflate(R.layout.launcher, null);
Michael Jurka7267fa52013-09-26 15:29:57 -0700371
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800372 setupViews();
Tony Wickham010d2552017-01-20 08:15:28 -0800373 mPopupDataProvider = new PopupDataProvider(this);
374
Sunny Goyal90548432018-04-04 17:17:00 -0700375 mAppTransitionManager = LauncherAppTransitionManager.newInstance(this);
Winson Chung24ab40c2019-10-30 22:35:09 -0700376 mAppTransitionManager.registerRemoteAnimations();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800377
Sunny Goyale84c5b82019-09-26 17:05:31 -0700378 boolean internalStateHandled = ACTIVITY_TRACKER.handleCreate(this);
Sunny Goyald3864fa2017-11-14 15:06:36 -0800379 if (internalStateHandled) {
Sunny Goyald3864fa2017-11-14 15:06:36 -0800380 if (savedInstanceState != null) {
381 // InternalStateHandler has already set the appropriate state.
382 // We dont need to do anything.
383 savedInstanceState.remove(RUNTIME_STATE);
384 }
385 }
386 restoreState(savedInstanceState);
Sunny Goyalbbece862019-03-01 13:13:52 -0800387 mStateManager.reapplyState();
Winson Chungb63b44c2017-11-10 17:54:44 -0800388
Sunny Goyal2100c782016-08-22 16:00:03 -0700389 // We only load the page synchronously if the user rotates (or triggers a
390 // configuration change) while launcher is in the foreground
Sunny Goyala7a5bf32020-01-05 15:35:29 +0530391 int currentScreen = PagedView.INVALID_PAGE;
Sunny Goyalfe770c92016-09-27 14:38:58 -0700392 if (savedInstanceState != null) {
393 currentScreen = savedInstanceState.getInt(RUNTIME_STATE_CURRENT_SCREEN, currentScreen);
394 }
Sunny Goyala7a5bf32020-01-05 15:35:29 +0530395 mPageToBindSynchronously = currentScreen;
Sunny Goyald3864fa2017-11-14 15:06:36 -0800396
Sunny Goyala7a5bf32020-01-05 15:35:29 +0530397 if (!mModel.addCallbacksAndLoad(this)) {
Sunny Goyald3864fa2017-11-14 15:06:36 -0800398 if (!internalStateHandled) {
399 // If we are not binding synchronously, show a fade in animation when
400 // the first page bind completes.
Sunny Goyal6001ea22018-05-10 16:31:00 -0700401 mDragLayer.getAlphaProperty(ALPHA_INDEX_LAUNCHER_LOAD).setValue(0);
Sunny Goyald3864fa2017-11-14 15:06:36 -0800402 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800403 }
404
405 // For handling default keys
Sunny Goyalf4aceab2017-12-06 16:16:31 -0800406 setDefaultKeyMode(DEFAULT_KEYS_SEARCH_LOCAL);
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800407
Sunny Goyal0bbd5542016-11-11 10:41:26 -0800408 setContentView(mLauncherView);
Sunny Goyalf8d56fc2018-01-31 15:18:11 -0800409 getRootView().dispatchInsets();
Mario Bertschlera6936942017-05-31 14:48:19 -0700410
Jon Miranda7fda2852017-07-19 16:07:01 -0700411 // Listen for broadcasts
Sunny Goyal5d1873a2018-05-08 11:10:44 -0700412 registerReceiver(mScreenOffReceiver, new IntentFilter(Intent.ACTION_SCREEN_OFF));
Sunny Goyala616d2b2017-06-12 13:54:01 -0700413
Sunny Goyal8392c822017-06-20 10:03:56 -0700414 getSystemUiController().updateUiState(SystemUiController.UI_STATE_BASE_WINDOW,
415 Themes.getAttrBoolean(this, R.attr.isWorkspaceDarkText));
Sunny Goyal14b32402017-07-31 10:03:28 -0700416
417 if (mLauncherCallbacks != null) {
418 mLauncherCallbacks.onCreate(savedInstanceState);
419 }
Sunny Goyalb1d7de22019-09-06 10:36:54 -0700420 mOverlayManager = getDefaultOverlay();
421 PluginManagerWrapper.INSTANCE.get(this).addPluginListener(this,
422 OverlayPlugin.class, false /* allowedMultiple */);
423
Sunny Goyal623eddd2018-03-02 12:24:41 -0800424 mRotationHelper.initialize();
Sunny Goyalfca6bc92017-09-28 16:28:34 -0700425
Govinda Wassermanc06e1512019-04-09 09:56:53 -0400426 mStateManager.addStateListener(new LauncherStateManager.StateListener() {
427 @Override
Samuel Fufaca37b8a2019-08-19 17:04:36 -0700428 public void onStateTransitionStart(LauncherState toState) {
429 }
Govinda Wassermanc06e1512019-04-09 09:56:53 -0400430
431 @Override
432 public void onStateTransitionComplete(LauncherState finalState) {
433 float alpha = 1f - mCurrentAssistantVisibility;
434 if (finalState == NORMAL) {
435 mAppsView.getAlphaProperty(APPS_VIEW_ALPHA_CHANNEL_INDEX).setValue(alpha);
436 } else if (finalState == OVERVIEW || finalState == OVERVIEW_PEEK) {
437 mAppsView.getAlphaProperty(APPS_VIEW_ALPHA_CHANNEL_INDEX).setValue(alpha);
438 mScrimView.getAlphaProperty(SCRIM_VIEW_ALPHA_CHANNEL_INDEX).setValue(alpha);
439 } else {
440 mAppsView.getAlphaProperty(APPS_VIEW_ALPHA_CHANNEL_INDEX).setValue(1f);
441 mScrimView.getAlphaProperty(SCRIM_VIEW_ALPHA_CHANNEL_INDEX).setValue(1f);
442 }
443 }
444 });
Sunny Goyal17c72fb2019-10-14 14:06:38 -0700445
Winson Chung5cc62c72019-10-16 11:32:41 -0700446 TraceHelper.INSTANCE.endSection(traceToken);
Adam Cohen9211d422014-10-07 18:14:53 -0700447 }
448
Sunny Goyalb1d7de22019-09-06 10:36:54 -0700449 protected LauncherOverlayManager getDefaultOverlay() {
450 return new LauncherOverlayManager() { };
451 }
452
453 @Override
454 public void onPluginConnected(OverlayPlugin overlayManager, Context context) {
455 switchOverlay(() -> overlayManager.createOverlayManager(this, this));
456 }
457
458 @Override
459 public void onPluginDisconnected(OverlayPlugin plugin) {
460 switchOverlay(this::getDefaultOverlay);
461 }
462
463 private void switchOverlay(Supplier<LauncherOverlayManager> overlaySupplier) {
464 if (mOverlayManager != null) {
465 mOverlayManager.onActivityDestroyed(this);
466 }
467 mOverlayManager = overlaySupplier.get();
468 if (getRootView().isAttachedToWindow()) {
469 mOverlayManager.onAttachedToWindow();
470 }
471 mDeferOverlayCallbacks = true;
472 checkIfOverlayStillDeferred();
473 }
474
475 @Override
476 protected void dispatchDeviceProfileChanged() {
477 super.dispatchDeviceProfileChanged();
478 mOverlayManager.onDeviceProvideChanged();
479 }
480
Sunny Goyal7779d622015-06-11 16:18:39 -0700481 @Override
Winson Chung8eb49e02018-07-16 13:33:31 -0700482 public void onEnterAnimationComplete() {
483 super.onEnterAnimationComplete();
arangelovad783052018-08-17 14:46:45 +0100484 mAllAppsController.highlightWorkTabIfNecessary();
Sunny Goyalbe8c3402019-05-22 15:17:52 -0700485 mRotationHelper.setCurrentTransitionRequest(REQUEST_NONE);
Winson Chung8eb49e02018-07-16 13:33:31 -0700486 }
487
488 @Override
Sunny Goyalf8d56fc2018-01-31 15:18:11 -0800489 public void onConfigurationChanged(Configuration newConfig) {
490 int diff = newConfig.diff(mOldConfig);
Jon Mirandaaeb4dd02018-07-11 14:16:23 -0700491
Sunny Goyalf8d56fc2018-01-31 15:18:11 -0800492 if ((diff & (CONFIG_ORIENTATION | CONFIG_SCREEN_SIZE)) != 0) {
Sunny Goyal371ea052019-03-06 15:38:32 -0800493 onIdpChanged(mDeviceProfile.inv);
Sunny Goyalf8d56fc2018-01-31 15:18:11 -0800494 }
495
496 mOldConfig.setTo(newConfig);
497 super.onConfigurationChanged(newConfig);
498 }
499
Sunny Goyal3e195d72019-06-19 14:24:38 -0700500 public void reload() {
501 onIdpChanged(mDeviceProfile.inv);
502 }
503
Sunny Goyal41d51a02019-05-14 09:44:34 -0700504 private boolean supportsFakeLandscapeUI() {
505 return FeatureFlags.FAKE_LANDSCAPE_UI.get() && !mRotationHelper.homeScreenCanRotate();
506 }
507
Sunny Goyal605bcf32018-03-02 15:16:12 -0800508 @Override
Sunny Goyal41d51a02019-05-14 09:44:34 -0700509 public void reapplyUi() {
Tony Wickham4df42f82019-11-13 15:38:28 -0800510 reapplyUi(true /* cancelCurrentAnimation */);
511 }
512
513 public void reapplyUi(boolean cancelCurrentAnimation) {
Sunny Goyal41d51a02019-05-14 09:44:34 -0700514 if (supportsFakeLandscapeUI()) {
Sunny Goyal7a39b1b2019-05-02 13:39:16 -0700515 mRotationMode = mStableDeviceProfile == null
Sunny Goyal210e1742019-10-17 12:05:38 -0700516 ? RotationMode.NORMAL : getFakeRotationMode(mDeviceProfile);
Sunny Goyalae6e3182019-04-30 12:04:37 -0700517 }
Sunny Goyal59d086c2018-05-07 17:31:40 -0700518 getRootView().dispatchInsets();
Tony Wickham4df42f82019-11-13 15:38:28 -0800519 getStateManager().reapplyState(cancelCurrentAnimation);
Sunny Goyal59d086c2018-05-07 17:31:40 -0700520 }
521
522 @Override
Hyunyoung Song31971a32019-01-27 12:31:12 -0800523 public void onIdpChanged(int changeFlags, InvariantDeviceProfile idp) {
Sunny Goyal371ea052019-03-06 15:38:32 -0800524 onIdpChanged(idp);
525 }
526
527 private void onIdpChanged(InvariantDeviceProfile idp) {
528 mUserEventDispatcher = null;
529
Sunny Goyalc8502c12019-06-10 12:14:47 -0700530 DeviceProfile oldWallpaperProfile = getWallpaperDeviceProfile();
Hyunyoung Song31971a32019-01-27 12:31:12 -0800531 initDeviceProfile(idp);
Sunny Goyal371ea052019-03-06 15:38:32 -0800532 dispatchDeviceProfileChanged();
533 reapplyUi();
534 mDragLayer.recreateControllers();
535
Sunny Goyal76ba0a32019-06-10 11:56:11 -0700536 // Calling onSaveInstanceState ensures that static cache used by listWidgets is
537 // initialized properly.
538 onSaveInstanceState(new Bundle());
Sunny Goyalc8502c12019-06-10 12:14:47 -0700539 if (oldWallpaperProfile != getWallpaperDeviceProfile()) {
Sunny Goyala7a5bf32020-01-05 15:35:29 +0530540 mModel.rebindCallbacks();
Sunny Goyalc8502c12019-06-10 12:14:47 -0700541 }
Hyunyoung Song31971a32019-01-27 12:31:12 -0800542 }
543
Govinda Wassermanc06e1512019-04-09 09:56:53 -0400544 public void onAssistantVisibilityChanged(float visibility) {
545 mCurrentAssistantVisibility = visibility;
546 float alpha = 1f - visibility;
547 LauncherState state = mStateManager.getState();
548 if (state == NORMAL) {
549 mAppsView.getAlphaProperty(APPS_VIEW_ALPHA_CHANNEL_INDEX).setValue(alpha);
550 } else if (state == OVERVIEW || state == OVERVIEW_PEEK) {
551 mAppsView.getAlphaProperty(APPS_VIEW_ALPHA_CHANNEL_INDEX).setValue(alpha);
552 mScrimView.getAlphaProperty(SCRIM_VIEW_ALPHA_CHANNEL_INDEX).setValue(alpha);
553 }
554 }
555
Sunny Goyalf8d56fc2018-01-31 15:18:11 -0800556 private void initDeviceProfile(InvariantDeviceProfile idp) {
557 // Load configuration-specific DeviceProfile
Sunny Goyal59d086c2018-05-07 17:31:40 -0700558 mDeviceProfile = idp.getDeviceProfile(this);
Sunny Goyal8c48d8b2019-01-25 15:10:18 -0800559 if (isInMultiWindowMode()) {
Winson Chung13c1c2c2019-09-06 11:46:19 -0700560 // Note: Calls to getSize() can't rely on our cached DefaultDisplay since it can return
561 // the app window size
Sunny Goyal59d086c2018-05-07 17:31:40 -0700562 Display display = getWindowManager().getDefaultDisplay();
563 Point mwSize = new Point();
564 display.getSize(mwSize);
565 mDeviceProfile = mDeviceProfile.getMultiWindowProfile(this, mwSize);
566 }
Sunny Goyalae6e3182019-04-30 12:04:37 -0700567
Sunny Goyalda14cf82019-05-30 10:31:09 -0700568 if (supportsFakeLandscapeUI() && mDeviceProfile.isVerticalBarLayout()) {
Sunny Goyalae6e3182019-04-30 12:04:37 -0700569 mStableDeviceProfile = mDeviceProfile.inv.portraitProfile;
Sunny Goyal210e1742019-10-17 12:05:38 -0700570 mRotationMode = getFakeRotationMode(mDeviceProfile);
Sunny Goyalae6e3182019-04-30 12:04:37 -0700571 } else {
572 mStableDeviceProfile = null;
573 mRotationMode = RotationMode.NORMAL;
574 }
575
Sunny Goyalda14cf82019-05-30 10:31:09 -0700576 mRotationHelper.updateRotationAnimation();
Sunny Goyal59d086c2018-05-07 17:31:40 -0700577 onDeviceProfileInitiated();
Sunny Goyalae6e3182019-04-30 12:04:37 -0700578 mModelWriter = mModel.getWriter(getWallpaperDeviceProfile().isVerticalBarLayout(), true);
579 }
580
581 public void updateInsets(Rect insets) {
582 mDeviceProfile.updateInsets(insets);
583 if (mStableDeviceProfile != null) {
Sunny Goyal7a39b1b2019-05-02 13:39:16 -0700584 Rect r = mStableDeviceProfile.getInsets();
585 mRotationMode.mapInsets(this, insets, r);
586 mStableDeviceProfile.updateInsets(r);
Sunny Goyalae6e3182019-04-30 12:04:37 -0700587 }
588 }
589
590 @Override
591 public RotationMode getRotationMode() {
592 return mRotationMode;
593 }
594
595 /**
596 * Device profile to be used by UI elements which are shown directly on top of the wallpaper
597 * and whose presentation is tied to the wallpaper (and physical device) and not the activity
598 * configuration.
599 */
600 @Override
601 public DeviceProfile getWallpaperDeviceProfile() {
602 return mStableDeviceProfile == null ? mDeviceProfile : mStableDeviceProfile;
Sunny Goyalf8d56fc2018-01-31 15:18:11 -0800603 }
604
Sunny Goyal623eddd2018-03-02 12:24:41 -0800605 public RotationHelper getRotationHelper() {
606 return mRotationHelper;
607 }
608
Tracy Zhou4d7b2442019-12-09 13:42:57 -0800609 public ViewGroupFocusHelper getFocusHandler() {
610 return mFocusHandler;
611 }
612
Sunny Goyal3e3f44c2017-10-23 17:14:52 -0700613 public LauncherStateManager getStateManager() {
614 return mStateManager;
Sunny Goyalbe93f262017-10-20 17:05:27 -0700615 }
616
Hyunyoung Song4c746202019-10-10 23:11:12 -0700617 public FolderNameProvider getFolderNameProvider() {
618 return new FolderNameProvider();
619 }
620
Mario Bertschler27288382017-05-24 15:35:09 -0700621 @Override
Sunny Goyalc7b8df82017-06-27 11:11:03 -0700622 public <T extends View> T findViewById(int id) {
Sunny Goyal0bbd5542016-11-11 10:41:26 -0800623 return mLauncherView.findViewById(id);
624 }
625
Adam Cohen9211d422014-10-07 18:14:53 -0700626 private LauncherCallbacks mLauncherCallbacks;
627
Sunny Goyal32554d12015-12-03 15:31:25 -0800628 /**
629 * Call this after onCreate to set or clear overlay.
630 */
Sunny Goyalb1d7de22019-09-06 10:36:54 -0700631 @Override
Sunny Goyal32554d12015-12-03 15:31:25 -0800632 public void setLauncherOverlay(LauncherOverlay overlay) {
633 if (overlay != null) {
634 overlay.setOverlayCallbacks(new LauncherOverlayCallbacksImpl());
635 }
636 mWorkspace.setLauncherOverlay(overlay);
637 }
638
Sunny Goyalb1d7de22019-09-06 10:36:54 -0700639 @Override
640 public void runOnOverlayHidden(Runnable runnable) {
641 getWorkspace().runOnOverlayHidden(runnable);
642 }
643
Adam Cohen9211d422014-10-07 18:14:53 -0700644 public boolean setLauncherCallbacks(LauncherCallbacks callbacks) {
645 mLauncherCallbacks = callbacks;
646 return true;
Adam Cohenf9426d52012-06-04 17:26:21 -0700647 }
648
Hyunyoung Song3f471442015-04-08 19:01:34 -0700649 public boolean isDraggingEnabled() {
Winson Chung36a62fe2012-05-06 18:04:42 -0700650 // We prevent dragging when we are loading the workspace as it is possible to pick up a view
651 // that is subsequently removed from the workspace in startBinding().
Sunny Goyal639e9062015-08-19 19:17:06 -0700652 return !isWorkspaceLoading();
Winson Chung36a62fe2012-05-06 18:04:42 -0700653 }
654
Tony Wickham010d2552017-01-20 08:15:28 -0800655 public PopupDataProvider getPopupDataProvider() {
656 return mPopupDataProvider;
657 }
658
Sunny Goyal0b0847b2018-03-14 12:30:11 -0700659 @Override
Tony Wickhamf34bee82018-12-03 18:11:39 -0800660 public DotInfo getDotInfoForItem(ItemInfo info) {
661 return mPopupDataProvider.getDotInfoForItem(info);
Sunny Goyal0b0847b2018-03-14 12:30:11 -0700662 }
663
664 @Override
665 public void invalidateParent(ItemInfo info) {
Jon Mirandae6f3fa42019-03-04 09:14:40 -0800666 if (info.container >= 0) {
Sunny Goyal0b0847b2018-03-14 12:30:11 -0700667 View folderIcon = getWorkspace().getHomescreenIconByItemId(info.container);
Jon Mirandae6f3fa42019-03-04 09:14:40 -0800668 if (folderIcon instanceof FolderIcon && folderIcon.getTag() instanceof FolderInfo) {
Sunny Goyal11a50742019-08-07 09:24:26 -0700669 if (new FolderGridOrganizer(getDeviceProfile().inv)
670 .setFolderInfo((FolderInfo) folderIcon.getTag())
671 .isItemInPreview(info.rank)) {
Jon Mirandae6f3fa42019-03-04 09:14:40 -0800672 folderIcon.invalidate();
673 }
Sunny Goyal0b0847b2018-03-14 12:30:11 -0700674 }
675 }
676 }
677
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000678 /**
Winson Chung557d6ed2011-07-08 15:34:52 -0700679 * Returns whether we should delay spring loaded mode -- for shortcuts and widgets that have
680 * a configuration step, this allows the proper animations to run after other transitions.
681 */
Sunny Goyalefb7e842018-10-04 15:11:00 -0700682 private int completeAdd(
Sunny Goyal2100c782016-08-22 16:00:03 -0700683 int requestCode, Intent intent, int appWidgetId, PendingRequestArgs info) {
Sunny Goyalefb7e842018-10-04 15:11:00 -0700684 int screenId = info.screenId;
Sunny Goyal2100c782016-08-22 16:00:03 -0700685 if (info.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
Adam Cohen83079e42014-09-19 17:43:08 -0700686 // When the screen id represents an actual screen (as opposed to a rank) we make sure
687 // that the drop page actually exists.
Sunny Goyal2100c782016-08-22 16:00:03 -0700688 screenId = ensurePendingDropLayoutExists(info.screenId);
Adam Cohen83079e42014-09-19 17:43:08 -0700689 }
Adam Cohendb364c32014-05-20 14:23:40 -0700690
Sunny Goyal2100c782016-08-22 16:00:03 -0700691 switch (requestCode) {
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800692 case REQUEST_CREATE_SHORTCUT:
Sunny Goyalfb5096d2016-09-08 14:32:06 -0700693 completeAddShortcut(intent, info.container, screenId, info.cellX, info.cellY, info);
Pinyao Tingc9074272019-11-11 11:51:44 -0800694 announceForAccessibility(R.string.item_added_to_workspace);
Winson Chungb8472bb2011-08-05 13:49:21 -0700695 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800696 case REQUEST_CREATE_APPWIDGET:
Sunny Goyal2100c782016-08-22 16:00:03 -0700697 completeAddAppWidget(appWidgetId, info, null, null);
Winson Chungb8472bb2011-08-05 13:49:21 -0700698 break;
Sunny Goyalff572272014-07-23 13:58:07 -0700699 case REQUEST_RECONFIGURE_APPWIDGET:
Sunny Goyal2100c782016-08-22 16:00:03 -0700700 completeRestoreAppWidget(appWidgetId, LauncherAppWidgetInfo.RESTORE_COMPLETED);
Sunny Goyalff572272014-07-23 13:58:07 -0700701 break;
Sunny Goyald478c832016-04-01 12:04:16 -0700702 case REQUEST_BIND_PENDING_APPWIDGET: {
Sunny Goyal2100c782016-08-22 16:00:03 -0700703 int widgetId = appWidgetId;
704 LauncherAppWidgetInfo widgetInfo =
Sunny Goyald478c832016-04-01 12:04:16 -0700705 completeRestoreAppWidget(widgetId, LauncherAppWidgetInfo.FLAG_UI_NOT_READY);
Sunny Goyal2100c782016-08-22 16:00:03 -0700706 if (widgetInfo != null) {
Sunny Goyald478c832016-04-01 12:04:16 -0700707 // Since the view was just bound, also launch the configure activity if needed
708 LauncherAppWidgetProviderInfo provider = mAppWidgetManager
709 .getLauncherAppWidgetInfo(widgetId);
Sunny Goyal04a324a2017-01-20 21:08:59 -0800710 if (provider != null) {
711 new WidgetAddFlowHandler(provider)
Samuel Fufaca37b8a2019-08-19 17:04:36 -0700712 .startConfigActivity(this, widgetInfo,
713 REQUEST_RECONFIGURE_APPWIDGET);
Sunny Goyald478c832016-04-01 12:04:16 -0700714 }
715 }
716 break;
717 }
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800718 }
Adam Cohendb364c32014-05-20 14:23:40 -0700719 return screenId;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800720 }
721
Adam Cohenc7cd2cb2014-11-17 17:45:34 -0800722 private void handleActivityResult(
Michael Jurka8b805b12012-04-18 14:23:14 -0700723 final int requestCode, final int resultCode, final Intent data) {
Sunny Goyal2100c782016-08-22 16:00:03 -0700724 if (isWorkspaceLoading()) {
725 // process the result once the workspace has loaded.
726 mPendingActivityResult = new ActivityResultInfo(requestCode, resultCode, data);
727 return;
728 }
729 mPendingActivityResult = null;
730
Winson Chunge341d302013-08-16 14:31:00 -0700731 // Reset the startActivity waiting flag
Sunny Goyal2100c782016-08-22 16:00:03 -0700732 final PendingRequestArgs requestArgs = mPendingRequestArgs;
733 setWaitingForResult(null);
734 if (requestArgs == null) {
735 return;
736 }
737
738 final int pendingAddWidgetId = requestArgs.getWidgetId();
Winson Chunge341d302013-08-16 14:31:00 -0700739
Adam Cohenad4e15c2013-10-17 16:21:35 -0700740 Runnable exitSpringLoaded = new Runnable() {
741 @Override
742 public void run() {
Sunny Goyal3e3f44c2017-10-23 17:14:52 -0700743 mStateManager.goToState(NORMAL, SPRING_LOADED_EXIT_DELAY);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700744 }
745 };
746
Michael Jurka8b805b12012-04-18 14:23:14 -0700747 if (requestCode == REQUEST_BIND_APPWIDGET) {
Winsona1f79d32015-08-05 14:00:45 -0700748 // This is called only if the user did not previously have permissions to bind widgets
Adam Cohenad4e15c2013-10-17 16:21:35 -0700749 final int appWidgetId = data != null ?
Michael Jurka8b805b12012-04-18 14:23:14 -0700750 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
751 if (resultCode == RESULT_CANCELED) {
Sunny Goyal2100c782016-08-22 16:00:03 -0700752 completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId, requestArgs);
Adam Cohen689ff162014-05-08 17:27:56 -0700753 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
Adam Cohenad4e15c2013-10-17 16:21:35 -0700754 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
Michael Jurka8b805b12012-04-18 14:23:14 -0700755 } else if (resultCode == RESULT_OK) {
Sunny Goyal2100c782016-08-22 16:00:03 -0700756 addAppWidgetImpl(
757 appWidgetId, requestArgs, null,
Sunny Goyal04a324a2017-01-20 21:08:59 -0800758 requestArgs.getWidgetHandler(),
Sunny Goyal2100c782016-08-22 16:00:03 -0700759 ON_ACTIVITY_RESULT_ANIMATION_DELAY);
Michael Jurka8b805b12012-04-18 14:23:14 -0700760 }
761 return;
762 }
Michael Jurka336fd4f2013-09-12 00:05:02 +0200763
Adam Cohened66b2b2012-01-23 17:28:51 -0800764 boolean isWidgetDrop = (requestCode == REQUEST_PICK_APPWIDGET ||
Sunny Goyal5c97f512015-05-19 16:03:28 -0700765 requestCode == REQUEST_CREATE_APPWIDGET);
Romain Guyaad5ef42009-06-10 02:48:37 -0700766
Adam Cohened66b2b2012-01-23 17:28:51 -0800767 // We have special handling for widgets
768 if (isWidgetDrop) {
Adam Cohen4637b5a2013-11-04 18:21:24 -0800769 final int appWidgetId;
770 int widgetId = data != null ? data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1)
771 : -1;
772 if (widgetId < 0) {
773 appWidgetId = pendingAddWidgetId;
774 } else {
775 appWidgetId = widgetId;
776 }
777
Adam Cohenad4e15c2013-10-17 16:21:35 -0700778 final int result;
Adam Cohenf0129b12013-11-04 17:57:36 -0800779 if (appWidgetId < 0 || resultCode == RESULT_CANCELED) {
Adam Cohendb364c32014-05-20 14:23:40 -0700780 Log.e(TAG, "Error: appWidgetId (EXTRA_APPWIDGET_ID) was not " +
781 "returned from the widget configuration activity.");
Adam Cohenad4e15c2013-10-17 16:21:35 -0700782 result = RESULT_CANCELED;
Sunny Goyal2100c782016-08-22 16:00:03 -0700783 completeTwoStageWidgetDrop(result, appWidgetId, requestArgs);
Adam Cohendb364c32014-05-20 14:23:40 -0700784 final Runnable onComplete = new Runnable() {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700785 @Override
786 public void run() {
Sunny Goyal3e3f44c2017-10-23 17:14:52 -0700787 getStateManager().goToState(NORMAL);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700788 }
789 };
Adam Cohendb364c32014-05-20 14:23:40 -0700790
Sunny Goyal2100c782016-08-22 16:00:03 -0700791 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete,
792 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
793 } else {
794 if (requestArgs.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
795 // When the screen id represents an actual screen (as opposed to a rank)
796 // we make sure that the drop page actually exists.
797 requestArgs.screenId =
798 ensurePendingDropLayoutExists(requestArgs.screenId);
Adam Cohendb364c32014-05-20 14:23:40 -0700799 }
Sunny Goyal2100c782016-08-22 16:00:03 -0700800 final CellLayout dropLayout =
801 mWorkspace.getScreenWithId(requestArgs.screenId);
802
803 dropLayout.setDropPending(true);
804 final Runnable onComplete = new Runnable() {
805 @Override
806 public void run() {
807 completeTwoStageWidgetDrop(resultCode, appWidgetId, requestArgs);
808 dropLayout.setDropPending(false);
809 }
810 };
811 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete,
812 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
Winson Chung5aaab772012-04-27 15:24:02 -0700813 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800814 return;
815 }
816
Sunny Goyald478c832016-04-01 12:04:16 -0700817 if (requestCode == REQUEST_RECONFIGURE_APPWIDGET
818 || requestCode == REQUEST_BIND_PENDING_APPWIDGET) {
Sunny Goyalff572272014-07-23 13:58:07 -0700819 if (resultCode == RESULT_OK) {
820 // Update the widget view.
Sunny Goyal2100c782016-08-22 16:00:03 -0700821 completeAdd(requestCode, data, pendingAddWidgetId, requestArgs);
Sunny Goyalff572272014-07-23 13:58:07 -0700822 }
823 // Leave the widget in the pending state if the user canceled the configure.
824 return;
825 }
826
Sunny Goyalaad90582015-07-09 14:22:50 -0700827 if (requestCode == REQUEST_CREATE_SHORTCUT) {
828 // Handle custom shortcuts created using ACTION_CREATE_SHORTCUT.
Sunny Goyal2100c782016-08-22 16:00:03 -0700829 if (resultCode == RESULT_OK && requestArgs.container != ItemInfo.NO_ID) {
830 completeAdd(requestCode, data, -1, requestArgs);
831 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
832 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
833
Sunny Goyalaad90582015-07-09 14:22:50 -0700834 } else if (resultCode == RESULT_CANCELED) {
Adam Cohendb364c32014-05-20 14:23:40 -0700835 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
836 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800837 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800838 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800839 mDragLayer.clearAnimatedView();
Adam Cohenc7cd2cb2014-11-17 17:45:34 -0800840 }
841
842 @Override
Sunny Goyal64a75aa2017-07-03 13:50:52 -0700843 public void onActivityResult(
Adam Cohenc7cd2cb2014-11-17 17:45:34 -0800844 final int requestCode, final int resultCode, final Intent data) {
Sunny Goyaldedda052019-05-14 15:23:48 -0700845 mPendingActivityRequestCode = -1;
Adam Cohenc7cd2cb2014-11-17 17:45:34 -0800846 handleActivityResult(requestCode, resultCode, data);
Adam Cohened66b2b2012-01-23 17:28:51 -0800847 }
848
Sunny Goyal7ce471b2017-08-02 03:37:39 -0700849 @Override
Sunny Goyaldd2e6df2015-07-07 10:57:57 -0700850 public void onRequestPermissionsResult(int requestCode, String[] permissions,
Dave Hawkey3a43ed62015-06-26 10:27:47 -0600851 int[] grantResults) {
Sunny Goyal2100c782016-08-22 16:00:03 -0700852 PendingRequestArgs pendingArgs = mPendingRequestArgs;
853 if (requestCode == REQUEST_PERMISSION_CALL_PHONE && pendingArgs != null
854 && pendingArgs.getRequestCode() == REQUEST_PERMISSION_CALL_PHONE) {
855 setWaitingForResult(null);
856
Sunny Goyal28c6b962015-10-12 11:42:05 -0700857 View v = null;
Sunny Goyal2100c782016-08-22 16:00:03 -0700858 CellLayout layout = getCellLayout(pendingArgs.container, pendingArgs.screenId);
Sunny Goyal28c6b962015-10-12 11:42:05 -0700859 if (layout != null) {
Sunny Goyal2100c782016-08-22 16:00:03 -0700860 v = layout.getChildAt(pendingArgs.cellX, pendingArgs.cellY);
Sunny Goyal28c6b962015-10-12 11:42:05 -0700861 }
Sunny Goyal2100c782016-08-22 16:00:03 -0700862 Intent intent = pendingArgs.getPendingIntent();
863
Sunny Goyal28c6b962015-10-12 11:42:05 -0700864 if (grantResults.length > 0
865 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
Sunny Goyal369212a2019-03-26 15:03:57 -0700866 startActivitySafely(v, intent, null, null);
Sunny Goyal28c6b962015-10-12 11:42:05 -0700867 } else {
868 // TODO: Show a snack bar with link to settings
869 Toast.makeText(this, getString(R.string.msg_no_phone_permission,
Sunny Goyal112ce422016-08-22 16:45:29 -0700870 getString(R.string.derived_app_name)), Toast.LENGTH_SHORT).show();
Sunny Goyal28c6b962015-10-12 11:42:05 -0700871 }
872 }
Dave Hawkey3a43ed62015-06-26 10:27:47 -0600873 }
874
Adam Cohendb364c32014-05-20 14:23:40 -0700875 /**
876 * Check to see if a given screen id exists. If not, create it at the end, return the new id.
877 *
878 * @param screenId the screen id to check
879 * @return the new screen, or screenId if it exists
880 */
Sunny Goyalefb7e842018-10-04 15:11:00 -0700881 private int ensurePendingDropLayoutExists(int screenId) {
Sunny Goyal32554d12015-12-03 15:31:25 -0800882 CellLayout dropLayout = mWorkspace.getScreenWithId(screenId);
Adam Cohendb364c32014-05-20 14:23:40 -0700883 if (dropLayout == null) {
884 // it's possible that the add screen was removed because it was
885 // empty and a re-bind occurred
886 mWorkspace.addExtraEmptyScreen();
887 return mWorkspace.commitExtraEmptyScreen();
888 } else {
889 return screenId;
890 }
891 }
892
Samuel Fufaca37b8a2019-08-19 17:04:36 -0700893 @Thunk
894 void completeTwoStageWidgetDrop(
Sunny Goyal2100c782016-08-22 16:00:03 -0700895 final int resultCode, final int appWidgetId, final PendingRequestArgs requestArgs) {
896 CellLayout cellLayout = mWorkspace.getScreenWithId(requestArgs.screenId);
Adam Cohened66b2b2012-01-23 17:28:51 -0800897 Runnable onCompleteRunnable = null;
898 int animationType = 0;
899
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700900 AppWidgetHostView boundWidget = null;
Adam Cohened66b2b2012-01-23 17:28:51 -0800901 if (resultCode == RESULT_OK) {
902 animationType = Workspace.COMPLETE_TWO_STAGE_WIDGET_DROP_ANIMATION;
903 final AppWidgetHostView layout = mAppWidgetHost.createView(this, appWidgetId,
Sunny Goyal04a324a2017-01-20 21:08:59 -0800904 requestArgs.getWidgetHandler().getProviderInfo(this));
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700905 boundWidget = layout;
Adam Cohened66b2b2012-01-23 17:28:51 -0800906 onCompleteRunnable = new Runnable() {
907 @Override
908 public void run() {
Sunny Goyal2100c782016-08-22 16:00:03 -0700909 completeAddAppWidget(appWidgetId, requestArgs, layout, null);
Sunny Goyal3e3f44c2017-10-23 17:14:52 -0700910 mStateManager.goToState(NORMAL, SPRING_LOADED_EXIT_DELAY);
Adam Cohened66b2b2012-01-23 17:28:51 -0800911 }
912 };
913 } else if (resultCode == RESULT_CANCELED) {
Adam Cohen4637b5a2013-11-04 18:21:24 -0800914 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
Adam Cohened66b2b2012-01-23 17:28:51 -0800915 animationType = Workspace.CANCEL_TWO_STAGE_WIDGET_DROP_ANIMATION;
Adam Cohened66b2b2012-01-23 17:28:51 -0800916 }
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700917 if (mDragLayer.getAnimatedView() != null) {
Sunny Goyal2100c782016-08-22 16:00:03 -0700918 mWorkspace.animateWidgetDrop(requestArgs, cellLayout,
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700919 (DragView) mDragLayer.getAnimatedView(), onCompleteRunnable,
920 animationType, boundWidget, true);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700921 } else if (onCompleteRunnable != null) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700922 // The animated view may be null in the case of a rotation during widget configuration
923 onCompleteRunnable.run();
924 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800925 }
926
927 @Override
Michael Jurkacd496d72013-04-11 11:32:45 -0700928 protected void onStop() {
929 super.onStop();
Winson Chung0b70cd42019-06-17 22:34:33 -0700930
Sunny Goyalb1d7de22019-09-06 10:36:54 -0700931 if (mDeferOverlayCallbacks) {
932 checkIfOverlayStillDeferred();
933 } else {
934 mOverlayManager.onActivityStopped(this);
Adam Cohen9211d422014-10-07 18:14:53 -0700935 }
Sunny Goyalb1d7de22019-09-06 10:36:54 -0700936
Becky Qiubfc2da12019-08-01 11:09:38 -0700937 logStopAndResume(Action.Command.STOP);
Hyunyoung Songbd6fba92018-05-16 15:54:31 -0700938
939 mAppWidgetHost.setListenIfResumed(false);
940
Tony Wickham010d2552017-01-20 08:15:28 -0800941 NotificationListener.removeNotificationsChangedListener();
Sunny Goyalaf161fd2018-02-05 16:34:57 -0800942 getStateManager().moveToRestState();
Winson Chungedb0d6b2018-03-21 17:32:55 -0700943
Winson Chungdea51352018-04-24 13:02:10 -0700944 // Workaround for b/78520668, explicitly trim memory once UI is hidden
Winson Chung473730f2018-04-26 11:54:22 -0700945 onTrimMemory(TRIM_MEMORY_UI_HIDDEN);
Michael Jurkacd496d72013-04-11 11:32:45 -0700946 }
947
948 @Override
949 protected void onStart() {
Winson Chung5cc62c72019-10-16 11:32:41 -0700950 Object traceToken = TraceHelper.INSTANCE.beginSection(ON_START_EVT,
951 TraceHelper.FLAG_UI_EVENT);
Michael Jurkacd496d72013-04-11 11:32:45 -0700952 super.onStart();
Sunny Goyalb1d7de22019-09-06 10:36:54 -0700953 if (!mDeferOverlayCallbacks) {
954 mOverlayManager.onActivityStarted(this);
Adam Cohen9211d422014-10-07 18:14:53 -0700955 }
Sunny Goyalb1d7de22019-09-06 10:36:54 -0700956
Sunny Goyal67419a12017-11-14 16:55:22 -0800957 mAppWidgetHost.setListenIfResumed(true);
Winson Chung5cc62c72019-10-16 11:32:41 -0700958 TraceHelper.INSTANCE.endSection(traceToken);
Michael Jurkacd496d72013-04-11 11:32:45 -0700959 }
960
Sunny Goyala002c6c2019-02-12 16:20:10 -0800961 private void handleDeferredResume() {
Sunny Goyale9c6f4c2019-05-30 11:35:25 -0700962 if (hasBeenResumed() && !mStateManager.getState().disableInteraction) {
Becky Qiubfc2da12019-08-01 11:09:38 -0700963 logStopAndResume(Action.Command.RESUME);
Hyunyoung Songbd6fba92018-05-16 15:54:31 -0700964 getUserEventDispatcher().startSession();
Sunny Goyala002c6c2019-02-12 16:20:10 -0800965
Sunny Goyal369212a2019-03-26 15:03:57 -0700966 AppLaunchTracker.INSTANCE.get(this).onReturnedToHome();
Hyunyoung Songbd6fba92018-05-16 15:54:31 -0700967
Sunny Goyale9c6f4c2019-05-30 11:35:25 -0700968 // Process any items that were added while Launcher was away.
969 InstallShortcutReceiver.disableAndFlushInstallQueue(
970 InstallShortcutReceiver.FLAG_ACTIVITY_PAUSED, this);
971
972 // Refresh shortcuts if the permission changed.
973 mModel.refreshShortcutsIfRequired();
974
Winson Chung87583112019-06-10 14:20:58 -0700975 // Set the notification listener and fetch updated notifications when we resume
976 NotificationListener.setNotificationsChangedListener(mPopupDataProvider);
977
Sunny Goyale9c6f4c2019-05-30 11:35:25 -0700978 DiscoveryBounce.showForHomeIfNeeded(this);
979
Sunny Goyal210e1742019-10-17 12:05:38 -0700980 onDeferredResumed();
981 addActivityFlags(ACTIVITY_STATE_DEFERRED_RESUMED);
982
Sunny Goyale9c6f4c2019-05-30 11:35:25 -0700983 mDeferredResumePending = false;
984 } else {
985 mDeferredResumePending = true;
Sunny Goyaldedda052019-05-14 15:23:48 -0700986 }
987 }
988
Sunny Goyal210e1742019-10-17 12:05:38 -0700989 protected void onDeferredResumed() { }
990
Becky Qiubfc2da12019-08-01 11:09:38 -0700991 private void logStopAndResume(int command) {
992 int containerType = mStateManager.getState().containerType;
993 if (containerType == ContainerType.WORKSPACE && mWorkspace != null) {
994 getUserEventDispatcher().logActionCommand(command,
Samuel Fufaca37b8a2019-08-19 17:04:36 -0700995 containerType, -1, mWorkspace.isOverlayShown() ? -1 : 0);
Becky Qiubfc2da12019-08-01 11:09:38 -0700996 } else {
997 getUserEventDispatcher().logActionCommand(command, containerType, -1);
998 }
Sunny Goyalb1d7de22019-09-06 10:36:54 -0700999 }
Becky Qiubfc2da12019-08-01 11:09:38 -07001000
Sunny Goyalb1d7de22019-09-06 10:36:54 -07001001 private void scheduleDeferredCheck() {
1002 mHandler.removeCallbacks(mDeferredOverlayCallbacks);
1003 postAsyncCallback(mHandler, mDeferredOverlayCallbacks);
1004 }
1005
1006 private void checkIfOverlayStillDeferred() {
1007 if (!mDeferOverlayCallbacks) {
1008 return;
1009 }
1010 if (isStarted() && (!hasBeenResumed() || mStateManager.getState().disableInteraction)) {
1011 return;
1012 }
1013 mDeferOverlayCallbacks = false;
1014
1015 // Move the client to the correct state. Calling the same method twice is no-op.
1016 if (isStarted()) {
1017 mOverlayManager.onActivityStarted(this);
1018 }
1019 if (hasBeenResumed()) {
1020 mOverlayManager.onActivityResumed(this);
1021 } else {
1022 mOverlayManager.onActivityPaused(this);
1023 }
1024 if (!isStarted()) {
1025 mOverlayManager.onActivityStopped(this);
1026 }
1027 }
1028
1029 public void deferOverlayCallbacksUntilNextResumeOrStop() {
1030 mDeferOverlayCallbacks = true;
1031 }
1032
1033 public LauncherOverlayManager getOverlayManager() {
1034 return mOverlayManager;
Becky Qiubfc2da12019-08-01 11:09:38 -07001035 }
1036
Winson Chungef528762019-09-06 12:05:52 -07001037 public void onStateSetStart(LauncherState state) {
Sunny Goyale9c6f4c2019-05-30 11:35:25 -07001038 if (mDeferredResumePending) {
1039 handleDeferredResume();
1040 }
Sunny Goyalb1d7de22019-09-06 10:36:54 -07001041 if (mDeferOverlayCallbacks) {
1042 scheduleDeferredCheck();
Sunny Goyale9c6f4c2019-05-30 11:35:25 -07001043 }
Sunny Goyal210e1742019-10-17 12:05:38 -07001044 addActivityFlags(ACTIVITY_STATE_TRANSITION_ACTIVE);
Sunny Goyaldedda052019-05-14 15:23:48 -07001045 }
1046
Winson Chungef528762019-09-06 12:05:52 -07001047 public void onStateSetEnd(LauncherState state) {
1048 getAppWidgetHost().setResumed(state == LauncherState.NORMAL);
1049 getWorkspace().setClipChildren(!state.disablePageClipping);
1050 finishAutoCancelActionMode();
Sunny Goyal210e1742019-10-17 12:05:38 -07001051 removeActivityFlags(ACTIVITY_STATE_TRANSITION_ACTIVE);
Winson Chungef528762019-09-06 12:05:52 -07001052 }
1053
Michael Jurkacd496d72013-04-11 11:32:45 -07001054 @Override
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001055 protected void onResume() {
Winson Chung5cc62c72019-10-16 11:32:41 -07001056 Object traceToken = TraceHelper.INSTANCE.beginSection(ON_RESUME_EVT,
1057 TraceHelper.FLAG_UI_EVENT);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001058 super.onResume();
Sunny Goyalfca6bc92017-09-28 16:28:34 -07001059
Sunny Goyala002c6c2019-02-12 16:20:10 -08001060 mHandler.removeCallbacks(mHandleDeferredResume);
1061 Utilities.postAsyncCallback(mHandler, mHandleDeferredResume);
Hyunyoung Songbd6fba92018-05-16 15:54:31 -07001062
Winson Chung940b0ac2019-07-09 11:33:50 -07001063 if (!mOnResumeCallbacks.isEmpty()) {
1064 final ArrayList<OnResumeCallback> resumeCallbacks = new ArrayList<>(mOnResumeCallbacks);
1065 mOnResumeCallbacks.clear();
1066 for (int i = resumeCallbacks.size() - 1; i >= 0; i--) {
1067 resumeCallbacks.get(i).onLauncherResume();
1068 }
1069 resumeCallbacks.clear();
Winson Chung0b70cd42019-06-17 22:34:33 -07001070 }
Sunny Goyal95f3d6b2016-08-10 16:09:29 -07001071
Sunny Goyalb1d7de22019-09-06 10:36:54 -07001072 if (mDeferOverlayCallbacks) {
1073 scheduleDeferredCheck();
1074 } else {
1075 mOverlayManager.onActivityResumed(this);
Adam Cohen9211d422014-10-07 18:14:53 -07001076 }
Mario Bertschler0fc6f682017-02-17 12:16:13 -08001077
Winson Chung5cc62c72019-10-16 11:32:41 -07001078 TraceHelper.INSTANCE.endSection(traceToken);
Adam Cohen06dff352012-06-01 17:17:08 -07001079 }
1080
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001081 @Override
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001082 protected void onPause() {
Winson Chung997a9232013-07-24 15:33:46 -07001083 // Ensure that items added to Launcher are queued until Launcher returns
Sunny Goyala474a9b2017-05-04 16:47:11 -07001084 InstallShortcutReceiver.enableInstallQueue(InstallShortcutReceiver.FLAG_ACTIVITY_PAUSED);
Winson Chung997a9232013-07-24 15:33:46 -07001085
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001086 super.onPause();
Joe Onorato24b6fd82009-11-12 13:47:09 -08001087 mDragController.cancelDrag();
Winson Chunga2413752012-04-03 14:22:34 -07001088 mDragController.resetLastGestureUpTime();
Hyunyoung Song497708c2019-05-01 16:16:53 -07001089 mDropTargetBar.animateToVisibility(false);
Sunny Goyalb1d7de22019-09-06 10:36:54 -07001090
1091 if (!mDeferOverlayCallbacks) {
1092 mOverlayManager.onActivityPaused(this);
Adam Cohenbffe7452013-07-22 18:21:45 -07001093 }
Adam Cohenbffe7452013-07-22 18:21:45 -07001094 }
1095
Adam Cohenc2d6e892014-10-16 09:49:24 -07001096 class LauncherOverlayCallbacksImpl implements LauncherOverlayCallbacks {
1097
Sunny Goyalc86df472016-02-25 09:19:38 -08001098 public void onScrollChanged(float progress) {
1099 if (mWorkspace != null) {
1100 mWorkspace.onOverlayScrollChanged(progress);
1101 }
1102 }
Adam Cohenc2d6e892014-10-16 09:49:24 -07001103 }
1104
Sunny Goyalf9403d92017-10-18 10:55:56 -07001105 public boolean isInState(LauncherState state) {
Sunny Goyalea609262017-10-25 15:47:38 -07001106 return mStateManager.getState() == state;
Sunny Goyalf9403d92017-10-18 10:55:56 -07001107 }
1108
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001109 /**
1110 * Restores the previous state, if it exists.
1111 *
1112 * @param savedState The previous state.
1113 */
1114 private void restoreState(Bundle savedState) {
1115 if (savedState == null) {
1116 return;
1117 }
1118
Sunny Goyal3e3f44c2017-10-23 17:14:52 -07001119 int stateOrdinal = savedState.getInt(RUNTIME_STATE, NORMAL.ordinal);
Sunny Goyalf9403d92017-10-18 10:55:56 -07001120 LauncherState[] stateValues = LauncherState.values();
1121 LauncherState state = stateValues[stateOrdinal];
Sunny Goyalbc683e92017-12-06 10:25:07 -08001122 if (!state.disableRestore) {
Sunny Goyal3e3f44c2017-10-23 17:14:52 -07001123 mStateManager.goToState(state, false /* animated */);
Joe Onorato3a8820b2009-11-10 15:06:42 -08001124 }
1125
Samuel Fufaca37b8a2019-08-19 17:04:36 -07001126 PendingRequestArgs requestArgs = savedState.getParcelable(
1127 RUNTIME_STATE_PENDING_REQUEST_ARGS);
Sunny Goyal2100c782016-08-22 16:00:03 -07001128 if (requestArgs != null) {
1129 setWaitingForResult(requestArgs);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001130 }
Sunny Goyaldedda052019-05-14 15:23:48 -07001131 mPendingActivityRequestCode = savedState.getInt(RUNTIME_STATE_PENDING_REQUEST_CODE);
Sunny Goyal2100c782016-08-22 16:00:03 -07001132
1133 mPendingActivityResult = savedState.getParcelable(RUNTIME_STATE_PENDING_ACTIVITY_RESULT);
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -07001134
1135 SparseArray<Parcelable> widgetsState =
1136 savedState.getSparseParcelableArray(RUNTIME_STATE_WIDGET_PANEL);
1137 if (widgetsState != null) {
1138 WidgetsFullSheet.show(this, false).restoreHierarchyState(widgetsState);
1139 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001140 }
1141
1142 /**
1143 * Finds all the views we need and configure them properly.
1144 */
1145 private void setupViews() {
Sunny Goyalcc96aa12018-01-11 09:56:07 -08001146 mDragLayer = findViewById(R.id.drag_layer);
Sunny Goyal3333b0c2016-05-09 20:43:21 -07001147 mFocusHandler = mDragLayer.getFocusIndicatorHelper();
Sunny Goyal966d9012017-06-06 16:43:59 -07001148 mWorkspace = mDragLayer.findViewById(R.id.workspace);
Sunny Goyald0a6ae72016-06-16 12:29:03 -07001149 mWorkspace.initParentViews(mDragLayer);
Sunny Goyal16764582017-11-06 16:00:34 -08001150 mOverviewPanel = findViewById(R.id.overview_panel);
Sunny Goyal7c7be8c2018-03-07 19:58:07 -08001151 mHotseat = findViewById(R.id.hotseat);
Craig Mautner360310b2012-10-26 15:13:08 -07001152
Sunny Goyal784f9c32016-03-23 16:56:54 -07001153 mLauncherView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
1154 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
1155 | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001156
Winson Chung4c98d922011-05-31 16:50:48 -07001157 // Setup the drag layer
Sunny Goyal5d1873a2018-05-08 11:10:44 -07001158 mDragLayer.setup(mDragController, mWorkspace);
Winson Chung4c98d922011-05-31 16:50:48 -07001159
Hyunyoung Song645764e2016-06-06 14:19:02 -07001160 mWorkspace.setup(mDragController);
Winsonc7d2e832016-07-28 12:24:55 -07001161 // Until the workspace is bound, ensure that we keep the wallpaper offset locked to the
1162 // default state, otherwise we will update to the wrong offsets in RTL
1163 mWorkspace.lockWallpaperToDefaultPage();
Sunny Goyalda4fe1a2016-05-26 16:05:17 -07001164 mWorkspace.bindAndInitFirstWorkspaceScreen(null /* recycled qsb */);
Hyunyoung Song645764e2016-06-06 14:19:02 -07001165 mDragController.addDragListener(mWorkspace);
Winson Chung4c98d922011-05-31 16:50:48 -07001166
Tony Wickham34d2c912015-09-11 09:27:58 -07001167 // Get the search/delete/uninstall bar
Rajeev Kumar43c0f582017-06-23 15:34:55 -07001168 mDropTargetBar = mDragLayer.findViewById(R.id.drop_target_bar);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07001169
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -07001170 // Setup Apps
1171 mAppsView = findViewById(R.id.apps_view);
Craig Mautner360310b2012-10-26 15:13:08 -07001172
Govinda Wassermanc06e1512019-04-09 09:56:53 -04001173 // Setup Scrim
1174 mScrimView = findViewById(R.id.scrim_view);
1175
Winson Chung3d503fb2011-07-13 17:25:49 -07001176 // Setup the drag controller (drop targets have to be added in reverse order in priority)
Hyunyoung Song645764e2016-06-06 14:19:02 -07001177 mDragController.setMoveTarget(mWorkspace);
Sunny Goyal47328fd2016-05-25 18:56:41 -07001178 mDropTargetBar.setup(mDragController);
Daniel Sandler924b9932013-06-12 00:38:25 -04001179
Sunny Goyal7185dd62018-03-14 17:51:49 -07001180 mAllAppsController.setupViews(mAppsView);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001181 }
1182
1183 /**
1184 * Creates a view representing a shortcut.
1185 *
1186 * @param info The data structure describing the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001187 */
Sunny Goyal95899162019-03-27 16:03:06 -07001188 View createShortcut(WorkspaceItemInfo info) {
Sunny Goyaldfaccf62015-05-11 16:30:44 -07001189 return createShortcut((ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001190 }
1191
1192 /**
1193 * Creates a view representing a shortcut inflated from the specified resource.
1194 *
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001195 * @param parent The group the shortcut belongs to.
Samuel Fufaca37b8a2019-08-19 17:04:36 -07001196 * @param info The data structure describing the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001197 * @return A View inflated from layoutResId.
1198 */
Sunny Goyal95899162019-03-27 16:03:06 -07001199 public View createShortcut(ViewGroup parent, WorkspaceItemInfo info) {
Sunny Goyal9b29ca52017-02-17 10:39:44 -08001200 BubbleTextView favorite = (BubbleTextView) LayoutInflater.from(parent.getContext())
1201 .inflate(R.layout.app_icon, parent, false);
Sunny Goyal95899162019-03-27 16:03:06 -07001202 favorite.applyFromWorkspaceItem(info);
Sunny Goyal8a2a63b2018-03-06 22:15:18 -08001203 favorite.setOnClickListener(ItemClickHandler.INSTANCE);
Sunny Goyaldcbcc862014-08-12 15:58:36 -07001204 favorite.setOnFocusChangeListener(mFocusHandler);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001205 return favorite;
1206 }
1207
1208 /**
Jon Mirandac476d6e2017-05-04 16:30:01 -07001209 * Add a shortcut to the workspace or to a Folder.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001210 *
1211 * @param data The intent describing the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001212 */
Sunny Goyalefb7e842018-10-04 15:11:00 -07001213 private void completeAddShortcut(Intent data, int container, int screenId, int cellX,
Sunny Goyalfb5096d2016-09-08 14:32:06 -07001214 int cellY, PendingRequestArgs args) {
Pinyao Ting5eee5f42019-10-31 16:47:35 -07001215 if (args.getRequestCode() != REQUEST_CREATE_SHORTCUT
Jon Mirandac476d6e2017-05-04 16:30:01 -07001216 || args.getPendingIntent().getComponent() == null) {
Sunny Goyalfb5096d2016-09-08 14:32:06 -07001217 return;
1218 }
Adam Cohen558baaf2011-08-15 15:22:57 -07001219
Jon Mirandac476d6e2017-05-04 16:30:01 -07001220 int[] cellXY = mTmpAddItemCellCoordinates;
1221 CellLayout layout = getCellLayout(container, screenId);
1222
Sunny Goyal95899162019-03-27 16:03:06 -07001223 WorkspaceItemInfo info = null;
Hyunyoung Songe24cb632017-09-11 11:18:03 -07001224 if (Utilities.ATLEAST_OREO) {
Sunny Goyale7b00122019-10-02 16:13:34 -07001225 info = PinRequestHelper.createWorkspaceItemFromPinItemRequest(
1226 this, PinRequestHelper.getPinItemRequest(data), 0);
Sunny Goyal782f0c92017-01-19 10:27:54 -08001227 }
1228
1229 if (info == null) {
Sunny Goyalb57645f2017-03-20 13:57:28 -07001230 // Legacy shortcuts are only supported for primary profile.
1231 info = Process.myUserHandle().equals(args.user)
1232 ? InstallShortcutReceiver.fromShortcutIntent(this, data) : null;
Sunny Goyal782f0c92017-01-19 10:27:54 -08001233
Sunny Goyalb57645f2017-03-20 13:57:28 -07001234 if (info == null) {
1235 Log.e(TAG, "Unable to parse a valid custom shortcut result");
1236 return;
1237 } else if (!new PackageManagerHelper(this).hasPermissionForActivity(
Sunny Goyal342e4662017-02-02 15:21:08 -08001238 info.intent, args.getPendingIntent().getComponent().getPackageName())) {
Sunny Goyal782f0c92017-01-19 10:27:54 -08001239 // The app is trying to add a shortcut without sufficient permissions
1240 Log.e(TAG, "Ignoring malicious intent " + info.intent.toUri(0));
1241 return;
1242 }
1243 }
1244
Jon Mirandac476d6e2017-05-04 16:30:01 -07001245 if (container < 0) {
1246 // Adding a shortcut to the Workspace.
1247 final View view = createShortcut(info);
1248 boolean foundCellSpan = false;
1249 // First we check if we already know the exact location where we want to add this item.
1250 if (cellX >= 0 && cellY >= 0) {
1251 cellXY[0] = cellX;
1252 cellXY[1] = cellY;
1253 foundCellSpan = true;
Adam Cohen558baaf2011-08-15 15:22:57 -07001254
Jon Mirandac476d6e2017-05-04 16:30:01 -07001255 // If appropriate, either create a folder or add to an existing folder
1256 if (mWorkspace.createUserFolderIfNecessary(view, container, layout, cellXY, 0,
Sunny Goyal1797af42017-10-06 13:29:57 -07001257 true, null)) {
Jon Mirandac476d6e2017-05-04 16:30:01 -07001258 return;
1259 }
1260 DragObject dragObject = new DragObject();
1261 dragObject.dragInfo = info;
1262 if (mWorkspace.addToExistingFolderIfNecessary(view, layout, cellXY, 0, dragObject,
1263 true)) {
1264 return;
1265 }
1266 } else {
1267 foundCellSpan = layout.findCellForSpan(cellXY, 1, 1);
1268 }
1269
1270 if (!foundCellSpan) {
1271 mWorkspace.onNoCellFound(layout);
Adam Cohen558baaf2011-08-15 15:22:57 -07001272 return;
1273 }
Jon Mirandac476d6e2017-05-04 16:30:01 -07001274
1275 getModelWriter().addItemToDatabase(info, container, screenId, cellXY[0], cellXY[1]);
1276 mWorkspace.addInScreen(view, info);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001277 } else {
Jon Mirandac476d6e2017-05-04 16:30:01 -07001278 // Adding a shortcut to a Folder.
Sunny Goyale29897f52017-07-20 10:09:42 -07001279 FolderIcon folderIcon = findFolderIcon(container);
Jon Mirandac476d6e2017-05-04 16:30:01 -07001280 if (folderIcon != null) {
1281 FolderInfo folderInfo = (FolderInfo) folderIcon.getTag();
1282 folderInfo.add(info, args.rank, false);
1283 } else {
Sunny Goyale29897f52017-07-20 10:09:42 -07001284 Log.e(TAG, "Could not find folder with id " + container + " to add shortcut.");
Jon Mirandac476d6e2017-05-04 16:30:01 -07001285 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001286 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001287 }
1288
Sunny Goyalefb7e842018-10-04 15:11:00 -07001289 public FolderIcon findFolderIcon(final int folderIconId) {
Sunny Goyal83fd25e2018-07-09 16:47:01 -07001290 return (FolderIcon) mWorkspace.getHomescreenIconByItemId(folderIconId);
Sunny Goyale29897f52017-07-20 10:09:42 -07001291 }
1292
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001293 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001294 * Add a widget to the workspace.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001295 *
Romain Guy5bbc91b2010-08-18 11:38:46 -07001296 * @param appWidgetId The app widget id
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001297 */
Samuel Fufaca37b8a2019-08-19 17:04:36 -07001298 @Thunk
1299 void completeAddAppWidget(int appWidgetId, ItemInfo itemInfo,
Adam Cohen59400422014-03-05 18:07:04 -08001300 AppWidgetHostView hostView, LauncherAppWidgetProviderInfo appWidgetInfo) {
1301
Adam Cohened66b2b2012-01-23 17:28:51 -08001302 if (appWidgetInfo == null) {
Sunny Goyal2e1efb42016-03-03 16:58:55 -08001303 appWidgetInfo = mAppWidgetManager.getLauncherAppWidgetInfo(appWidgetId);
Adam Cohened66b2b2012-01-23 17:28:51 -08001304 }
Romain Guycbb89e42009-06-08 15:52:54 -07001305
Adam Cohen59400422014-03-05 18:07:04 -08001306 LauncherAppWidgetInfo launcherInfo;
1307 launcherInfo = new LauncherAppWidgetInfo(appWidgetId, appWidgetInfo.provider);
Sunny Goyal2100c782016-08-22 16:00:03 -07001308 launcherInfo.spanX = itemInfo.spanX;
1309 launcherInfo.spanY = itemInfo.spanY;
1310 launcherInfo.minSpanX = itemInfo.minSpanX;
1311 launcherInfo.minSpanY = itemInfo.minSpanY;
Sunny Goyal952e63d2017-08-16 04:59:08 -07001312 launcherInfo.user = appWidgetInfo.getProfile();
Romain Guycbb89e42009-06-08 15:52:54 -07001313
Sunny Goyal43bf11d2017-02-02 13:52:53 -08001314 getModelWriter().addItemToDatabase(launcherInfo,
Sunny Goyal2100c782016-08-22 16:00:03 -07001315 itemInfo.container, itemInfo.screenId, itemInfo.cellX, itemInfo.cellY);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001316
Sunny Goyal2100c782016-08-22 16:00:03 -07001317 if (hostView == null) {
1318 // Perform actual inflation because we're live
1319 hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001320 }
Sunny Goyal2100c782016-08-22 16:00:03 -07001321 hostView.setVisibility(View.VISIBLE);
Sunny Goyald5462aa2016-11-22 16:52:39 +05301322 prepareAppWidget(hostView, launcherInfo);
1323 mWorkspace.addInScreen(hostView, launcherInfo);
Pinyao Tingc9074272019-11-11 11:51:44 -08001324 announceForAccessibility(R.string.item_added_to_workspace);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001325 }
Romain Guycbb89e42009-06-08 15:52:54 -07001326
Sunny Goyald5462aa2016-11-22 16:52:39 +05301327 private void prepareAppWidget(AppWidgetHostView hostView, LauncherAppWidgetInfo item) {
Sunny Goyal87af0fd2016-05-16 14:56:02 -07001328 hostView.setTag(item);
1329 item.onBindAppWidget(this, hostView);
Sunny Goyal87af0fd2016-05-16 14:56:02 -07001330 hostView.setFocusable(true);
1331 hostView.setOnFocusChangeListener(mFocusHandler);
Sunny Goyal25c2e3e2015-10-28 23:28:21 -07001332 }
1333
Sunny Goyal5d1873a2018-05-08 11:10:44 -07001334 private final BroadcastReceiver mScreenOffReceiver = new BroadcastReceiver() {
Adam Cohended9f8d2010-11-03 13:25:16 -07001335 @Override
1336 public void onReceive(Context context, Intent intent) {
Sunny Goyal5d1873a2018-05-08 11:10:44 -07001337 // Reset AllApps to its initial state only if we are not in the middle of
1338 // processing a multi-step drop
1339 if (mPendingRequestArgs == null) {
1340 mStateManager.goToState(NORMAL);
Adam Cohended9f8d2010-11-03 13:25:16 -07001341 }
1342 }
1343 };
1344
Sunny Goyalaae6fbb2019-01-31 16:05:58 -08001345 public void updateNotificationDots(Predicate<PackageUserKey> updatedDots) {
Tony Wickhamf34bee82018-12-03 18:11:39 -08001346 mWorkspace.updateNotificationDots(updatedDots);
1347 mAppsView.getAppsStore().updateNotificationDots(updatedDots);
Tony Wickham010d2552017-01-20 08:15:28 -08001348 }
1349
Adam Cohended9f8d2010-11-03 13:25:16 -07001350 @Override
1351 public void onAttachedToWindow() {
1352 super.onAttachedToWindow();
Sunny Goyalb1d7de22019-09-06 10:36:54 -07001353 mOverlayManager.onAttachedToWindow();
Adam Cohended9f8d2010-11-03 13:25:16 -07001354 }
1355
1356 @Override
1357 public void onDetachedFromWindow() {
1358 super.onDetachedFromWindow();
Sunny Goyalb1d7de22019-09-06 10:36:54 -07001359 mOverlayManager.onDetachedFromWindow();
1360 closeContextMenu();
Adam Cohended9f8d2010-11-03 13:25:16 -07001361 }
1362
Sunny Goyalc4fa8c32017-11-07 12:23:58 -08001363 public AllAppsTransitionController getAllAppsController() {
1364 return mAllAppsController;
1365 }
1366
Sunny Goyal9d69c8d2018-03-19 13:41:31 -07001367 @Override
Winson Chung1a341002018-01-17 10:00:23 -08001368 public LauncherRootView getRootView() {
1369 return (LauncherRootView) mLauncherView;
1370 }
1371
Sunny Goyal0b0847b2018-03-14 12:30:11 -07001372 @Override
Winson Chunga6945242014-01-08 14:04:34 -08001373 public DragLayer getDragLayer() {
1374 return mDragLayer;
1375 }
1376
Winson Chung5f4e0fd2015-05-22 11:12:27 -07001377 public AllAppsContainerView getAppsView() {
Winson Chungb745afb2015-03-02 11:51:23 -08001378 return mAppsView;
1379 }
1380
Winson Chunga6945242014-01-08 14:04:34 -08001381 public Workspace getWorkspace() {
1382 return mWorkspace;
1383 }
1384
1385 public Hotseat getHotseat() {
1386 return mHotseat;
1387 }
1388
Sunny Goyal7c7be8c2018-03-07 19:58:07 -08001389 public <T extends View> T getOverviewPanel() {
Winson Chung8ae41982017-11-10 11:42:13 -08001390 return (T) mOverviewPanel;
Winson Chunga6945242014-01-08 14:04:34 -08001391 }
1392
Sunny Goyal47328fd2016-05-25 18:56:41 -07001393 public DropTargetBar getDropTargetBar() {
1394 return mDropTargetBar;
Tony Wickham34d2c912015-09-11 09:27:58 -07001395 }
1396
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001397 public LauncherAppWidgetHost getAppWidgetHost() {
1398 return mAppWidgetHost;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001399 }
Romain Guycbb89e42009-06-08 15:52:54 -07001400
Winson Chunga9abd0e2010-10-27 17:18:37 -07001401 public LauncherModel getModel() {
1402 return mModel;
1403 }
1404
Sunny Goyal43bf11d2017-02-02 13:52:53 -08001405 public ModelWriter getModelWriter() {
1406 return mModelWriter;
1407 }
1408
Sunny Goyalb1d7de22019-09-06 10:36:54 -07001409 @Override
Adam Cohen79d90c52016-04-22 13:29:20 -07001410 public SharedPreferences getSharedPrefs() {
Winson Chunga6945242014-01-08 14:04:34 -08001411 return mSharedPrefs;
1412 }
1413
Sunny Goyalb1d7de22019-09-06 10:36:54 -07001414 @Override
1415 public SharedPreferences getDevicePrefs() {
1416 return Utilities.getDevicePrefs(this);
1417 }
1418
Samuel Fufaca37b8a2019-08-19 17:04:36 -07001419 public int getOrientation() {
1420 return mOldConfig.orientation;
1421 }
Jon Miranda6bed3502017-09-19 14:43:17 -07001422
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001423 @Override
1424 protected void onNewIntent(Intent intent) {
vadimtbaf5fbb2019-12-16 18:56:09 -08001425 if (Utilities.IS_RUNNING_IN_TEST_HARNESS) {
1426 Log.d(TestProtocol.PERMANENT_DIAG_TAG, "Launcher.onNewIntent: " + intent);
1427 }
Winson Chung5cc62c72019-10-16 11:32:41 -07001428 Object traceToken = TraceHelper.INSTANCE.beginSection(ON_NEW_INTENT_EVT);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001429 super.onNewIntent(intent);
1430
Sunny Goyalf4aceab2017-12-06 16:16:31 -08001431 boolean alreadyOnHome = hasWindowFocus() && ((intent.getFlags() &
Winson15f8b172015-08-19 11:02:39 -07001432 Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
1433 != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
Sunny Goyal85313732016-09-28 12:00:07 -07001434
1435 // Check this condition before handling isActionMain, as this will get reset.
Sunny Goyal3e3f44c2017-10-23 17:14:52 -07001436 boolean shouldMoveToDefaultScreen = alreadyOnHome && isInState(NORMAL)
Sunny Goyalf9403d92017-10-18 10:55:56 -07001437 && AbstractFloatingView.getTopOpenView(this) == null;
Winson15f8b172015-08-19 11:02:39 -07001438 boolean isActionMain = Intent.ACTION_MAIN.equals(intent.getAction());
Sunny Goyale84c5b82019-09-26 17:05:31 -07001439 boolean internalStateHandled = ACTIVITY_TRACKER.handleNewIntent(this, intent);
Sunny Goyald3864fa2017-11-14 15:06:36 -08001440
Winson15f8b172015-08-19 11:02:39 -07001441 if (isActionMain) {
Sunny Goyald3864fa2017-11-14 15:06:36 -08001442 if (!internalStateHandled) {
Sunny Goyald3864fa2017-11-14 15:06:36 -08001443 // In all these cases, only animate if we're already on home
Sunny Goyalcc96aa12018-01-11 09:56:07 -08001444 AbstractFloatingView.closeAllOpenViews(this, isStarted());
Jon Mirandafeba90f2016-10-06 10:53:29 -07001445
Sunny Goyala2467272018-03-16 14:53:05 -07001446 if (!isInState(NORMAL)) {
1447 // Only change state, if not already the same. This prevents cancelling any
1448 // animations running as part of resume
1449 mStateManager.goToState(NORMAL);
1450 }
Sunny Goyald3864fa2017-11-14 15:06:36 -08001451
1452 // Reset the apps view
Sunny Goyal5d1873a2018-05-08 11:10:44 -07001453 if (!alreadyOnHome) {
Sunny Goyal7185dd62018-03-14 17:51:49 -07001454 mAppsView.reset(isStarted() /* animate */);
Sunny Goyald3864fa2017-11-14 15:06:36 -08001455 }
1456
Sunny Goyalaad33592018-08-07 17:20:35 -07001457 if (shouldMoveToDefaultScreen && !mWorkspace.isHandlingTouch()) {
Sunny Goyald3864fa2017-11-14 15:06:36 -08001458 mWorkspace.post(mWorkspace::moveToDefaultScreen);
1459 }
1460 }
Adam Cohen6fecd412013-10-02 17:41:50 -07001461
Hyunyoung Song2a70b3d2019-06-11 12:47:07 -07001462 // Handle HOME_INTENT
1463 UserEventDispatcher ued = getUserEventDispatcher();
1464 Target target = newContainerTarget(mStateManager.getState().containerType);
1465 target.pageIndex = mWorkspace.getCurrentPage();
1466 ued.logActionCommand(Action.Command.HOME_INTENT, target,
1467 newContainerTarget(ContainerType.WORKSPACE));
1468
Adam Cohen6fecd412013-10-02 17:41:50 -07001469 final View v = getWindow().peekDecorView();
1470 if (v != null && v.getWindowToken() != null) {
Sunny Goyal326403e2017-10-02 12:45:10 -07001471 UiThreadHelper.hideKeyboardAsync(this, v.getWindowToken());
Adam Cohen6fecd412013-10-02 17:41:50 -07001472 }
1473
Adam Cohen9211d422014-10-07 18:14:53 -07001474 if (mLauncherCallbacks != null) {
Sunny Goyal85462132018-04-24 11:39:37 -07001475 mLauncherCallbacks.onHomeIntent(internalStateHandled);
Adam Cohen9211d422014-10-07 18:14:53 -07001476 }
Sunny Goyalb1d7de22019-09-06 10:36:54 -07001477 mOverlayManager.hideOverlay(isStarted() && !isForceInvisible());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001478 }
Winson15f8b172015-08-19 11:02:39 -07001479
Winson Chung5cc62c72019-10-16 11:32:41 -07001480 TraceHelper.INSTANCE.endSection(traceToken);
Adam Coppa120b8e2013-11-12 16:26:04 +00001481 }
1482
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001483 @Override
Adam Cohen1462de32012-07-24 22:34:36 -07001484 public void onRestoreInstanceState(Bundle state) {
1485 super.onRestoreInstanceState(state);
Sunny Goyalf4aceab2017-12-06 16:16:31 -08001486 mWorkspace.restoreInstanceStateForChild(mSynchronouslyBoundPage);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001487 }
1488
1489 @Override
1490 protected void onSaveInstanceState(Bundle outState) {
Adam Cohen21cd0022013-10-09 18:57:02 -07001491 if (mWorkspace.getChildCount() > 0) {
Sunny Goyal7ce471b2017-08-02 03:37:39 -07001492 outState.putInt(RUNTIME_STATE_CURRENT_SCREEN, mWorkspace.getNextPage());
Hyunyoung Song645764e2016-06-06 14:19:02 -07001493
Adam Cohen21cd0022013-10-09 18:57:02 -07001494 }
Sunny Goyalea609262017-10-25 15:47:38 -07001495 outState.putInt(RUNTIME_STATE, mStateManager.getState().ordinal);
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -07001496
1497
1498 AbstractFloatingView widgets = AbstractFloatingView
1499 .getOpenView(this, AbstractFloatingView.TYPE_WIDGETS_FULL_SHEET);
1500 if (widgets != null) {
1501 SparseArray<Parcelable> widgetsState = new SparseArray<>();
1502 widgets.saveHierarchyState(widgetsState);
1503 outState.putSparseParcelableArray(RUNTIME_STATE_WIDGET_PANEL, widgetsState);
1504 } else {
1505 outState.remove(RUNTIME_STATE_WIDGET_PANEL);
1506 }
1507
Pinyao Tinga74b63a2019-07-17 23:26:06 -07001508 // We close any open folders and shortcut containers that are not safe for rebind,
Sunny Goyal740ac7f2016-09-28 16:47:32 -07001509 // and we need to make sure this state is reflected.
Pinyao Tinga74b63a2019-07-17 23:26:06 -07001510 AbstractFloatingView.closeOpenViews(this, false, TYPE_ALL & ~TYPE_REBIND_SAFE);
1511 finishAutoCancelActionMode();
Tony Wickham49c8d292016-07-01 11:44:34 -07001512
Sunny Goyal2100c782016-08-22 16:00:03 -07001513 if (mPendingRequestArgs != null) {
1514 outState.putParcelable(RUNTIME_STATE_PENDING_REQUEST_ARGS, mPendingRequestArgs);
1515 }
Sunny Goyaldedda052019-05-14 15:23:48 -07001516 outState.putInt(RUNTIME_STATE_PENDING_REQUEST_CODE, mPendingActivityRequestCode);
1517
Sunny Goyal2100c782016-08-22 16:00:03 -07001518 if (mPendingActivityResult != null) {
1519 outState.putParcelable(RUNTIME_STATE_PENDING_ACTIVITY_RESULT, mPendingActivityResult);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001520 }
1521
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -07001522 super.onSaveInstanceState(outState);
Sunny Goyalb1d7de22019-09-06 10:36:54 -07001523 mOverlayManager.onActivitySaveInstanceState(this, outState);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001524 }
1525
1526 @Override
1527 public void onDestroy() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001528 super.onDestroy();
Sunny Goyale84c5b82019-09-26 17:05:31 -07001529 ACTIVITY_TRACKER.onActivityDestroyed(this);
Romain Guycbb89e42009-06-08 15:52:54 -07001530
Sunny Goyal5d1873a2018-05-08 11:10:44 -07001531 unregisterReceiver(mScreenOffReceiver);
Sunny Goyalaaf7d1d2016-05-17 13:38:54 -07001532 mWorkspace.removeFolderListeners();
Sunny Goyalb1d7de22019-09-06 10:36:54 -07001533 PluginManagerWrapper.INSTANCE.get(this).removePluginListener(this);
Winson Chunge7a03942011-08-05 15:05:12 -07001534
Sunny Goyala7a5bf32020-01-05 15:35:29 +05301535 mModel.removeCallbacks(this);
Sunny Goyal623eddd2018-03-02 12:24:41 -08001536 mRotationHelper.destroy();
Sunny Goyal745bad92016-05-02 10:54:12 -07001537
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001538 try {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001539 mAppWidgetHost.stopListening();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001540 } catch (NullPointerException ex) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001541 Log.w(TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001542 }
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001543
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001544 TextKeyListener.getInstance().release();
Tony2917a8b2017-07-31 23:29:42 -07001545 clearPendingBinds();
Hyunyoung Song31971a32019-01-27 12:31:12 -08001546 LauncherAppState.getIDP(this).removeOnChangeListener(this);
Sunny Goyalb1d7de22019-09-06 10:36:54 -07001547
1548 mOverlayManager.onActivityDestroyed(this);
Winson Chung24ab40c2019-10-30 22:35:09 -07001549 mAppTransitionManager.unregisterRemoteAnimations();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001550 }
1551
Sunny Goyalae502842016-06-17 08:43:56 -07001552 public LauncherAccessibilityDelegate getAccessibilityDelegate() {
1553 return mAccessibilityDelegate;
1554 }
1555
Adam Cohena9cf38f2011-05-02 15:36:58 -07001556 public DragController getDragController() {
1557 return mDragController;
1558 }
1559
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001560 @Override
Sunny Goyal0eca4e22016-07-20 11:43:06 -07001561 public void startActivityForResult(Intent intent, int requestCode, Bundle options) {
Sunny Goyaldedda052019-05-14 15:23:48 -07001562 if (requestCode != -1) {
1563 mPendingActivityRequestCode = requestCode;
1564 }
Sunny Goyal210e1742019-10-17 12:05:38 -07001565 super.startActivityForResult(intent, requestCode, options);
Adam Cohen173f7112015-03-27 15:14:00 -07001566 }
1567
1568 @Override
Sunny Goyaldedda052019-05-14 15:23:48 -07001569 public void startIntentSenderForResult(IntentSender intent, int requestCode,
Adam Cohen173f7112015-03-27 15:14:00 -07001570 Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags, Bundle options) {
Sunny Goyaldedda052019-05-14 15:23:48 -07001571 if (requestCode != -1) {
1572 mPendingActivityRequestCode = requestCode;
1573 }
Sunny Goyal210e1742019-10-17 12:05:38 -07001574 try {
1575 super.startIntentSenderForResult(intent, requestCode,
1576 fillInIntent, flagsMask, flagsValues, extraFlags, options);
1577 } catch (IntentSender.SendIntentException e) {
1578 throw new ActivityNotFoundException();
Adam Cohen173f7112015-03-27 15:14:00 -07001579 }
1580 }
1581
Winson Chung70d72102011-08-12 11:24:35 -07001582 /**
1583 * Indicates that we want global search for this activity by setting the globalSearch
1584 * argument for {@link #startSearch} to true.
1585 */
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001586 @Override
Romain Guycbb89e42009-06-08 15:52:54 -07001587 public void startSearch(String initialQuery, boolean selectInitialQuery,
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001588 Bundle appSearchData, boolean globalSearch) {
1589 if (appSearchData == null) {
1590 appSearchData = new Bundle();
Bjorn Bringert32b12d22013-06-06 13:00:41 +01001591 appSearchData.putString("source", "launcher-search");
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001592 }
Sunny Goyalda4fe1a2016-05-26 16:05:17 -07001593
Sunny Goyal6f28e712016-09-13 14:19:29 -07001594 if (mLauncherCallbacks == null ||
1595 !mLauncherCallbacks.startSearch(initialQuery, selectInitialQuery, appSearchData)) {
1596 // Starting search from the callbacks failed. Start the default global search.
Sunny Goyalf4aceab2017-12-06 16:16:31 -08001597 super.startSearch(initialQuery, selectInitialQuery, appSearchData, true);
Ian Parkinson047036e2014-09-01 15:40:53 +01001598 }
Winson Chungcd99cd32015-04-29 11:03:24 -07001599
1600 // We need to show the workspace after starting the search
Sunny Goyal3e3f44c2017-10-23 17:14:52 -07001601 mStateManager.goToState(NORMAL);
Bjorn Bringertc459e522013-06-07 19:36:01 +01001602 }
1603
Joe Onorato9c1289c2009-08-17 11:03:03 -04001604 public boolean isWorkspaceLocked() {
Sunny Goyal2100c782016-08-22 16:00:03 -07001605 return mWorkspaceLoading || mPendingRequestArgs != null;
Joe Onorato9c1289c2009-08-17 11:03:03 -04001606 }
1607
Adam Cohen517a7f52014-03-01 12:12:59 -08001608 public boolean isWorkspaceLoading() {
1609 return mWorkspaceLoading;
1610 }
1611
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001612 private void setWorkspaceLoading(boolean value) {
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001613 mWorkspaceLoading = value;
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001614 }
1615
Sunny Goyal04a324a2017-01-20 21:08:59 -08001616 public void setWaitingForResult(PendingRequestArgs args) {
Sunny Goyal2100c782016-08-22 16:00:03 -07001617 mPendingRequestArgs = args;
Adam Cohen9211d422014-10-07 18:14:53 -07001618 }
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001619
Sunny Goyal2100c782016-08-22 16:00:03 -07001620 void addAppWidgetFromDropImpl(int appWidgetId, ItemInfo info, AppWidgetHostView boundWidget,
Sunny Goyal04a324a2017-01-20 21:08:59 -08001621 WidgetAddFlowHandler addFlowHandler) {
Tony Wickhama0628cc2015-10-14 15:23:04 -07001622 if (LOGD) {
1623 Log.d(TAG, "Adding widget from drop");
1624 }
Sunny Goyal04a324a2017-01-20 21:08:59 -08001625 addAppWidgetImpl(appWidgetId, info, boundWidget, addFlowHandler, 0);
Adam Cohenad4e15c2013-10-17 16:21:35 -07001626 }
1627
Sunny Goyal2100c782016-08-22 16:00:03 -07001628 void addAppWidgetImpl(int appWidgetId, ItemInfo info,
Sunny Goyal04a324a2017-01-20 21:08:59 -08001629 AppWidgetHostView boundWidget, WidgetAddFlowHandler addFlowHandler, int delay) {
Samuel Fufaca37b8a2019-08-19 17:04:36 -07001630 if (!addFlowHandler.startConfigActivity(this, appWidgetId, info,
1631 REQUEST_CREATE_APPWIDGET)) {
Sunny Goyal04a324a2017-01-20 21:08:59 -08001632 // If the configuration flow was not started, add the widget
Michael Jurkaaf442092010-06-10 17:01:57 -07001633
Adam Cohenad4e15c2013-10-17 16:21:35 -07001634 Runnable onComplete = new Runnable() {
1635 @Override
1636 public void run() {
1637 // Exit spring loaded mode if necessary after adding the widget
Sunny Goyal3e3f44c2017-10-23 17:14:52 -07001638 mStateManager.goToState(NORMAL, SPRING_LOADED_EXIT_DELAY);
Adam Cohenad4e15c2013-10-17 16:21:35 -07001639 }
1640 };
Samuel Fufaca37b8a2019-08-19 17:04:36 -07001641 completeAddAppWidget(appWidgetId, info, boundWidget,
1642 addFlowHandler.getProviderInfo(this));
Adam Cohen689ff162014-05-08 17:27:56 -07001643 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete, delay, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001644 }
1645 }
Romain Guycbb89e42009-06-08 15:52:54 -07001646
Sunny Goyalefb7e842018-10-04 15:11:00 -07001647 public void addPendingItem(PendingAddItemInfo info, int container, int screenId,
Sunny Goyal71b5c0b2015-01-08 16:59:04 -08001648 int[] cell, int spanX, int spanY) {
Sunny Goyal2100c782016-08-22 16:00:03 -07001649 info.container = container;
1650 info.screenId = screenId;
1651 if (cell != null) {
1652 info.cellX = cell[0];
1653 info.cellY = cell[1];
1654 }
1655 info.spanX = spanX;
1656 info.spanY = spanY;
1657
Sunny Goyal71b5c0b2015-01-08 16:59:04 -08001658 switch (info.itemType) {
1659 case LauncherSettings.Favorites.ITEM_TYPE_CUSTOM_APPWIDGET:
1660 case LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET:
Sunny Goyal2100c782016-08-22 16:00:03 -07001661 addAppWidgetFromDrop((PendingAddWidgetInfo) info);
Sunny Goyal71b5c0b2015-01-08 16:59:04 -08001662 break;
1663 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Sunny Goyal782f0c92017-01-19 10:27:54 -08001664 processShortcutFromDrop((PendingAddShortcutInfo) info);
Sunny Goyal71b5c0b2015-01-08 16:59:04 -08001665 break;
1666 default:
1667 throw new IllegalStateException("Unknown item type: " + info.itemType);
Samuel Fufaca37b8a2019-08-19 17:04:36 -07001668 }
Sunny Goyal71b5c0b2015-01-08 16:59:04 -08001669 }
1670
Adam Cohenfbba09b2011-07-18 21:43:05 -07001671 /**
1672 * Process a shortcut drop.
Adam Cohenfbba09b2011-07-18 21:43:05 -07001673 */
Sunny Goyal782f0c92017-01-19 10:27:54 -08001674 private void processShortcutFromDrop(PendingAddShortcutInfo info) {
Sunny Goyalfb5096d2016-09-08 14:32:06 -07001675 Intent intent = new Intent(Intent.ACTION_CREATE_SHORTCUT).setComponent(info.componentName);
1676 setWaitingForResult(PendingRequestArgs.forIntent(REQUEST_CREATE_SHORTCUT, intent, info));
Sunny Goyal782f0c92017-01-19 10:27:54 -08001677 if (!info.activityInfo.startConfigActivity(this, REQUEST_CREATE_SHORTCUT)) {
1678 handleActivityResult(REQUEST_CREATE_SHORTCUT, RESULT_CANCELED, null);
1679 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001680 }
1681
Adam Cohenfbba09b2011-07-18 21:43:05 -07001682 /**
1683 * Process a widget drop.
Adam Cohenfbba09b2011-07-18 21:43:05 -07001684 */
Sunny Goyal2100c782016-08-22 16:00:03 -07001685 private void addAppWidgetFromDrop(PendingAddWidgetInfo info) {
Adam Cohened66b2b2012-01-23 17:28:51 -08001686 AppWidgetHostView hostView = info.boundWidget;
Sunny Goyal952e63d2017-08-16 04:59:08 -07001687 final int appWidgetId;
Sunny Goyal8a0dc382017-01-25 11:30:06 -08001688 WidgetAddFlowHandler addFlowHandler = info.getHandler();
Adam Cohened66b2b2012-01-23 17:28:51 -08001689 if (hostView != null) {
Tony Wickhama0628cc2015-10-14 15:23:04 -07001690 // In the case where we've prebound the widget, we remove it from the DragLayer
1691 if (LOGD) {
1692 Log.d(TAG, "Removing widget view from drag layer and setting boundWidget to null");
1693 }
1694 getDragLayer().removeView(hostView);
1695
Adam Cohened66b2b2012-01-23 17:28:51 -08001696 appWidgetId = hostView.getAppWidgetId();
Sunny Goyal04a324a2017-01-20 21:08:59 -08001697 addAppWidgetFromDropImpl(appWidgetId, info, hostView, addFlowHandler);
Sunny Goyal5b9ebca2015-06-01 18:37:32 -07001698
1699 // Clear the boundWidget so that it doesn't get destroyed.
1700 info.boundWidget = null;
Adam Cohened66b2b2012-01-23 17:28:51 -08001701 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001702 // In this case, we either need to start an activity to get permission to bind
1703 // the widget, or we need to start an activity to configure the widget, or both.
Pinyao Tingc7a6c292019-08-26 14:36:02 -07001704 if (info.itemType == LauncherSettings.Favorites.ITEM_TYPE_CUSTOM_APPWIDGET) {
1705 appWidgetId = CustomWidgetManager.INSTANCE.get(this).getWidgetIdForCustomProvider(
1706 info.componentName);
Sunny Goyal952e63d2017-08-16 04:59:08 -07001707 } else {
1708 appWidgetId = getAppWidgetHost().allocateAppWidgetId();
1709 }
Adam Cohendd70d662012-10-04 16:53:44 -07001710 Bundle options = info.bindOptions;
1711
Sunny Goyalffe83f12014-08-14 17:39:34 -07001712 boolean success = mAppWidgetManager.bindAppWidgetIdIfAllowed(
1713 appWidgetId, info.info, options);
Adam Cohendd70d662012-10-04 16:53:44 -07001714 if (success) {
Sunny Goyal04a324a2017-01-20 21:08:59 -08001715 addAppWidgetFromDropImpl(appWidgetId, info, null, addFlowHandler);
Michael Jurka8b805b12012-04-18 14:23:14 -07001716 } else {
Sunny Goyal04a324a2017-01-20 21:08:59 -08001717 addFlowHandler.startBindFlow(this, appWidgetId, info, REQUEST_BIND_APPWIDGET);
Michael Jurka8b805b12012-04-18 14:23:14 -07001718 }
Adam Cohened66b2b2012-01-23 17:28:51 -08001719 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001720 }
1721
Sunny Goyalefb7e842018-10-04 15:11:00 -07001722 FolderIcon addFolder(CellLayout layout, int container, final int screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07001723 int cellY) {
Michael Jurkac9d95c52011-08-29 14:03:34 -07001724 final FolderInfo folderInfo = new FolderInfo();
Samuel Fufa84245e82019-08-14 13:44:12 -07001725 folderInfo.title = "";
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001726
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001727 // Update the model
Sunny Goyal43bf11d2017-02-02 13:52:53 -08001728 getModelWriter().addItemToDatabase(folderInfo, container, screenId, cellX, cellY);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001729
1730 // Create the view
Tracy Zhou4d7b2442019-12-09 13:42:57 -08001731 FolderIcon newFolder = FolderIcon.inflateFolderAndIcon(R.layout.folder_icon, this, layout, folderInfo);
Sunny Goyald5462aa2016-11-22 16:52:39 +05301732 mWorkspace.addInScreen(newFolder, folderInfo);
Winson Chung5f8afe62013-08-12 16:19:28 -07001733 // Force measure the new folder icon
1734 CellLayout parent = mWorkspace.getParentCellLayoutForView(newFolder);
1735 parent.getShortcutsAndWidgets().measureChild(newFolder);
Adam Cohendf035382011-04-11 17:22:04 -07001736 return newFolder;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001737 }
Romain Guycbb89e42009-06-08 15:52:54 -07001738
Winsonc0b52fe2015-09-09 16:38:15 -07001739 /**
Winsonfa56b3f2015-09-14 12:01:13 -07001740 * Unbinds the view for the specified item, and removes the item and all its children.
1741 *
1742 * @param v the view being removed.
Winsonfa56b3f2015-09-14 12:01:13 -07001743 * @param itemInfo the {@link ItemInfo} for this view.
1744 * @param deleteFromDb whether or not to delete this item from the db.
Winsonc0b52fe2015-09-09 16:38:15 -07001745 */
Tony Wickhambfbf7f92016-05-19 11:19:39 -07001746 public boolean removeItem(View v, final ItemInfo itemInfo, boolean deleteFromDb) {
Sunny Goyal95899162019-03-27 16:03:06 -07001747 if (itemInfo instanceof WorkspaceItemInfo) {
Winsonfa56b3f2015-09-14 12:01:13 -07001748 // Remove the shortcut from the folder before removing it from launcher
Sunny Goyal44c06432016-04-02 10:56:02 -07001749 View folderIcon = mWorkspace.getHomescreenIconByItemId(itemInfo.container);
1750 if (folderIcon instanceof FolderIcon) {
Sunny Goyal95899162019-03-27 16:03:06 -07001751 ((FolderInfo) folderIcon.getTag()).remove((WorkspaceItemInfo) itemInfo, true);
Winsonfa56b3f2015-09-14 12:01:13 -07001752 } else {
1753 mWorkspace.removeWorkspaceItem(v);
1754 }
Winsonc0b52fe2015-09-09 16:38:15 -07001755 if (deleteFromDb) {
Sunny Goyal43bf11d2017-02-02 13:52:53 -08001756 getModelWriter().deleteItemFromDatabase(itemInfo);
Winsonc0b52fe2015-09-09 16:38:15 -07001757 }
1758 } else if (itemInfo instanceof FolderInfo) {
1759 final FolderInfo folderInfo = (FolderInfo) itemInfo;
Sunny Goyalaaf7d1d2016-05-17 13:38:54 -07001760 if (v instanceof FolderIcon) {
1761 ((FolderIcon) v).removeListeners();
1762 }
Winsonc0b52fe2015-09-09 16:38:15 -07001763 mWorkspace.removeWorkspaceItem(v);
1764 if (deleteFromDb) {
Sunny Goyal43bf11d2017-02-02 13:52:53 -08001765 getModelWriter().deleteFolderAndContentsFromDatabase(folderInfo);
Winsonc0b52fe2015-09-09 16:38:15 -07001766 }
1767 } else if (itemInfo instanceof LauncherAppWidgetInfo) {
1768 final LauncherAppWidgetInfo widgetInfo = (LauncherAppWidgetInfo) itemInfo;
Winson44818e02015-10-02 11:25:46 -07001769 mWorkspace.removeWorkspaceItem(v);
Winsonc0b52fe2015-09-09 16:38:15 -07001770 if (deleteFromDb) {
Tony Wickham6a71a5b2018-08-21 11:40:23 -07001771 getModelWriter().deleteWidgetInfo(widgetInfo, getAppWidgetHost());
Winsonc0b52fe2015-09-09 16:38:15 -07001772 }
1773 } else {
1774 return false;
1775 }
1776 return true;
1777 }
1778
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001779 @Override
1780 public boolean dispatchKeyEvent(KeyEvent event) {
Hyunyoung Song3c7d9cb2017-01-30 15:11:27 -08001781 return (event.getKeyCode() == KeyEvent.KEYCODE_HOME) || super.dispatchKeyEvent(event);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001782 }
1783
Joe Onorato88ec0992009-11-19 13:16:06 -08001784 @Override
1785 public void onBackPressed() {
Sunny Goyal7c8a65e2017-12-22 11:11:33 -08001786 if (finishAutoCancelActionMode()) {
1787 return;
1788 }
Adam Cohen9211d422014-10-07 18:14:53 -07001789
Sunny Goyal45478022015-06-08 16:52:41 -07001790 if (mDragController.isDragging()) {
1791 mDragController.cancelDrag();
Adam Cohenc9735cf2015-01-23 16:11:55 -08001792 return;
1793 }
1794
Jon Mirandafeba90f2016-10-06 10:53:29 -07001795 // Note: There should be at most one log per method call. This is enforced implicitly
1796 // by using if-else statements.
1797 UserEventDispatcher ued = getUserEventDispatcher();
Sunny Goyal740ac7f2016-09-28 16:47:32 -07001798 AbstractFloatingView topView = AbstractFloatingView.getTopOpenView(this);
Tony Wickham52c1b662018-05-21 13:13:58 -07001799 if (topView != null && topView.onBackPressed()) {
1800 // Handled by the floating view.
Patrick Dubroy94f78a52011-02-28 17:39:16 -08001801 } else {
Sunny Goyale39690b2018-08-02 13:35:07 -07001802 mStateManager.getState().onBackPressed(this);
Michael Jurkaaf442092010-06-10 17:01:57 -07001803 }
Joe Onorato88ec0992009-11-19 13:16:06 -08001804 }
1805
Sunny Goyalfe770c92016-09-27 14:38:58 -07001806 @TargetApi(Build.VERSION_CODES.M)
Sunny Goyal0b0847b2018-03-14 12:30:11 -07001807 @Override
Jon Miranda73c27ec2018-05-16 18:06:23 -07001808 public ActivityOptions getActivityLaunchOptions(View v) {
1809 return mAppTransitionManager.getActivityLaunchOptions(this, v);
Sunny Goyala7ce1662016-05-31 15:01:35 -07001810 }
1811
Tony Wickham3a6746a2018-03-29 09:39:56 -07001812 public LauncherAppTransitionManager getAppTransitionManager() {
1813 return mAppTransitionManager;
1814 }
1815
Sunny Goyal0b0847b2018-03-14 12:30:11 -07001816 @TargetApi(Build.VERSION_CODES.M)
1817 @Override
1818 protected boolean onErrorStartingShortcut(Intent intent, ItemInfo info) {
1819 // Due to legacy reasons, direct call shortcuts require Launchers to have the
1820 // corresponding permission. Show the appropriate permission prompt if that
1821 // is the case.
1822 if (intent.getComponent() == null
1823 && Intent.ACTION_CALL.equals(intent.getAction())
1824 && checkSelfPermission(android.Manifest.permission.CALL_PHONE) !=
1825 PackageManager.PERMISSION_GRANTED) {
1826
1827 setWaitingForResult(PendingRequestArgs
1828 .forIntent(REQUEST_PERMISSION_CALL_PHONE, intent, info));
1829 requestPermissions(new String[]{android.Manifest.permission.CALL_PHONE},
1830 REQUEST_PERMISSION_CALL_PHONE);
1831 return true;
1832 } else {
1833 return false;
1834 }
Sunny Goyal0eca4e22016-07-20 11:43:06 -07001835 }
1836
Hyunyoung Song46d07f72018-05-22 15:41:25 -07001837 @Override
Hyunyoung Songfc007472018-10-25 14:09:50 -07001838 public int getCurrentState() {
Samuel Fufaca37b8a2019-08-19 17:04:36 -07001839 if (mStateManager.getState() == LauncherState.ALL_APPS) {
Hyunyoung Songfc007472018-10-25 14:09:50 -07001840 return StatsLogUtils.LAUNCHER_STATE_ALLAPPS;
Govinda Wassermanc06e1512019-04-09 09:56:53 -04001841 } else if (mStateManager.getState() == OVERVIEW) {
Hyunyoung Songfc007472018-10-25 14:09:50 -07001842 return StatsLogUtils.LAUNCHER_STATE_OVERVIEW;
1843 }
Hyunyoung Song0ae38882018-11-05 14:45:19 -08001844 return StatsLogUtils.LAUNCHER_STATE_HOME;
Hyunyoung Songfc007472018-10-25 14:09:50 -07001845 }
1846
1847 @Override
Hyunyoung Song46d07f72018-05-22 15:41:25 -07001848 public void modifyUserEvent(LauncherLogProto.LauncherEvent event) {
1849 if (event.srcTarget != null && event.srcTarget.length > 0 &&
1850 event.srcTarget[1].containerType == ContainerType.PREDICTION) {
1851 Target[] targets = new Target[3];
1852 targets[0] = event.srcTarget[0];
1853 targets[1] = event.srcTarget[1];
1854 targets[2] = newTarget(Target.Type.CONTAINER);
1855 event.srcTarget = targets;
1856 LauncherState state = mStateManager.getState();
1857 if (state == LauncherState.ALL_APPS) {
1858 event.srcTarget[2].containerType = ContainerType.ALLAPPS;
Govinda Wassermanc06e1512019-04-09 09:56:53 -04001859 } else if (state == OVERVIEW) {
Hyunyoung Song46d07f72018-05-22 15:41:25 -07001860 event.srcTarget[2].containerType = ContainerType.TASKSWITCHER;
1861 }
1862 }
1863 }
1864
Sunny Goyal369212a2019-03-26 15:03:57 -07001865 public boolean startActivitySafely(View v, Intent intent, ItemInfo item,
1866 @Nullable String sourceContainer) {
Winson Chung0b70cd42019-06-17 22:34:33 -07001867 if (!hasBeenResumed()) {
1868 // Workaround an issue where the WM launch animation is clobbered when finishing the
1869 // recents animation into launcher. Defer launching the activity until Launcher is
1870 // next resumed.
1871 addOnResumeCallback(() -> startActivitySafely(v, intent, item, sourceContainer));
Winson Chungc9bf6d42019-10-04 15:33:18 -07001872 if (mOnDeferredActivityLaunchCallback != null) {
1873 mOnDeferredActivityLaunchCallback.run();
1874 mOnDeferredActivityLaunchCallback = null;
1875 }
Winson Chung0b70cd42019-06-17 22:34:33 -07001876 return true;
1877 }
1878
Sunny Goyal369212a2019-03-26 15:03:57 -07001879 boolean success = super.startActivitySafely(v, intent, item, sourceContainer);
Hyunyoung Song1241e612018-05-15 21:46:51 -07001880 if (success && v instanceof BubbleTextView) {
Sunny Goyal0b0847b2018-03-14 12:30:11 -07001881 // This is set to the view that launched the activity that navigated the user away
1882 // from launcher. Since there is no callback for when the activity has finished
1883 // launching, enable the press state and keep this reference to reset the press
1884 // state when we return to launcher.
1885 BubbleTextView btv = (BubbleTextView) v;
1886 btv.setStayPressed(true);
Winson Chung0b70cd42019-06-17 22:34:33 -07001887 addOnResumeCallback(btv);
Sunny Goyala7ce1662016-05-31 15:01:35 -07001888 }
Hyunyoung Song1241e612018-05-15 21:46:51 -07001889 return success;
Michael Jurka86a720e2012-05-09 11:23:23 -07001890 }
1891
Winson Chung3d503fb2011-07-13 17:25:49 -07001892 boolean isHotseatLayout(View layout) {
Sunny Goyalc13403c2016-11-18 23:44:48 -08001893 // TODO: Remove this method
Sunny Goyal876e4622018-11-02 13:50:40 -07001894 return mHotseat != null && (layout == mHotseat);
Winson Chung3d503fb2011-07-13 17:25:49 -07001895 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08001896
Winson Chung3d503fb2011-07-13 17:25:49 -07001897 /**
1898 * Returns the CellLayout of the specified container at the specified screen.
1899 */
Sunny Goyalefb7e842018-10-04 15:11:00 -07001900 public CellLayout getCellLayout(int container, int screenId) {
Sunny Goyal876e4622018-11-02 13:50:40 -07001901 return (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT)
1902 ? mHotseat : mWorkspace.getScreenWithId(screenId);
Romain Guya6abce82009-11-10 02:54:41 -08001903 }
1904
Michael Jurkae326f182011-11-21 14:05:46 -08001905 @Override
1906 public void onTrimMemory(int level) {
1907 super.onTrimMemory(level);
Adam Cohen3f9c9712014-10-31 11:48:25 -07001908 if (level >= ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN) {
1909 // The widget preview db can result in holding onto over
1910 // 3MB of memory for caching which isn't necessary.
1911 SQLiteDatabase.releaseMemory();
1912
Adam Cohenc8f4e1b2014-11-19 16:03:20 -08001913 // This clears all widget bitmaps from the widget tray
Hyunyoung Song3f471442015-04-08 19:01:34 -07001914 // TODO(hyunyoungs)
Michael Jurkae326f182011-11-21 14:05:46 -08001915 }
1916 }
1917
Michael Jurkad7c28052012-04-27 15:43:36 -07001918 @Override
1919 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
alanv1d4fde62012-10-17 13:15:47 -07001920 final boolean result = super.dispatchPopulateAccessibilityEvent(event);
Michael Jurkad7c28052012-04-27 15:43:36 -07001921 final List<CharSequence> text = event.getText();
1922 text.clear();
alanv1d4fde62012-10-17 13:15:47 -07001923 // Populate event with a fake title based on the current state.
Sunny Goyal3e3f44c2017-10-23 17:14:52 -07001924 // TODO: When can workspace be null?
1925 text.add(mWorkspace == null
1926 ? getString(R.string.all_apps_home_button_label)
Sunny Goyalea609262017-10-25 15:47:38 -07001927 : mStateManager.getState().getDescription(this));
Michael Jurkad7c28052012-04-27 15:43:36 -07001928 return result;
1929 }
1930
Winson Chung0b70cd42019-06-17 22:34:33 -07001931 public void addOnResumeCallback(OnResumeCallback callback) {
1932 mOnResumeCallbacks.add(callback);
Michael Jurka1e2f4652013-07-08 18:03:46 -07001933 }
1934
Michael Jurka7607c2f2013-04-03 14:33:19 -07001935 /**
Winson Chungc9bf6d42019-10-04 15:33:18 -07001936 * Persistant callback which notifies when an activity launch is deferred because the activity
1937 * was not yet resumed.
1938 */
1939 public void setOnDeferredActivityLaunchCallback(Runnable callback) {
1940 mOnDeferredActivityLaunchCallback = callback;
1941 }
1942
1943 /**
Sunny Goyala7a5bf32020-01-05 15:35:29 +05301944 * Sets the next page to bind synchronously on next bind.
1945 * @param page
1946 */
1947 public void setPageToBindSynchronously(int page) {
1948 mPageToBindSynchronously = page;
1949 }
1950
1951 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04001952 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001953 */
Sunny Goyal93f878c2016-03-30 17:31:24 -07001954 @Override
Sunny Goyala7a5bf32020-01-05 15:35:29 +05301955 public int getPageToBindSynchronously() {
1956 if (mPageToBindSynchronously != PagedView.INVALID_PAGE) {
1957 return mPageToBindSynchronously;
1958 } else if (mWorkspace != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07001959 return mWorkspace.getCurrentPage();
Joe Onoratod0afc872010-06-11 00:03:15 -07001960 } else {
Winson Chung882a52e2015-07-08 14:32:26 -07001961 return 0;
Joe Onoratod0afc872010-06-11 00:03:15 -07001962 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04001963 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07001964
Joe Onorato9c1289c2009-08-17 11:03:03 -04001965 /**
Sunny Goyal527c7d32015-08-28 15:19:36 -07001966 * Clear any pending bind callbacks. This is called when is loader is planning to
1967 * perform a full rebind from scratch.
1968 */
1969 @Override
1970 public void clearPendingBinds() {
Sunny Goyal527c7d32015-08-28 15:19:36 -07001971 if (mPendingExecutor != null) {
1972 mPendingExecutor.markCompleted();
1973 mPendingExecutor = null;
Sunny Goyal6b6d0a32019-08-05 17:19:32 -07001974
1975 // We might have set this flag previously and forgot to clear it.
1976 mAppsView.getAppsStore()
1977 .disableDeferUpdatesSilently(AllAppsStore.DEFER_UPDATES_NEXT_DRAW);
Sunny Goyal527c7d32015-08-28 15:19:36 -07001978 }
1979 }
1980
1981 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04001982 * Refreshes the shortcuts shown on the workspace.
1983 *
1984 * Implementation of the method from LauncherModel.Callbacks.
1985 */
1986 public void startBinding() {
Winson Chung5cc62c72019-10-16 11:32:41 -07001987 Object traceToken = TraceHelper.INSTANCE.beginSection("startBinding");
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -07001988 // Floating panels (except the full widget sheet) are associated with individual icons. If
1989 // we are starting a fresh bind, close all such panels as all the icons are about
1990 // to go away.
Pinyao Tinga74b63a2019-07-17 23:26:06 -07001991 AbstractFloatingView.closeOpenViews(this, true, TYPE_ALL & ~TYPE_REBIND_SAFE);
Jon Miranda6dc7f1e2017-02-21 12:37:51 -08001992
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001993 setWorkspaceLoading(true);
Adam Cohen517a7f52014-03-01 12:12:59 -08001994
Winson Chungd64d1762013-08-20 14:37:16 -07001995 // Clear the workspace because it's going to be rebound
Sunny Goyal2db53422019-03-01 16:06:12 -08001996 mDragController.cancelDrag();
1997
Adam Cohendf035382011-04-11 17:22:04 -07001998 mWorkspace.clearDropTargets();
Winson Chung9e6a0a22013-08-27 11:58:12 -07001999 mWorkspace.removeAllWorkspaceScreens();
Sunny Goyalc11fac32018-02-27 19:20:15 -08002000 mAppWidgetHost.clearViews();
Winson Chungd64d1762013-08-20 14:37:16 -07002001
Winson Chung3d503fb2011-07-13 17:25:49 -07002002 if (mHotseat != null) {
Sunny Goyalae6e3182019-04-30 12:04:37 -07002003 mHotseat.resetLayout(getWallpaperDeviceProfile().isVerticalBarLayout());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002004 }
Winson Chung5cc62c72019-10-16 11:32:41 -07002005 TraceHelper.INSTANCE.endSection(traceToken);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002006 }
2007
Adam Cohendcd297f2013-06-18 13:13:40 -07002008 @Override
Sunny Goyalefb7e842018-10-04 15:11:00 -07002009 public void bindScreens(IntArray orderedScreenIds) {
Sunny Goyalda4fe1a2016-05-26 16:05:17 -07002010 // Make sure the first screen is always at the start.
Jon Miranda7143ba62019-03-15 09:00:05 -07002011 if (FeatureFlags.QSB_ON_FIRST_SCREEN &&
Sunny Goyala9e2f5a2016-06-10 12:22:04 -07002012 orderedScreenIds.indexOf(Workspace.FIRST_SCREEN_ID) != 0) {
Sunny Goyalefb7e842018-10-04 15:11:00 -07002013 orderedScreenIds.removeValue(Workspace.FIRST_SCREEN_ID);
Sunny Goyalda4fe1a2016-05-26 16:05:17 -07002014 orderedScreenIds.add(0, Workspace.FIRST_SCREEN_ID);
Jon Miranda7143ba62019-03-15 09:00:05 -07002015 } else if (!FeatureFlags.QSB_ON_FIRST_SCREEN && orderedScreenIds.isEmpty()) {
Sunny Goyala9e2f5a2016-06-10 12:22:04 -07002016 // If there are no screens, we need to have an empty screen
2017 mWorkspace.addExtraEmptyScreen();
Adam Cohen5084cba2013-09-03 12:01:16 -07002018 }
Sunny Goyalda4fe1a2016-05-26 16:05:17 -07002019 bindAddScreens(orderedScreenIds);
Winson Chung0e6a7132013-08-23 12:55:10 -07002020
Winsonc7d2e832016-07-28 12:24:55 -07002021 // After we have added all the screens, if the wallpaper was locked to the default state,
2022 // then notify to indicate that it can be released and a proper wallpaper offset can be
2023 // computed before the next layout
2024 mWorkspace.unlockWallpaperFromDefaultPageOnNextLayout();
Winson Chung64359a52013-07-08 17:17:08 -07002025 }
2026
Sunny Goyalefb7e842018-10-04 15:11:00 -07002027 private void bindAddScreens(IntArray orderedScreenIds) {
Adam Cohendcd297f2013-06-18 13:13:40 -07002028 int count = orderedScreenIds.size();
2029 for (int i = 0; i < count; i++) {
Sunny Goyalefb7e842018-10-04 15:11:00 -07002030 int screenId = orderedScreenIds.get(i);
Jon Miranda7143ba62019-03-15 09:00:05 -07002031 if (!FeatureFlags.QSB_ON_FIRST_SCREEN || screenId != Workspace.FIRST_SCREEN_ID) {
Sunny Goyalda4fe1a2016-05-26 16:05:17 -07002032 // No need to bind the first screen, as its always bound.
2033 mWorkspace.insertNewWorkspaceScreenBeforeEmptyScreen(screenId);
2034 }
Adam Cohendcd297f2013-06-18 13:13:40 -07002035 }
Adam Cohendcd297f2013-06-18 13:13:40 -07002036 }
2037
Sunny Goyalb23980c2017-08-17 07:45:25 -07002038 @Override
Tony Wickham6a71a5b2018-08-21 11:40:23 -07002039 public void preAddApps() {
2040 // If there's an undo snackbar, force it to complete to ensure empty screens are removed
2041 // before trying to add new items.
2042 mModelWriter.commitDelete();
2043 AbstractFloatingView snackbar = AbstractFloatingView.getOpenView(this, TYPE_SNACKBAR);
2044 if (snackbar != null) {
2045 snackbar.post(() -> snackbar.close(true));
2046 }
2047 }
2048
2049 @Override
Sunny Goyalefb7e842018-10-04 15:11:00 -07002050 public void bindAppsAdded(IntArray newScreens, ArrayList<ItemInfo> addNotAnimated,
Sunny Goyal29947f02017-12-18 13:49:44 -08002051 ArrayList<ItemInfo> addAnimated) {
Winson Chungd64d1762013-08-20 14:37:16 -07002052 // Add the new screens
Adam Cohen76a47a12014-02-05 11:47:43 -08002053 if (newScreens != null) {
2054 bindAddScreens(newScreens);
2055 }
Winson Chungd64d1762013-08-20 14:37:16 -07002056
2057 // We add the items without animation on non-visible pages, and with
2058 // animations on the new page (which we will try and snap to).
Adam Cohen76a47a12014-02-05 11:47:43 -08002059 if (addNotAnimated != null && !addNotAnimated.isEmpty()) {
Sunny Goyalb23980c2017-08-17 07:45:25 -07002060 bindItems(addNotAnimated, false);
Winson Chungd64d1762013-08-20 14:37:16 -07002061 }
Adam Cohen76a47a12014-02-05 11:47:43 -08002062 if (addAnimated != null && !addAnimated.isEmpty()) {
Sunny Goyalb23980c2017-08-17 07:45:25 -07002063 bindItems(addAnimated, true);
Winson Chungd64d1762013-08-20 14:37:16 -07002064 }
Winson Chungc58497e2013-09-03 17:48:37 -07002065
Winson Chung87412982013-10-03 18:34:14 -07002066 // Remove the extra empty screen
Adam Cohen689ff162014-05-08 17:27:56 -07002067 mWorkspace.removeExtraEmptyScreen(false, false);
Winson Chungd64d1762013-08-20 14:37:16 -07002068 }
2069
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002070 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04002071 * Bind the items start-end from the list.
2072 *
2073 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002074 */
Tony Wickham0bb211a2015-10-02 16:22:08 -07002075 @Override
Sunny Goyalb23980c2017-08-17 07:45:25 -07002076 public void bindItems(final List<ItemInfo> items, final boolean forceAnimateIcons) {
Sunny Goyal3be633b2016-12-08 09:59:25 -08002077 // Get the list of added items and intersect them with the set of items here
Rajeev Kumar43c0f582017-06-23 15:34:55 -07002078 final Collection<Animator> bounceAnims = new ArrayList<>();
Winson Chung997a9232013-07-24 15:33:46 -07002079 final boolean animateIcons = forceAnimateIcons && canRunNewAppsAnimation();
Winson Chungf0c6ae02012-03-21 16:10:31 -07002080 Workspace workspace = mWorkspace;
Sunny Goyalefb7e842018-10-04 15:11:00 -07002081 int newItemsScreenId = -1;
Sunny Goyalb23980c2017-08-17 07:45:25 -07002082 int end = items.size();
2083 for (int i = 0; i < end; i++) {
Sunny Goyal3be633b2016-12-08 09:59:25 -08002084 final ItemInfo item = items.get(i);
Winson Chung4d279d92011-07-21 11:46:32 -07002085
2086 // Short circuit if we are loading dock items for a configuration which has no dock
2087 if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT &&
2088 mHotseat == null) {
2089 continue;
2090 }
2091
Sunny Goyal639e9062015-08-19 19:17:06 -07002092 final View view;
Joe Onorato9c1289c2009-08-17 11:03:03 -04002093 switch (item.itemType) {
2094 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
2095 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Sunny Goyal3be633b2016-12-08 09:59:25 -08002096 case LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT: {
Sunny Goyal95899162019-03-27 16:03:06 -07002097 WorkspaceItemInfo info = (WorkspaceItemInfo) item;
Sunny Goyal639e9062015-08-19 19:17:06 -07002098 view = createShortcut(info);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002099 break;
Sunny Goyal3be633b2016-12-08 09:59:25 -08002100 }
2101 case LauncherSettings.Favorites.ITEM_TYPE_FOLDER: {
Tracy Zhou4d7b2442019-12-09 13:42:57 -08002102 view = FolderIcon.inflateFolderAndIcon(R.layout.folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07002103 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Sunny Goyal1cd01b02016-11-09 10:43:58 -08002104 (FolderInfo) item);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002105 break;
Sunny Goyal3be633b2016-12-08 09:59:25 -08002106 }
Sunny Goyal952e63d2017-08-16 04:59:08 -07002107 case LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET:
2108 case LauncherSettings.Favorites.ITEM_TYPE_CUSTOM_APPWIDGET: {
Sunny Goyala9a1a212017-08-18 01:03:21 -07002109 view = inflateAppWidget((LauncherAppWidgetInfo) item);
Sunny Goyalb23980c2017-08-17 07:45:25 -07002110 if (view == null) {
2111 continue;
Sunny Goyal3be633b2016-12-08 09:59:25 -08002112 }
Sunny Goyal3be633b2016-12-08 09:59:25 -08002113 break;
2114 }
Winson Chungc763c4e2013-07-19 13:49:06 -07002115 default:
2116 throw new RuntimeException("Invalid Item Type");
Joe Onorato9c1289c2009-08-17 11:03:03 -04002117 }
Sunny Goyal639e9062015-08-19 19:17:06 -07002118
Samuel Fufaca37b8a2019-08-19 17:04:36 -07002119 /*
Sunny Goyalda4fe1a2016-05-26 16:05:17 -07002120 * Remove colliding items.
2121 */
2122 if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
2123 CellLayout cl = mWorkspace.getScreenWithId(item.screenId);
2124 if (cl != null && cl.isOccupied(item.cellX, item.cellY)) {
2125 View v = cl.getChildAt(item.cellX, item.cellY);
2126 Object tag = v.getTag();
2127 String desc = "Collision while binding workspace item: " + item
2128 + ". Collides with " + tag;
Sunny Goyal3d706ad2017-03-06 16:56:39 -08002129 if (FeatureFlags.IS_DOGFOOD_BUILD) {
Sunny Goyalda4fe1a2016-05-26 16:05:17 -07002130 throw (new RuntimeException(desc));
2131 } else {
2132 Log.d(TAG, desc);
Sunny Goyal43bf11d2017-02-02 13:52:53 -08002133 getModelWriter().deleteItemFromDatabase(item);
Sunny Goyalda4fe1a2016-05-26 16:05:17 -07002134 continue;
2135 }
2136 }
2137 }
Sunny Goyald5462aa2016-11-22 16:52:39 +05302138 workspace.addInScreenFromBind(view, item);
Sunny Goyal639e9062015-08-19 19:17:06 -07002139 if (animateIcons) {
2140 // Animate all the applications up now
2141 view.setAlpha(0f);
2142 view.setScaleX(0f);
2143 view.setScaleY(0f);
2144 bounceAnims.add(createNewAppBounceAnimation(view, i));
Sunny Goyal3be633b2016-12-08 09:59:25 -08002145 newItemsScreenId = item.screenId;
Sunny Goyal639e9062015-08-19 19:17:06 -07002146 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002147 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07002148
Sunny Goyalf0b6db72018-08-13 16:10:14 -07002149 // Animate to the correct page
2150 if (animateIcons && newItemsScreenId > -1) {
2151 AnimatorSet anim = new AnimatorSet();
2152 anim.playTogether(bounceAnims);
Jon Miranda64eb8ea2018-03-29 11:43:58 -07002153
Sunny Goyalefb7e842018-10-04 15:11:00 -07002154 int currentScreenId = mWorkspace.getScreenIdForPageIndex(mWorkspace.getNextPage());
Sunny Goyalf0b6db72018-08-13 16:10:14 -07002155 final int newScreenIndex = mWorkspace.getPageIndexForScreenId(newItemsScreenId);
2156 final Runnable startBounceAnimRunnable = anim::start;
2157
2158 if (newItemsScreenId != currentScreenId) {
2159 // We post the animation slightly delayed to prevent slowdowns
2160 // when we are loading right after we return to launcher.
2161 mWorkspace.postDelayed(new Runnable() {
2162 public void run() {
2163 if (mWorkspace != null) {
2164 AbstractFloatingView.closeAllOpenViews(Launcher.this, false);
2165
2166 mWorkspace.snapToPage(newScreenIndex);
2167 mWorkspace.postDelayed(startBounceAnimRunnable,
2168 NEW_APPS_ANIMATION_DELAY);
Winson Chung94d67682013-09-25 16:29:40 -07002169 }
Sunny Goyalf0b6db72018-08-13 16:10:14 -07002170 }
2171 }, NEW_APPS_PAGE_MOVE_DELAY);
2172 } else {
2173 mWorkspace.postDelayed(startBounceAnimRunnable, NEW_APPS_ANIMATION_DELAY);
Winson Chung997a9232013-07-24 15:33:46 -07002174 }
Winson Chung64359a52013-07-08 17:17:08 -07002175 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04002176 workspace.requestLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002177 }
2178
Joe Onorato9c1289c2009-08-17 11:03:03 -04002179 /**
2180 * Add the views for a widget to the workspace.
Joe Onorato9c1289c2009-08-17 11:03:03 -04002181 */
Sunny Goyala9a1a212017-08-18 01:03:21 -07002182 public void bindAppWidget(LauncherAppWidgetInfo item) {
2183 View view = inflateAppWidget(item);
2184 if (view != null) {
2185 mWorkspace.addInScreen(view, item);
2186 mWorkspace.requestLayout();
2187 }
2188 }
2189
2190 private View inflateAppWidget(LauncherAppWidgetInfo item) {
Samuel Fufaca37b8a2019-08-19 17:04:36 -07002191 if (item.hasOptionFlag(LauncherAppWidgetInfo.OPTION_SEARCH_WIDGET)) {
2192 item.providerName = QsbContainerView.getSearchComponentName(this);
2193 if (item.providerName == null) {
2194 getModelWriter().deleteItemFromDatabase(item);
2195 return null;
2196 }
2197 }
Sunny Goyal17c72fb2019-10-14 14:06:38 -07002198 final AppWidgetHostView view;
Sunny Goyal2e1efb42016-03-03 16:58:55 -08002199 if (mIsSafeModeEnabled) {
Sunny Goyal17c72fb2019-10-14 14:06:38 -07002200 view = new PendingAppWidgetHostView(this, item, mIconCache, true);
Sunny Goyald5462aa2016-11-22 16:52:39 +05302201 prepareAppWidget(view, item);
Sunny Goyalb23980c2017-08-17 07:45:25 -07002202 return view;
Sunny Goyal2e1efb42016-03-03 16:58:55 -08002203 }
2204
Winson Chung5cc62c72019-10-16 11:32:41 -07002205 Object traceToken = TraceHelper.INSTANCE.beginSection("BIND_WIDGET_id=" + item.appWidgetId);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002206
Sunny Goyal17c72fb2019-10-14 14:06:38 -07002207 try {
2208 final LauncherAppWidgetProviderInfo appWidgetInfo;
Adam Cohen59400422014-03-05 18:07:04 -08002209
Sunny Goyal17c72fb2019-10-14 14:06:38 -07002210 if (item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_PROVIDER_NOT_READY)) {
2211 // If the provider is not ready, bind as a pending widget.
2212 appWidgetInfo = null;
2213 } else if (item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_ID_NOT_VALID)) {
2214 // The widget id is not valid. Try to find the widget based on the provider info.
2215 appWidgetInfo = mAppWidgetManager.findProvider(item.providerName, item.user);
2216 } else {
2217 appWidgetInfo = mAppWidgetManager.getLauncherAppWidgetInfo(item.appWidgetId);
Sunny Goyalff572272014-07-23 13:58:07 -07002218 }
Sunny Goyalff572272014-07-23 13:58:07 -07002219
Sunny Goyal17c72fb2019-10-14 14:06:38 -07002220 // If the provider is ready, but the width is not yet restored, try to restore it.
2221 if (!item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_PROVIDER_NOT_READY)
2222 && (item.restoreStatus != LauncherAppWidgetInfo.RESTORE_COMPLETED)) {
2223 if (appWidgetInfo == null) {
2224 Log.d(TAG, "Removing restored widget: id=" + item.appWidgetId
2225 + " belongs to component " + item.providerName
2226 + ", as the provider is null");
2227 getModelWriter().deleteItemFromDatabase(item);
2228 return null;
2229 }
Sunny Goyalff572272014-07-23 13:58:07 -07002230
Sunny Goyal17c72fb2019-10-14 14:06:38 -07002231 // If we do not have a valid id, try to bind an id.
2232 if (item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_ID_NOT_VALID)) {
2233 if (!item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_ID_ALLOCATED)) {
2234 // Id has not been allocated yet. Allocate a new id.
2235 item.appWidgetId = mAppWidgetHost.allocateAppWidgetId();
2236 item.restoreStatus |= LauncherAppWidgetInfo.FLAG_ID_ALLOCATED;
Sunny Goyal86df1382016-08-10 15:03:22 -07002237
Sunny Goyal17c72fb2019-10-14 14:06:38 -07002238 // Also try to bind the widget. If the bind fails, the user will be shown
2239 // a click to setup UI, which will ask for the bind permission.
2240 PendingAddWidgetInfo pendingInfo = new PendingAddWidgetInfo(appWidgetInfo);
2241 pendingInfo.spanX = item.spanX;
2242 pendingInfo.spanY = item.spanY;
2243 pendingInfo.minSpanX = item.minSpanX;
2244 pendingInfo.minSpanY = item.minSpanY;
2245 Bundle options = WidgetHostViewLoader.getDefaultOptionsForWidget(this,
2246 pendingInfo);
2247
2248 boolean isDirectConfig =
2249 item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_DIRECT_CONFIG);
2250 if (isDirectConfig && item.bindOptions != null) {
2251 Bundle newOptions = item.bindOptions.getExtras();
2252 if (options != null) {
2253 newOptions.putAll(options);
2254 }
2255 options = newOptions;
Sunny Goyal86df1382016-08-10 15:03:22 -07002256 }
Sunny Goyal17c72fb2019-10-14 14:06:38 -07002257 boolean success = mAppWidgetManager.bindAppWidgetIdIfAllowed(
2258 item.appWidgetId, appWidgetInfo, options);
2259
2260 // We tried to bind once. If we were not able to bind, we would need to
2261 // go through the permission dialog, which means we cannot skip the config
2262 // activity.
2263 item.bindOptions = null;
2264 item.restoreStatus &= ~LauncherAppWidgetInfo.FLAG_DIRECT_CONFIG;
2265
2266 // Bind succeeded
2267 if (success) {
2268 // If the widget has a configure activity, it is still needs to set it
2269 // up, otherwise the widget is ready to go.
2270 item.restoreStatus = (appWidgetInfo.configure == null) || isDirectConfig
2271 ? LauncherAppWidgetInfo.RESTORE_COMPLETED
2272 : LauncherAppWidgetInfo.FLAG_UI_NOT_READY;
2273 }
2274
2275 getModelWriter().updateItemInDatabase(item);
Sunny Goyal86df1382016-08-10 15:03:22 -07002276 }
Sunny Goyal17c72fb2019-10-14 14:06:38 -07002277 } else if (item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_UI_NOT_READY)
2278 && (appWidgetInfo.configure == null)) {
2279 // The widget was marked as UI not ready, but there is no configure activity to
2280 // update the UI.
2281 item.restoreStatus = LauncherAppWidgetInfo.RESTORE_COMPLETED;
Sunny Goyal43bf11d2017-02-02 13:52:53 -08002282 getModelWriter().updateItemInDatabase(item);
Sunny Goyalff572272014-07-23 13:58:07 -07002283 }
Sunny Goyal56c73602015-09-25 12:55:01 -07002284 }
2285
Sunny Goyal17c72fb2019-10-14 14:06:38 -07002286 if (item.restoreStatus == LauncherAppWidgetInfo.RESTORE_COMPLETED) {
2287 // Verify that we own the widget
2288 if (appWidgetInfo == null) {
2289 FileLog.e(TAG, "Removing invalid widget: id=" + item.appWidgetId);
2290 getModelWriter().deleteWidgetInfo(item, getAppWidgetHost());
2291 return null;
2292 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04002293
Sunny Goyal17c72fb2019-10-14 14:06:38 -07002294 item.minSpanX = appWidgetInfo.minSpanX;
2295 item.minSpanY = appWidgetInfo.minSpanY;
2296 view = mAppWidgetHost.createView(this, item.appWidgetId, appWidgetInfo);
2297 } else {
2298 view = new PendingAppWidgetHostView(this, item, mIconCache, false);
2299 }
2300 prepareAppWidget(view, item);
2301 } finally {
Winson Chung5cc62c72019-10-16 11:32:41 -07002302 TraceHelper.INSTANCE.endSection(traceToken);
Sunny Goyal17c72fb2019-10-14 14:06:38 -07002303 }
2304
Sunny Goyalb23980c2017-08-17 07:45:25 -07002305 return view;
Joe Onorato9c1289c2009-08-17 11:03:03 -04002306 }
2307
Sunny Goyalff572272014-07-23 13:58:07 -07002308 /**
2309 * Restores a pending widget.
2310 *
2311 * @param appWidgetId The app widget id
Sunny Goyalff572272014-07-23 13:58:07 -07002312 */
Sunny Goyald478c832016-04-01 12:04:16 -07002313 private LauncherAppWidgetInfo completeRestoreAppWidget(int appWidgetId, int finalRestoreFlag) {
Sunny Goyalff572272014-07-23 13:58:07 -07002314 LauncherAppWidgetHostView view = mWorkspace.getWidgetForAppWidgetId(appWidgetId);
2315 if ((view == null) || !(view instanceof PendingAppWidgetHostView)) {
2316 Log.e(TAG, "Widget update called, when the widget no longer exists.");
Sunny Goyald478c832016-04-01 12:04:16 -07002317 return null;
Sunny Goyalff572272014-07-23 13:58:07 -07002318 }
2319
Sunny Goyal0fc1be12014-08-11 17:05:23 -07002320 LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) view.getTag();
Sunny Goyald478c832016-04-01 12:04:16 -07002321 info.restoreStatus = finalRestoreFlag;
Jon Miranda2b823f42017-05-02 18:36:18 -07002322 if (info.restoreStatus == LauncherAppWidgetInfo.RESTORE_COMPLETED) {
2323 info.pendingItemInfo = null;
2324 }
Sunny Goyalff572272014-07-23 13:58:07 -07002325
Sunny Goyalba47faa2017-10-04 16:50:57 -07002326 if (((PendingAppWidgetHostView) view).isReinflateIfNeeded()) {
Sunny Goyal29947f02017-12-18 13:49:44 -08002327 view.reInflate();
Sunny Goyalba47faa2017-10-04 16:50:57 -07002328 }
2329
Sunny Goyal43bf11d2017-02-02 13:52:53 -08002330 getModelWriter().updateItemInDatabase(info);
Sunny Goyald478c832016-04-01 12:04:16 -07002331 return info;
Sunny Goyalff572272014-07-23 13:58:07 -07002332 }
2333
Adam Cohen1462de32012-07-24 22:34:36 -07002334 public void onPageBoundSynchronously(int page) {
Sunny Goyalf4aceab2017-12-06 16:16:31 -08002335 mSynchronouslyBoundPage = page;
Sunny Goyala7a5bf32020-01-05 15:35:29 +05302336 mWorkspace.setCurrentPage(page);
2337 mPageToBindSynchronously = PagedView.INVALID_PAGE;
Adam Cohen1462de32012-07-24 22:34:36 -07002338 }
2339
Sunny Goyal527c7d32015-08-28 15:19:36 -07002340 @Override
2341 public void executeOnNextDraw(ViewOnDrawExecutor executor) {
Sunny Goyal6b6d0a32019-08-05 17:19:32 -07002342 clearPendingBinds();
Sunny Goyal527c7d32015-08-28 15:19:36 -07002343 mPendingExecutor = executor;
Sunny Goyal60180b02018-02-07 12:56:30 -08002344 if (!isInState(ALL_APPS)) {
vadimtd4c90e12019-06-04 13:59:43 -07002345 mAppsView.getAppsStore().enableDeferUpdates(AllAppsStore.DEFER_UPDATES_NEXT_DRAW);
2346 mPendingExecutor.execute(() -> mAppsView.getAppsStore().disableDeferUpdates(
2347 AllAppsStore.DEFER_UPDATES_NEXT_DRAW));
Sunny Goyal60180b02018-02-07 12:56:30 -08002348 }
2349
Sunny Goyal527c7d32015-08-28 15:19:36 -07002350 executor.attachTo(this);
2351 }
2352
2353 public void clearPendingExecutor(ViewOnDrawExecutor executor) {
2354 if (mPendingExecutor == executor) {
2355 mPendingExecutor = null;
2356 }
2357 }
2358
Sunny Goyalb5b9ad62016-04-02 11:23:39 -07002359 @Override
2360 public void finishFirstPageBind(final ViewOnDrawExecutor executor) {
Sunny Goyal6001ea22018-05-10 16:31:00 -07002361 AlphaProperty property = mDragLayer.getAlphaProperty(ALPHA_INDEX_LAUNCHER_LOAD);
2362 if (property.getValue() < 1) {
2363 ObjectAnimator anim = ObjectAnimator.ofFloat(property, MultiValueAlpha.VALUE, 1);
2364 if (executor != null) {
2365 anim.addListener(new AnimatorListenerAdapter() {
2366 @Override
2367 public void onAnimationEnd(Animator animation) {
2368 executor.onLoadAnimationCompleted();
2369 }
2370 });
2371 }
2372 anim.start();
Sunny Goyal29947f02017-12-18 13:49:44 -08002373 } else if (executor != null) {
2374 executor.onLoadAnimationCompleted();
Sunny Goyalb5b9ad62016-04-02 11:23:39 -07002375 }
2376 }
2377
Joe Onorato9c1289c2009-08-17 11:03:03 -04002378 /**
2379 * Callback saying that there aren't any more items to bind.
2380 *
2381 * Implementation of the method from LauncherModel.Callbacks.
2382 */
Tonyf80e8932018-12-21 11:58:04 -08002383 public void finishBindingItems(int pageBoundFirst) {
Winson Chung5cc62c72019-10-16 11:32:41 -07002384 Object traceToken = TraceHelper.INSTANCE.beginSection("finishBindingItems");
Adam Cohen1462de32012-07-24 22:34:36 -07002385 mWorkspace.restoreInstanceStateForRemainingPages();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002386
Anjali Koppalff7ceff2014-05-01 18:26:37 -07002387 setWorkspaceLoading(false);
Adam Cohendb364c32014-05-20 14:23:40 -07002388
Sunny Goyal2100c782016-08-22 16:00:03 -07002389 if (mPendingActivityResult != null) {
2390 handleActivityResult(mPendingActivityResult.requestCode,
2391 mPendingActivityResult.resultCode, mPendingActivityResult.data);
2392 mPendingActivityResult = null;
Adam Cohendb364c32014-05-20 14:23:40 -07002393 }
2394
Sunny Goyala474a9b2017-05-04 16:47:11 -07002395 InstallShortcutReceiver.disableAndFlushInstallQueue(
2396 InstallShortcutReceiver.FLAG_LOADER_RUNNING, this);
Adam Cohen9211d422014-10-07 18:14:53 -07002397
Tonyf80e8932018-12-21 11:58:04 -08002398 // When undoing the removal of the last item on a page, return to that page.
Tony Wickham03f27012019-04-25 14:22:54 -07002399 // Since we are just resetting the current page without user interaction,
2400 // override the previous page so we don't log the page switch.
2401 mWorkspace.setCurrentPage(pageBoundFirst, pageBoundFirst /* overridePrevPage */);
Sunny Goyala7a5bf32020-01-05 15:35:29 +05302402 mPageToBindSynchronously = PagedView.INVALID_PAGE;
Tony Wickham6a71a5b2018-08-21 11:40:23 -07002403
Sunny Goyalac6f69f2019-08-16 11:59:55 -07002404 // Cache one page worth of icons
2405 getViewCache().setCacheSize(R.layout.folder_application,
2406 mDeviceProfile.inv.numFolderColumns * mDeviceProfile.inv.numFolderRows);
2407 getViewCache().setCacheSize(R.layout.folder_page, 2);
2408
Winson Chung5cc62c72019-10-16 11:32:41 -07002409 TraceHelper.INSTANCE.endSection(traceToken);
Winson Chungf0c6ae02012-03-21 16:10:31 -07002410 }
2411
Winson Chunga2413752012-04-03 14:22:34 -07002412 private boolean canRunNewAppsAnimation() {
2413 long diff = System.currentTimeMillis() - mDragController.getLastGestureUpTime();
Andrew Sapperstein932eb832016-06-30 18:10:09 -07002414 return diff > (NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS * 1000);
Winson Chunga2413752012-04-03 14:22:34 -07002415 }
2416
Winson Chungc9168342013-06-26 14:54:55 -07002417 private ValueAnimator createNewAppBounceAnimation(View v, int i) {
Sunny Goyalf0b6db72018-08-13 16:10:14 -07002418 ValueAnimator bounceAnim = new PropertyListBuilder().alpha(1).scale(1).build(v)
2419 .setDuration(InstallShortcutReceiver.NEW_SHORTCUT_BOUNCE_DURATION);
Winson Chungc9168342013-06-26 14:54:55 -07002420 bounceAnim.setStartDelay(i * InstallShortcutReceiver.NEW_SHORTCUT_STAGGER_DELAY);
Sunny Goyal5a1f53b2015-05-27 10:24:24 -07002421 bounceAnim.setInterpolator(new OvershootInterpolator(BOUNCE_ANIMATION_TENSION));
Winson Chungc9168342013-06-26 14:54:55 -07002422 return bounceAnim;
2423 }
2424
Pinyao Tingc9074272019-11-11 11:51:44 -08002425 private void announceForAccessibility(@StringRes int stringResId) {
2426 getDragLayer().announceForAccessibility(getString(stringResId));
2427 }
2428
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002429 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04002430 * Add the icons for all apps.
2431 *
2432 * Implementation of the method from LauncherModel.Callbacks.
2433 */
Sunny Goyal87dcde62019-07-17 20:35:56 -07002434 public void bindAllApplications(AppInfo[] apps) {
Sunny Goyal60180b02018-02-07 12:56:30 -08002435 mAppsView.getAppsStore().setApps(apps);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002436 }
2437
2438 /**
Zak Cohen658c67a2018-10-19 14:21:05 -07002439 * Copies LauncherModel's map of activities to shortcut counts to Launcher's. This is necessary
Tony Wickhambfbf7f92016-05-19 11:19:39 -07002440 * because LauncherModel's map is updated in the background, while Launcher runs on the UI.
2441 */
2442 @Override
Zak Cohen658c67a2018-10-19 14:21:05 -07002443 public void bindDeepShortcutMap(HashMap<ComponentKey, Integer> deepShortcutMapCopy) {
Tony Wickham010d2552017-01-20 08:15:28 -08002444 mPopupDataProvider.setDeepShortcutMap(deepShortcutMapCopy);
Tony Wickham1bce7fd2016-04-28 17:39:03 -07002445 }
2446
Sunny Goyal4390ace2014-10-13 11:33:11 -07002447 @Override
Sunny Goyal29947f02017-12-18 13:49:44 -08002448 public void bindPromiseAppProgressUpdated(PromiseAppInfo app) {
Sunny Goyal60180b02018-02-07 12:56:30 -08002449 mAppsView.getAppsStore().updatePromiseAppProgress(app);
Mario Bertschler08ffaae2017-03-20 11:30:27 -07002450 }
2451
2452 @Override
Sunny Goyal29947f02017-12-18 13:49:44 -08002453 public void bindWidgetsRestored(ArrayList<LauncherAppWidgetInfo> widgets) {
Sunny Goyal4390ace2014-10-13 11:33:11 -07002454 mWorkspace.widgetsRestored(widgets);
2455 }
2456
Joe Onorato9c1289c2009-08-17 11:03:03 -04002457 /**
Sunny Goyalb50cc8c2014-10-06 16:23:56 -07002458 * Some shortcuts were updated in the background.
Sunny Goyalb50cc8c2014-10-06 16:23:56 -07002459 * Implementation of the method from LauncherModel.Callbacks.
Sunny Goyald3b87ef2016-07-28 12:11:54 -07002460 *
2461 * @param updated list of shortcuts which have changed.
Sunny Goyalb50cc8c2014-10-06 16:23:56 -07002462 */
Sunny Goyal4390ace2014-10-13 11:33:11 -07002463 @Override
Sunny Goyal95899162019-03-27 16:03:06 -07002464 public void bindWorkspaceItemsChanged(ArrayList<WorkspaceItemInfo> updated) {
Sunny Goyal4390ace2014-10-13 11:33:11 -07002465 if (!updated.isEmpty()) {
2466 mWorkspace.updateShortcuts(updated);
2467 }
Sunny Goyalb50cc8c2014-10-06 16:23:56 -07002468 }
2469
2470 /**
Chris Wrenaeff7ea2014-02-14 16:59:24 -05002471 * Update the state of a package, typically related to install state.
2472 *
2473 * Implementation of the method from LauncherModel.Callbacks.
2474 */
Sunny Goyale755d462014-07-22 13:48:29 -07002475 @Override
Sunny Goyal29947f02017-12-18 13:49:44 -08002476 public void bindRestoreItemsChange(HashSet<ItemInfo> updates) {
Sunny Goyal756adbc2015-04-16 15:20:51 -07002477 mWorkspace.updateRestoreItems(updates);
Sunny Goyala22666f2014-09-18 13:25:15 -07002478 }
2479
2480 /**
Sunny Goyal3bbbabc2016-03-15 09:16:30 -07002481 * A package was uninstalled/updated. We take both the super set of packageNames
Winson Chung83892cc2013-05-01 16:53:33 -07002482 * in addition to specific applications to remove, the reason being that
2483 * this can be called when a package is updated as well. In that scenario,
Sunny Goyal3bbbabc2016-03-15 09:16:30 -07002484 * we only remove specific components from the workspace and hotseat, where as
Winson Chung83892cc2013-05-01 16:53:33 -07002485 * package-removal should clear all items by package name.
Joe Onorato9c1289c2009-08-17 11:03:03 -04002486 */
Sunny Goyal1a745e82014-10-02 15:58:31 -07002487 @Override
Sunny Goyal6e13dd32017-08-17 03:01:19 -07002488 public void bindWorkspaceComponentsRemoved(final ItemInfoMatcher matcher) {
Sunny Goyal6e13dd32017-08-17 03:01:19 -07002489 mWorkspace.removeItemsByMatcher(matcher);
2490 mDragController.onAppsRemoved(matcher);
Sunny Goyal3bbbabc2016-03-15 09:16:30 -07002491 }
Sunny Goyal4390ace2014-10-13 11:33:11 -07002492
Sunny Goyal3bbbabc2016-03-15 09:16:30 -07002493 @Override
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -07002494 public void bindAllWidgets(final ArrayList<WidgetListRowEntry> allWidgets) {
2495 mPopupDataProvider.setAllWidgets(allWidgets);
Tony Wickham26b17462017-03-20 17:12:24 -07002496 }
2497
Tony Wickham86222d22017-03-29 15:30:43 -07002498 /**
2499 * @param packageUser if null, refreshes all widgets and shortcuts, otherwise only
2500 * refreshes the widgets and shortcuts associated with the given package/user
2501 */
2502 public void refreshAndBindWidgetsForPackageUser(@Nullable PackageUserKey packageUser) {
Sunny Goyalc6e97692017-06-02 13:46:55 -07002503 mModel.refreshAndBindWidgetsAndShortcuts(packageUser);
Sunny Goyal2e1efb42016-03-03 16:58:55 -08002504 }
2505
Winson Chung80baf5a2010-08-09 16:03:15 -07002506 /**
Hyunyoung Song3c7d9cb2017-01-30 15:11:27 -08002507 * $ adb shell dumpsys activity com.android.launcher3.Launcher [--all]
Joe Onoratobe386092009-11-17 17:32:16 -08002508 */
Adam Cohen16d7ffc2011-10-05 17:49:14 -07002509 @Override
2510 public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
2511 super.dump(prefix, fd, writer, args);
Sunny Goyala1365452015-10-01 15:46:24 -07002512
Hyunyoung Song3c7d9cb2017-01-30 15:11:27 -08002513 if (args.length > 0 && TextUtils.equals(args[0], "--all")) {
2514 writer.println(prefix + "Workspace Items");
Sunny Goyal7ce471b2017-08-02 03:37:39 -07002515 for (int i = 0; i < mWorkspace.getPageCount(); i++) {
Hyunyoung Song3c7d9cb2017-01-30 15:11:27 -08002516 writer.println(prefix + " Homescreen " + i);
2517
2518 ViewGroup layout = ((CellLayout) mWorkspace.getPageAt(i)).getShortcutsAndWidgets();
2519 for (int j = 0; j < layout.getChildCount(); j++) {
2520 Object tag = layout.getChildAt(j).getTag();
2521 if (tag != null) {
2522 writer.println(prefix + " " + tag.toString());
2523 }
2524 }
2525 }
2526
2527 writer.println(prefix + " Hotseat");
Sunny Goyal876e4622018-11-02 13:50:40 -07002528 ViewGroup layout = mHotseat.getShortcutsAndWidgets();
Sunny Goyala1365452015-10-01 15:46:24 -07002529 for (int j = 0; j < layout.getChildCount(); j++) {
2530 Object tag = layout.getChildAt(j).getTag();
2531 if (tag != null) {
2532 writer.println(prefix + " " + tag.toString());
2533 }
Adam Cohen4caf2982013-08-20 18:54:31 -07002534 }
Sunny Goyala1365452015-10-01 15:46:24 -07002535 }
2536
Hyunyoung Song3c7d9cb2017-01-30 15:11:27 -08002537 writer.println(prefix + "Misc:");
Winson Chungef528762019-09-06 12:05:52 -07002538 dumpMisc(prefix + "\t", writer);
2539 writer.println(prefix + "\tmWorkspaceLoading=" + mWorkspaceLoading);
2540 writer.println(prefix + "\tmPendingRequestArgs=" + mPendingRequestArgs
2541 + " mPendingActivityResult=" + mPendingActivityResult);
2542 writer.println(prefix + "\tmRotationHelper: " + mRotationHelper);
2543 writer.println(prefix + "\tmAppWidgetHost.isListening: " + mAppWidgetHost.isListening());
2544
Sunny Goyalcb2c5052018-10-15 12:30:29 -07002545 // Extra logging for b/116853349
Hyunyoung Songa310a802019-04-25 13:57:16 -07002546 mDragLayer.dump(prefix, writer);
2547 mStateManager.dump(prefix, writer);
Sunny Goyal2bba1902018-02-27 12:20:50 -08002548
2549 try {
2550 FileLog.flushAll(writer);
2551 } catch (Exception e) {
2552 // Ignore
2553 }
Hyunyoung Song3c7d9cb2017-01-30 15:11:27 -08002554
2555 mModel.dumpState(prefix, fd, writer, args);
Sunny Goyala1365452015-10-01 15:46:24 -07002556
Adam Cohen9211d422014-10-07 18:14:53 -07002557 if (mLauncherCallbacks != null) {
2558 mLauncherCallbacks.dump(prefix, fd, writer, args);
2559 }
Sunny Goyalb1d7de22019-09-06 10:36:54 -07002560 mOverlayManager.dump(prefix, writer);
Adam Cohen16d7ffc2011-10-05 17:49:14 -07002561 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07002562
Sunny Goyal66b24572016-09-21 15:57:55 -07002563 @Override
Sunny Goyal66b24572016-09-21 15:57:55 -07002564 public void onProvideKeyboardShortcuts(
2565 List<KeyboardShortcutGroup> data, Menu menu, int deviceId) {
2566
2567 ArrayList<KeyboardShortcutInfo> shortcutInfos = new ArrayList<>();
Sunny Goyal3e3f44c2017-10-23 17:14:52 -07002568 if (isInState(NORMAL)) {
Sunny Goyal66b24572016-09-21 15:57:55 -07002569 shortcutInfos.add(new KeyboardShortcutInfo(getString(R.string.all_apps_button_label),
2570 KeyEvent.KEYCODE_A, KeyEvent.META_CTRL_ON));
Vadim Tryshev74c261c2018-06-12 13:44:43 -07002571 shortcutInfos.add(new KeyboardShortcutInfo(getString(R.string.widget_button_text),
2572 KeyEvent.KEYCODE_W, KeyEvent.META_CTRL_ON));
Sunny Goyal66b24572016-09-21 15:57:55 -07002573 }
Vadim Tryshev3455f8d2018-05-11 20:02:20 -07002574 final View currentFocus = getCurrentFocus();
2575 if (currentFocus != null) {
2576 if (new CustomActionsPopup(this, currentFocus).canShow()) {
2577 shortcutInfos.add(new KeyboardShortcutInfo(getString(R.string.custom_actions),
2578 KeyEvent.KEYCODE_O, KeyEvent.META_CTRL_ON));
2579 }
2580 if (currentFocus.getTag() instanceof ItemInfo
Pinyao Ting49a3e692019-07-26 12:28:38 -07002581 && ShortcutUtil.supportsShortcuts((ItemInfo) currentFocus.getTag())) {
Vadim Tryshev3455f8d2018-05-11 20:02:20 -07002582 shortcutInfos.add(new KeyboardShortcutInfo(
2583 getString(R.string.shortcuts_menu_with_notifications_description),
2584 KeyEvent.KEYCODE_S, KeyEvent.META_CTRL_ON));
2585 }
Sunny Goyal66b24572016-09-21 15:57:55 -07002586 }
2587 if (!shortcutInfos.isEmpty()) {
2588 data.add(new KeyboardShortcutGroup(getString(R.string.home_screen), shortcutInfos));
2589 }
2590
2591 super.onProvideKeyboardShortcuts(data, menu, deviceId);
2592 }
2593
2594 @Override
2595 public boolean onKeyShortcut(int keyCode, KeyEvent event) {
2596 if (event.hasModifiers(KeyEvent.META_CTRL_ON)) {
2597 switch (keyCode) {
2598 case KeyEvent.KEYCODE_A:
Sunny Goyal3e3f44c2017-10-23 17:14:52 -07002599 if (isInState(NORMAL)) {
2600 getStateManager().goToState(ALL_APPS);
Sunny Goyal66b24572016-09-21 15:57:55 -07002601 return true;
2602 }
2603 break;
2604 case KeyEvent.KEYCODE_S: {
2605 View focusedView = getCurrentFocus();
2606 if (focusedView instanceof BubbleTextView
2607 && focusedView.getTag() instanceof ItemInfo
2608 && mAccessibilityDelegate.performAction(focusedView,
Samuel Fufaca37b8a2019-08-19 17:04:36 -07002609 (ItemInfo) focusedView.getTag(),
2610 LauncherAccessibilityDelegate.DEEP_SHORTCUTS)) {
Sunny Goyal00ac9202017-11-09 15:24:06 -08002611 PopupContainerWithArrow.getOpen(this).requestFocus();
Sunny Goyal66b24572016-09-21 15:57:55 -07002612 return true;
2613 }
2614 break;
2615 }
2616 case KeyEvent.KEYCODE_O:
2617 if (new CustomActionsPopup(this, getCurrentFocus()).show()) {
2618 return true;
2619 }
2620 break;
Vadim Tryshev74c261c2018-06-12 13:44:43 -07002621 case KeyEvent.KEYCODE_W:
2622 if (isInState(NORMAL)) {
2623 OptionsPopupView.openWidgets(this);
2624 return true;
2625 }
2626 break;
Sunny Goyal66b24572016-09-21 15:57:55 -07002627 }
2628 }
2629 return super.onKeyShortcut(keyCode, event);
2630 }
2631
Vadim Tryshev646a0dd2018-02-05 16:27:50 -08002632 @Override
2633 public boolean onKeyUp(int keyCode, KeyEvent event) {
2634 if (keyCode == KeyEvent.KEYCODE_MENU) {
2635 // KEYCODE_MENU is sent by some tests, for example
2636 // LauncherJankTests#testWidgetsContainerFling. Don't just remove its handling.
2637 if (!mDragController.isDragging() && !mWorkspace.isSwitchingState() &&
2638 isInState(NORMAL)) {
2639 // Close any open floating views.
2640 AbstractFloatingView.closeAllOpenViews(this);
2641
2642 // Setting the touch point to (-1, -1) will show the options popup in the center of
2643 // the screen.
vadimtbc5d7e62019-12-09 13:53:05 -08002644 if (Utilities.IS_RUNNING_IN_TEST_HARNESS) {
2645 Log.d(TestProtocol.PERMANENT_DIAG_TAG, "Opening options popup on key up");
2646 }
Sunny Goyal2fd7a8b2018-03-30 17:10:13 -07002647 OptionsPopupView.showDefaultOptions(this, -1, -1);
Vadim Tryshev646a0dd2018-02-05 16:27:50 -08002648 }
2649 return true;
2650 }
2651 return super.onKeyUp(keyCode, event);
2652 }
2653
Sunny Goyal210e1742019-10-17 12:05:38 -07002654 protected StateHandler[] createStateHandlers() {
2655 return new StateHandler[] { getAllAppsController(), getWorkspace() };
Andrew Sappersteinabef55a2016-06-19 12:49:00 -07002656 }
2657
Sunny Goyal210e1742019-10-17 12:05:38 -07002658 public TouchController[] createTouchControllers() {
2659 return new TouchController[] {getDragController(), new AllAppsSwipeController(this)};
2660 }
2661
2662 protected RotationMode getFakeRotationMode(DeviceProfile deviceProfile) {
2663 return RotationMode.NORMAL;
2664 }
2665
2666 protected ScaleAndTranslation getOverviewScaleAndTranslationForNormalState() {
2667 return new ScaleAndTranslation(1.1f, 0f, 0f);
2668 }
2669
2670 public void useFadeOutAnimationForLauncherStart(CancellationSignal signal) { }
2671
2672 public void onDragLayerHierarchyChanged() { }
2673
Vinit Nayakf9b585b2019-07-10 14:25:32 -07002674 @Override
2675 public void returnToHomescreen() {
2676 super.returnToHomescreen();
2677 getStateManager().goToState(LauncherState.NORMAL);
2678 }
2679
Sunny Goyal3a1eadd2019-10-23 17:44:27 -07002680 public Stream<SystemShortcut.Factory> getSupportedShortcuts() {
2681 return Stream.of(APP_INFO, WIDGETS, INSTALL, DISMISS_PREDICTION);
2682 }
2683
Sunny Goyal210e1742019-10-17 12:05:38 -07002684 public static Launcher getLauncher(Context context) {
2685 return (Launcher) fromContext(context);
2686 }
2687
Sunny Goyal3dce5f32017-10-05 11:40:05 -07002688 /**
Sunny Goyalab770a12018-11-14 15:17:26 -08002689 * Just a wrapper around the type cast to allow easier tracking of calls.
2690 */
2691 public static <T extends Launcher> T cast(ActivityContext activityContext) {
2692 return (T) activityContext;
2693 }
2694
2695 /**
Sunny Goyal3dce5f32017-10-05 11:40:05 -07002696 * Callback for listening for onResume
2697 */
2698 public interface OnResumeCallback {
2699
2700 void onLauncherResume();
2701 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002702}