blob: 577acb27f63c59d3d976053f95d0fd1a83afee9a [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;
Sunny Goyalb1d7de22019-09-06 10:36:54 -070086import androidx.annotation.VisibleForTesting;
Sunny Goyal11a50742019-08-07 09:24:26 -070087
Sunny Goyal651077b2014-06-30 14:15:31 -070088import com.android.launcher3.DropTarget.DragObject;
Sunny Goyal210e1742019-10-17 12:05:38 -070089import com.android.launcher3.LauncherState.ScaleAndTranslation;
90import com.android.launcher3.LauncherStateManager.StateHandler;
Sunny Goyalae502842016-06-17 08:43:56 -070091import com.android.launcher3.accessibility.LauncherAccessibilityDelegate;
Winson Chung5f4e0fd2015-05-22 11:12:27 -070092import com.android.launcher3.allapps.AllAppsContainerView;
vadimtd4c90e12019-06-04 13:59:43 -070093import com.android.launcher3.allapps.AllAppsStore;
Hyunyoung Song645764e2016-06-06 14:19:02 -070094import com.android.launcher3.allapps.AllAppsTransitionController;
Sunny Goyal7ede6112017-12-05 15:11:21 -080095import com.android.launcher3.allapps.DiscoveryBounce;
Sunny Goyalf0b6db72018-08-13 16:10:14 -070096import com.android.launcher3.anim.PropertyListBuilder;
Sunny Goyalffe83f12014-08-14 17:39:34 -070097import com.android.launcher3.compat.AppWidgetManagerCompat;
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;
Sunny Goyal210e1742019-10-17 12:05:38 -0700124import com.android.launcher3.touch.AllAppsSwipeController;
Sunny Goyal8a2a63b2018-03-06 22:15:18 -0800125import com.android.launcher3.touch.ItemClickHandler;
Sunny Goyalb1d7de22019-09-06 10:36:54 -0700126import com.android.launcher3.uioverrides.plugins.PluginManagerWrapper;
Hyunyoung Song46d07f72018-05-22 15:41:25 -0700127import com.android.launcher3.userevent.nano.LauncherLogProto;
Sunny Goyal6c46a6d2016-11-23 02:24:32 +0530128import com.android.launcher3.userevent.nano.LauncherLogProto.Action;
129import com.android.launcher3.userevent.nano.LauncherLogProto.ContainerType;
Sunny Goyalaeb16432017-10-16 11:46:41 -0700130import com.android.launcher3.userevent.nano.LauncherLogProto.Target;
Sunny Goyal2100c782016-08-22 16:00:03 -0700131import com.android.launcher3.util.ActivityResultInfo;
Sunny Goyale84c5b82019-09-26 17:05:31 -0700132import com.android.launcher3.util.ActivityTracker;
Winson Chung6b1c73f2015-06-18 11:38:42 -0700133import com.android.launcher3.util.ComponentKey;
Sunny Goyalefb7e842018-10-04 15:11:00 -0700134import com.android.launcher3.util.IntArray;
Sunny Goyald3b87ef2016-07-28 12:11:54 -0700135import com.android.launcher3.util.ItemInfoMatcher;
Sunny Goyal6001ea22018-05-10 16:31:00 -0700136import com.android.launcher3.util.MultiValueAlpha;
137import com.android.launcher3.util.MultiValueAlpha.AlphaProperty;
Sunny Goyal04cc3a72016-05-17 10:32:43 -0700138import com.android.launcher3.util.PackageManagerHelper;
Tony Wickham010d2552017-01-20 08:15:28 -0800139import com.android.launcher3.util.PackageUserKey;
Sunny Goyal2100c782016-08-22 16:00:03 -0700140import com.android.launcher3.util.PendingRequestArgs;
Pinyao Ting49a3e692019-07-26 12:28:38 -0700141import com.android.launcher3.util.ShortcutUtil;
Sunny Goyal8392c822017-06-20 10:03:56 -0700142import com.android.launcher3.util.SystemUiController;
Mario Bertschlera6936942017-05-31 14:48:19 -0700143import com.android.launcher3.util.Themes;
Adam Cohen091440a2015-03-18 14:16:05 -0700144import com.android.launcher3.util.Thunk;
Sunny Goyal210e1742019-10-17 12:05:38 -0700145import com.android.launcher3.util.TouchController;
Sunny Goyalfca6bc92017-09-28 16:28:34 -0700146import com.android.launcher3.util.TraceHelper;
Sunny Goyal326403e2017-10-02 12:45:10 -0700147import com.android.launcher3.util.UiThreadHelper;
Sunny Goyal527c7d32015-08-28 15:19:36 -0700148import com.android.launcher3.util.ViewOnDrawExecutor;
Sunny Goyalab770a12018-11-14 15:17:26 -0800149import com.android.launcher3.views.ActivityContext;
Sunny Goyal7c7be8c2018-03-07 19:58:07 -0800150import com.android.launcher3.views.OptionsPopupView;
Govinda Wassermanc06e1512019-04-09 09:56:53 -0400151import com.android.launcher3.views.ScrimView;
Sunny Goyal29947f02017-12-18 13:49:44 -0800152import com.android.launcher3.widget.LauncherAppWidgetHostView;
Sunny Goyal782f0c92017-01-19 10:27:54 -0800153import com.android.launcher3.widget.PendingAddShortcutInfo;
Hyunyoung Song3f471442015-04-08 19:01:34 -0700154import com.android.launcher3.widget.PendingAddWidgetInfo;
Sunny Goyal29947f02017-12-18 13:49:44 -0800155import com.android.launcher3.widget.PendingAppWidgetHostView;
Sunny Goyal04a324a2017-01-20 21:08:59 -0800156import com.android.launcher3.widget.WidgetAddFlowHandler;
Hyunyoung Songb99ff3e2015-04-23 15:17:50 -0700157import com.android.launcher3.widget.WidgetHostViewLoader;
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -0700158import com.android.launcher3.widget.WidgetListRowEntry;
159import com.android.launcher3.widget.WidgetsFullSheet;
Pinyao Tingc7a6c292019-08-26 14:36:02 -0700160import com.android.launcher3.widget.custom.CustomWidgetManager;
Sunny Goyalb1d7de22019-09-06 10:36:54 -0700161import com.android.systemui.plugins.OverlayPlugin;
162import com.android.systemui.plugins.PluginListener;
163import com.android.systemui.plugins.shared.LauncherExterns;
164import com.android.systemui.plugins.shared.LauncherOverlayManager;
165import com.android.systemui.plugins.shared.LauncherOverlayManager.LauncherOverlay;
166import com.android.systemui.plugins.shared.LauncherOverlayManager.LauncherOverlayCallbacks;
Adam Cohen6c5891a2014-07-09 23:53:15 -0700167
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700168import java.io.FileDescriptor;
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700169import java.io.PrintWriter;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700170import java.util.ArrayList;
Winson Chungf0c6ae02012-03-21 16:10:31 -0700171import java.util.Collection;
Zak Cohen658c67a2018-10-19 14:21:05 -0700172import java.util.HashMap;
Sunny Goyal4390ace2014-10-13 11:33:11 -0700173import java.util.HashSet;
Michael Jurkad7c28052012-04-27 15:43:36 -0700174import java.util.List;
Sunny Goyalaae6fbb2019-01-31 16:05:58 -0800175import java.util.function.Predicate;
Sunny Goyalb1d7de22019-09-06 10:36:54 -0700176import java.util.function.Supplier;
Sunny Goyal3a1eadd2019-10-23 17:44:27 -0700177import java.util.stream.Stream;
Jon Mirandaf5197fc2019-09-04 16:55:41 -0700178
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800179/**
180 * Default launcher application.
181 */
Hyunyoung Song46d07f72018-05-22 15:41:25 -0700182public class Launcher extends BaseDraggingActivity implements LauncherExterns,
Sunny Goyal01615a62019-09-20 12:00:07 -0700183 Callbacks, UserEventDelegate,
Sunny Goyalb1d7de22019-09-06 10:36:54 -0700184 InvariantDeviceProfile.OnIDPChangeListener, PluginListener<OverlayPlugin> {
Vadim Tryshevfedca432015-08-19 17:55:02 -0700185 public static final String TAG = "Launcher";
Sunny Goyale84c5b82019-09-26 17:05:31 -0700186
187 public static final ActivityTracker<Launcher> ACTIVITY_TRACKER = new ActivityTracker<>();
188
Sunny Goyal2bba4c32015-05-18 15:42:48 -0700189 static final boolean LOGD = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800190
Winson Chunga2413752012-04-03 14:22:34 -0700191 static final boolean DEBUG_STRICT_MODE = false;
Romain Guy6fefcf12009-06-11 13:07:43 -0700192
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800193 private static final int REQUEST_CREATE_SHORTCUT = 1;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700194 private static final int REQUEST_CREATE_APPWIDGET = 5;
Jon Mirandac476d6e2017-05-04 16:30:01 -0700195
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700196 private static final int REQUEST_PICK_APPWIDGET = 9;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800197
Michael Jurka8b805b12012-04-18 14:23:14 -0700198 private static final int REQUEST_BIND_APPWIDGET = 11;
Sunny Goyal8a2a63b2018-03-06 22:15:18 -0800199 public static final int REQUEST_BIND_PENDING_APPWIDGET = 12;
200 public static final int REQUEST_RECONFIGURE_APPWIDGET = 13;
Michael Jurka8b805b12012-04-18 14:23:14 -0700201
Jon Mirandac476d6e2017-05-04 16:30:01 -0700202 private static final int REQUEST_PERMISSION_CALL_PHONE = 14;
Sunny Goyal28c6b962015-10-12 11:42:05 -0700203
Sunny Goyal5a1f53b2015-05-27 10:24:24 -0700204 private static final float BOUNCE_ANIMATION_TENSION = 1.3f;
205
Mathew Inwood876a8462013-06-14 14:12:41 +0100206 /**
207 * IntentStarter uses request codes starting with this. This must be greater than all activity
208 * request codes used internally.
209 */
210 protected static final int REQUEST_LAST = 100;
211
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800212 // Type: int
213 private static final String RUNTIME_STATE_CURRENT_SCREEN = "launcher.current_screen";
Michael Jurka883f55b2010-10-21 15:47:14 -0700214 // Type: int
215 private static final String RUNTIME_STATE = "launcher.state";
Sunny Goyal2100c782016-08-22 16:00:03 -0700216 // Type: PendingRequestArgs
217 private static final String RUNTIME_STATE_PENDING_REQUEST_ARGS = "launcher.request_args";
Sunny Goyaldedda052019-05-14 15:23:48 -0700218 // Type: int
219 private static final String RUNTIME_STATE_PENDING_REQUEST_CODE = "launcher.request_code";
Sunny Goyal2100c782016-08-22 16:00:03 -0700220 // Type: ActivityResultInfo
221 private static final String RUNTIME_STATE_PENDING_ACTIVITY_RESULT = "launcher.activity_result";
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -0700222 // Type: SparseArray<Parcelable>
223 private static final String RUNTIME_STATE_WIDGET_PANEL = "launcher.widget_panel";
Sunny Goyal17c72fb2019-10-14 14:06:38 -0700224
vadimt00d42552018-12-11 17:59:36 -0800225 public static final String ON_CREATE_EVT = "Launcher.onCreate";
Sunny Goyal17c72fb2019-10-14 14:06:38 -0700226 public static final String ON_START_EVT = "Launcher.onStart";
227 public static final String ON_RESUME_EVT = "Launcher.onResume";
228 public static final String ON_NEW_INTENT_EVT = "Launcher.onNewIntent";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800229
Sunny Goyal3e3f44c2017-10-23 17:14:52 -0700230 private LauncherStateManager mStateManager;
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700231
Adam Cohenad4e15c2013-10-17 16:21:35 -0700232 private static final int ON_ACTIVITY_RESULT_ANIMATION_DELAY = 500;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800233
Winson Chunga2413752012-04-03 14:22:34 -0700234 // How long to wait before the new-shortcut animation automatically pans the workspace
Jon Mirandaf5197fc2019-09-04 16:55:41 -0700235 @VisibleForTesting public static final int NEW_APPS_PAGE_MOVE_DELAY = 500;
Rajeev Kumar43c0f582017-06-23 15:34:55 -0700236 private static final int NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS = 5;
Jon Mirandaf5197fc2019-09-04 16:55:41 -0700237 @Thunk @VisibleForTesting public static final int NEW_APPS_ANIMATION_DELAY = 500;
Winson Chunga2413752012-04-03 14:22:34 -0700238
Govinda Wassermanc06e1512019-04-09 09:56:53 -0400239 private static final int APPS_VIEW_ALPHA_CHANNEL_INDEX = 1;
240 private static final int SCRIM_VIEW_ALPHA_CHANNEL_INDEX = 0;
241
Jon Miranda54441f52018-01-24 15:38:25 -0800242 private LauncherAppTransitionManager mAppTransitionManager;
Sunny Goyalf8d56fc2018-01-31 15:18:11 -0800243 private Configuration mOldConfig;
Jon Miranda54441f52018-01-24 15:38:25 -0800244
Samuel Fufaca37b8a2019-08-19 17:04:36 -0700245 @Thunk
246 Workspace mWorkspace;
Craig Mautner360310b2012-10-26 15:13:08 -0700247 private View mLauncherView;
Samuel Fufaca37b8a2019-08-19 17:04:36 -0700248 @Thunk
249 DragLayer mDragLayer;
Michael Jurkab737ee62011-11-15 15:57:22 -0800250 private DragController mDragController;
Sunny Goyal322d5562015-06-25 19:35:49 -0700251
Sunny Goyalffe83f12014-08-14 17:39:34 -0700252 private AppWidgetManagerCompat mAppWidgetManager;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700253 private LauncherAppWidgetHost mAppWidgetHost;
Romain Guycbb89e42009-06-08 15:52:54 -0700254
Rajeev Kumar43c0f582017-06-23 15:34:55 -0700255 private final int[] mTmpAddItemCellCoordinates = new int[2];
Michael Jurka0280c3b2010-09-17 15:00:07 -0700256
Samuel Fufaca37b8a2019-08-19 17:04:36 -0700257 @Thunk
258 Hotseat mHotseat;
Adam Cohenf358a4b2013-07-23 16:47:31 -0700259
Sunny Goyal47328fd2016-05-25 18:56:41 -0700260 private DropTargetBar mDropTargetBar;
Hyunyoung Song3f471442015-04-08 19:01:34 -0700261
262 // Main container view for the all apps screen.
Samuel Fufaca37b8a2019-08-19 17:04:36 -0700263 @Thunk
264 AllAppsContainerView mAppsView;
Hyunyoung Song645764e2016-06-06 14:19:02 -0700265 AllAppsTransitionController mAllAppsController;
Hyunyoung Song3f471442015-04-08 19:01:34 -0700266
Govinda Wassermanc06e1512019-04-09 09:56:53 -0400267 // Scrim view for the all apps and overview state.
Samuel Fufaca37b8a2019-08-19 17:04:36 -0700268 @Thunk
269 ScrimView mScrimView;
Govinda Wassermanc06e1512019-04-09 09:56:53 -0400270
Winson Chung8ae41982017-11-10 11:42:13 -0800271 // UI and state for the overview panel
Sunny Goyal7c7be8c2018-03-07 19:58:07 -0800272 private View mOverviewPanel;
Winson Chung8ae41982017-11-10 11:42:13 -0800273
Samuel Fufaca37b8a2019-08-19 17:04:36 -0700274 @Thunk
275 boolean mWorkspaceLoading = true;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400276
Winson Chung0b70cd42019-06-17 22:34:33 -0700277 private ArrayList<OnResumeCallback> mOnResumeCallbacks = new ArrayList<>();
Sunny Goyal3dce5f32017-10-05 11:40:05 -0700278
Winson Chungc9bf6d42019-10-04 15:33:18 -0700279 // Used to notify when an activity launch has been deferred because launcher is not yet resumed
280 // TODO: See if we can remove this later
281 private Runnable mOnDeferredActivityLaunchCallback;
282
Sunny Goyal527c7d32015-08-28 15:19:36 -0700283 private ViewOnDrawExecutor mPendingExecutor;
Michael Jurka7607c2f2013-04-03 14:33:19 -0700284
Joe Onorato9c1289c2009-08-17 11:03:03 -0400285 private LauncherModel mModel;
Sunny Goyal43bf11d2017-02-02 13:52:53 -0800286 private ModelWriter mModelWriter;
Joe Onorato0589f0f2010-02-08 13:44:00 -0800287 private IconCache mIconCache;
Sunny Goyalae502842016-06-17 08:43:56 -0700288 private LauncherAccessibilityDelegate mAccessibilityDelegate;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400289
Tony Wickham010d2552017-01-20 08:15:28 -0800290 private PopupDataProvider mPopupDataProvider;
Tony Wickhambfbf7f92016-05-19 11:19:39 -0700291
Sunny Goyalf4aceab2017-12-06 16:16:31 -0800292 private int mSynchronouslyBoundPage = PagedView.INVALID_PAGE;
Adam Cohen1462de32012-07-24 22:34:36 -0700293
Winson Chung46353de2012-02-16 14:05:10 -0800294 // We only want to get the SharedPreferences once since it does an FS stat each time we get
295 // it from the context.
296 private SharedPreferences mSharedPrefs;
297
Sunny Goyal2100c782016-08-22 16:00:03 -0700298 // Activity result which needs to be processed after workspace has loaded.
299 private ActivityResultInfo mPendingActivityResult;
300 /**
301 * Holds extra information required to handle a result from an external call, like
302 * {@link #startActivityForResult(Intent, int)} or {@link #requestPermissions(String[], int)}
303 */
304 private PendingRequestArgs mPendingRequestArgs;
Sunny Goyaldedda052019-05-14 15:23:48 -0700305 // Request id for any pending activity result
Sunny Goyal210e1742019-10-17 12:05:38 -0700306 protected int mPendingActivityRequestCode = -1;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800307
Sunny Goyal3333b0c2016-05-09 20:43:21 -0700308 public ViewGroupFocusHelper mFocusHandler;
Hyunyoung Song7fb3ccc2017-10-17 15:39:46 -0700309
Sunny Goyal623eddd2018-03-02 12:24:41 -0800310 private RotationHelper mRotationHelper;
Sunny Goyal7779d622015-06-11 16:18:39 -0700311
Sunny Goyal2db53422019-03-01 16:06:12 -0800312 final Handler mHandler = new Handler();
Sunny Goyala002c6c2019-02-12 16:20:10 -0800313 private final Runnable mHandleDeferredResume = this::handleDeferredResume;
Sunny Goyale9c6f4c2019-05-30 11:35:25 -0700314 private boolean mDeferredResumePending;
Hyunyoung Songbd6fba92018-05-16 15:54:31 -0700315
Govinda Wassermanc06e1512019-04-09 09:56:53 -0400316 private float mCurrentAssistantVisibility = 0f;
317
Sunny Goyalae6e3182019-04-30 12:04:37 -0700318 private DeviceProfile mStableDeviceProfile;
319 private RotationMode mRotationMode = RotationMode.NORMAL;
320
Sunny Goyalb1d7de22019-09-06 10:36:54 -0700321 protected LauncherOverlayManager mOverlayManager;
322 // If true, overlay callbacks are deferred
323 private boolean mDeferOverlayCallbacks;
324 private final Runnable mDeferredOverlayCallbacks = this::checkIfOverlayStillDeferred;
325
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800326 @Override
327 protected void onCreate(Bundle savedInstanceState) {
Winson Chung5cc62c72019-10-16 11:32:41 -0700328 Object traceToken = TraceHelper.INSTANCE.beginSection(ON_CREATE_EVT,
329 TraceHelper.FLAG_UI_EVENT);
Winson Chunga2413752012-04-03 14:22:34 -0700330 if (DEBUG_STRICT_MODE) {
331 StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
332 .detectDiskReads()
333 .detectDiskWrites()
334 .detectNetwork() // or .detectAll() for all detectable problems
335 .penaltyLog()
336 .build());
337 StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
338 .detectLeakedSqlLiteObjects()
339 .detectLeakedClosableObjects()
340 .penaltyLog()
341 .penaltyDeath()
342 .build());
343 }
344
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800345 super.onCreate(savedInstanceState);
Daniel Sandlere060b0b2013-06-27 21:47:55 -0400346
Sunny Goyal87f784c2017-01-11 10:48:34 -0800347 LauncherAppState app = LauncherAppState.getInstance(this);
Sunny Goyalf8d56fc2018-01-31 15:18:11 -0800348 mOldConfig = new Configuration(getResources().getConfiguration());
Sunny Goyal0e7724c2018-02-22 13:22:21 -0800349 mModel = app.setLauncher(this);
Sunny Goyal41d51a02019-05-14 09:44:34 -0700350 mRotationHelper = new RotationHelper(this);
Hyunyoung Song31971a32019-01-27 12:31:12 -0800351 InvariantDeviceProfile idp = app.getInvariantDeviceProfile();
352 initDeviceProfile(idp);
353 idp.addOnChangeListener(this);
Sunny Goyalf7258242015-10-19 16:59:07 -0700354 mSharedPrefs = Utilities.getPrefs(this);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800355 mIconCache = app.getIconCache();
Sunny Goyalae502842016-06-17 08:43:56 -0700356 mAccessibilityDelegate = new LauncherAccessibilityDelegate(this);
Adam Cohen2e6da152015-05-06 11:42:25 -0700357
Joe Onorato41a12d22009-10-31 18:30:00 -0400358 mDragController = new DragController(this);
Hyunyoung Song645764e2016-06-06 14:19:02 -0700359 mAllAppsController = new AllAppsTransitionController(this);
Sunny Goyalc4fa8c32017-11-07 12:23:58 -0800360 mStateManager = new LauncherStateManager(this);
Romain Guycbb89e42009-06-08 15:52:54 -0700361
Sunny Goyalffe83f12014-08-14 17:39:34 -0700362 mAppWidgetManager = AppWidgetManagerCompat.getInstance(this);
Samuel Fufa44043ec2019-08-26 15:00:30 -0700363 mAppWidgetHost = new LauncherAppWidgetHost(this,
364 appWidgetId -> getWorkspace().removeWidget(appWidgetId));
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700365 mAppWidgetHost.startListening();
Romain Guycbb89e42009-06-08 15:52:54 -0700366
Sunny Goyal60820d72017-05-09 12:40:11 -0700367 mLauncherView = LayoutInflater.from(this).inflate(R.layout.launcher, null);
Michael Jurka7267fa52013-09-26 15:29:57 -0700368
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800369 setupViews();
Tony Wickham010d2552017-01-20 08:15:28 -0800370 mPopupDataProvider = new PopupDataProvider(this);
371
Sunny Goyal90548432018-04-04 17:17:00 -0700372 mAppTransitionManager = LauncherAppTransitionManager.newInstance(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800373
Sunny Goyale84c5b82019-09-26 17:05:31 -0700374 boolean internalStateHandled = ACTIVITY_TRACKER.handleCreate(this);
Sunny Goyald3864fa2017-11-14 15:06:36 -0800375 if (internalStateHandled) {
Sunny Goyald3864fa2017-11-14 15:06:36 -0800376 if (savedInstanceState != null) {
377 // InternalStateHandler has already set the appropriate state.
378 // We dont need to do anything.
379 savedInstanceState.remove(RUNTIME_STATE);
380 }
381 }
382 restoreState(savedInstanceState);
Sunny Goyalbbece862019-03-01 13:13:52 -0800383 mStateManager.reapplyState();
Winson Chungb63b44c2017-11-10 17:54:44 -0800384
Sunny Goyal2100c782016-08-22 16:00:03 -0700385 // We only load the page synchronously if the user rotates (or triggers a
386 // configuration change) while launcher is in the foreground
Sunny Goyalfe770c92016-09-27 14:38:58 -0700387 int currentScreen = PagedView.INVALID_RESTORE_PAGE;
388 if (savedInstanceState != null) {
389 currentScreen = savedInstanceState.getInt(RUNTIME_STATE_CURRENT_SCREEN, currentScreen);
390 }
Sunny Goyald3864fa2017-11-14 15:06:36 -0800391
Sunny Goyalfe770c92016-09-27 14:38:58 -0700392 if (!mModel.startLoader(currentScreen)) {
Sunny Goyald3864fa2017-11-14 15:06:36 -0800393 if (!internalStateHandled) {
394 // If we are not binding synchronously, show a fade in animation when
395 // the first page bind completes.
Sunny Goyal6001ea22018-05-10 16:31:00 -0700396 mDragLayer.getAlphaProperty(ALPHA_INDEX_LAUNCHER_LOAD).setValue(0);
Sunny Goyald3864fa2017-11-14 15:06:36 -0800397 }
Sunny Goyal2100c782016-08-22 16:00:03 -0700398 } else {
Sunny Goyalfe770c92016-09-27 14:38:58 -0700399 // Pages bound synchronously.
400 mWorkspace.setCurrentPage(currentScreen);
401
Sunny Goyal2100c782016-08-22 16:00:03 -0700402 setWorkspaceLoading(true);
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
Sunny Goyal605bcf32018-03-02 15:16:12 -0800523 public void rebindModel() {
524 int currentPage = mWorkspace.getNextPage();
525 if (mModel.startLoader(currentPage)) {
526 mWorkspace.setCurrentPage(currentPage);
527 setWorkspaceLoading(true);
528 }
529 }
530
Hyunyoung Song31971a32019-01-27 12:31:12 -0800531 @Override
532 public void onIdpChanged(int changeFlags, InvariantDeviceProfile idp) {
Sunny Goyal371ea052019-03-06 15:38:32 -0800533 onIdpChanged(idp);
534 }
535
536 private void onIdpChanged(InvariantDeviceProfile idp) {
537 mUserEventDispatcher = null;
538
Sunny Goyalc8502c12019-06-10 12:14:47 -0700539 DeviceProfile oldWallpaperProfile = getWallpaperDeviceProfile();
Hyunyoung Song31971a32019-01-27 12:31:12 -0800540 initDeviceProfile(idp);
Sunny Goyal371ea052019-03-06 15:38:32 -0800541 dispatchDeviceProfileChanged();
542 reapplyUi();
543 mDragLayer.recreateControllers();
544
Sunny Goyal76ba0a32019-06-10 11:56:11 -0700545 // Calling onSaveInstanceState ensures that static cache used by listWidgets is
546 // initialized properly.
547 onSaveInstanceState(new Bundle());
Sunny Goyalc8502c12019-06-10 12:14:47 -0700548 if (oldWallpaperProfile != getWallpaperDeviceProfile()) {
549 rebindModel();
550 }
Hyunyoung Song31971a32019-01-27 12:31:12 -0800551 }
552
Govinda Wassermanc06e1512019-04-09 09:56:53 -0400553 public void onAssistantVisibilityChanged(float visibility) {
554 mCurrentAssistantVisibility = visibility;
555 float alpha = 1f - visibility;
556 LauncherState state = mStateManager.getState();
557 if (state == NORMAL) {
558 mAppsView.getAlphaProperty(APPS_VIEW_ALPHA_CHANNEL_INDEX).setValue(alpha);
559 } else if (state == OVERVIEW || state == OVERVIEW_PEEK) {
560 mAppsView.getAlphaProperty(APPS_VIEW_ALPHA_CHANNEL_INDEX).setValue(alpha);
561 mScrimView.getAlphaProperty(SCRIM_VIEW_ALPHA_CHANNEL_INDEX).setValue(alpha);
562 }
563 }
564
Sunny Goyalf8d56fc2018-01-31 15:18:11 -0800565 private void initDeviceProfile(InvariantDeviceProfile idp) {
566 // Load configuration-specific DeviceProfile
Sunny Goyal59d086c2018-05-07 17:31:40 -0700567 mDeviceProfile = idp.getDeviceProfile(this);
Sunny Goyal8c48d8b2019-01-25 15:10:18 -0800568 if (isInMultiWindowMode()) {
Winson Chung13c1c2c2019-09-06 11:46:19 -0700569 // Note: Calls to getSize() can't rely on our cached DefaultDisplay since it can return
570 // the app window size
Sunny Goyal59d086c2018-05-07 17:31:40 -0700571 Display display = getWindowManager().getDefaultDisplay();
572 Point mwSize = new Point();
573 display.getSize(mwSize);
574 mDeviceProfile = mDeviceProfile.getMultiWindowProfile(this, mwSize);
575 }
Sunny Goyalae6e3182019-04-30 12:04:37 -0700576
Sunny Goyalda14cf82019-05-30 10:31:09 -0700577 if (supportsFakeLandscapeUI() && mDeviceProfile.isVerticalBarLayout()) {
Sunny Goyalae6e3182019-04-30 12:04:37 -0700578 mStableDeviceProfile = mDeviceProfile.inv.portraitProfile;
Sunny Goyal210e1742019-10-17 12:05:38 -0700579 mRotationMode = getFakeRotationMode(mDeviceProfile);
Sunny Goyalae6e3182019-04-30 12:04:37 -0700580 } else {
581 mStableDeviceProfile = null;
582 mRotationMode = RotationMode.NORMAL;
583 }
584
Sunny Goyalda14cf82019-05-30 10:31:09 -0700585 mRotationHelper.updateRotationAnimation();
Sunny Goyal59d086c2018-05-07 17:31:40 -0700586 onDeviceProfileInitiated();
Sunny Goyalae6e3182019-04-30 12:04:37 -0700587 mModelWriter = mModel.getWriter(getWallpaperDeviceProfile().isVerticalBarLayout(), true);
588 }
589
590 public void updateInsets(Rect insets) {
591 mDeviceProfile.updateInsets(insets);
592 if (mStableDeviceProfile != null) {
Sunny Goyal7a39b1b2019-05-02 13:39:16 -0700593 Rect r = mStableDeviceProfile.getInsets();
594 mRotationMode.mapInsets(this, insets, r);
595 mStableDeviceProfile.updateInsets(r);
Sunny Goyalae6e3182019-04-30 12:04:37 -0700596 }
597 }
598
599 @Override
600 public RotationMode getRotationMode() {
601 return mRotationMode;
602 }
603
604 /**
605 * Device profile to be used by UI elements which are shown directly on top of the wallpaper
606 * and whose presentation is tied to the wallpaper (and physical device) and not the activity
607 * configuration.
608 */
609 @Override
610 public DeviceProfile getWallpaperDeviceProfile() {
611 return mStableDeviceProfile == null ? mDeviceProfile : mStableDeviceProfile;
Sunny Goyalf8d56fc2018-01-31 15:18:11 -0800612 }
613
Sunny Goyal623eddd2018-03-02 12:24:41 -0800614 public RotationHelper getRotationHelper() {
615 return mRotationHelper;
616 }
617
Sunny Goyal3e3f44c2017-10-23 17:14:52 -0700618 public LauncherStateManager getStateManager() {
619 return mStateManager;
Sunny Goyalbe93f262017-10-20 17:05:27 -0700620 }
621
Hyunyoung Song4c746202019-10-10 23:11:12 -0700622 public FolderNameProvider getFolderNameProvider() {
623 return new FolderNameProvider();
624 }
625
Mario Bertschler27288382017-05-24 15:35:09 -0700626 @Override
Sunny Goyalc7b8df82017-06-27 11:11:03 -0700627 public <T extends View> T findViewById(int id) {
Sunny Goyal0bbd5542016-11-11 10:41:26 -0800628 return mLauncherView.findViewById(id);
629 }
630
Adam Cohen9211d422014-10-07 18:14:53 -0700631 private LauncherCallbacks mLauncherCallbacks;
632
Sunny Goyal32554d12015-12-03 15:31:25 -0800633 /**
634 * Call this after onCreate to set or clear overlay.
635 */
Sunny Goyalb1d7de22019-09-06 10:36:54 -0700636 @Override
Sunny Goyal32554d12015-12-03 15:31:25 -0800637 public void setLauncherOverlay(LauncherOverlay overlay) {
638 if (overlay != null) {
639 overlay.setOverlayCallbacks(new LauncherOverlayCallbacksImpl());
640 }
641 mWorkspace.setLauncherOverlay(overlay);
642 }
643
Sunny Goyalb1d7de22019-09-06 10:36:54 -0700644 @Override
645 public void runOnOverlayHidden(Runnable runnable) {
646 getWorkspace().runOnOverlayHidden(runnable);
647 }
648
Adam Cohen9211d422014-10-07 18:14:53 -0700649 public boolean setLauncherCallbacks(LauncherCallbacks callbacks) {
650 mLauncherCallbacks = callbacks;
651 return true;
Adam Cohenf9426d52012-06-04 17:26:21 -0700652 }
653
Hyunyoung Song3f471442015-04-08 19:01:34 -0700654 public boolean isDraggingEnabled() {
Winson Chung36a62fe2012-05-06 18:04:42 -0700655 // We prevent dragging when we are loading the workspace as it is possible to pick up a view
656 // that is subsequently removed from the workspace in startBinding().
Sunny Goyal639e9062015-08-19 19:17:06 -0700657 return !isWorkspaceLoading();
Winson Chung36a62fe2012-05-06 18:04:42 -0700658 }
659
Tony Wickham010d2552017-01-20 08:15:28 -0800660 public PopupDataProvider getPopupDataProvider() {
661 return mPopupDataProvider;
662 }
663
Sunny Goyal0b0847b2018-03-14 12:30:11 -0700664 @Override
Tony Wickhamf34bee82018-12-03 18:11:39 -0800665 public DotInfo getDotInfoForItem(ItemInfo info) {
666 return mPopupDataProvider.getDotInfoForItem(info);
Sunny Goyal0b0847b2018-03-14 12:30:11 -0700667 }
668
669 @Override
670 public void invalidateParent(ItemInfo info) {
Jon Mirandae6f3fa42019-03-04 09:14:40 -0800671 if (info.container >= 0) {
Sunny Goyal0b0847b2018-03-14 12:30:11 -0700672 View folderIcon = getWorkspace().getHomescreenIconByItemId(info.container);
Jon Mirandae6f3fa42019-03-04 09:14:40 -0800673 if (folderIcon instanceof FolderIcon && folderIcon.getTag() instanceof FolderInfo) {
Sunny Goyal11a50742019-08-07 09:24:26 -0700674 if (new FolderGridOrganizer(getDeviceProfile().inv)
675 .setFolderInfo((FolderInfo) folderIcon.getTag())
676 .isItemInPreview(info.rank)) {
Jon Mirandae6f3fa42019-03-04 09:14:40 -0800677 folderIcon.invalidate();
678 }
Sunny Goyal0b0847b2018-03-14 12:30:11 -0700679 }
680 }
681 }
682
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000683 /**
Winson Chung557d6ed2011-07-08 15:34:52 -0700684 * Returns whether we should delay spring loaded mode -- for shortcuts and widgets that have
685 * a configuration step, this allows the proper animations to run after other transitions.
686 */
Sunny Goyalefb7e842018-10-04 15:11:00 -0700687 private int completeAdd(
Sunny Goyal2100c782016-08-22 16:00:03 -0700688 int requestCode, Intent intent, int appWidgetId, PendingRequestArgs info) {
Sunny Goyalefb7e842018-10-04 15:11:00 -0700689 int screenId = info.screenId;
Sunny Goyal2100c782016-08-22 16:00:03 -0700690 if (info.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
Adam Cohen83079e42014-09-19 17:43:08 -0700691 // When the screen id represents an actual screen (as opposed to a rank) we make sure
692 // that the drop page actually exists.
Sunny Goyal2100c782016-08-22 16:00:03 -0700693 screenId = ensurePendingDropLayoutExists(info.screenId);
Adam Cohen83079e42014-09-19 17:43:08 -0700694 }
Adam Cohendb364c32014-05-20 14:23:40 -0700695
Sunny Goyal2100c782016-08-22 16:00:03 -0700696 switch (requestCode) {
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800697 case REQUEST_CREATE_SHORTCUT:
Sunny Goyalfb5096d2016-09-08 14:32:06 -0700698 completeAddShortcut(intent, info.container, screenId, info.cellX, info.cellY, info);
Winson Chungb8472bb2011-08-05 13:49:21 -0700699 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800700 case REQUEST_CREATE_APPWIDGET:
Sunny Goyal2100c782016-08-22 16:00:03 -0700701 completeAddAppWidget(appWidgetId, info, null, null);
Winson Chungb8472bb2011-08-05 13:49:21 -0700702 break;
Sunny Goyalff572272014-07-23 13:58:07 -0700703 case REQUEST_RECONFIGURE_APPWIDGET:
Sunny Goyal2100c782016-08-22 16:00:03 -0700704 completeRestoreAppWidget(appWidgetId, LauncherAppWidgetInfo.RESTORE_COMPLETED);
Sunny Goyalff572272014-07-23 13:58:07 -0700705 break;
Sunny Goyald478c832016-04-01 12:04:16 -0700706 case REQUEST_BIND_PENDING_APPWIDGET: {
Sunny Goyal2100c782016-08-22 16:00:03 -0700707 int widgetId = appWidgetId;
708 LauncherAppWidgetInfo widgetInfo =
Sunny Goyald478c832016-04-01 12:04:16 -0700709 completeRestoreAppWidget(widgetId, LauncherAppWidgetInfo.FLAG_UI_NOT_READY);
Sunny Goyal2100c782016-08-22 16:00:03 -0700710 if (widgetInfo != null) {
Sunny Goyald478c832016-04-01 12:04:16 -0700711 // Since the view was just bound, also launch the configure activity if needed
712 LauncherAppWidgetProviderInfo provider = mAppWidgetManager
713 .getLauncherAppWidgetInfo(widgetId);
Sunny Goyal04a324a2017-01-20 21:08:59 -0800714 if (provider != null) {
715 new WidgetAddFlowHandler(provider)
Samuel Fufaca37b8a2019-08-19 17:04:36 -0700716 .startConfigActivity(this, widgetInfo,
717 REQUEST_RECONFIGURE_APPWIDGET);
Sunny Goyald478c832016-04-01 12:04:16 -0700718 }
719 }
720 break;
721 }
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800722 }
Sunny Goyal2100c782016-08-22 16:00:03 -0700723
Adam Cohendb364c32014-05-20 14:23:40 -0700724 return screenId;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800725 }
726
Adam Cohenc7cd2cb2014-11-17 17:45:34 -0800727 private void handleActivityResult(
Michael Jurka8b805b12012-04-18 14:23:14 -0700728 final int requestCode, final int resultCode, final Intent data) {
Sunny Goyal2100c782016-08-22 16:00:03 -0700729 if (isWorkspaceLoading()) {
730 // process the result once the workspace has loaded.
731 mPendingActivityResult = new ActivityResultInfo(requestCode, resultCode, data);
732 return;
733 }
734 mPendingActivityResult = null;
735
Winson Chunge341d302013-08-16 14:31:00 -0700736 // Reset the startActivity waiting flag
Sunny Goyal2100c782016-08-22 16:00:03 -0700737 final PendingRequestArgs requestArgs = mPendingRequestArgs;
738 setWaitingForResult(null);
739 if (requestArgs == null) {
740 return;
741 }
742
743 final int pendingAddWidgetId = requestArgs.getWidgetId();
Winson Chunge341d302013-08-16 14:31:00 -0700744
Adam Cohenad4e15c2013-10-17 16:21:35 -0700745 Runnable exitSpringLoaded = new Runnable() {
746 @Override
747 public void run() {
Sunny Goyal3e3f44c2017-10-23 17:14:52 -0700748 mStateManager.goToState(NORMAL, SPRING_LOADED_EXIT_DELAY);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700749 }
750 };
751
Michael Jurka8b805b12012-04-18 14:23:14 -0700752 if (requestCode == REQUEST_BIND_APPWIDGET) {
Winsona1f79d32015-08-05 14:00:45 -0700753 // This is called only if the user did not previously have permissions to bind widgets
Adam Cohenad4e15c2013-10-17 16:21:35 -0700754 final int appWidgetId = data != null ?
Michael Jurka8b805b12012-04-18 14:23:14 -0700755 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
756 if (resultCode == RESULT_CANCELED) {
Sunny Goyal2100c782016-08-22 16:00:03 -0700757 completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId, requestArgs);
Adam Cohen689ff162014-05-08 17:27:56 -0700758 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
Adam Cohenad4e15c2013-10-17 16:21:35 -0700759 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
Michael Jurka8b805b12012-04-18 14:23:14 -0700760 } else if (resultCode == RESULT_OK) {
Sunny Goyal2100c782016-08-22 16:00:03 -0700761 addAppWidgetImpl(
762 appWidgetId, requestArgs, null,
Sunny Goyal04a324a2017-01-20 21:08:59 -0800763 requestArgs.getWidgetHandler(),
Sunny Goyal2100c782016-08-22 16:00:03 -0700764 ON_ACTIVITY_RESULT_ANIMATION_DELAY);
Michael Jurka8b805b12012-04-18 14:23:14 -0700765 }
766 return;
767 }
Michael Jurka336fd4f2013-09-12 00:05:02 +0200768
Adam Cohened66b2b2012-01-23 17:28:51 -0800769 boolean isWidgetDrop = (requestCode == REQUEST_PICK_APPWIDGET ||
Sunny Goyal5c97f512015-05-19 16:03:28 -0700770 requestCode == REQUEST_CREATE_APPWIDGET);
Romain Guyaad5ef42009-06-10 02:48:37 -0700771
Adam Cohened66b2b2012-01-23 17:28:51 -0800772 // We have special handling for widgets
773 if (isWidgetDrop) {
Adam Cohen4637b5a2013-11-04 18:21:24 -0800774 final int appWidgetId;
775 int widgetId = data != null ? data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1)
776 : -1;
777 if (widgetId < 0) {
778 appWidgetId = pendingAddWidgetId;
779 } else {
780 appWidgetId = widgetId;
781 }
782
Adam Cohenad4e15c2013-10-17 16:21:35 -0700783 final int result;
Adam Cohenf0129b12013-11-04 17:57:36 -0800784 if (appWidgetId < 0 || resultCode == RESULT_CANCELED) {
Adam Cohendb364c32014-05-20 14:23:40 -0700785 Log.e(TAG, "Error: appWidgetId (EXTRA_APPWIDGET_ID) was not " +
786 "returned from the widget configuration activity.");
Adam Cohenad4e15c2013-10-17 16:21:35 -0700787 result = RESULT_CANCELED;
Sunny Goyal2100c782016-08-22 16:00:03 -0700788 completeTwoStageWidgetDrop(result, appWidgetId, requestArgs);
Adam Cohendb364c32014-05-20 14:23:40 -0700789 final Runnable onComplete = new Runnable() {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700790 @Override
791 public void run() {
Sunny Goyal3e3f44c2017-10-23 17:14:52 -0700792 getStateManager().goToState(NORMAL);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700793 }
794 };
Adam Cohendb364c32014-05-20 14:23:40 -0700795
Sunny Goyal2100c782016-08-22 16:00:03 -0700796 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete,
797 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
798 } else {
799 if (requestArgs.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
800 // When the screen id represents an actual screen (as opposed to a rank)
801 // we make sure that the drop page actually exists.
802 requestArgs.screenId =
803 ensurePendingDropLayoutExists(requestArgs.screenId);
Adam Cohendb364c32014-05-20 14:23:40 -0700804 }
Sunny Goyal2100c782016-08-22 16:00:03 -0700805 final CellLayout dropLayout =
806 mWorkspace.getScreenWithId(requestArgs.screenId);
807
808 dropLayout.setDropPending(true);
809 final Runnable onComplete = new Runnable() {
810 @Override
811 public void run() {
812 completeTwoStageWidgetDrop(resultCode, appWidgetId, requestArgs);
813 dropLayout.setDropPending(false);
814 }
815 };
816 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete,
817 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
Winson Chung5aaab772012-04-27 15:24:02 -0700818 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800819 return;
820 }
821
Sunny Goyald478c832016-04-01 12:04:16 -0700822 if (requestCode == REQUEST_RECONFIGURE_APPWIDGET
823 || requestCode == REQUEST_BIND_PENDING_APPWIDGET) {
Sunny Goyalff572272014-07-23 13:58:07 -0700824 if (resultCode == RESULT_OK) {
825 // Update the widget view.
Sunny Goyal2100c782016-08-22 16:00:03 -0700826 completeAdd(requestCode, data, pendingAddWidgetId, requestArgs);
Sunny Goyalff572272014-07-23 13:58:07 -0700827 }
828 // Leave the widget in the pending state if the user canceled the configure.
829 return;
830 }
831
Sunny Goyalaad90582015-07-09 14:22:50 -0700832 if (requestCode == REQUEST_CREATE_SHORTCUT) {
833 // Handle custom shortcuts created using ACTION_CREATE_SHORTCUT.
Sunny Goyal2100c782016-08-22 16:00:03 -0700834 if (resultCode == RESULT_OK && requestArgs.container != ItemInfo.NO_ID) {
835 completeAdd(requestCode, data, -1, requestArgs);
836 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
837 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
838
Sunny Goyalaad90582015-07-09 14:22:50 -0700839 } else if (resultCode == RESULT_CANCELED) {
Adam Cohendb364c32014-05-20 14:23:40 -0700840 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
841 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800842 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800843 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800844 mDragLayer.clearAnimatedView();
Adam Cohenc7cd2cb2014-11-17 17:45:34 -0800845 }
846
847 @Override
Sunny Goyal64a75aa2017-07-03 13:50:52 -0700848 public void onActivityResult(
Adam Cohenc7cd2cb2014-11-17 17:45:34 -0800849 final int requestCode, final int resultCode, final Intent data) {
Sunny Goyaldedda052019-05-14 15:23:48 -0700850 mPendingActivityRequestCode = -1;
Adam Cohenc7cd2cb2014-11-17 17:45:34 -0800851 handleActivityResult(requestCode, resultCode, data);
Adam Cohened66b2b2012-01-23 17:28:51 -0800852 }
853
Sunny Goyal7ce471b2017-08-02 03:37:39 -0700854 @Override
Sunny Goyaldd2e6df2015-07-07 10:57:57 -0700855 public void onRequestPermissionsResult(int requestCode, String[] permissions,
Dave Hawkey3a43ed62015-06-26 10:27:47 -0600856 int[] grantResults) {
Sunny Goyal2100c782016-08-22 16:00:03 -0700857 PendingRequestArgs pendingArgs = mPendingRequestArgs;
858 if (requestCode == REQUEST_PERMISSION_CALL_PHONE && pendingArgs != null
859 && pendingArgs.getRequestCode() == REQUEST_PERMISSION_CALL_PHONE) {
860 setWaitingForResult(null);
861
Sunny Goyal28c6b962015-10-12 11:42:05 -0700862 View v = null;
Sunny Goyal2100c782016-08-22 16:00:03 -0700863 CellLayout layout = getCellLayout(pendingArgs.container, pendingArgs.screenId);
Sunny Goyal28c6b962015-10-12 11:42:05 -0700864 if (layout != null) {
Sunny Goyal2100c782016-08-22 16:00:03 -0700865 v = layout.getChildAt(pendingArgs.cellX, pendingArgs.cellY);
Sunny Goyal28c6b962015-10-12 11:42:05 -0700866 }
Sunny Goyal2100c782016-08-22 16:00:03 -0700867 Intent intent = pendingArgs.getPendingIntent();
868
Sunny Goyal28c6b962015-10-12 11:42:05 -0700869 if (grantResults.length > 0
870 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
Sunny Goyal369212a2019-03-26 15:03:57 -0700871 startActivitySafely(v, intent, null, null);
Sunny Goyal28c6b962015-10-12 11:42:05 -0700872 } else {
873 // TODO: Show a snack bar with link to settings
874 Toast.makeText(this, getString(R.string.msg_no_phone_permission,
Sunny Goyal112ce422016-08-22 16:45:29 -0700875 getString(R.string.derived_app_name)), Toast.LENGTH_SHORT).show();
Sunny Goyal28c6b962015-10-12 11:42:05 -0700876 }
877 }
Dave Hawkey3a43ed62015-06-26 10:27:47 -0600878 }
879
Adam Cohendb364c32014-05-20 14:23:40 -0700880 /**
881 * Check to see if a given screen id exists. If not, create it at the end, return the new id.
882 *
883 * @param screenId the screen id to check
884 * @return the new screen, or screenId if it exists
885 */
Sunny Goyalefb7e842018-10-04 15:11:00 -0700886 private int ensurePendingDropLayoutExists(int screenId) {
Sunny Goyal32554d12015-12-03 15:31:25 -0800887 CellLayout dropLayout = mWorkspace.getScreenWithId(screenId);
Adam Cohendb364c32014-05-20 14:23:40 -0700888 if (dropLayout == null) {
889 // it's possible that the add screen was removed because it was
890 // empty and a re-bind occurred
891 mWorkspace.addExtraEmptyScreen();
892 return mWorkspace.commitExtraEmptyScreen();
893 } else {
894 return screenId;
895 }
896 }
897
Samuel Fufaca37b8a2019-08-19 17:04:36 -0700898 @Thunk
899 void completeTwoStageWidgetDrop(
Sunny Goyal2100c782016-08-22 16:00:03 -0700900 final int resultCode, final int appWidgetId, final PendingRequestArgs requestArgs) {
901 CellLayout cellLayout = mWorkspace.getScreenWithId(requestArgs.screenId);
Adam Cohened66b2b2012-01-23 17:28:51 -0800902 Runnable onCompleteRunnable = null;
903 int animationType = 0;
904
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700905 AppWidgetHostView boundWidget = null;
Adam Cohened66b2b2012-01-23 17:28:51 -0800906 if (resultCode == RESULT_OK) {
907 animationType = Workspace.COMPLETE_TWO_STAGE_WIDGET_DROP_ANIMATION;
908 final AppWidgetHostView layout = mAppWidgetHost.createView(this, appWidgetId,
Sunny Goyal04a324a2017-01-20 21:08:59 -0800909 requestArgs.getWidgetHandler().getProviderInfo(this));
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700910 boundWidget = layout;
Adam Cohened66b2b2012-01-23 17:28:51 -0800911 onCompleteRunnable = new Runnable() {
912 @Override
913 public void run() {
Sunny Goyal2100c782016-08-22 16:00:03 -0700914 completeAddAppWidget(appWidgetId, requestArgs, layout, null);
Sunny Goyal3e3f44c2017-10-23 17:14:52 -0700915 mStateManager.goToState(NORMAL, SPRING_LOADED_EXIT_DELAY);
Adam Cohened66b2b2012-01-23 17:28:51 -0800916 }
917 };
918 } else if (resultCode == RESULT_CANCELED) {
Adam Cohen4637b5a2013-11-04 18:21:24 -0800919 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
Adam Cohened66b2b2012-01-23 17:28:51 -0800920 animationType = Workspace.CANCEL_TWO_STAGE_WIDGET_DROP_ANIMATION;
Adam Cohened66b2b2012-01-23 17:28:51 -0800921 }
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700922 if (mDragLayer.getAnimatedView() != null) {
Sunny Goyal2100c782016-08-22 16:00:03 -0700923 mWorkspace.animateWidgetDrop(requestArgs, cellLayout,
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700924 (DragView) mDragLayer.getAnimatedView(), onCompleteRunnable,
925 animationType, boundWidget, true);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700926 } else if (onCompleteRunnable != null) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700927 // The animated view may be null in the case of a rotation during widget configuration
928 onCompleteRunnable.run();
929 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800930 }
931
932 @Override
Michael Jurkacd496d72013-04-11 11:32:45 -0700933 protected void onStop() {
934 super.onStop();
Winson Chung0b70cd42019-06-17 22:34:33 -0700935
Sunny Goyalb1d7de22019-09-06 10:36:54 -0700936 if (mDeferOverlayCallbacks) {
937 checkIfOverlayStillDeferred();
938 } else {
939 mOverlayManager.onActivityStopped(this);
Adam Cohen9211d422014-10-07 18:14:53 -0700940 }
Sunny Goyalb1d7de22019-09-06 10:36:54 -0700941
Becky Qiubfc2da12019-08-01 11:09:38 -0700942 logStopAndResume(Action.Command.STOP);
Hyunyoung Songbd6fba92018-05-16 15:54:31 -0700943
944 mAppWidgetHost.setListenIfResumed(false);
945
Tony Wickham010d2552017-01-20 08:15:28 -0800946 NotificationListener.removeNotificationsChangedListener();
Sunny Goyalaf161fd2018-02-05 16:34:57 -0800947 getStateManager().moveToRestState();
Winson Chungedb0d6b2018-03-21 17:32:55 -0700948
Winson Chungdea51352018-04-24 13:02:10 -0700949 // Workaround for b/78520668, explicitly trim memory once UI is hidden
Winson Chung473730f2018-04-26 11:54:22 -0700950 onTrimMemory(TRIM_MEMORY_UI_HIDDEN);
Michael Jurkacd496d72013-04-11 11:32:45 -0700951 }
952
953 @Override
954 protected void onStart() {
Winson Chung5cc62c72019-10-16 11:32:41 -0700955 Object traceToken = TraceHelper.INSTANCE.beginSection(ON_START_EVT,
956 TraceHelper.FLAG_UI_EVENT);
Michael Jurkacd496d72013-04-11 11:32:45 -0700957 super.onStart();
Sunny Goyalb1d7de22019-09-06 10:36:54 -0700958 if (!mDeferOverlayCallbacks) {
959 mOverlayManager.onActivityStarted(this);
Adam Cohen9211d422014-10-07 18:14:53 -0700960 }
Sunny Goyalb1d7de22019-09-06 10:36:54 -0700961
Sunny Goyal67419a12017-11-14 16:55:22 -0800962 mAppWidgetHost.setListenIfResumed(true);
Winson Chung5cc62c72019-10-16 11:32:41 -0700963 TraceHelper.INSTANCE.endSection(traceToken);
Michael Jurkacd496d72013-04-11 11:32:45 -0700964 }
965
Sunny Goyala002c6c2019-02-12 16:20:10 -0800966 private void handleDeferredResume() {
Sunny Goyale9c6f4c2019-05-30 11:35:25 -0700967 if (hasBeenResumed() && !mStateManager.getState().disableInteraction) {
Becky Qiubfc2da12019-08-01 11:09:38 -0700968 logStopAndResume(Action.Command.RESUME);
Hyunyoung Songbd6fba92018-05-16 15:54:31 -0700969 getUserEventDispatcher().startSession();
Sunny Goyala002c6c2019-02-12 16:20:10 -0800970
Sunny Goyal369212a2019-03-26 15:03:57 -0700971 AppLaunchTracker.INSTANCE.get(this).onReturnedToHome();
Hyunyoung Songbd6fba92018-05-16 15:54:31 -0700972
Sunny Goyale9c6f4c2019-05-30 11:35:25 -0700973 // Process any items that were added while Launcher was away.
974 InstallShortcutReceiver.disableAndFlushInstallQueue(
975 InstallShortcutReceiver.FLAG_ACTIVITY_PAUSED, this);
976
977 // Refresh shortcuts if the permission changed.
978 mModel.refreshShortcutsIfRequired();
979
Winson Chung87583112019-06-10 14:20:58 -0700980 // Set the notification listener and fetch updated notifications when we resume
981 NotificationListener.setNotificationsChangedListener(mPopupDataProvider);
982
Sunny Goyale9c6f4c2019-05-30 11:35:25 -0700983 DiscoveryBounce.showForHomeIfNeeded(this);
984
Sunny Goyal210e1742019-10-17 12:05:38 -0700985 onDeferredResumed();
986 addActivityFlags(ACTIVITY_STATE_DEFERRED_RESUMED);
987
Sunny Goyale9c6f4c2019-05-30 11:35:25 -0700988 mDeferredResumePending = false;
989 } else {
990 mDeferredResumePending = true;
Sunny Goyaldedda052019-05-14 15:23:48 -0700991 }
992 }
993
Sunny Goyal210e1742019-10-17 12:05:38 -0700994 protected void onDeferredResumed() { }
995
Becky Qiubfc2da12019-08-01 11:09:38 -0700996 private void logStopAndResume(int command) {
997 int containerType = mStateManager.getState().containerType;
998 if (containerType == ContainerType.WORKSPACE && mWorkspace != null) {
999 getUserEventDispatcher().logActionCommand(command,
Samuel Fufaca37b8a2019-08-19 17:04:36 -07001000 containerType, -1, mWorkspace.isOverlayShown() ? -1 : 0);
Becky Qiubfc2da12019-08-01 11:09:38 -07001001 } else {
1002 getUserEventDispatcher().logActionCommand(command, containerType, -1);
1003 }
Sunny Goyalb1d7de22019-09-06 10:36:54 -07001004 }
Becky Qiubfc2da12019-08-01 11:09:38 -07001005
Sunny Goyalb1d7de22019-09-06 10:36:54 -07001006 private void scheduleDeferredCheck() {
1007 mHandler.removeCallbacks(mDeferredOverlayCallbacks);
1008 postAsyncCallback(mHandler, mDeferredOverlayCallbacks);
1009 }
1010
1011 private void checkIfOverlayStillDeferred() {
1012 if (!mDeferOverlayCallbacks) {
1013 return;
1014 }
1015 if (isStarted() && (!hasBeenResumed() || mStateManager.getState().disableInteraction)) {
1016 return;
1017 }
1018 mDeferOverlayCallbacks = false;
1019
1020 // Move the client to the correct state. Calling the same method twice is no-op.
1021 if (isStarted()) {
1022 mOverlayManager.onActivityStarted(this);
1023 }
1024 if (hasBeenResumed()) {
1025 mOverlayManager.onActivityResumed(this);
1026 } else {
1027 mOverlayManager.onActivityPaused(this);
1028 }
1029 if (!isStarted()) {
1030 mOverlayManager.onActivityStopped(this);
1031 }
1032 }
1033
1034 public void deferOverlayCallbacksUntilNextResumeOrStop() {
1035 mDeferOverlayCallbacks = true;
1036 }
1037
1038 public LauncherOverlayManager getOverlayManager() {
1039 return mOverlayManager;
Becky Qiubfc2da12019-08-01 11:09:38 -07001040 }
1041
Winson Chungef528762019-09-06 12:05:52 -07001042 public void onStateSetStart(LauncherState state) {
Sunny Goyale9c6f4c2019-05-30 11:35:25 -07001043 if (mDeferredResumePending) {
1044 handleDeferredResume();
1045 }
Sunny Goyalb1d7de22019-09-06 10:36:54 -07001046 if (mDeferOverlayCallbacks) {
1047 scheduleDeferredCheck();
Sunny Goyale9c6f4c2019-05-30 11:35:25 -07001048 }
Sunny Goyal210e1742019-10-17 12:05:38 -07001049 addActivityFlags(ACTIVITY_STATE_TRANSITION_ACTIVE);
Sunny Goyaldedda052019-05-14 15:23:48 -07001050 }
1051
Winson Chungef528762019-09-06 12:05:52 -07001052 public void onStateSetEnd(LauncherState state) {
1053 getAppWidgetHost().setResumed(state == LauncherState.NORMAL);
1054 getWorkspace().setClipChildren(!state.disablePageClipping);
1055 finishAutoCancelActionMode();
Sunny Goyal210e1742019-10-17 12:05:38 -07001056 removeActivityFlags(ACTIVITY_STATE_TRANSITION_ACTIVE);
Winson Chungef528762019-09-06 12:05:52 -07001057 }
1058
Michael Jurkacd496d72013-04-11 11:32:45 -07001059 @Override
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001060 protected void onResume() {
Winson Chung5cc62c72019-10-16 11:32:41 -07001061 Object traceToken = TraceHelper.INSTANCE.beginSection(ON_RESUME_EVT,
1062 TraceHelper.FLAG_UI_EVENT);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001063 super.onResume();
Sunny Goyalfca6bc92017-09-28 16:28:34 -07001064
Sunny Goyala002c6c2019-02-12 16:20:10 -08001065 mHandler.removeCallbacks(mHandleDeferredResume);
1066 Utilities.postAsyncCallback(mHandler, mHandleDeferredResume);
Hyunyoung Songbd6fba92018-05-16 15:54:31 -07001067
Winson Chung940b0ac2019-07-09 11:33:50 -07001068 if (!mOnResumeCallbacks.isEmpty()) {
1069 final ArrayList<OnResumeCallback> resumeCallbacks = new ArrayList<>(mOnResumeCallbacks);
1070 mOnResumeCallbacks.clear();
1071 for (int i = resumeCallbacks.size() - 1; i >= 0; i--) {
1072 resumeCallbacks.get(i).onLauncherResume();
1073 }
1074 resumeCallbacks.clear();
Winson Chung0b70cd42019-06-17 22:34:33 -07001075 }
Sunny Goyal95f3d6b2016-08-10 16:09:29 -07001076
Sunny Goyalb1d7de22019-09-06 10:36:54 -07001077 if (mDeferOverlayCallbacks) {
1078 scheduleDeferredCheck();
1079 } else {
1080 mOverlayManager.onActivityResumed(this);
Adam Cohen9211d422014-10-07 18:14:53 -07001081 }
Mario Bertschler0fc6f682017-02-17 12:16:13 -08001082
Winson Chung5cc62c72019-10-16 11:32:41 -07001083 TraceHelper.INSTANCE.endSection(traceToken);
Adam Cohen06dff352012-06-01 17:17:08 -07001084 }
1085
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001086 @Override
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001087 protected void onPause() {
Winson Chung997a9232013-07-24 15:33:46 -07001088 // Ensure that items added to Launcher are queued until Launcher returns
Sunny Goyala474a9b2017-05-04 16:47:11 -07001089 InstallShortcutReceiver.enableInstallQueue(InstallShortcutReceiver.FLAG_ACTIVITY_PAUSED);
Winson Chung997a9232013-07-24 15:33:46 -07001090
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001091 super.onPause();
Joe Onorato24b6fd82009-11-12 13:47:09 -08001092 mDragController.cancelDrag();
Winson Chunga2413752012-04-03 14:22:34 -07001093 mDragController.resetLastGestureUpTime();
Hyunyoung Song497708c2019-05-01 16:16:53 -07001094 mDropTargetBar.animateToVisibility(false);
Sunny Goyalb1d7de22019-09-06 10:36:54 -07001095
1096 if (!mDeferOverlayCallbacks) {
1097 mOverlayManager.onActivityPaused(this);
Adam Cohenbffe7452013-07-22 18:21:45 -07001098 }
Adam Cohenbffe7452013-07-22 18:21:45 -07001099 }
1100
Adam Cohenc2d6e892014-10-16 09:49:24 -07001101 class LauncherOverlayCallbacksImpl implements LauncherOverlayCallbacks {
1102
Sunny Goyalc86df472016-02-25 09:19:38 -08001103 public void onScrollChanged(float progress) {
1104 if (mWorkspace != null) {
1105 mWorkspace.onOverlayScrollChanged(progress);
1106 }
1107 }
Adam Cohenc2d6e892014-10-16 09:49:24 -07001108 }
1109
Sunny Goyalf9403d92017-10-18 10:55:56 -07001110 public boolean isInState(LauncherState state) {
Sunny Goyalea609262017-10-25 15:47:38 -07001111 return mStateManager.getState() == state;
Sunny Goyalf9403d92017-10-18 10:55:56 -07001112 }
1113
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001114 /**
1115 * Restores the previous state, if it exists.
1116 *
1117 * @param savedState The previous state.
1118 */
1119 private void restoreState(Bundle savedState) {
1120 if (savedState == null) {
1121 return;
1122 }
1123
Sunny Goyal3e3f44c2017-10-23 17:14:52 -07001124 int stateOrdinal = savedState.getInt(RUNTIME_STATE, NORMAL.ordinal);
Sunny Goyalf9403d92017-10-18 10:55:56 -07001125 LauncherState[] stateValues = LauncherState.values();
1126 LauncherState state = stateValues[stateOrdinal];
Sunny Goyalbc683e92017-12-06 10:25:07 -08001127 if (!state.disableRestore) {
Sunny Goyal3e3f44c2017-10-23 17:14:52 -07001128 mStateManager.goToState(state, false /* animated */);
Joe Onorato3a8820b2009-11-10 15:06:42 -08001129 }
1130
Samuel Fufaca37b8a2019-08-19 17:04:36 -07001131 PendingRequestArgs requestArgs = savedState.getParcelable(
1132 RUNTIME_STATE_PENDING_REQUEST_ARGS);
Sunny Goyal2100c782016-08-22 16:00:03 -07001133 if (requestArgs != null) {
1134 setWaitingForResult(requestArgs);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001135 }
Sunny Goyaldedda052019-05-14 15:23:48 -07001136 mPendingActivityRequestCode = savedState.getInt(RUNTIME_STATE_PENDING_REQUEST_CODE);
Sunny Goyal2100c782016-08-22 16:00:03 -07001137
1138 mPendingActivityResult = savedState.getParcelable(RUNTIME_STATE_PENDING_ACTIVITY_RESULT);
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -07001139
1140 SparseArray<Parcelable> widgetsState =
1141 savedState.getSparseParcelableArray(RUNTIME_STATE_WIDGET_PANEL);
1142 if (widgetsState != null) {
1143 WidgetsFullSheet.show(this, false).restoreHierarchyState(widgetsState);
1144 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001145 }
1146
1147 /**
1148 * Finds all the views we need and configure them properly.
1149 */
1150 private void setupViews() {
Sunny Goyalcc96aa12018-01-11 09:56:07 -08001151 mDragLayer = findViewById(R.id.drag_layer);
Sunny Goyal3333b0c2016-05-09 20:43:21 -07001152 mFocusHandler = mDragLayer.getFocusIndicatorHelper();
Sunny Goyal966d9012017-06-06 16:43:59 -07001153 mWorkspace = mDragLayer.findViewById(R.id.workspace);
Sunny Goyald0a6ae72016-06-16 12:29:03 -07001154 mWorkspace.initParentViews(mDragLayer);
Sunny Goyal16764582017-11-06 16:00:34 -08001155 mOverviewPanel = findViewById(R.id.overview_panel);
Sunny Goyal7c7be8c2018-03-07 19:58:07 -08001156 mHotseat = findViewById(R.id.hotseat);
Craig Mautner360310b2012-10-26 15:13:08 -07001157
Sunny Goyal784f9c32016-03-23 16:56:54 -07001158 mLauncherView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
1159 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
1160 | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001161
Winson Chung4c98d922011-05-31 16:50:48 -07001162 // Setup the drag layer
Sunny Goyal5d1873a2018-05-08 11:10:44 -07001163 mDragLayer.setup(mDragController, mWorkspace);
Winson Chung4c98d922011-05-31 16:50:48 -07001164
Hyunyoung Song645764e2016-06-06 14:19:02 -07001165 mWorkspace.setup(mDragController);
Winsonc7d2e832016-07-28 12:24:55 -07001166 // Until the workspace is bound, ensure that we keep the wallpaper offset locked to the
1167 // default state, otherwise we will update to the wrong offsets in RTL
1168 mWorkspace.lockWallpaperToDefaultPage();
Sunny Goyalda4fe1a2016-05-26 16:05:17 -07001169 mWorkspace.bindAndInitFirstWorkspaceScreen(null /* recycled qsb */);
Hyunyoung Song645764e2016-06-06 14:19:02 -07001170 mDragController.addDragListener(mWorkspace);
Winson Chung4c98d922011-05-31 16:50:48 -07001171
Tony Wickham34d2c912015-09-11 09:27:58 -07001172 // Get the search/delete/uninstall bar
Rajeev Kumar43c0f582017-06-23 15:34:55 -07001173 mDropTargetBar = mDragLayer.findViewById(R.id.drop_target_bar);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07001174
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -07001175 // Setup Apps
1176 mAppsView = findViewById(R.id.apps_view);
Craig Mautner360310b2012-10-26 15:13:08 -07001177
Govinda Wassermanc06e1512019-04-09 09:56:53 -04001178 // Setup Scrim
1179 mScrimView = findViewById(R.id.scrim_view);
1180
Winson Chung3d503fb2011-07-13 17:25:49 -07001181 // Setup the drag controller (drop targets have to be added in reverse order in priority)
Hyunyoung Song645764e2016-06-06 14:19:02 -07001182 mDragController.setMoveTarget(mWorkspace);
Sunny Goyal47328fd2016-05-25 18:56:41 -07001183 mDropTargetBar.setup(mDragController);
Daniel Sandler924b9932013-06-12 00:38:25 -04001184
Sunny Goyal7185dd62018-03-14 17:51:49 -07001185 mAllAppsController.setupViews(mAppsView);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001186 }
1187
1188 /**
1189 * Creates a view representing a shortcut.
1190 *
1191 * @param info The data structure describing the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001192 */
Sunny Goyal95899162019-03-27 16:03:06 -07001193 View createShortcut(WorkspaceItemInfo info) {
Sunny Goyaldfaccf62015-05-11 16:30:44 -07001194 return createShortcut((ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001195 }
1196
1197 /**
1198 * Creates a view representing a shortcut inflated from the specified resource.
1199 *
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001200 * @param parent The group the shortcut belongs to.
Samuel Fufaca37b8a2019-08-19 17:04:36 -07001201 * @param info The data structure describing the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001202 * @return A View inflated from layoutResId.
1203 */
Sunny Goyal95899162019-03-27 16:03:06 -07001204 public View createShortcut(ViewGroup parent, WorkspaceItemInfo info) {
Sunny Goyal9b29ca52017-02-17 10:39:44 -08001205 BubbleTextView favorite = (BubbleTextView) LayoutInflater.from(parent.getContext())
1206 .inflate(R.layout.app_icon, parent, false);
Sunny Goyal95899162019-03-27 16:03:06 -07001207 favorite.applyFromWorkspaceItem(info);
Sunny Goyal8a2a63b2018-03-06 22:15:18 -08001208 favorite.setOnClickListener(ItemClickHandler.INSTANCE);
Sunny Goyaldcbcc862014-08-12 15:58:36 -07001209 favorite.setOnFocusChangeListener(mFocusHandler);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001210 return favorite;
1211 }
1212
1213 /**
Jon Mirandac476d6e2017-05-04 16:30:01 -07001214 * Add a shortcut to the workspace or to a Folder.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001215 *
1216 * @param data The intent describing the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001217 */
Sunny Goyalefb7e842018-10-04 15:11:00 -07001218 private void completeAddShortcut(Intent data, int container, int screenId, int cellX,
Sunny Goyalfb5096d2016-09-08 14:32:06 -07001219 int cellY, PendingRequestArgs args) {
Pinyao Ting5eee5f42019-10-31 16:47:35 -07001220 if (args.getRequestCode() != REQUEST_CREATE_SHORTCUT
Jon Mirandac476d6e2017-05-04 16:30:01 -07001221 || args.getPendingIntent().getComponent() == null) {
Sunny Goyalfb5096d2016-09-08 14:32:06 -07001222 return;
1223 }
Adam Cohen558baaf2011-08-15 15:22:57 -07001224
Jon Mirandac476d6e2017-05-04 16:30:01 -07001225 int[] cellXY = mTmpAddItemCellCoordinates;
1226 CellLayout layout = getCellLayout(container, screenId);
1227
Sunny Goyal95899162019-03-27 16:03:06 -07001228 WorkspaceItemInfo info = null;
Hyunyoung Songe24cb632017-09-11 11:18:03 -07001229 if (Utilities.ATLEAST_OREO) {
Sunny Goyale7b00122019-10-02 16:13:34 -07001230 info = PinRequestHelper.createWorkspaceItemFromPinItemRequest(
1231 this, PinRequestHelper.getPinItemRequest(data), 0);
Sunny Goyal782f0c92017-01-19 10:27:54 -08001232 }
1233
1234 if (info == null) {
Sunny Goyalb57645f2017-03-20 13:57:28 -07001235 // Legacy shortcuts are only supported for primary profile.
1236 info = Process.myUserHandle().equals(args.user)
1237 ? InstallShortcutReceiver.fromShortcutIntent(this, data) : null;
Sunny Goyal782f0c92017-01-19 10:27:54 -08001238
Sunny Goyalb57645f2017-03-20 13:57:28 -07001239 if (info == null) {
1240 Log.e(TAG, "Unable to parse a valid custom shortcut result");
1241 return;
1242 } else if (!new PackageManagerHelper(this).hasPermissionForActivity(
Sunny Goyal342e4662017-02-02 15:21:08 -08001243 info.intent, args.getPendingIntent().getComponent().getPackageName())) {
Sunny Goyal782f0c92017-01-19 10:27:54 -08001244 // The app is trying to add a shortcut without sufficient permissions
1245 Log.e(TAG, "Ignoring malicious intent " + info.intent.toUri(0));
1246 return;
1247 }
1248 }
1249
Jon Mirandac476d6e2017-05-04 16:30:01 -07001250 if (container < 0) {
1251 // Adding a shortcut to the Workspace.
1252 final View view = createShortcut(info);
1253 boolean foundCellSpan = false;
1254 // First we check if we already know the exact location where we want to add this item.
1255 if (cellX >= 0 && cellY >= 0) {
1256 cellXY[0] = cellX;
1257 cellXY[1] = cellY;
1258 foundCellSpan = true;
Adam Cohen558baaf2011-08-15 15:22:57 -07001259
Jon Mirandac476d6e2017-05-04 16:30:01 -07001260 // If appropriate, either create a folder or add to an existing folder
1261 if (mWorkspace.createUserFolderIfNecessary(view, container, layout, cellXY, 0,
Sunny Goyal1797af42017-10-06 13:29:57 -07001262 true, null)) {
Jon Mirandac476d6e2017-05-04 16:30:01 -07001263 return;
1264 }
1265 DragObject dragObject = new DragObject();
1266 dragObject.dragInfo = info;
1267 if (mWorkspace.addToExistingFolderIfNecessary(view, layout, cellXY, 0, dragObject,
1268 true)) {
1269 return;
1270 }
1271 } else {
1272 foundCellSpan = layout.findCellForSpan(cellXY, 1, 1);
1273 }
1274
1275 if (!foundCellSpan) {
1276 mWorkspace.onNoCellFound(layout);
Adam Cohen558baaf2011-08-15 15:22:57 -07001277 return;
1278 }
Jon Mirandac476d6e2017-05-04 16:30:01 -07001279
1280 getModelWriter().addItemToDatabase(info, container, screenId, cellXY[0], cellXY[1]);
1281 mWorkspace.addInScreen(view, info);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001282 } else {
Jon Mirandac476d6e2017-05-04 16:30:01 -07001283 // Adding a shortcut to a Folder.
Sunny Goyale29897f2017-07-20 10:09:42 -07001284 FolderIcon folderIcon = findFolderIcon(container);
Jon Mirandac476d6e2017-05-04 16:30:01 -07001285 if (folderIcon != null) {
1286 FolderInfo folderInfo = (FolderInfo) folderIcon.getTag();
1287 folderInfo.add(info, args.rank, false);
1288 } else {
Sunny Goyale29897f2017-07-20 10:09:42 -07001289 Log.e(TAG, "Could not find folder with id " + container + " to add shortcut.");
Jon Mirandac476d6e2017-05-04 16:30:01 -07001290 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001291 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001292 }
1293
Sunny Goyalefb7e842018-10-04 15:11:00 -07001294 public FolderIcon findFolderIcon(final int folderIconId) {
Sunny Goyal83fd25e2018-07-09 16:47:01 -07001295 return (FolderIcon) mWorkspace.getHomescreenIconByItemId(folderIconId);
Sunny Goyale29897f2017-07-20 10:09:42 -07001296 }
1297
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001298 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001299 * Add a widget to the workspace.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001300 *
Romain Guy5bbc91b2010-08-18 11:38:46 -07001301 * @param appWidgetId The app widget id
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001302 */
Samuel Fufaca37b8a2019-08-19 17:04:36 -07001303 @Thunk
1304 void completeAddAppWidget(int appWidgetId, ItemInfo itemInfo,
Adam Cohen59400422014-03-05 18:07:04 -08001305 AppWidgetHostView hostView, LauncherAppWidgetProviderInfo appWidgetInfo) {
1306
Adam Cohened66b2b2012-01-23 17:28:51 -08001307 if (appWidgetInfo == null) {
Sunny Goyal2e1efb42016-03-03 16:58:55 -08001308 appWidgetInfo = mAppWidgetManager.getLauncherAppWidgetInfo(appWidgetId);
Adam Cohened66b2b2012-01-23 17:28:51 -08001309 }
Romain Guycbb89e42009-06-08 15:52:54 -07001310
Adam Cohen59400422014-03-05 18:07:04 -08001311 LauncherAppWidgetInfo launcherInfo;
1312 launcherInfo = new LauncherAppWidgetInfo(appWidgetId, appWidgetInfo.provider);
Sunny Goyal2100c782016-08-22 16:00:03 -07001313 launcherInfo.spanX = itemInfo.spanX;
1314 launcherInfo.spanY = itemInfo.spanY;
1315 launcherInfo.minSpanX = itemInfo.minSpanX;
1316 launcherInfo.minSpanY = itemInfo.minSpanY;
Sunny Goyal952e63d2017-08-16 04:59:08 -07001317 launcherInfo.user = appWidgetInfo.getProfile();
Romain Guycbb89e42009-06-08 15:52:54 -07001318
Sunny Goyal43bf11d2017-02-02 13:52:53 -08001319 getModelWriter().addItemToDatabase(launcherInfo,
Sunny Goyal2100c782016-08-22 16:00:03 -07001320 itemInfo.container, itemInfo.screenId, itemInfo.cellX, itemInfo.cellY);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001321
Sunny Goyal2100c782016-08-22 16:00:03 -07001322 if (hostView == null) {
1323 // Perform actual inflation because we're live
1324 hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001325 }
Sunny Goyal2100c782016-08-22 16:00:03 -07001326 hostView.setVisibility(View.VISIBLE);
Sunny Goyald5462aa2016-11-22 16:52:39 +05301327 prepareAppWidget(hostView, launcherInfo);
1328 mWorkspace.addInScreen(hostView, launcherInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001329 }
Romain Guycbb89e42009-06-08 15:52:54 -07001330
Sunny Goyald5462aa2016-11-22 16:52:39 +05301331 private void prepareAppWidget(AppWidgetHostView hostView, LauncherAppWidgetInfo item) {
Sunny Goyal87af0fd2016-05-16 14:56:02 -07001332 hostView.setTag(item);
1333 item.onBindAppWidget(this, hostView);
Sunny Goyal87af0fd2016-05-16 14:56:02 -07001334 hostView.setFocusable(true);
1335 hostView.setOnFocusChangeListener(mFocusHandler);
Sunny Goyal25c2e3e2015-10-28 23:28:21 -07001336 }
1337
Sunny Goyal5d1873a2018-05-08 11:10:44 -07001338 private final BroadcastReceiver mScreenOffReceiver = new BroadcastReceiver() {
Adam Cohended9f8d2010-11-03 13:25:16 -07001339 @Override
1340 public void onReceive(Context context, Intent intent) {
Sunny Goyal5d1873a2018-05-08 11:10:44 -07001341 // Reset AllApps to its initial state only if we are not in the middle of
1342 // processing a multi-step drop
1343 if (mPendingRequestArgs == null) {
1344 mStateManager.goToState(NORMAL);
Adam Cohended9f8d2010-11-03 13:25:16 -07001345 }
1346 }
1347 };
1348
Sunny Goyalaae6fbb2019-01-31 16:05:58 -08001349 public void updateNotificationDots(Predicate<PackageUserKey> updatedDots) {
Tony Wickhamf34bee82018-12-03 18:11:39 -08001350 mWorkspace.updateNotificationDots(updatedDots);
1351 mAppsView.getAppsStore().updateNotificationDots(updatedDots);
Tony Wickham010d2552017-01-20 08:15:28 -08001352 }
1353
Adam Cohended9f8d2010-11-03 13:25:16 -07001354 @Override
1355 public void onAttachedToWindow() {
1356 super.onAttachedToWindow();
Sunny Goyalb1d7de22019-09-06 10:36:54 -07001357 mOverlayManager.onAttachedToWindow();
Adam Cohended9f8d2010-11-03 13:25:16 -07001358 }
1359
1360 @Override
1361 public void onDetachedFromWindow() {
1362 super.onDetachedFromWindow();
Sunny Goyalb1d7de22019-09-06 10:36:54 -07001363 mOverlayManager.onDetachedFromWindow();
1364 closeContextMenu();
Adam Cohended9f8d2010-11-03 13:25:16 -07001365 }
1366
Sunny Goyalc4fa8c32017-11-07 12:23:58 -08001367 public AllAppsTransitionController getAllAppsController() {
1368 return mAllAppsController;
1369 }
1370
Sunny Goyal9d69c8d2018-03-19 13:41:31 -07001371 @Override
Winson Chung1a341002018-01-17 10:00:23 -08001372 public LauncherRootView getRootView() {
1373 return (LauncherRootView) mLauncherView;
1374 }
1375
Sunny Goyal0b0847b2018-03-14 12:30:11 -07001376 @Override
Winson Chunga6945242014-01-08 14:04:34 -08001377 public DragLayer getDragLayer() {
1378 return mDragLayer;
1379 }
1380
Winson Chung5f4e0fd2015-05-22 11:12:27 -07001381 public AllAppsContainerView getAppsView() {
Winson Chungb745afb2015-03-02 11:51:23 -08001382 return mAppsView;
1383 }
1384
Winson Chunga6945242014-01-08 14:04:34 -08001385 public Workspace getWorkspace() {
1386 return mWorkspace;
1387 }
1388
1389 public Hotseat getHotseat() {
1390 return mHotseat;
1391 }
1392
Sunny Goyal7c7be8c2018-03-07 19:58:07 -08001393 public <T extends View> T getOverviewPanel() {
Winson Chung8ae41982017-11-10 11:42:13 -08001394 return (T) mOverviewPanel;
Winson Chunga6945242014-01-08 14:04:34 -08001395 }
1396
Sunny Goyal47328fd2016-05-25 18:56:41 -07001397 public DropTargetBar getDropTargetBar() {
1398 return mDropTargetBar;
Tony Wickham34d2c912015-09-11 09:27:58 -07001399 }
1400
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001401 public LauncherAppWidgetHost getAppWidgetHost() {
1402 return mAppWidgetHost;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001403 }
Romain Guycbb89e42009-06-08 15:52:54 -07001404
Winson Chunga9abd0e2010-10-27 17:18:37 -07001405 public LauncherModel getModel() {
1406 return mModel;
1407 }
1408
Sunny Goyal43bf11d2017-02-02 13:52:53 -08001409 public ModelWriter getModelWriter() {
1410 return mModelWriter;
1411 }
1412
Sunny Goyalb1d7de22019-09-06 10:36:54 -07001413 @Override
Adam Cohen79d90c52016-04-22 13:29:20 -07001414 public SharedPreferences getSharedPrefs() {
Winson Chunga6945242014-01-08 14:04:34 -08001415 return mSharedPrefs;
1416 }
1417
Sunny Goyalb1d7de22019-09-06 10:36:54 -07001418 @Override
1419 public SharedPreferences getDevicePrefs() {
1420 return Utilities.getDevicePrefs(this);
1421 }
1422
Samuel Fufaca37b8a2019-08-19 17:04:36 -07001423 public int getOrientation() {
1424 return mOldConfig.orientation;
1425 }
Jon Miranda6bed3502017-09-19 14:43:17 -07001426
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001427 @Override
1428 protected void onNewIntent(Intent intent) {
Winson Chung5cc62c72019-10-16 11:32:41 -07001429 Object traceToken = TraceHelper.INSTANCE.beginSection(ON_NEW_INTENT_EVT);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001430 super.onNewIntent(intent);
1431
Sunny Goyalf4aceab2017-12-06 16:16:31 -08001432 boolean alreadyOnHome = hasWindowFocus() && ((intent.getFlags() &
Winson15f8b172015-08-19 11:02:39 -07001433 Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
1434 != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
Sunny Goyal85313732016-09-28 12:00:07 -07001435
1436 // Check this condition before handling isActionMain, as this will get reset.
Sunny Goyal3e3f44c2017-10-23 17:14:52 -07001437 boolean shouldMoveToDefaultScreen = alreadyOnHome && isInState(NORMAL)
Sunny Goyalf9403d92017-10-18 10:55:56 -07001438 && AbstractFloatingView.getTopOpenView(this) == null;
Winson15f8b172015-08-19 11:02:39 -07001439 boolean isActionMain = Intent.ACTION_MAIN.equals(intent.getAction());
Sunny Goyale84c5b82019-09-26 17:05:31 -07001440 boolean internalStateHandled = ACTIVITY_TRACKER.handleNewIntent(this, intent);
Sunny Goyald3864fa2017-11-14 15:06:36 -08001441
Winson15f8b172015-08-19 11:02:39 -07001442 if (isActionMain) {
Sunny Goyald3864fa2017-11-14 15:06:36 -08001443 if (!internalStateHandled) {
Sunny Goyald3864fa2017-11-14 15:06:36 -08001444 // In all these cases, only animate if we're already on home
Sunny Goyalcc96aa12018-01-11 09:56:07 -08001445 AbstractFloatingView.closeAllOpenViews(this, isStarted());
Jon Mirandafeba90f2016-10-06 10:53:29 -07001446
Sunny Goyala2467272018-03-16 14:53:05 -07001447 if (!isInState(NORMAL)) {
1448 // Only change state, if not already the same. This prevents cancelling any
1449 // animations running as part of resume
1450 mStateManager.goToState(NORMAL);
1451 }
Sunny Goyald3864fa2017-11-14 15:06:36 -08001452
1453 // Reset the apps view
Sunny Goyal5d1873a2018-05-08 11:10:44 -07001454 if (!alreadyOnHome) {
Sunny Goyal7185dd62018-03-14 17:51:49 -07001455 mAppsView.reset(isStarted() /* animate */);
Sunny Goyald3864fa2017-11-14 15:06:36 -08001456 }
1457
Sunny Goyalaad33592018-08-07 17:20:35 -07001458 if (shouldMoveToDefaultScreen && !mWorkspace.isHandlingTouch()) {
Sunny Goyald3864fa2017-11-14 15:06:36 -08001459 mWorkspace.post(mWorkspace::moveToDefaultScreen);
1460 }
1461 }
Adam Cohen6fecd412013-10-02 17:41:50 -07001462
Hyunyoung Song2a70b3d2019-06-11 12:47:07 -07001463 // Handle HOME_INTENT
1464 UserEventDispatcher ued = getUserEventDispatcher();
1465 Target target = newContainerTarget(mStateManager.getState().containerType);
1466 target.pageIndex = mWorkspace.getCurrentPage();
1467 ued.logActionCommand(Action.Command.HOME_INTENT, target,
1468 newContainerTarget(ContainerType.WORKSPACE));
1469
Adam Cohen6fecd412013-10-02 17:41:50 -07001470 final View v = getWindow().peekDecorView();
1471 if (v != null && v.getWindowToken() != null) {
Sunny Goyal326403e2017-10-02 12:45:10 -07001472 UiThreadHelper.hideKeyboardAsync(this, v.getWindowToken());
Adam Cohen6fecd412013-10-02 17:41:50 -07001473 }
1474
Adam Cohen9211d422014-10-07 18:14:53 -07001475 if (mLauncherCallbacks != null) {
Sunny Goyal85462132018-04-24 11:39:37 -07001476 mLauncherCallbacks.onHomeIntent(internalStateHandled);
Adam Cohen9211d422014-10-07 18:14:53 -07001477 }
Sunny Goyalb1d7de22019-09-06 10:36:54 -07001478 mOverlayManager.hideOverlay(isStarted() && !isForceInvisible());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001479 }
Winson15f8b172015-08-19 11:02:39 -07001480
Winson Chung5cc62c72019-10-16 11:32:41 -07001481 TraceHelper.INSTANCE.endSection(traceToken);
Adam Coppa120b8e2013-11-12 16:26:04 +00001482 }
1483
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001484 @Override
Adam Cohen1462de32012-07-24 22:34:36 -07001485 public void onRestoreInstanceState(Bundle state) {
1486 super.onRestoreInstanceState(state);
Sunny Goyalf4aceab2017-12-06 16:16:31 -08001487 mWorkspace.restoreInstanceStateForChild(mSynchronouslyBoundPage);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001488 }
1489
1490 @Override
1491 protected void onSaveInstanceState(Bundle outState) {
Adam Cohen21cd0022013-10-09 18:57:02 -07001492 if (mWorkspace.getChildCount() > 0) {
Sunny Goyal7ce471b2017-08-02 03:37:39 -07001493 outState.putInt(RUNTIME_STATE_CURRENT_SCREEN, mWorkspace.getNextPage());
Hyunyoung Song645764e2016-06-06 14:19:02 -07001494
Adam Cohen21cd0022013-10-09 18:57:02 -07001495 }
Sunny Goyalea609262017-10-25 15:47:38 -07001496 outState.putInt(RUNTIME_STATE, mStateManager.getState().ordinal);
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -07001497
1498
1499 AbstractFloatingView widgets = AbstractFloatingView
1500 .getOpenView(this, AbstractFloatingView.TYPE_WIDGETS_FULL_SHEET);
1501 if (widgets != null) {
1502 SparseArray<Parcelable> widgetsState = new SparseArray<>();
1503 widgets.saveHierarchyState(widgetsState);
1504 outState.putSparseParcelableArray(RUNTIME_STATE_WIDGET_PANEL, widgetsState);
1505 } else {
1506 outState.remove(RUNTIME_STATE_WIDGET_PANEL);
1507 }
1508
Pinyao Tinga74b63a2019-07-17 23:26:06 -07001509 // We close any open folders and shortcut containers that are not safe for rebind,
Sunny Goyal740ac7f2016-09-28 16:47:32 -07001510 // and we need to make sure this state is reflected.
Pinyao Tinga74b63a2019-07-17 23:26:06 -07001511 AbstractFloatingView.closeOpenViews(this, false, TYPE_ALL & ~TYPE_REBIND_SAFE);
1512 finishAutoCancelActionMode();
Tony Wickham49c8d292016-07-01 11:44:34 -07001513
Sunny Goyal2100c782016-08-22 16:00:03 -07001514 if (mPendingRequestArgs != null) {
1515 outState.putParcelable(RUNTIME_STATE_PENDING_REQUEST_ARGS, mPendingRequestArgs);
1516 }
Sunny Goyaldedda052019-05-14 15:23:48 -07001517 outState.putInt(RUNTIME_STATE_PENDING_REQUEST_CODE, mPendingActivityRequestCode);
1518
Sunny Goyal2100c782016-08-22 16:00:03 -07001519 if (mPendingActivityResult != null) {
1520 outState.putParcelable(RUNTIME_STATE_PENDING_ACTIVITY_RESULT, mPendingActivityResult);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001521 }
1522
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -07001523 super.onSaveInstanceState(outState);
Sunny Goyalb1d7de22019-09-06 10:36:54 -07001524 mOverlayManager.onActivitySaveInstanceState(this, outState);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001525 }
1526
1527 @Override
1528 public void onDestroy() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001529 super.onDestroy();
Sunny Goyale84c5b82019-09-26 17:05:31 -07001530 ACTIVITY_TRACKER.onActivityDestroyed(this);
Romain Guycbb89e42009-06-08 15:52:54 -07001531
Sunny Goyal5d1873a2018-05-08 11:10:44 -07001532 unregisterReceiver(mScreenOffReceiver);
Sunny Goyalaaf7d1d2016-05-17 13:38:54 -07001533 mWorkspace.removeFolderListeners();
Sunny Goyalb1d7de22019-09-06 10:36:54 -07001534 PluginManagerWrapper.INSTANCE.get(this).removePluginListener(this);
Winson Chunge7a03942011-08-05 15:05:12 -07001535
Winson Chungcd2b0142011-06-08 16:02:26 -07001536 // Stop callbacks from LauncherModel
Adam Cohen1a85c582014-09-30 09:48:49 -07001537 // It's possible to receive onDestroy after a new Launcher activity has
1538 // been created. In this case, don't interfere with the new Launcher.
1539 if (mModel.isCurrentCallbacks(this)) {
1540 mModel.stopLoader();
Sunny Goyal87f784c2017-01-11 10:48:34 -08001541 LauncherAppState.getInstance(this).setLauncher(null);
Adam Cohen1a85c582014-09-30 09:48:49 -07001542 }
Sunny Goyal623eddd2018-03-02 12:24:41 -08001543 mRotationHelper.destroy();
Sunny Goyal745bad92016-05-02 10:54:12 -07001544
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001545 try {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001546 mAppWidgetHost.stopListening();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001547 } catch (NullPointerException ex) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001548 Log.w(TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001549 }
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001550
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001551 TextKeyListener.getInstance().release();
Tony2917a8b2017-07-31 23:29:42 -07001552 clearPendingBinds();
Hyunyoung Song31971a32019-01-27 12:31:12 -08001553 LauncherAppState.getIDP(this).removeOnChangeListener(this);
Sunny Goyalb1d7de22019-09-06 10:36:54 -07001554
1555 mOverlayManager.onActivityDestroyed(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001556 }
1557
Sunny Goyalae502842016-06-17 08:43:56 -07001558 public LauncherAccessibilityDelegate getAccessibilityDelegate() {
1559 return mAccessibilityDelegate;
1560 }
1561
Adam Cohena9cf38f2011-05-02 15:36:58 -07001562 public DragController getDragController() {
1563 return mDragController;
1564 }
1565
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001566 @Override
Sunny Goyal0eca4e22016-07-20 11:43:06 -07001567 public void startActivityForResult(Intent intent, int requestCode, Bundle options) {
Sunny Goyaldedda052019-05-14 15:23:48 -07001568 if (requestCode != -1) {
1569 mPendingActivityRequestCode = requestCode;
1570 }
Sunny Goyal210e1742019-10-17 12:05:38 -07001571 super.startActivityForResult(intent, requestCode, options);
Adam Cohen173f7112015-03-27 15:14:00 -07001572 }
1573
1574 @Override
Sunny Goyaldedda052019-05-14 15:23:48 -07001575 public void startIntentSenderForResult(IntentSender intent, int requestCode,
Adam Cohen173f7112015-03-27 15:14:00 -07001576 Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags, Bundle options) {
Sunny Goyaldedda052019-05-14 15:23:48 -07001577 if (requestCode != -1) {
1578 mPendingActivityRequestCode = requestCode;
1579 }
Sunny Goyal210e1742019-10-17 12:05:38 -07001580 try {
1581 super.startIntentSenderForResult(intent, requestCode,
1582 fillInIntent, flagsMask, flagsValues, extraFlags, options);
1583 } catch (IntentSender.SendIntentException e) {
1584 throw new ActivityNotFoundException();
Adam Cohen173f7112015-03-27 15:14:00 -07001585 }
1586 }
1587
Winson Chung70d72102011-08-12 11:24:35 -07001588 /**
1589 * Indicates that we want global search for this activity by setting the globalSearch
1590 * argument for {@link #startSearch} to true.
1591 */
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001592 @Override
Romain Guycbb89e42009-06-08 15:52:54 -07001593 public void startSearch(String initialQuery, boolean selectInitialQuery,
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001594 Bundle appSearchData, boolean globalSearch) {
1595 if (appSearchData == null) {
1596 appSearchData = new Bundle();
Bjorn Bringert32b12d22013-06-06 13:00:41 +01001597 appSearchData.putString("source", "launcher-search");
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001598 }
Sunny Goyalda4fe1a2016-05-26 16:05:17 -07001599
Sunny Goyal6f28e712016-09-13 14:19:29 -07001600 if (mLauncherCallbacks == null ||
1601 !mLauncherCallbacks.startSearch(initialQuery, selectInitialQuery, appSearchData)) {
1602 // Starting search from the callbacks failed. Start the default global search.
Sunny Goyalf4aceab2017-12-06 16:16:31 -08001603 super.startSearch(initialQuery, selectInitialQuery, appSearchData, true);
Ian Parkinson047036e2014-09-01 15:40:53 +01001604 }
Winson Chungcd99cd32015-04-29 11:03:24 -07001605
1606 // We need to show the workspace after starting the search
Sunny Goyal3e3f44c2017-10-23 17:14:52 -07001607 mStateManager.goToState(NORMAL);
Bjorn Bringertc459e522013-06-07 19:36:01 +01001608 }
1609
Joe Onorato9c1289c2009-08-17 11:03:03 -04001610 public boolean isWorkspaceLocked() {
Sunny Goyal2100c782016-08-22 16:00:03 -07001611 return mWorkspaceLoading || mPendingRequestArgs != null;
Joe Onorato9c1289c2009-08-17 11:03:03 -04001612 }
1613
Adam Cohen517a7f52014-03-01 12:12:59 -08001614 public boolean isWorkspaceLoading() {
1615 return mWorkspaceLoading;
1616 }
1617
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001618 private void setWorkspaceLoading(boolean value) {
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001619 mWorkspaceLoading = value;
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001620 }
1621
Sunny Goyal04a324a2017-01-20 21:08:59 -08001622 public void setWaitingForResult(PendingRequestArgs args) {
Sunny Goyal2100c782016-08-22 16:00:03 -07001623 mPendingRequestArgs = args;
Adam Cohen9211d422014-10-07 18:14:53 -07001624 }
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001625
Sunny Goyal2100c782016-08-22 16:00:03 -07001626 void addAppWidgetFromDropImpl(int appWidgetId, ItemInfo info, AppWidgetHostView boundWidget,
Sunny Goyal04a324a2017-01-20 21:08:59 -08001627 WidgetAddFlowHandler addFlowHandler) {
Tony Wickhama0628cc2015-10-14 15:23:04 -07001628 if (LOGD) {
1629 Log.d(TAG, "Adding widget from drop");
1630 }
Sunny Goyal04a324a2017-01-20 21:08:59 -08001631 addAppWidgetImpl(appWidgetId, info, boundWidget, addFlowHandler, 0);
Adam Cohenad4e15c2013-10-17 16:21:35 -07001632 }
1633
Sunny Goyal2100c782016-08-22 16:00:03 -07001634 void addAppWidgetImpl(int appWidgetId, ItemInfo info,
Sunny Goyal04a324a2017-01-20 21:08:59 -08001635 AppWidgetHostView boundWidget, WidgetAddFlowHandler addFlowHandler, int delay) {
Samuel Fufaca37b8a2019-08-19 17:04:36 -07001636 if (!addFlowHandler.startConfigActivity(this, appWidgetId, info,
1637 REQUEST_CREATE_APPWIDGET)) {
Sunny Goyal04a324a2017-01-20 21:08:59 -08001638 // If the configuration flow was not started, add the widget
Michael Jurkaaf442092010-06-10 17:01:57 -07001639
Adam Cohenad4e15c2013-10-17 16:21:35 -07001640 Runnable onComplete = new Runnable() {
1641 @Override
1642 public void run() {
1643 // Exit spring loaded mode if necessary after adding the widget
Sunny Goyal3e3f44c2017-10-23 17:14:52 -07001644 mStateManager.goToState(NORMAL, SPRING_LOADED_EXIT_DELAY);
Adam Cohenad4e15c2013-10-17 16:21:35 -07001645 }
1646 };
Samuel Fufaca37b8a2019-08-19 17:04:36 -07001647 completeAddAppWidget(appWidgetId, info, boundWidget,
1648 addFlowHandler.getProviderInfo(this));
Adam Cohen689ff162014-05-08 17:27:56 -07001649 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete, delay, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001650 }
1651 }
Romain Guycbb89e42009-06-08 15:52:54 -07001652
Sunny Goyalefb7e842018-10-04 15:11:00 -07001653 public void addPendingItem(PendingAddItemInfo info, int container, int screenId,
Sunny Goyal71b5c0b2015-01-08 16:59:04 -08001654 int[] cell, int spanX, int spanY) {
Sunny Goyal2100c782016-08-22 16:00:03 -07001655 info.container = container;
1656 info.screenId = screenId;
1657 if (cell != null) {
1658 info.cellX = cell[0];
1659 info.cellY = cell[1];
1660 }
1661 info.spanX = spanX;
1662 info.spanY = spanY;
1663
Sunny Goyal71b5c0b2015-01-08 16:59:04 -08001664 switch (info.itemType) {
1665 case LauncherSettings.Favorites.ITEM_TYPE_CUSTOM_APPWIDGET:
1666 case LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET:
Sunny Goyal2100c782016-08-22 16:00:03 -07001667 addAppWidgetFromDrop((PendingAddWidgetInfo) info);
Sunny Goyal71b5c0b2015-01-08 16:59:04 -08001668 break;
1669 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Sunny Goyal782f0c92017-01-19 10:27:54 -08001670 processShortcutFromDrop((PendingAddShortcutInfo) info);
Sunny Goyal71b5c0b2015-01-08 16:59:04 -08001671 break;
1672 default:
1673 throw new IllegalStateException("Unknown item type: " + info.itemType);
Samuel Fufaca37b8a2019-08-19 17:04:36 -07001674 }
Sunny Goyal71b5c0b2015-01-08 16:59:04 -08001675 }
1676
Adam Cohenfbba09b2011-07-18 21:43:05 -07001677 /**
1678 * Process a shortcut drop.
Adam Cohenfbba09b2011-07-18 21:43:05 -07001679 */
Sunny Goyal782f0c92017-01-19 10:27:54 -08001680 private void processShortcutFromDrop(PendingAddShortcutInfo info) {
Sunny Goyalfb5096d2016-09-08 14:32:06 -07001681 Intent intent = new Intent(Intent.ACTION_CREATE_SHORTCUT).setComponent(info.componentName);
1682 setWaitingForResult(PendingRequestArgs.forIntent(REQUEST_CREATE_SHORTCUT, intent, info));
Sunny Goyal782f0c92017-01-19 10:27:54 -08001683 if (!info.activityInfo.startConfigActivity(this, REQUEST_CREATE_SHORTCUT)) {
1684 handleActivityResult(REQUEST_CREATE_SHORTCUT, RESULT_CANCELED, null);
1685 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001686 }
1687
Adam Cohenfbba09b2011-07-18 21:43:05 -07001688 /**
1689 * Process a widget drop.
Adam Cohenfbba09b2011-07-18 21:43:05 -07001690 */
Sunny Goyal2100c782016-08-22 16:00:03 -07001691 private void addAppWidgetFromDrop(PendingAddWidgetInfo info) {
Adam Cohened66b2b2012-01-23 17:28:51 -08001692 AppWidgetHostView hostView = info.boundWidget;
Sunny Goyal952e63d2017-08-16 04:59:08 -07001693 final int appWidgetId;
Sunny Goyal8a0dc382017-01-25 11:30:06 -08001694 WidgetAddFlowHandler addFlowHandler = info.getHandler();
Adam Cohened66b2b2012-01-23 17:28:51 -08001695 if (hostView != null) {
Tony Wickhama0628cc2015-10-14 15:23:04 -07001696 // In the case where we've prebound the widget, we remove it from the DragLayer
1697 if (LOGD) {
1698 Log.d(TAG, "Removing widget view from drag layer and setting boundWidget to null");
1699 }
1700 getDragLayer().removeView(hostView);
1701
Adam Cohened66b2b2012-01-23 17:28:51 -08001702 appWidgetId = hostView.getAppWidgetId();
Sunny Goyal04a324a2017-01-20 21:08:59 -08001703 addAppWidgetFromDropImpl(appWidgetId, info, hostView, addFlowHandler);
Sunny Goyal5b9ebca2015-06-01 18:37:32 -07001704
1705 // Clear the boundWidget so that it doesn't get destroyed.
1706 info.boundWidget = null;
Adam Cohened66b2b2012-01-23 17:28:51 -08001707 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001708 // In this case, we either need to start an activity to get permission to bind
1709 // the widget, or we need to start an activity to configure the widget, or both.
Pinyao Tingc7a6c292019-08-26 14:36:02 -07001710 if (info.itemType == LauncherSettings.Favorites.ITEM_TYPE_CUSTOM_APPWIDGET) {
1711 appWidgetId = CustomWidgetManager.INSTANCE.get(this).getWidgetIdForCustomProvider(
1712 info.componentName);
Sunny Goyal952e63d2017-08-16 04:59:08 -07001713 } else {
1714 appWidgetId = getAppWidgetHost().allocateAppWidgetId();
1715 }
Adam Cohendd70d662012-10-04 16:53:44 -07001716 Bundle options = info.bindOptions;
1717
Sunny Goyalffe83f12014-08-14 17:39:34 -07001718 boolean success = mAppWidgetManager.bindAppWidgetIdIfAllowed(
1719 appWidgetId, info.info, options);
Adam Cohendd70d662012-10-04 16:53:44 -07001720 if (success) {
Sunny Goyal04a324a2017-01-20 21:08:59 -08001721 addAppWidgetFromDropImpl(appWidgetId, info, null, addFlowHandler);
Michael Jurka8b805b12012-04-18 14:23:14 -07001722 } else {
Sunny Goyal04a324a2017-01-20 21:08:59 -08001723 addFlowHandler.startBindFlow(this, appWidgetId, info, REQUEST_BIND_APPWIDGET);
Michael Jurka8b805b12012-04-18 14:23:14 -07001724 }
Adam Cohened66b2b2012-01-23 17:28:51 -08001725 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001726 }
1727
Sunny Goyalefb7e842018-10-04 15:11:00 -07001728 FolderIcon addFolder(CellLayout layout, int container, final int screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07001729 int cellY) {
Michael Jurkac9d95c52011-08-29 14:03:34 -07001730 final FolderInfo folderInfo = new FolderInfo();
Samuel Fufa84245e82019-08-14 13:44:12 -07001731 folderInfo.title = "";
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001732
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001733 // Update the model
Sunny Goyal43bf11d2017-02-02 13:52:53 -08001734 getModelWriter().addItemToDatabase(folderInfo, container, screenId, cellX, cellY);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001735
1736 // Create the view
Sunny Goyal1cd01b02016-11-09 10:43:58 -08001737 FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this, layout, folderInfo);
Sunny Goyald5462aa2016-11-22 16:52:39 +05301738 mWorkspace.addInScreen(newFolder, folderInfo);
Winson Chung5f8afe62013-08-12 16:19:28 -07001739 // Force measure the new folder icon
1740 CellLayout parent = mWorkspace.getParentCellLayoutForView(newFolder);
1741 parent.getShortcutsAndWidgets().measureChild(newFolder);
Adam Cohendf035382011-04-11 17:22:04 -07001742 return newFolder;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001743 }
Romain Guycbb89e42009-06-08 15:52:54 -07001744
Winsonc0b52fe2015-09-09 16:38:15 -07001745 /**
Winsonfa56b3f2015-09-14 12:01:13 -07001746 * Unbinds the view for the specified item, and removes the item and all its children.
1747 *
1748 * @param v the view being removed.
Winsonfa56b3f2015-09-14 12:01:13 -07001749 * @param itemInfo the {@link ItemInfo} for this view.
1750 * @param deleteFromDb whether or not to delete this item from the db.
Winsonc0b52fe2015-09-09 16:38:15 -07001751 */
Tony Wickhambfbf7f92016-05-19 11:19:39 -07001752 public boolean removeItem(View v, final ItemInfo itemInfo, boolean deleteFromDb) {
Sunny Goyal95899162019-03-27 16:03:06 -07001753 if (itemInfo instanceof WorkspaceItemInfo) {
Winsonfa56b3f2015-09-14 12:01:13 -07001754 // Remove the shortcut from the folder before removing it from launcher
Sunny Goyal44c06432016-04-02 10:56:02 -07001755 View folderIcon = mWorkspace.getHomescreenIconByItemId(itemInfo.container);
1756 if (folderIcon instanceof FolderIcon) {
Sunny Goyal95899162019-03-27 16:03:06 -07001757 ((FolderInfo) folderIcon.getTag()).remove((WorkspaceItemInfo) itemInfo, true);
Winsonfa56b3f2015-09-14 12:01:13 -07001758 } else {
1759 mWorkspace.removeWorkspaceItem(v);
1760 }
Winsonc0b52fe2015-09-09 16:38:15 -07001761 if (deleteFromDb) {
Sunny Goyal43bf11d2017-02-02 13:52:53 -08001762 getModelWriter().deleteItemFromDatabase(itemInfo);
Winsonc0b52fe2015-09-09 16:38:15 -07001763 }
1764 } else if (itemInfo instanceof FolderInfo) {
1765 final FolderInfo folderInfo = (FolderInfo) itemInfo;
Sunny Goyalaaf7d1d2016-05-17 13:38:54 -07001766 if (v instanceof FolderIcon) {
1767 ((FolderIcon) v).removeListeners();
1768 }
Winsonc0b52fe2015-09-09 16:38:15 -07001769 mWorkspace.removeWorkspaceItem(v);
1770 if (deleteFromDb) {
Sunny Goyal43bf11d2017-02-02 13:52:53 -08001771 getModelWriter().deleteFolderAndContentsFromDatabase(folderInfo);
Winsonc0b52fe2015-09-09 16:38:15 -07001772 }
1773 } else if (itemInfo instanceof LauncherAppWidgetInfo) {
1774 final LauncherAppWidgetInfo widgetInfo = (LauncherAppWidgetInfo) itemInfo;
Winson44818e02015-10-02 11:25:46 -07001775 mWorkspace.removeWorkspaceItem(v);
Winsonc0b52fe2015-09-09 16:38:15 -07001776 if (deleteFromDb) {
Tony Wickham6a71a5b2018-08-21 11:40:23 -07001777 getModelWriter().deleteWidgetInfo(widgetInfo, getAppWidgetHost());
Winsonc0b52fe2015-09-09 16:38:15 -07001778 }
1779 } else {
1780 return false;
1781 }
1782 return true;
1783 }
1784
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001785 @Override
1786 public boolean dispatchKeyEvent(KeyEvent event) {
Hyunyoung Song3c7d9cb2017-01-30 15:11:27 -08001787 return (event.getKeyCode() == KeyEvent.KEYCODE_HOME) || super.dispatchKeyEvent(event);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001788 }
1789
Joe Onorato88ec0992009-11-19 13:16:06 -08001790 @Override
1791 public void onBackPressed() {
Sunny Goyal7c8a65e2017-12-22 11:11:33 -08001792 if (finishAutoCancelActionMode()) {
1793 return;
1794 }
Adam Cohen9211d422014-10-07 18:14:53 -07001795
Sunny Goyal45478022015-06-08 16:52:41 -07001796 if (mDragController.isDragging()) {
1797 mDragController.cancelDrag();
Adam Cohenc9735cf2015-01-23 16:11:55 -08001798 return;
1799 }
1800
Jon Mirandafeba90f2016-10-06 10:53:29 -07001801 // Note: There should be at most one log per method call. This is enforced implicitly
1802 // by using if-else statements.
1803 UserEventDispatcher ued = getUserEventDispatcher();
Sunny Goyal740ac7f2016-09-28 16:47:32 -07001804 AbstractFloatingView topView = AbstractFloatingView.getTopOpenView(this);
Tony Wickham52c1b662018-05-21 13:13:58 -07001805 if (topView != null && topView.onBackPressed()) {
1806 // Handled by the floating view.
Patrick Dubroy94f78a52011-02-28 17:39:16 -08001807 } else {
Sunny Goyale39690b2018-08-02 13:35:07 -07001808 mStateManager.getState().onBackPressed(this);
Michael Jurkaaf442092010-06-10 17:01:57 -07001809 }
Joe Onorato88ec0992009-11-19 13:16:06 -08001810 }
1811
Sunny Goyalfe770c92016-09-27 14:38:58 -07001812 @TargetApi(Build.VERSION_CODES.M)
Sunny Goyal0b0847b2018-03-14 12:30:11 -07001813 @Override
Jon Miranda73c27ec2018-05-16 18:06:23 -07001814 public ActivityOptions getActivityLaunchOptions(View v) {
1815 return mAppTransitionManager.getActivityLaunchOptions(this, v);
Sunny Goyala7ce1662016-05-31 15:01:35 -07001816 }
1817
Tony Wickham3a6746a2018-03-29 09:39:56 -07001818 public LauncherAppTransitionManager getAppTransitionManager() {
1819 return mAppTransitionManager;
1820 }
1821
Sunny Goyal0b0847b2018-03-14 12:30:11 -07001822 @TargetApi(Build.VERSION_CODES.M)
1823 @Override
1824 protected boolean onErrorStartingShortcut(Intent intent, ItemInfo info) {
1825 // Due to legacy reasons, direct call shortcuts require Launchers to have the
1826 // corresponding permission. Show the appropriate permission prompt if that
1827 // is the case.
1828 if (intent.getComponent() == null
1829 && Intent.ACTION_CALL.equals(intent.getAction())
1830 && checkSelfPermission(android.Manifest.permission.CALL_PHONE) !=
1831 PackageManager.PERMISSION_GRANTED) {
1832
1833 setWaitingForResult(PendingRequestArgs
1834 .forIntent(REQUEST_PERMISSION_CALL_PHONE, intent, info));
1835 requestPermissions(new String[]{android.Manifest.permission.CALL_PHONE},
1836 REQUEST_PERMISSION_CALL_PHONE);
1837 return true;
1838 } else {
1839 return false;
1840 }
Sunny Goyal0eca4e22016-07-20 11:43:06 -07001841 }
1842
Hyunyoung Song46d07f72018-05-22 15:41:25 -07001843 @Override
Hyunyoung Songfc007472018-10-25 14:09:50 -07001844 public int getCurrentState() {
Samuel Fufaca37b8a2019-08-19 17:04:36 -07001845 if (mStateManager.getState() == LauncherState.ALL_APPS) {
Hyunyoung Songfc007472018-10-25 14:09:50 -07001846 return StatsLogUtils.LAUNCHER_STATE_ALLAPPS;
Govinda Wassermanc06e1512019-04-09 09:56:53 -04001847 } else if (mStateManager.getState() == OVERVIEW) {
Hyunyoung Songfc007472018-10-25 14:09:50 -07001848 return StatsLogUtils.LAUNCHER_STATE_OVERVIEW;
1849 }
Hyunyoung Song0ae38882018-11-05 14:45:19 -08001850 return StatsLogUtils.LAUNCHER_STATE_HOME;
Hyunyoung Songfc007472018-10-25 14:09:50 -07001851 }
1852
1853 @Override
Hyunyoung Song46d07f72018-05-22 15:41:25 -07001854 public void modifyUserEvent(LauncherLogProto.LauncherEvent event) {
1855 if (event.srcTarget != null && event.srcTarget.length > 0 &&
1856 event.srcTarget[1].containerType == ContainerType.PREDICTION) {
1857 Target[] targets = new Target[3];
1858 targets[0] = event.srcTarget[0];
1859 targets[1] = event.srcTarget[1];
1860 targets[2] = newTarget(Target.Type.CONTAINER);
1861 event.srcTarget = targets;
1862 LauncherState state = mStateManager.getState();
1863 if (state == LauncherState.ALL_APPS) {
1864 event.srcTarget[2].containerType = ContainerType.ALLAPPS;
Govinda Wassermanc06e1512019-04-09 09:56:53 -04001865 } else if (state == OVERVIEW) {
Hyunyoung Song46d07f72018-05-22 15:41:25 -07001866 event.srcTarget[2].containerType = ContainerType.TASKSWITCHER;
1867 }
1868 }
1869 }
1870
Sunny Goyal369212a2019-03-26 15:03:57 -07001871 public boolean startActivitySafely(View v, Intent intent, ItemInfo item,
1872 @Nullable String sourceContainer) {
Winson Chung0b70cd42019-06-17 22:34:33 -07001873 if (!hasBeenResumed()) {
1874 // Workaround an issue where the WM launch animation is clobbered when finishing the
1875 // recents animation into launcher. Defer launching the activity until Launcher is
1876 // next resumed.
1877 addOnResumeCallback(() -> startActivitySafely(v, intent, item, sourceContainer));
Winson Chungc9bf6d42019-10-04 15:33:18 -07001878 if (mOnDeferredActivityLaunchCallback != null) {
1879 mOnDeferredActivityLaunchCallback.run();
1880 mOnDeferredActivityLaunchCallback = null;
1881 }
Winson Chung0b70cd42019-06-17 22:34:33 -07001882 return true;
1883 }
1884
Sunny Goyal369212a2019-03-26 15:03:57 -07001885 boolean success = super.startActivitySafely(v, intent, item, sourceContainer);
Hyunyoung Song1241e612018-05-15 21:46:51 -07001886 if (success && v instanceof BubbleTextView) {
Sunny Goyal0b0847b2018-03-14 12:30:11 -07001887 // This is set to the view that launched the activity that navigated the user away
1888 // from launcher. Since there is no callback for when the activity has finished
1889 // launching, enable the press state and keep this reference to reset the press
1890 // state when we return to launcher.
1891 BubbleTextView btv = (BubbleTextView) v;
1892 btv.setStayPressed(true);
Winson Chung0b70cd42019-06-17 22:34:33 -07001893 addOnResumeCallback(btv);
Sunny Goyala7ce1662016-05-31 15:01:35 -07001894 }
Hyunyoung Song1241e612018-05-15 21:46:51 -07001895 return success;
Michael Jurka86a720e2012-05-09 11:23:23 -07001896 }
1897
Winson Chung3d503fb2011-07-13 17:25:49 -07001898 boolean isHotseatLayout(View layout) {
Sunny Goyalc13403c2016-11-18 23:44:48 -08001899 // TODO: Remove this method
Sunny Goyal876e4622018-11-02 13:50:40 -07001900 return mHotseat != null && (layout == mHotseat);
Winson Chung3d503fb2011-07-13 17:25:49 -07001901 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08001902
Winson Chung3d503fb2011-07-13 17:25:49 -07001903 /**
1904 * Returns the CellLayout of the specified container at the specified screen.
1905 */
Sunny Goyalefb7e842018-10-04 15:11:00 -07001906 public CellLayout getCellLayout(int container, int screenId) {
Sunny Goyal876e4622018-11-02 13:50:40 -07001907 return (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT)
1908 ? mHotseat : mWorkspace.getScreenWithId(screenId);
Romain Guya6abce82009-11-10 02:54:41 -08001909 }
1910
Michael Jurkae326f182011-11-21 14:05:46 -08001911 @Override
1912 public void onTrimMemory(int level) {
1913 super.onTrimMemory(level);
Adam Cohen3f9c9712014-10-31 11:48:25 -07001914 if (level >= ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN) {
1915 // The widget preview db can result in holding onto over
1916 // 3MB of memory for caching which isn't necessary.
1917 SQLiteDatabase.releaseMemory();
1918
Adam Cohenc8f4e1b2014-11-19 16:03:20 -08001919 // This clears all widget bitmaps from the widget tray
Hyunyoung Song3f471442015-04-08 19:01:34 -07001920 // TODO(hyunyoungs)
Michael Jurkae326f182011-11-21 14:05:46 -08001921 }
1922 }
1923
Michael Jurkad7c28052012-04-27 15:43:36 -07001924 @Override
1925 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
alanv1d4fde62012-10-17 13:15:47 -07001926 final boolean result = super.dispatchPopulateAccessibilityEvent(event);
Michael Jurkad7c28052012-04-27 15:43:36 -07001927 final List<CharSequence> text = event.getText();
1928 text.clear();
alanv1d4fde62012-10-17 13:15:47 -07001929 // Populate event with a fake title based on the current state.
Sunny Goyal3e3f44c2017-10-23 17:14:52 -07001930 // TODO: When can workspace be null?
1931 text.add(mWorkspace == null
1932 ? getString(R.string.all_apps_home_button_label)
Sunny Goyalea609262017-10-25 15:47:38 -07001933 : mStateManager.getState().getDescription(this));
Michael Jurkad7c28052012-04-27 15:43:36 -07001934 return result;
1935 }
1936
Winson Chung0b70cd42019-06-17 22:34:33 -07001937 public void addOnResumeCallback(OnResumeCallback callback) {
1938 mOnResumeCallbacks.add(callback);
Michael Jurka1e2f4652013-07-08 18:03:46 -07001939 }
1940
Michael Jurka7607c2f2013-04-03 14:33:19 -07001941 /**
Winson Chungc9bf6d42019-10-04 15:33:18 -07001942 * Persistant callback which notifies when an activity launch is deferred because the activity
1943 * was not yet resumed.
1944 */
1945 public void setOnDeferredActivityLaunchCallback(Runnable callback) {
1946 mOnDeferredActivityLaunchCallback = callback;
1947 }
1948
1949 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04001950 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001951 */
Sunny Goyal93f878c2016-03-30 17:31:24 -07001952 @Override
Joe Onorato9c1289c2009-08-17 11:03:03 -04001953 public int getCurrentWorkspaceScreen() {
Joe Onoratod0afc872010-06-11 00:03:15 -07001954 if (mWorkspace != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07001955 return mWorkspace.getCurrentPage();
Joe Onoratod0afc872010-06-11 00:03:15 -07001956 } else {
Winson Chung882a52e2015-07-08 14:32:26 -07001957 return 0;
Joe Onoratod0afc872010-06-11 00:03:15 -07001958 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04001959 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07001960
Joe Onorato9c1289c2009-08-17 11:03:03 -04001961 /**
Sunny Goyal527c7d32015-08-28 15:19:36 -07001962 * Clear any pending bind callbacks. This is called when is loader is planning to
1963 * perform a full rebind from scratch.
1964 */
1965 @Override
1966 public void clearPendingBinds() {
Sunny Goyal527c7d32015-08-28 15:19:36 -07001967 if (mPendingExecutor != null) {
1968 mPendingExecutor.markCompleted();
1969 mPendingExecutor = null;
Sunny Goyal6b6d0a32019-08-05 17:19:32 -07001970
1971 // We might have set this flag previously and forgot to clear it.
1972 mAppsView.getAppsStore()
1973 .disableDeferUpdatesSilently(AllAppsStore.DEFER_UPDATES_NEXT_DRAW);
Sunny Goyal527c7d32015-08-28 15:19:36 -07001974 }
1975 }
1976
1977 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04001978 * Refreshes the shortcuts shown on the workspace.
1979 *
1980 * Implementation of the method from LauncherModel.Callbacks.
1981 */
1982 public void startBinding() {
Winson Chung5cc62c72019-10-16 11:32:41 -07001983 Object traceToken = TraceHelper.INSTANCE.beginSection("startBinding");
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -07001984 // Floating panels (except the full widget sheet) are associated with individual icons. If
1985 // we are starting a fresh bind, close all such panels as all the icons are about
1986 // to go away.
Pinyao Tinga74b63a2019-07-17 23:26:06 -07001987 AbstractFloatingView.closeOpenViews(this, true, TYPE_ALL & ~TYPE_REBIND_SAFE);
Jon Miranda6dc7f1e2017-02-21 12:37:51 -08001988
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001989 setWorkspaceLoading(true);
Adam Cohen517a7f52014-03-01 12:12:59 -08001990
Winson Chungd64d1762013-08-20 14:37:16 -07001991 // Clear the workspace because it's going to be rebound
Sunny Goyal2db53422019-03-01 16:06:12 -08001992 mDragController.cancelDrag();
1993
Adam Cohendf035382011-04-11 17:22:04 -07001994 mWorkspace.clearDropTargets();
Winson Chung9e6a0a22013-08-27 11:58:12 -07001995 mWorkspace.removeAllWorkspaceScreens();
Sunny Goyalc11fac32018-02-27 19:20:15 -08001996 mAppWidgetHost.clearViews();
Winson Chungd64d1762013-08-20 14:37:16 -07001997
Winson Chung3d503fb2011-07-13 17:25:49 -07001998 if (mHotseat != null) {
Sunny Goyalae6e3182019-04-30 12:04:37 -07001999 mHotseat.resetLayout(getWallpaperDeviceProfile().isVerticalBarLayout());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002000 }
Winson Chung5cc62c72019-10-16 11:32:41 -07002001 TraceHelper.INSTANCE.endSection(traceToken);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002002 }
2003
Adam Cohendcd297f2013-06-18 13:13:40 -07002004 @Override
Sunny Goyalefb7e842018-10-04 15:11:00 -07002005 public void bindScreens(IntArray orderedScreenIds) {
Sunny Goyalda4fe1a2016-05-26 16:05:17 -07002006 // Make sure the first screen is always at the start.
Jon Miranda7143ba62019-03-15 09:00:05 -07002007 if (FeatureFlags.QSB_ON_FIRST_SCREEN &&
Sunny Goyala9e2f5a2016-06-10 12:22:04 -07002008 orderedScreenIds.indexOf(Workspace.FIRST_SCREEN_ID) != 0) {
Sunny Goyalefb7e842018-10-04 15:11:00 -07002009 orderedScreenIds.removeValue(Workspace.FIRST_SCREEN_ID);
Sunny Goyalda4fe1a2016-05-26 16:05:17 -07002010 orderedScreenIds.add(0, Workspace.FIRST_SCREEN_ID);
Jon Miranda7143ba62019-03-15 09:00:05 -07002011 } else if (!FeatureFlags.QSB_ON_FIRST_SCREEN && orderedScreenIds.isEmpty()) {
Sunny Goyala9e2f5a2016-06-10 12:22:04 -07002012 // If there are no screens, we need to have an empty screen
2013 mWorkspace.addExtraEmptyScreen();
Adam Cohen5084cba2013-09-03 12:01:16 -07002014 }
Sunny Goyalda4fe1a2016-05-26 16:05:17 -07002015 bindAddScreens(orderedScreenIds);
Winson Chung0e6a7132013-08-23 12:55:10 -07002016
Winsonc7d2e832016-07-28 12:24:55 -07002017 // After we have added all the screens, if the wallpaper was locked to the default state,
2018 // then notify to indicate that it can be released and a proper wallpaper offset can be
2019 // computed before the next layout
2020 mWorkspace.unlockWallpaperFromDefaultPageOnNextLayout();
Winson Chung64359a52013-07-08 17:17:08 -07002021 }
2022
Sunny Goyalefb7e842018-10-04 15:11:00 -07002023 private void bindAddScreens(IntArray orderedScreenIds) {
Adam Cohendcd297f2013-06-18 13:13:40 -07002024 int count = orderedScreenIds.size();
2025 for (int i = 0; i < count; i++) {
Sunny Goyalefb7e842018-10-04 15:11:00 -07002026 int screenId = orderedScreenIds.get(i);
Jon Miranda7143ba62019-03-15 09:00:05 -07002027 if (!FeatureFlags.QSB_ON_FIRST_SCREEN || screenId != Workspace.FIRST_SCREEN_ID) {
Sunny Goyalda4fe1a2016-05-26 16:05:17 -07002028 // No need to bind the first screen, as its always bound.
2029 mWorkspace.insertNewWorkspaceScreenBeforeEmptyScreen(screenId);
2030 }
Adam Cohendcd297f2013-06-18 13:13:40 -07002031 }
Adam Cohendcd297f2013-06-18 13:13:40 -07002032 }
2033
Sunny Goyalb23980c2017-08-17 07:45:25 -07002034 @Override
Tony Wickham6a71a5b2018-08-21 11:40:23 -07002035 public void preAddApps() {
2036 // If there's an undo snackbar, force it to complete to ensure empty screens are removed
2037 // before trying to add new items.
2038 mModelWriter.commitDelete();
2039 AbstractFloatingView snackbar = AbstractFloatingView.getOpenView(this, TYPE_SNACKBAR);
2040 if (snackbar != null) {
2041 snackbar.post(() -> snackbar.close(true));
2042 }
2043 }
2044
2045 @Override
Sunny Goyalefb7e842018-10-04 15:11:00 -07002046 public void bindAppsAdded(IntArray newScreens, ArrayList<ItemInfo> addNotAnimated,
Sunny Goyal29947f02017-12-18 13:49:44 -08002047 ArrayList<ItemInfo> addAnimated) {
Winson Chungd64d1762013-08-20 14:37:16 -07002048 // Add the new screens
Adam Cohen76a47a12014-02-05 11:47:43 -08002049 if (newScreens != null) {
2050 bindAddScreens(newScreens);
2051 }
Winson Chungd64d1762013-08-20 14:37:16 -07002052
2053 // We add the items without animation on non-visible pages, and with
2054 // animations on the new page (which we will try and snap to).
Adam Cohen76a47a12014-02-05 11:47:43 -08002055 if (addNotAnimated != null && !addNotAnimated.isEmpty()) {
Sunny Goyalb23980c2017-08-17 07:45:25 -07002056 bindItems(addNotAnimated, false);
Winson Chungd64d1762013-08-20 14:37:16 -07002057 }
Adam Cohen76a47a12014-02-05 11:47:43 -08002058 if (addAnimated != null && !addAnimated.isEmpty()) {
Sunny Goyalb23980c2017-08-17 07:45:25 -07002059 bindItems(addAnimated, true);
Winson Chungd64d1762013-08-20 14:37:16 -07002060 }
Winson Chungc58497e2013-09-03 17:48:37 -07002061
Winson Chung87412982013-10-03 18:34:14 -07002062 // Remove the extra empty screen
Adam Cohen689ff162014-05-08 17:27:56 -07002063 mWorkspace.removeExtraEmptyScreen(false, false);
Winson Chungd64d1762013-08-20 14:37:16 -07002064 }
2065
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002066 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04002067 * Bind the items start-end from the list.
2068 *
2069 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002070 */
Tony Wickham0bb211a2015-10-02 16:22:08 -07002071 @Override
Sunny Goyalb23980c2017-08-17 07:45:25 -07002072 public void bindItems(final List<ItemInfo> items, final boolean forceAnimateIcons) {
Sunny Goyal3be633b2016-12-08 09:59:25 -08002073 // Get the list of added items and intersect them with the set of items here
Rajeev Kumar43c0f582017-06-23 15:34:55 -07002074 final Collection<Animator> bounceAnims = new ArrayList<>();
Winson Chung997a9232013-07-24 15:33:46 -07002075 final boolean animateIcons = forceAnimateIcons && canRunNewAppsAnimation();
Winson Chungf0c6ae02012-03-21 16:10:31 -07002076 Workspace workspace = mWorkspace;
Sunny Goyalefb7e842018-10-04 15:11:00 -07002077 int newItemsScreenId = -1;
Sunny Goyalb23980c2017-08-17 07:45:25 -07002078 int end = items.size();
2079 for (int i = 0; i < end; i++) {
Sunny Goyal3be633b2016-12-08 09:59:25 -08002080 final ItemInfo item = items.get(i);
Winson Chung4d279d92011-07-21 11:46:32 -07002081
2082 // Short circuit if we are loading dock items for a configuration which has no dock
2083 if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT &&
2084 mHotseat == null) {
2085 continue;
2086 }
2087
Sunny Goyal639e9062015-08-19 19:17:06 -07002088 final View view;
Joe Onorato9c1289c2009-08-17 11:03:03 -04002089 switch (item.itemType) {
2090 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
2091 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Sunny Goyal3be633b2016-12-08 09:59:25 -08002092 case LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT: {
Sunny Goyal95899162019-03-27 16:03:06 -07002093 WorkspaceItemInfo info = (WorkspaceItemInfo) item;
Sunny Goyal639e9062015-08-19 19:17:06 -07002094 view = createShortcut(info);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002095 break;
Sunny Goyal3be633b2016-12-08 09:59:25 -08002096 }
2097 case LauncherSettings.Favorites.ITEM_TYPE_FOLDER: {
Sunny Goyal639e9062015-08-19 19:17:06 -07002098 view = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07002099 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Sunny Goyal1cd01b02016-11-09 10:43:58 -08002100 (FolderInfo) item);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002101 break;
Sunny Goyal3be633b2016-12-08 09:59:25 -08002102 }
Sunny Goyal952e63d2017-08-16 04:59:08 -07002103 case LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET:
2104 case LauncherSettings.Favorites.ITEM_TYPE_CUSTOM_APPWIDGET: {
Sunny Goyala9a1a212017-08-18 01:03:21 -07002105 view = inflateAppWidget((LauncherAppWidgetInfo) item);
Sunny Goyalb23980c2017-08-17 07:45:25 -07002106 if (view == null) {
2107 continue;
Sunny Goyal3be633b2016-12-08 09:59:25 -08002108 }
Sunny Goyal3be633b2016-12-08 09:59:25 -08002109 break;
2110 }
Winson Chungc763c4e2013-07-19 13:49:06 -07002111 default:
2112 throw new RuntimeException("Invalid Item Type");
Joe Onorato9c1289c2009-08-17 11:03:03 -04002113 }
Sunny Goyal639e9062015-08-19 19:17:06 -07002114
Samuel Fufaca37b8a2019-08-19 17:04:36 -07002115 /*
Sunny Goyalda4fe1a2016-05-26 16:05:17 -07002116 * Remove colliding items.
2117 */
2118 if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
2119 CellLayout cl = mWorkspace.getScreenWithId(item.screenId);
2120 if (cl != null && cl.isOccupied(item.cellX, item.cellY)) {
2121 View v = cl.getChildAt(item.cellX, item.cellY);
2122 Object tag = v.getTag();
2123 String desc = "Collision while binding workspace item: " + item
2124 + ". Collides with " + tag;
Sunny Goyal3d706ad2017-03-06 16:56:39 -08002125 if (FeatureFlags.IS_DOGFOOD_BUILD) {
Sunny Goyalda4fe1a2016-05-26 16:05:17 -07002126 throw (new RuntimeException(desc));
2127 } else {
2128 Log.d(TAG, desc);
Sunny Goyal43bf11d2017-02-02 13:52:53 -08002129 getModelWriter().deleteItemFromDatabase(item);
Sunny Goyalda4fe1a2016-05-26 16:05:17 -07002130 continue;
2131 }
2132 }
2133 }
Sunny Goyald5462aa2016-11-22 16:52:39 +05302134 workspace.addInScreenFromBind(view, item);
Sunny Goyal639e9062015-08-19 19:17:06 -07002135 if (animateIcons) {
2136 // Animate all the applications up now
2137 view.setAlpha(0f);
2138 view.setScaleX(0f);
2139 view.setScaleY(0f);
2140 bounceAnims.add(createNewAppBounceAnimation(view, i));
Sunny Goyal3be633b2016-12-08 09:59:25 -08002141 newItemsScreenId = item.screenId;
Sunny Goyal639e9062015-08-19 19:17:06 -07002142 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002143 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07002144
Sunny Goyalf0b6db72018-08-13 16:10:14 -07002145 // Animate to the correct page
2146 if (animateIcons && newItemsScreenId > -1) {
2147 AnimatorSet anim = new AnimatorSet();
2148 anim.playTogether(bounceAnims);
Jon Miranda64eb8ea2018-03-29 11:43:58 -07002149
Sunny Goyalefb7e842018-10-04 15:11:00 -07002150 int currentScreenId = mWorkspace.getScreenIdForPageIndex(mWorkspace.getNextPage());
Sunny Goyalf0b6db72018-08-13 16:10:14 -07002151 final int newScreenIndex = mWorkspace.getPageIndexForScreenId(newItemsScreenId);
2152 final Runnable startBounceAnimRunnable = anim::start;
2153
2154 if (newItemsScreenId != currentScreenId) {
2155 // We post the animation slightly delayed to prevent slowdowns
2156 // when we are loading right after we return to launcher.
2157 mWorkspace.postDelayed(new Runnable() {
2158 public void run() {
2159 if (mWorkspace != null) {
2160 AbstractFloatingView.closeAllOpenViews(Launcher.this, false);
2161
2162 mWorkspace.snapToPage(newScreenIndex);
2163 mWorkspace.postDelayed(startBounceAnimRunnable,
2164 NEW_APPS_ANIMATION_DELAY);
Winson Chung94d67682013-09-25 16:29:40 -07002165 }
Sunny Goyalf0b6db72018-08-13 16:10:14 -07002166 }
2167 }, NEW_APPS_PAGE_MOVE_DELAY);
2168 } else {
2169 mWorkspace.postDelayed(startBounceAnimRunnable, NEW_APPS_ANIMATION_DELAY);
Winson Chung997a9232013-07-24 15:33:46 -07002170 }
Winson Chung64359a52013-07-08 17:17:08 -07002171 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04002172 workspace.requestLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002173 }
2174
Joe Onorato9c1289c2009-08-17 11:03:03 -04002175 /**
2176 * Add the views for a widget to the workspace.
Joe Onorato9c1289c2009-08-17 11:03:03 -04002177 */
Sunny Goyala9a1a212017-08-18 01:03:21 -07002178 public void bindAppWidget(LauncherAppWidgetInfo item) {
2179 View view = inflateAppWidget(item);
2180 if (view != null) {
2181 mWorkspace.addInScreen(view, item);
2182 mWorkspace.requestLayout();
2183 }
2184 }
2185
2186 private View inflateAppWidget(LauncherAppWidgetInfo item) {
Samuel Fufaca37b8a2019-08-19 17:04:36 -07002187 if (item.hasOptionFlag(LauncherAppWidgetInfo.OPTION_SEARCH_WIDGET)) {
2188 item.providerName = QsbContainerView.getSearchComponentName(this);
2189 if (item.providerName == null) {
2190 getModelWriter().deleteItemFromDatabase(item);
2191 return null;
2192 }
2193 }
Sunny Goyal17c72fb2019-10-14 14:06:38 -07002194 final AppWidgetHostView view;
Sunny Goyal2e1efb42016-03-03 16:58:55 -08002195 if (mIsSafeModeEnabled) {
Sunny Goyal17c72fb2019-10-14 14:06:38 -07002196 view = new PendingAppWidgetHostView(this, item, mIconCache, true);
Sunny Goyald5462aa2016-11-22 16:52:39 +05302197 prepareAppWidget(view, item);
Sunny Goyalb23980c2017-08-17 07:45:25 -07002198 return view;
Sunny Goyal2e1efb42016-03-03 16:58:55 -08002199 }
2200
Winson Chung5cc62c72019-10-16 11:32:41 -07002201 Object traceToken = TraceHelper.INSTANCE.beginSection("BIND_WIDGET_id=" + item.appWidgetId);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002202
Sunny Goyal17c72fb2019-10-14 14:06:38 -07002203 try {
2204 final LauncherAppWidgetProviderInfo appWidgetInfo;
Adam Cohen59400422014-03-05 18:07:04 -08002205
Sunny Goyal17c72fb2019-10-14 14:06:38 -07002206 if (item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_PROVIDER_NOT_READY)) {
2207 // If the provider is not ready, bind as a pending widget.
2208 appWidgetInfo = null;
2209 } else if (item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_ID_NOT_VALID)) {
2210 // The widget id is not valid. Try to find the widget based on the provider info.
2211 appWidgetInfo = mAppWidgetManager.findProvider(item.providerName, item.user);
2212 } else {
2213 appWidgetInfo = mAppWidgetManager.getLauncherAppWidgetInfo(item.appWidgetId);
Sunny Goyalff572272014-07-23 13:58:07 -07002214 }
Sunny Goyalff572272014-07-23 13:58:07 -07002215
Sunny Goyal17c72fb2019-10-14 14:06:38 -07002216 // If the provider is ready, but the width is not yet restored, try to restore it.
2217 if (!item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_PROVIDER_NOT_READY)
2218 && (item.restoreStatus != LauncherAppWidgetInfo.RESTORE_COMPLETED)) {
2219 if (appWidgetInfo == null) {
2220 Log.d(TAG, "Removing restored widget: id=" + item.appWidgetId
2221 + " belongs to component " + item.providerName
2222 + ", as the provider is null");
2223 getModelWriter().deleteItemFromDatabase(item);
2224 return null;
2225 }
Sunny Goyalff572272014-07-23 13:58:07 -07002226
Sunny Goyal17c72fb2019-10-14 14:06:38 -07002227 // If we do not have a valid id, try to bind an id.
2228 if (item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_ID_NOT_VALID)) {
2229 if (!item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_ID_ALLOCATED)) {
2230 // Id has not been allocated yet. Allocate a new id.
2231 item.appWidgetId = mAppWidgetHost.allocateAppWidgetId();
2232 item.restoreStatus |= LauncherAppWidgetInfo.FLAG_ID_ALLOCATED;
Sunny Goyal86df1382016-08-10 15:03:22 -07002233
Sunny Goyal17c72fb2019-10-14 14:06:38 -07002234 // Also try to bind the widget. If the bind fails, the user will be shown
2235 // a click to setup UI, which will ask for the bind permission.
2236 PendingAddWidgetInfo pendingInfo = new PendingAddWidgetInfo(appWidgetInfo);
2237 pendingInfo.spanX = item.spanX;
2238 pendingInfo.spanY = item.spanY;
2239 pendingInfo.minSpanX = item.minSpanX;
2240 pendingInfo.minSpanY = item.minSpanY;
2241 Bundle options = WidgetHostViewLoader.getDefaultOptionsForWidget(this,
2242 pendingInfo);
2243
2244 boolean isDirectConfig =
2245 item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_DIRECT_CONFIG);
2246 if (isDirectConfig && item.bindOptions != null) {
2247 Bundle newOptions = item.bindOptions.getExtras();
2248 if (options != null) {
2249 newOptions.putAll(options);
2250 }
2251 options = newOptions;
Sunny Goyal86df1382016-08-10 15:03:22 -07002252 }
Sunny Goyal17c72fb2019-10-14 14:06:38 -07002253 boolean success = mAppWidgetManager.bindAppWidgetIdIfAllowed(
2254 item.appWidgetId, appWidgetInfo, options);
2255
2256 // We tried to bind once. If we were not able to bind, we would need to
2257 // go through the permission dialog, which means we cannot skip the config
2258 // activity.
2259 item.bindOptions = null;
2260 item.restoreStatus &= ~LauncherAppWidgetInfo.FLAG_DIRECT_CONFIG;
2261
2262 // Bind succeeded
2263 if (success) {
2264 // If the widget has a configure activity, it is still needs to set it
2265 // up, otherwise the widget is ready to go.
2266 item.restoreStatus = (appWidgetInfo.configure == null) || isDirectConfig
2267 ? LauncherAppWidgetInfo.RESTORE_COMPLETED
2268 : LauncherAppWidgetInfo.FLAG_UI_NOT_READY;
2269 }
2270
2271 getModelWriter().updateItemInDatabase(item);
Sunny Goyal86df1382016-08-10 15:03:22 -07002272 }
Sunny Goyal17c72fb2019-10-14 14:06:38 -07002273 } else if (item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_UI_NOT_READY)
2274 && (appWidgetInfo.configure == null)) {
2275 // The widget was marked as UI not ready, but there is no configure activity to
2276 // update the UI.
2277 item.restoreStatus = LauncherAppWidgetInfo.RESTORE_COMPLETED;
Sunny Goyal43bf11d2017-02-02 13:52:53 -08002278 getModelWriter().updateItemInDatabase(item);
Sunny Goyalff572272014-07-23 13:58:07 -07002279 }
Sunny Goyal56c73602015-09-25 12:55:01 -07002280 }
2281
Sunny Goyal17c72fb2019-10-14 14:06:38 -07002282 if (item.restoreStatus == LauncherAppWidgetInfo.RESTORE_COMPLETED) {
2283 // Verify that we own the widget
2284 if (appWidgetInfo == null) {
2285 FileLog.e(TAG, "Removing invalid widget: id=" + item.appWidgetId);
2286 getModelWriter().deleteWidgetInfo(item, getAppWidgetHost());
2287 return null;
2288 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04002289
Sunny Goyal17c72fb2019-10-14 14:06:38 -07002290 item.minSpanX = appWidgetInfo.minSpanX;
2291 item.minSpanY = appWidgetInfo.minSpanY;
2292 view = mAppWidgetHost.createView(this, item.appWidgetId, appWidgetInfo);
2293 } else {
2294 view = new PendingAppWidgetHostView(this, item, mIconCache, false);
2295 }
2296 prepareAppWidget(view, item);
2297 } finally {
Winson Chung5cc62c72019-10-16 11:32:41 -07002298 TraceHelper.INSTANCE.endSection(traceToken);
Sunny Goyal17c72fb2019-10-14 14:06:38 -07002299 }
2300
Sunny Goyalb23980c2017-08-17 07:45:25 -07002301 return view;
Joe Onorato9c1289c2009-08-17 11:03:03 -04002302 }
2303
Sunny Goyalff572272014-07-23 13:58:07 -07002304 /**
2305 * Restores a pending widget.
2306 *
2307 * @param appWidgetId The app widget id
Sunny Goyalff572272014-07-23 13:58:07 -07002308 */
Sunny Goyald478c832016-04-01 12:04:16 -07002309 private LauncherAppWidgetInfo completeRestoreAppWidget(int appWidgetId, int finalRestoreFlag) {
Sunny Goyalff572272014-07-23 13:58:07 -07002310 LauncherAppWidgetHostView view = mWorkspace.getWidgetForAppWidgetId(appWidgetId);
2311 if ((view == null) || !(view instanceof PendingAppWidgetHostView)) {
2312 Log.e(TAG, "Widget update called, when the widget no longer exists.");
Sunny Goyald478c832016-04-01 12:04:16 -07002313 return null;
Sunny Goyalff572272014-07-23 13:58:07 -07002314 }
2315
Sunny Goyal0fc1be12014-08-11 17:05:23 -07002316 LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) view.getTag();
Sunny Goyald478c832016-04-01 12:04:16 -07002317 info.restoreStatus = finalRestoreFlag;
Jon Miranda2b823f42017-05-02 18:36:18 -07002318 if (info.restoreStatus == LauncherAppWidgetInfo.RESTORE_COMPLETED) {
2319 info.pendingItemInfo = null;
2320 }
Sunny Goyalff572272014-07-23 13:58:07 -07002321
Sunny Goyalba47faa2017-10-04 16:50:57 -07002322 if (((PendingAppWidgetHostView) view).isReinflateIfNeeded()) {
Sunny Goyal29947f02017-12-18 13:49:44 -08002323 view.reInflate();
Sunny Goyalba47faa2017-10-04 16:50:57 -07002324 }
2325
Sunny Goyal43bf11d2017-02-02 13:52:53 -08002326 getModelWriter().updateItemInDatabase(info);
Sunny Goyald478c832016-04-01 12:04:16 -07002327 return info;
Sunny Goyalff572272014-07-23 13:58:07 -07002328 }
2329
Adam Cohen1462de32012-07-24 22:34:36 -07002330 public void onPageBoundSynchronously(int page) {
Sunny Goyalf4aceab2017-12-06 16:16:31 -08002331 mSynchronouslyBoundPage = page;
Adam Cohen1462de32012-07-24 22:34:36 -07002332 }
2333
Sunny Goyal527c7d32015-08-28 15:19:36 -07002334 @Override
2335 public void executeOnNextDraw(ViewOnDrawExecutor executor) {
Sunny Goyal6b6d0a32019-08-05 17:19:32 -07002336 clearPendingBinds();
Sunny Goyal527c7d32015-08-28 15:19:36 -07002337 mPendingExecutor = executor;
Sunny Goyal60180b02018-02-07 12:56:30 -08002338 if (!isInState(ALL_APPS)) {
vadimtd4c90e12019-06-04 13:59:43 -07002339 mAppsView.getAppsStore().enableDeferUpdates(AllAppsStore.DEFER_UPDATES_NEXT_DRAW);
2340 mPendingExecutor.execute(() -> mAppsView.getAppsStore().disableDeferUpdates(
2341 AllAppsStore.DEFER_UPDATES_NEXT_DRAW));
Sunny Goyal60180b02018-02-07 12:56:30 -08002342 }
2343
Sunny Goyal527c7d32015-08-28 15:19:36 -07002344 executor.attachTo(this);
2345 }
2346
2347 public void clearPendingExecutor(ViewOnDrawExecutor executor) {
2348 if (mPendingExecutor == executor) {
2349 mPendingExecutor = null;
2350 }
2351 }
2352
Sunny Goyalb5b9ad62016-04-02 11:23:39 -07002353 @Override
2354 public void finishFirstPageBind(final ViewOnDrawExecutor executor) {
Sunny Goyal6001ea22018-05-10 16:31:00 -07002355 AlphaProperty property = mDragLayer.getAlphaProperty(ALPHA_INDEX_LAUNCHER_LOAD);
2356 if (property.getValue() < 1) {
2357 ObjectAnimator anim = ObjectAnimator.ofFloat(property, MultiValueAlpha.VALUE, 1);
2358 if (executor != null) {
2359 anim.addListener(new AnimatorListenerAdapter() {
2360 @Override
2361 public void onAnimationEnd(Animator animation) {
2362 executor.onLoadAnimationCompleted();
2363 }
2364 });
2365 }
2366 anim.start();
Sunny Goyal29947f02017-12-18 13:49:44 -08002367 } else if (executor != null) {
2368 executor.onLoadAnimationCompleted();
Sunny Goyalb5b9ad62016-04-02 11:23:39 -07002369 }
2370 }
2371
Joe Onorato9c1289c2009-08-17 11:03:03 -04002372 /**
2373 * Callback saying that there aren't any more items to bind.
2374 *
2375 * Implementation of the method from LauncherModel.Callbacks.
2376 */
Tonyf80e8932018-12-21 11:58:04 -08002377 public void finishBindingItems(int pageBoundFirst) {
Winson Chung5cc62c72019-10-16 11:32:41 -07002378 Object traceToken = TraceHelper.INSTANCE.beginSection("finishBindingItems");
Adam Cohen1462de32012-07-24 22:34:36 -07002379 mWorkspace.restoreInstanceStateForRemainingPages();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002380
Anjali Koppalff7ceff2014-05-01 18:26:37 -07002381 setWorkspaceLoading(false);
Adam Cohendb364c32014-05-20 14:23:40 -07002382
Sunny Goyal2100c782016-08-22 16:00:03 -07002383 if (mPendingActivityResult != null) {
2384 handleActivityResult(mPendingActivityResult.requestCode,
2385 mPendingActivityResult.resultCode, mPendingActivityResult.data);
2386 mPendingActivityResult = null;
Adam Cohendb364c32014-05-20 14:23:40 -07002387 }
2388
Sunny Goyala474a9b2017-05-04 16:47:11 -07002389 InstallShortcutReceiver.disableAndFlushInstallQueue(
2390 InstallShortcutReceiver.FLAG_LOADER_RUNNING, this);
Adam Cohen9211d422014-10-07 18:14:53 -07002391
Tonyf80e8932018-12-21 11:58:04 -08002392 // When undoing the removal of the last item on a page, return to that page.
Tony Wickham03f27012019-04-25 14:22:54 -07002393 // Since we are just resetting the current page without user interaction,
2394 // override the previous page so we don't log the page switch.
2395 mWorkspace.setCurrentPage(pageBoundFirst, pageBoundFirst /* overridePrevPage */);
Tony Wickham6a71a5b2018-08-21 11:40:23 -07002396
Sunny Goyalac6f69f2019-08-16 11:59:55 -07002397 // Cache one page worth of icons
2398 getViewCache().setCacheSize(R.layout.folder_application,
2399 mDeviceProfile.inv.numFolderColumns * mDeviceProfile.inv.numFolderRows);
2400 getViewCache().setCacheSize(R.layout.folder_page, 2);
2401
Winson Chung5cc62c72019-10-16 11:32:41 -07002402 TraceHelper.INSTANCE.endSection(traceToken);
Winson Chungf0c6ae02012-03-21 16:10:31 -07002403 }
2404
Winson Chunga2413752012-04-03 14:22:34 -07002405 private boolean canRunNewAppsAnimation() {
2406 long diff = System.currentTimeMillis() - mDragController.getLastGestureUpTime();
Andrew Sapperstein932eb832016-06-30 18:10:09 -07002407 return diff > (NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS * 1000);
Winson Chunga2413752012-04-03 14:22:34 -07002408 }
2409
Winson Chungc9168342013-06-26 14:54:55 -07002410 private ValueAnimator createNewAppBounceAnimation(View v, int i) {
Sunny Goyalf0b6db72018-08-13 16:10:14 -07002411 ValueAnimator bounceAnim = new PropertyListBuilder().alpha(1).scale(1).build(v)
2412 .setDuration(InstallShortcutReceiver.NEW_SHORTCUT_BOUNCE_DURATION);
Winson Chungc9168342013-06-26 14:54:55 -07002413 bounceAnim.setStartDelay(i * InstallShortcutReceiver.NEW_SHORTCUT_STAGGER_DELAY);
Sunny Goyal5a1f53b2015-05-27 10:24:24 -07002414 bounceAnim.setInterpolator(new OvershootInterpolator(BOUNCE_ANIMATION_TENSION));
Winson Chungc9168342013-06-26 14:54:55 -07002415 return bounceAnim;
2416 }
2417
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002418 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04002419 * Add the icons for all apps.
2420 *
2421 * Implementation of the method from LauncherModel.Callbacks.
2422 */
Sunny Goyal87dcde62019-07-17 20:35:56 -07002423 public void bindAllApplications(AppInfo[] apps) {
Sunny Goyal60180b02018-02-07 12:56:30 -08002424 mAppsView.getAppsStore().setApps(apps);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002425 }
2426
2427 /**
Zak Cohen658c67a2018-10-19 14:21:05 -07002428 * Copies LauncherModel's map of activities to shortcut counts to Launcher's. This is necessary
Tony Wickhambfbf7f92016-05-19 11:19:39 -07002429 * because LauncherModel's map is updated in the background, while Launcher runs on the UI.
2430 */
2431 @Override
Zak Cohen658c67a2018-10-19 14:21:05 -07002432 public void bindDeepShortcutMap(HashMap<ComponentKey, Integer> deepShortcutMapCopy) {
Tony Wickham010d2552017-01-20 08:15:28 -08002433 mPopupDataProvider.setDeepShortcutMap(deepShortcutMapCopy);
Tony Wickham1bce7fd2016-04-28 17:39:03 -07002434 }
2435
Sunny Goyal4390ace2014-10-13 11:33:11 -07002436 @Override
Sunny Goyal29947f02017-12-18 13:49:44 -08002437 public void bindPromiseAppProgressUpdated(PromiseAppInfo app) {
Sunny Goyal60180b02018-02-07 12:56:30 -08002438 mAppsView.getAppsStore().updatePromiseAppProgress(app);
Mario Bertschler08ffaae2017-03-20 11:30:27 -07002439 }
2440
2441 @Override
Sunny Goyal29947f02017-12-18 13:49:44 -08002442 public void bindWidgetsRestored(ArrayList<LauncherAppWidgetInfo> widgets) {
Sunny Goyal4390ace2014-10-13 11:33:11 -07002443 mWorkspace.widgetsRestored(widgets);
2444 }
2445
Joe Onorato9c1289c2009-08-17 11:03:03 -04002446 /**
Sunny Goyalb50cc8c2014-10-06 16:23:56 -07002447 * Some shortcuts were updated in the background.
Sunny Goyalb50cc8c2014-10-06 16:23:56 -07002448 * Implementation of the method from LauncherModel.Callbacks.
Sunny Goyald3b87ef2016-07-28 12:11:54 -07002449 *
2450 * @param updated list of shortcuts which have changed.
Sunny Goyalb50cc8c2014-10-06 16:23:56 -07002451 */
Sunny Goyal4390ace2014-10-13 11:33:11 -07002452 @Override
Sunny Goyal95899162019-03-27 16:03:06 -07002453 public void bindWorkspaceItemsChanged(ArrayList<WorkspaceItemInfo> updated) {
Sunny Goyal4390ace2014-10-13 11:33:11 -07002454 if (!updated.isEmpty()) {
2455 mWorkspace.updateShortcuts(updated);
2456 }
Sunny Goyalb50cc8c2014-10-06 16:23:56 -07002457 }
2458
2459 /**
Chris Wrenaeff7ea2014-02-14 16:59:24 -05002460 * Update the state of a package, typically related to install state.
2461 *
2462 * Implementation of the method from LauncherModel.Callbacks.
2463 */
Sunny Goyale755d462014-07-22 13:48:29 -07002464 @Override
Sunny Goyal29947f02017-12-18 13:49:44 -08002465 public void bindRestoreItemsChange(HashSet<ItemInfo> updates) {
Sunny Goyal756adbc2015-04-16 15:20:51 -07002466 mWorkspace.updateRestoreItems(updates);
Sunny Goyala22666f2014-09-18 13:25:15 -07002467 }
2468
2469 /**
Sunny Goyal3bbbabc2016-03-15 09:16:30 -07002470 * A package was uninstalled/updated. We take both the super set of packageNames
Winson Chung83892cc2013-05-01 16:53:33 -07002471 * in addition to specific applications to remove, the reason being that
2472 * this can be called when a package is updated as well. In that scenario,
Sunny Goyal3bbbabc2016-03-15 09:16:30 -07002473 * we only remove specific components from the workspace and hotseat, where as
Winson Chung83892cc2013-05-01 16:53:33 -07002474 * package-removal should clear all items by package name.
Joe Onorato9c1289c2009-08-17 11:03:03 -04002475 */
Sunny Goyal1a745e82014-10-02 15:58:31 -07002476 @Override
Sunny Goyal6e13dd32017-08-17 03:01:19 -07002477 public void bindWorkspaceComponentsRemoved(final ItemInfoMatcher matcher) {
Sunny Goyal6e13dd32017-08-17 03:01:19 -07002478 mWorkspace.removeItemsByMatcher(matcher);
2479 mDragController.onAppsRemoved(matcher);
Sunny Goyal3bbbabc2016-03-15 09:16:30 -07002480 }
Sunny Goyal4390ace2014-10-13 11:33:11 -07002481
Sunny Goyal3bbbabc2016-03-15 09:16:30 -07002482 @Override
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -07002483 public void bindAllWidgets(final ArrayList<WidgetListRowEntry> allWidgets) {
2484 mPopupDataProvider.setAllWidgets(allWidgets);
Tony Wickham26b17462017-03-20 17:12:24 -07002485 }
2486
Tony Wickham86222d22017-03-29 15:30:43 -07002487 /**
2488 * @param packageUser if null, refreshes all widgets and shortcuts, otherwise only
2489 * refreshes the widgets and shortcuts associated with the given package/user
2490 */
2491 public void refreshAndBindWidgetsForPackageUser(@Nullable PackageUserKey packageUser) {
Sunny Goyalc6e97692017-06-02 13:46:55 -07002492 mModel.refreshAndBindWidgetsAndShortcuts(packageUser);
Sunny Goyal2e1efb42016-03-03 16:58:55 -08002493 }
2494
Winson Chung80baf5a2010-08-09 16:03:15 -07002495 /**
Hyunyoung Song3c7d9cb2017-01-30 15:11:27 -08002496 * $ adb shell dumpsys activity com.android.launcher3.Launcher [--all]
Joe Onoratobe386092009-11-17 17:32:16 -08002497 */
Adam Cohen16d7ffc2011-10-05 17:49:14 -07002498 @Override
2499 public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
2500 super.dump(prefix, fd, writer, args);
Sunny Goyala1365452015-10-01 15:46:24 -07002501
Hyunyoung Song3c7d9cb2017-01-30 15:11:27 -08002502 if (args.length > 0 && TextUtils.equals(args[0], "--all")) {
2503 writer.println(prefix + "Workspace Items");
Sunny Goyal7ce471b2017-08-02 03:37:39 -07002504 for (int i = 0; i < mWorkspace.getPageCount(); i++) {
Hyunyoung Song3c7d9cb2017-01-30 15:11:27 -08002505 writer.println(prefix + " Homescreen " + i);
2506
2507 ViewGroup layout = ((CellLayout) mWorkspace.getPageAt(i)).getShortcutsAndWidgets();
2508 for (int j = 0; j < layout.getChildCount(); j++) {
2509 Object tag = layout.getChildAt(j).getTag();
2510 if (tag != null) {
2511 writer.println(prefix + " " + tag.toString());
2512 }
2513 }
2514 }
2515
2516 writer.println(prefix + " Hotseat");
Sunny Goyal876e4622018-11-02 13:50:40 -07002517 ViewGroup layout = mHotseat.getShortcutsAndWidgets();
Sunny Goyala1365452015-10-01 15:46:24 -07002518 for (int j = 0; j < layout.getChildCount(); j++) {
2519 Object tag = layout.getChildAt(j).getTag();
2520 if (tag != null) {
2521 writer.println(prefix + " " + tag.toString());
2522 }
Adam Cohen4caf2982013-08-20 18:54:31 -07002523 }
Sunny Goyala1365452015-10-01 15:46:24 -07002524 }
2525
Hyunyoung Song3c7d9cb2017-01-30 15:11:27 -08002526 writer.println(prefix + "Misc:");
Winson Chungef528762019-09-06 12:05:52 -07002527 dumpMisc(prefix + "\t", writer);
2528 writer.println(prefix + "\tmWorkspaceLoading=" + mWorkspaceLoading);
2529 writer.println(prefix + "\tmPendingRequestArgs=" + mPendingRequestArgs
2530 + " mPendingActivityResult=" + mPendingActivityResult);
2531 writer.println(prefix + "\tmRotationHelper: " + mRotationHelper);
2532 writer.println(prefix + "\tmAppWidgetHost.isListening: " + mAppWidgetHost.isListening());
2533
Sunny Goyalcb2c5052018-10-15 12:30:29 -07002534 // Extra logging for b/116853349
Hyunyoung Songa310a802019-04-25 13:57:16 -07002535 mDragLayer.dump(prefix, writer);
2536 mStateManager.dump(prefix, writer);
Sunny Goyal2bba1902018-02-27 12:20:50 -08002537
2538 try {
2539 FileLog.flushAll(writer);
2540 } catch (Exception e) {
2541 // Ignore
2542 }
Hyunyoung Song3c7d9cb2017-01-30 15:11:27 -08002543
2544 mModel.dumpState(prefix, fd, writer, args);
Sunny Goyala1365452015-10-01 15:46:24 -07002545
Adam Cohen9211d422014-10-07 18:14:53 -07002546 if (mLauncherCallbacks != null) {
2547 mLauncherCallbacks.dump(prefix, fd, writer, args);
2548 }
Sunny Goyalb1d7de22019-09-06 10:36:54 -07002549 mOverlayManager.dump(prefix, writer);
Adam Cohen16d7ffc2011-10-05 17:49:14 -07002550 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07002551
Sunny Goyal66b24572016-09-21 15:57:55 -07002552 @Override
Sunny Goyal66b24572016-09-21 15:57:55 -07002553 public void onProvideKeyboardShortcuts(
2554 List<KeyboardShortcutGroup> data, Menu menu, int deviceId) {
2555
2556 ArrayList<KeyboardShortcutInfo> shortcutInfos = new ArrayList<>();
Sunny Goyal3e3f44c2017-10-23 17:14:52 -07002557 if (isInState(NORMAL)) {
Sunny Goyal66b24572016-09-21 15:57:55 -07002558 shortcutInfos.add(new KeyboardShortcutInfo(getString(R.string.all_apps_button_label),
2559 KeyEvent.KEYCODE_A, KeyEvent.META_CTRL_ON));
Vadim Tryshev74c261c2018-06-12 13:44:43 -07002560 shortcutInfos.add(new KeyboardShortcutInfo(getString(R.string.widget_button_text),
2561 KeyEvent.KEYCODE_W, KeyEvent.META_CTRL_ON));
Sunny Goyal66b24572016-09-21 15:57:55 -07002562 }
Vadim Tryshev3455f8d2018-05-11 20:02:20 -07002563 final View currentFocus = getCurrentFocus();
2564 if (currentFocus != null) {
2565 if (new CustomActionsPopup(this, currentFocus).canShow()) {
2566 shortcutInfos.add(new KeyboardShortcutInfo(getString(R.string.custom_actions),
2567 KeyEvent.KEYCODE_O, KeyEvent.META_CTRL_ON));
2568 }
2569 if (currentFocus.getTag() instanceof ItemInfo
Pinyao Ting49a3e692019-07-26 12:28:38 -07002570 && ShortcutUtil.supportsShortcuts((ItemInfo) currentFocus.getTag())) {
Vadim Tryshev3455f8d2018-05-11 20:02:20 -07002571 shortcutInfos.add(new KeyboardShortcutInfo(
2572 getString(R.string.shortcuts_menu_with_notifications_description),
2573 KeyEvent.KEYCODE_S, KeyEvent.META_CTRL_ON));
2574 }
Sunny Goyal66b24572016-09-21 15:57:55 -07002575 }
2576 if (!shortcutInfos.isEmpty()) {
2577 data.add(new KeyboardShortcutGroup(getString(R.string.home_screen), shortcutInfos));
2578 }
2579
2580 super.onProvideKeyboardShortcuts(data, menu, deviceId);
2581 }
2582
2583 @Override
2584 public boolean onKeyShortcut(int keyCode, KeyEvent event) {
2585 if (event.hasModifiers(KeyEvent.META_CTRL_ON)) {
2586 switch (keyCode) {
2587 case KeyEvent.KEYCODE_A:
Sunny Goyal3e3f44c2017-10-23 17:14:52 -07002588 if (isInState(NORMAL)) {
2589 getStateManager().goToState(ALL_APPS);
Sunny Goyal66b24572016-09-21 15:57:55 -07002590 return true;
2591 }
2592 break;
2593 case KeyEvent.KEYCODE_S: {
2594 View focusedView = getCurrentFocus();
2595 if (focusedView instanceof BubbleTextView
2596 && focusedView.getTag() instanceof ItemInfo
2597 && mAccessibilityDelegate.performAction(focusedView,
Samuel Fufaca37b8a2019-08-19 17:04:36 -07002598 (ItemInfo) focusedView.getTag(),
2599 LauncherAccessibilityDelegate.DEEP_SHORTCUTS)) {
Sunny Goyal00ac9202017-11-09 15:24:06 -08002600 PopupContainerWithArrow.getOpen(this).requestFocus();
Sunny Goyal66b24572016-09-21 15:57:55 -07002601 return true;
2602 }
2603 break;
2604 }
2605 case KeyEvent.KEYCODE_O:
2606 if (new CustomActionsPopup(this, getCurrentFocus()).show()) {
2607 return true;
2608 }
2609 break;
Vadim Tryshev74c261c2018-06-12 13:44:43 -07002610 case KeyEvent.KEYCODE_W:
2611 if (isInState(NORMAL)) {
2612 OptionsPopupView.openWidgets(this);
2613 return true;
2614 }
2615 break;
Sunny Goyal66b24572016-09-21 15:57:55 -07002616 }
2617 }
2618 return super.onKeyShortcut(keyCode, event);
2619 }
2620
Vadim Tryshev646a0dd2018-02-05 16:27:50 -08002621 @Override
2622 public boolean onKeyUp(int keyCode, KeyEvent event) {
2623 if (keyCode == KeyEvent.KEYCODE_MENU) {
2624 // KEYCODE_MENU is sent by some tests, for example
2625 // LauncherJankTests#testWidgetsContainerFling. Don't just remove its handling.
2626 if (!mDragController.isDragging() && !mWorkspace.isSwitchingState() &&
2627 isInState(NORMAL)) {
2628 // Close any open floating views.
2629 AbstractFloatingView.closeAllOpenViews(this);
2630
2631 // Setting the touch point to (-1, -1) will show the options popup in the center of
2632 // the screen.
Sunny Goyal2fd7a8b2018-03-30 17:10:13 -07002633 OptionsPopupView.showDefaultOptions(this, -1, -1);
Vadim Tryshev646a0dd2018-02-05 16:27:50 -08002634 }
2635 return true;
2636 }
2637 return super.onKeyUp(keyCode, event);
2638 }
2639
Sunny Goyal210e1742019-10-17 12:05:38 -07002640 protected StateHandler[] createStateHandlers() {
2641 return new StateHandler[] { getAllAppsController(), getWorkspace() };
Andrew Sappersteinabef55a2016-06-19 12:49:00 -07002642 }
2643
Sunny Goyal210e1742019-10-17 12:05:38 -07002644 public TouchController[] createTouchControllers() {
2645 return new TouchController[] {getDragController(), new AllAppsSwipeController(this)};
2646 }
2647
2648 protected RotationMode getFakeRotationMode(DeviceProfile deviceProfile) {
2649 return RotationMode.NORMAL;
2650 }
2651
2652 protected ScaleAndTranslation getOverviewScaleAndTranslationForNormalState() {
2653 return new ScaleAndTranslation(1.1f, 0f, 0f);
2654 }
2655
2656 public void useFadeOutAnimationForLauncherStart(CancellationSignal signal) { }
2657
2658 public void onDragLayerHierarchyChanged() { }
2659
Vinit Nayakf9b585b2019-07-10 14:25:32 -07002660 @Override
2661 public void returnToHomescreen() {
2662 super.returnToHomescreen();
2663 getStateManager().goToState(LauncherState.NORMAL);
2664 }
2665
Sunny Goyal3a1eadd2019-10-23 17:44:27 -07002666 public Stream<SystemShortcut.Factory> getSupportedShortcuts() {
2667 return Stream.of(APP_INFO, WIDGETS, INSTALL, DISMISS_PREDICTION);
2668 }
2669
Sunny Goyal210e1742019-10-17 12:05:38 -07002670 public static Launcher getLauncher(Context context) {
2671 return (Launcher) fromContext(context);
2672 }
2673
Sunny Goyal3dce5f32017-10-05 11:40:05 -07002674 /**
Sunny Goyalab770a12018-11-14 15:17:26 -08002675 * Just a wrapper around the type cast to allow easier tracking of calls.
2676 */
2677 public static <T extends Launcher> T cast(ActivityContext activityContext) {
2678 return (T) activityContext;
2679 }
2680
2681 /**
Sunny Goyal3dce5f32017-10-05 11:40:05 -07002682 * Callback for listening for onResume
2683 */
2684 public interface OnResumeCallback {
2685
2686 void onLauncherResume();
2687 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002688}