blob: a19ba21a48496a915564863c0c7f93f95007fbfc [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 Goyalbe8c3402019-05-22 15:17:52 -070034import static com.android.launcher3.states.RotationHelper.REQUEST_NONE;
Sunny Goyal326403e2017-10-02 12:45:10 -070035
Gilles Debunnedd6c9922010-10-25 11:23:41 -070036import android.animation.Animator;
Sunny Goyal6001ea22018-05-10 16:31:00 -070037import android.animation.AnimatorListenerAdapter;
Gilles Debunnedd6c9922010-10-25 11:23:41 -070038import android.animation.AnimatorSet;
Sunny Goyal6001ea22018-05-10 16:31:00 -070039import android.animation.ObjectAnimator;
Gilles Debunnedd6c9922010-10-25 11:23:41 -070040import android.animation.ValueAnimator;
Adam Cohen0b395352014-06-09 22:54:36 +000041import android.annotation.TargetApi;
Tony Wickham005df0b2018-02-13 11:28:12 -080042import android.app.ActivityOptions;
Adam Cohen0cf2a7c2011-11-08 15:07:01 -080043import android.appwidget.AppWidgetHostView;
Michael Jurkaaf442092010-06-10 17:01:57 -070044import android.appwidget.AppWidgetManager;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080045import android.content.ActivityNotFoundException;
Joe Onorato2ca0ae72009-11-10 13:14:13 -080046import android.content.BroadcastReceiver;
Michael Jurkae326f182011-11-21 14:05:46 -080047import android.content.ComponentCallbacks2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080048import android.content.Context;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080049import android.content.Intent;
Winson Chungf0ea4d32011-06-06 14:27:16 -070050import android.content.IntentFilter;
Adam Cohen173f7112015-03-27 15:14:00 -070051import android.content.IntentSender;
Winson Chung82f55532011-08-09 14:14:23 -070052import android.content.SharedPreferences;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080053import android.content.pm.PackageManager;
Sunny Goyalf8d56fc2018-01-31 15:18:11 -080054import android.content.res.Configuration;
Adam Cohen3f9c9712014-10-31 11:48:25 -070055import android.database.sqlite.SQLiteDatabase;
Sunny Goyal59d086c2018-05-07 17:31:40 -070056import android.graphics.Point;
Sunny Goyalae6e3182019-04-30 12:04:37 -070057import android.graphics.Rect;
Adam Cohen0f668f32014-09-08 19:54:17 +020058import android.os.Build;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080059import android.os.Bundle;
Hyunyoung Songbd6fba92018-05-16 15:54:31 -070060import android.os.Handler;
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -070061import android.os.Parcelable;
Sunny Goyal7c74e4a2016-12-15 15:53:17 -080062import android.os.Process;
Winson Chunga2413752012-04-03 14:22:34 -070063import android.os.StrictMode;
Michael Jurkaa33411c2012-06-14 16:18:21 -070064import android.text.TextUtils;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080065import android.text.method.TextKeyListener;
Joe Onorato7c312c12009-08-13 21:36:53 -070066import android.util.Log;
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -070067import android.util.SparseArray;
Sunny Goyal59d086c2018-05-07 17:31:40 -070068import android.view.Display;
Adam Cohen96d30a12013-07-16 18:13:21 -070069import android.view.KeyEvent;
Sunny Goyal66b24572016-09-21 15:57:55 -070070import android.view.KeyboardShortcutGroup;
71import android.view.KeyboardShortcutInfo;
Sunny Goyal9b29ca52017-02-17 10:39:44 -080072import android.view.LayoutInflater;
Adam Cohen96d30a12013-07-16 18:13:21 -070073import android.view.Menu;
Adam Cohen96d30a12013-07-16 18:13:21 -070074import android.view.View;
Adam Cohen96d30a12013-07-16 18:13:21 -070075import android.view.ViewGroup;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -080076import android.view.accessibility.AccessibilityEvent;
Sunny Goyal5a1f53b2015-05-27 10:24:24 -070077import android.view.animation.OvershootInterpolator;
Adam Cohen96d30a12013-07-16 18:13:21 -070078import android.widget.Toast;
Sunny Goyala1d1bf32015-06-26 13:24:53 -070079
Sunny Goyal11a50742019-08-07 09:24:26 -070080import androidx.annotation.Nullable;
Sunny Goyalb1d7de22019-09-06 10:36:54 -070081import androidx.annotation.VisibleForTesting;
Sunny Goyal11a50742019-08-07 09:24:26 -070082
Sunny Goyal651077b2014-06-30 14:15:31 -070083import com.android.launcher3.DropTarget.DragObject;
Sunny Goyalae502842016-06-17 08:43:56 -070084import com.android.launcher3.accessibility.LauncherAccessibilityDelegate;
Winson Chung5f4e0fd2015-05-22 11:12:27 -070085import com.android.launcher3.allapps.AllAppsContainerView;
vadimtd4c90e12019-06-04 13:59:43 -070086import com.android.launcher3.allapps.AllAppsStore;
Hyunyoung Song645764e2016-06-06 14:19:02 -070087import com.android.launcher3.allapps.AllAppsTransitionController;
Sunny Goyal7ede6112017-12-05 15:11:21 -080088import com.android.launcher3.allapps.DiscoveryBounce;
Sunny Goyalf0b6db72018-08-13 16:10:14 -070089import com.android.launcher3.anim.PropertyListBuilder;
Sunny Goyalffe83f12014-08-14 17:39:34 -070090import com.android.launcher3.compat.AppWidgetManagerCompat;
Tony Wickhame0c33232016-02-08 11:37:04 -080091import com.android.launcher3.config.FeatureFlags;
vadimt00d42552018-12-11 17:59:36 -080092import com.android.launcher3.dot.DotInfo;
Vadim Tryshevfedca432015-08-19 17:55:02 -070093import com.android.launcher3.dragndrop.DragController;
94import com.android.launcher3.dragndrop.DragLayer;
95import com.android.launcher3.dragndrop.DragView;
Sunny Goyal11a50742019-08-07 09:24:26 -070096import com.android.launcher3.folder.FolderGridOrganizer;
Sunny Goyal26119432016-02-18 22:09:23 +000097import com.android.launcher3.folder.FolderIcon;
Sunny Goyalae6e3182019-04-30 12:04:37 -070098import com.android.launcher3.graphics.RotationMode;
Sunny Goyalf840f102018-09-21 14:41:05 -070099import com.android.launcher3.icons.IconCache;
Sunny Goyal66b24572016-09-21 15:57:55 -0700100import com.android.launcher3.keyboard.CustomActionsPopup;
Sunny Goyal3333b0c2016-05-09 20:43:21 -0700101import com.android.launcher3.keyboard.ViewGroupFocusHelper;
Sunny Goyala7ce1662016-05-31 15:01:35 -0700102import com.android.launcher3.logging.FileLog;
Hyunyoung Songfc007472018-10-25 14:09:50 -0700103import com.android.launcher3.logging.StatsLogUtils;
Hyunyoung Songaa953652016-04-19 18:30:24 -0700104import com.android.launcher3.logging.UserEventDispatcher;
Hyunyoung Song46d07f72018-05-22 15:41:25 -0700105import com.android.launcher3.logging.UserEventDispatcher.UserEventDelegate;
Sunny Goyal369212a2019-03-26 15:03:57 -0700106import com.android.launcher3.model.AppLaunchTracker;
Sunny Goyal87dcde62019-07-17 20:35:56 -0700107import com.android.launcher3.model.BgDataModel.Callbacks;
Sunny Goyala535ae42017-02-27 10:07:13 -0800108import com.android.launcher3.model.ModelWriter;
Sunny Goyala535ae42017-02-27 10:07:13 -0800109import com.android.launcher3.notification.NotificationListener;
Sunny Goyale7b00122019-10-02 16:13:34 -0700110import com.android.launcher3.pm.PinRequestHelper;
Tony Wickham540913e2017-01-23 11:47:51 -0800111import com.android.launcher3.popup.PopupContainerWithArrow;
Sunny Goyala535ae42017-02-27 10:07:13 -0800112import com.android.launcher3.popup.PopupDataProvider;
Samuel Fufaca37b8a2019-08-19 17:04:36 -0700113import com.android.launcher3.qsb.QsbContainerView;
Sunny Goyal623eddd2018-03-02 12:24:41 -0800114import com.android.launcher3.states.RotationHelper;
Sunny Goyal8a2a63b2018-03-06 22:15:18 -0800115import com.android.launcher3.touch.ItemClickHandler;
Sunny Goyala5ace712017-11-15 17:12:51 -0800116import com.android.launcher3.uioverrides.UiFactory;
Sunny Goyalb1d7de22019-09-06 10:36:54 -0700117import com.android.launcher3.uioverrides.plugins.PluginManagerWrapper;
Hyunyoung Song46d07f72018-05-22 15:41:25 -0700118import com.android.launcher3.userevent.nano.LauncherLogProto;
Sunny Goyal6c46a6d2016-11-23 02:24:32 +0530119import com.android.launcher3.userevent.nano.LauncherLogProto.Action;
120import com.android.launcher3.userevent.nano.LauncherLogProto.ContainerType;
Sunny Goyalaeb16432017-10-16 11:46:41 -0700121import com.android.launcher3.userevent.nano.LauncherLogProto.Target;
Sunny Goyal2100c782016-08-22 16:00:03 -0700122import com.android.launcher3.util.ActivityResultInfo;
Sunny Goyale84c5b82019-09-26 17:05:31 -0700123import com.android.launcher3.util.ActivityTracker;
Winson Chung6b1c73f2015-06-18 11:38:42 -0700124import com.android.launcher3.util.ComponentKey;
Sunny Goyalefb7e842018-10-04 15:11:00 -0700125import com.android.launcher3.util.IntArray;
Sunny Goyald3b87ef2016-07-28 12:11:54 -0700126import com.android.launcher3.util.ItemInfoMatcher;
Sunny Goyal6001ea22018-05-10 16:31:00 -0700127import com.android.launcher3.util.MultiValueAlpha;
128import com.android.launcher3.util.MultiValueAlpha.AlphaProperty;
Sunny Goyal04cc3a72016-05-17 10:32:43 -0700129import com.android.launcher3.util.PackageManagerHelper;
Tony Wickham010d2552017-01-20 08:15:28 -0800130import com.android.launcher3.util.PackageUserKey;
Sunny Goyal2100c782016-08-22 16:00:03 -0700131import com.android.launcher3.util.PendingRequestArgs;
Pinyao Ting49a3e692019-07-26 12:28:38 -0700132import com.android.launcher3.util.ShortcutUtil;
Sunny Goyal8392c822017-06-20 10:03:56 -0700133import com.android.launcher3.util.SystemUiController;
Mario Bertschlera6936942017-05-31 14:48:19 -0700134import com.android.launcher3.util.Themes;
Adam Cohen091440a2015-03-18 14:16:05 -0700135import com.android.launcher3.util.Thunk;
Sunny Goyalfca6bc92017-09-28 16:28:34 -0700136import com.android.launcher3.util.TraceHelper;
Sunny Goyal326403e2017-10-02 12:45:10 -0700137import com.android.launcher3.util.UiThreadHelper;
Sunny Goyal527c7d32015-08-28 15:19:36 -0700138import com.android.launcher3.util.ViewOnDrawExecutor;
Sunny Goyalab770a12018-11-14 15:17:26 -0800139import com.android.launcher3.views.ActivityContext;
Sunny Goyal7c7be8c2018-03-07 19:58:07 -0800140import com.android.launcher3.views.OptionsPopupView;
Govinda Wassermanc06e1512019-04-09 09:56:53 -0400141import com.android.launcher3.views.ScrimView;
Sunny Goyal29947f02017-12-18 13:49:44 -0800142import com.android.launcher3.widget.LauncherAppWidgetHostView;
Sunny Goyal782f0c92017-01-19 10:27:54 -0800143import com.android.launcher3.widget.PendingAddShortcutInfo;
Hyunyoung Song3f471442015-04-08 19:01:34 -0700144import com.android.launcher3.widget.PendingAddWidgetInfo;
Sunny Goyal29947f02017-12-18 13:49:44 -0800145import com.android.launcher3.widget.PendingAppWidgetHostView;
Sunny Goyal04a324a2017-01-20 21:08:59 -0800146import com.android.launcher3.widget.WidgetAddFlowHandler;
Hyunyoung Songb99ff3e2015-04-23 15:17:50 -0700147import com.android.launcher3.widget.WidgetHostViewLoader;
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -0700148import com.android.launcher3.widget.WidgetListRowEntry;
149import com.android.launcher3.widget.WidgetsFullSheet;
Pinyao Tingc7a6c292019-08-26 14:36:02 -0700150import com.android.launcher3.widget.custom.CustomWidgetManager;
Sunny Goyalb1d7de22019-09-06 10:36:54 -0700151import com.android.systemui.plugins.OverlayPlugin;
152import com.android.systemui.plugins.PluginListener;
153import com.android.systemui.plugins.shared.LauncherExterns;
154import com.android.systemui.plugins.shared.LauncherOverlayManager;
155import com.android.systemui.plugins.shared.LauncherOverlayManager.LauncherOverlay;
156import com.android.systemui.plugins.shared.LauncherOverlayManager.LauncherOverlayCallbacks;
Adam Cohen6c5891a2014-07-09 23:53:15 -0700157
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700158import java.io.FileDescriptor;
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700159import java.io.PrintWriter;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700160import java.util.ArrayList;
Winson Chungf0c6ae02012-03-21 16:10:31 -0700161import java.util.Collection;
Zak Cohen658c67a2018-10-19 14:21:05 -0700162import java.util.HashMap;
Sunny Goyal4390ace2014-10-13 11:33:11 -0700163import java.util.HashSet;
Michael Jurkad7c28052012-04-27 15:43:36 -0700164import java.util.List;
Sunny Goyalaae6fbb2019-01-31 16:05:58 -0800165import java.util.function.Predicate;
Sunny Goyalb1d7de22019-09-06 10:36:54 -0700166import java.util.function.Supplier;
Jon Mirandaf5197fc2019-09-04 16:55:41 -0700167
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800168/**
169 * Default launcher application.
170 */
Hyunyoung Song46d07f72018-05-22 15:41:25 -0700171public class Launcher extends BaseDraggingActivity implements LauncherExterns,
Sunny Goyal01615a62019-09-20 12:00:07 -0700172 Callbacks, UserEventDelegate,
Sunny Goyalb1d7de22019-09-06 10:36:54 -0700173 InvariantDeviceProfile.OnIDPChangeListener, PluginListener<OverlayPlugin> {
Vadim Tryshevfedca432015-08-19 17:55:02 -0700174 public static final String TAG = "Launcher";
Sunny Goyale84c5b82019-09-26 17:05:31 -0700175
176 public static final ActivityTracker<Launcher> ACTIVITY_TRACKER = new ActivityTracker<>();
177
Sunny Goyal2bba4c32015-05-18 15:42:48 -0700178 static final boolean LOGD = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800179
Winson Chunga2413752012-04-03 14:22:34 -0700180 static final boolean DEBUG_STRICT_MODE = false;
Romain Guy6fefcf12009-06-11 13:07:43 -0700181
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800182 private static final int REQUEST_CREATE_SHORTCUT = 1;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700183 private static final int REQUEST_CREATE_APPWIDGET = 5;
Jon Mirandac476d6e2017-05-04 16:30:01 -0700184
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700185 private static final int REQUEST_PICK_APPWIDGET = 9;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800186
Michael Jurka8b805b12012-04-18 14:23:14 -0700187 private static final int REQUEST_BIND_APPWIDGET = 11;
Sunny Goyal8a2a63b2018-03-06 22:15:18 -0800188 public static final int REQUEST_BIND_PENDING_APPWIDGET = 12;
189 public static final int REQUEST_RECONFIGURE_APPWIDGET = 13;
Michael Jurka8b805b12012-04-18 14:23:14 -0700190
Jon Mirandac476d6e2017-05-04 16:30:01 -0700191 private static final int REQUEST_PERMISSION_CALL_PHONE = 14;
Sunny Goyal28c6b962015-10-12 11:42:05 -0700192
Sunny Goyal5a1f53b2015-05-27 10:24:24 -0700193 private static final float BOUNCE_ANIMATION_TENSION = 1.3f;
194
Mathew Inwood876a8462013-06-14 14:12:41 +0100195 /**
196 * IntentStarter uses request codes starting with this. This must be greater than all activity
197 * request codes used internally.
198 */
199 protected static final int REQUEST_LAST = 100;
200
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800201 // Type: int
202 private static final String RUNTIME_STATE_CURRENT_SCREEN = "launcher.current_screen";
Michael Jurka883f55b2010-10-21 15:47:14 -0700203 // Type: int
204 private static final String RUNTIME_STATE = "launcher.state";
Sunny Goyal2100c782016-08-22 16:00:03 -0700205 // Type: PendingRequestArgs
206 private static final String RUNTIME_STATE_PENDING_REQUEST_ARGS = "launcher.request_args";
Sunny Goyaldedda052019-05-14 15:23:48 -0700207 // Type: int
208 private static final String RUNTIME_STATE_PENDING_REQUEST_CODE = "launcher.request_code";
Sunny Goyal2100c782016-08-22 16:00:03 -0700209 // Type: ActivityResultInfo
210 private static final String RUNTIME_STATE_PENDING_ACTIVITY_RESULT = "launcher.activity_result";
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -0700211 // Type: SparseArray<Parcelable>
212 private static final String RUNTIME_STATE_WIDGET_PANEL = "launcher.widget_panel";
Sunny Goyal17c72fb2019-10-14 14:06:38 -0700213
vadimt00d42552018-12-11 17:59:36 -0800214 public static final String ON_CREATE_EVT = "Launcher.onCreate";
Sunny Goyal17c72fb2019-10-14 14:06:38 -0700215 public static final String ON_START_EVT = "Launcher.onStart";
216 public static final String ON_RESUME_EVT = "Launcher.onResume";
217 public static final String ON_NEW_INTENT_EVT = "Launcher.onNewIntent";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800218
Sunny Goyal3e3f44c2017-10-23 17:14:52 -0700219 private LauncherStateManager mStateManager;
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700220
Adam Cohenad4e15c2013-10-17 16:21:35 -0700221 private static final int ON_ACTIVITY_RESULT_ANIMATION_DELAY = 500;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800222
Winson Chunga2413752012-04-03 14:22:34 -0700223 // How long to wait before the new-shortcut animation automatically pans the workspace
Jon Mirandaf5197fc2019-09-04 16:55:41 -0700224 @VisibleForTesting public static final int NEW_APPS_PAGE_MOVE_DELAY = 500;
Rajeev Kumar43c0f582017-06-23 15:34:55 -0700225 private static final int NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS = 5;
Jon Mirandaf5197fc2019-09-04 16:55:41 -0700226 @Thunk @VisibleForTesting public static final int NEW_APPS_ANIMATION_DELAY = 500;
Winson Chunga2413752012-04-03 14:22:34 -0700227
Govinda Wassermanc06e1512019-04-09 09:56:53 -0400228 private static final int APPS_VIEW_ALPHA_CHANNEL_INDEX = 1;
229 private static final int SCRIM_VIEW_ALPHA_CHANNEL_INDEX = 0;
230
Jon Miranda54441f52018-01-24 15:38:25 -0800231 private LauncherAppTransitionManager mAppTransitionManager;
Sunny Goyalf8d56fc2018-01-31 15:18:11 -0800232 private Configuration mOldConfig;
Jon Miranda54441f52018-01-24 15:38:25 -0800233
Samuel Fufaca37b8a2019-08-19 17:04:36 -0700234 @Thunk
235 Workspace mWorkspace;
Craig Mautner360310b2012-10-26 15:13:08 -0700236 private View mLauncherView;
Samuel Fufaca37b8a2019-08-19 17:04:36 -0700237 @Thunk
238 DragLayer mDragLayer;
Michael Jurkab737ee62011-11-15 15:57:22 -0800239 private DragController mDragController;
Sunny Goyal322d5562015-06-25 19:35:49 -0700240
Sunny Goyalffe83f12014-08-14 17:39:34 -0700241 private AppWidgetManagerCompat mAppWidgetManager;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700242 private LauncherAppWidgetHost mAppWidgetHost;
Romain Guycbb89e42009-06-08 15:52:54 -0700243
Rajeev Kumar43c0f582017-06-23 15:34:55 -0700244 private final int[] mTmpAddItemCellCoordinates = new int[2];
Michael Jurka0280c3b2010-09-17 15:00:07 -0700245
Samuel Fufaca37b8a2019-08-19 17:04:36 -0700246 @Thunk
247 Hotseat mHotseat;
Adam Cohenf358a4b2013-07-23 16:47:31 -0700248
Sunny Goyal47328fd2016-05-25 18:56:41 -0700249 private DropTargetBar mDropTargetBar;
Hyunyoung Song3f471442015-04-08 19:01:34 -0700250
251 // Main container view for the all apps screen.
Samuel Fufaca37b8a2019-08-19 17:04:36 -0700252 @Thunk
253 AllAppsContainerView mAppsView;
Hyunyoung Song645764e2016-06-06 14:19:02 -0700254 AllAppsTransitionController mAllAppsController;
Hyunyoung Song3f471442015-04-08 19:01:34 -0700255
Govinda Wassermanc06e1512019-04-09 09:56:53 -0400256 // Scrim view for the all apps and overview state.
Samuel Fufaca37b8a2019-08-19 17:04:36 -0700257 @Thunk
258 ScrimView mScrimView;
Govinda Wassermanc06e1512019-04-09 09:56:53 -0400259
Winson Chung8ae41982017-11-10 11:42:13 -0800260 // UI and state for the overview panel
Sunny Goyal7c7be8c2018-03-07 19:58:07 -0800261 private View mOverviewPanel;
Winson Chung8ae41982017-11-10 11:42:13 -0800262
Samuel Fufaca37b8a2019-08-19 17:04:36 -0700263 @Thunk
264 boolean mWorkspaceLoading = true;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400265
Winson Chung0b70cd42019-06-17 22:34:33 -0700266 private ArrayList<OnResumeCallback> mOnResumeCallbacks = new ArrayList<>();
Sunny Goyal3dce5f32017-10-05 11:40:05 -0700267
Sunny Goyal527c7d32015-08-28 15:19:36 -0700268 private ViewOnDrawExecutor mPendingExecutor;
Michael Jurka7607c2f2013-04-03 14:33:19 -0700269
Joe Onorato9c1289c2009-08-17 11:03:03 -0400270 private LauncherModel mModel;
Sunny Goyal43bf11d2017-02-02 13:52:53 -0800271 private ModelWriter mModelWriter;
Joe Onorato0589f0f2010-02-08 13:44:00 -0800272 private IconCache mIconCache;
Sunny Goyalae502842016-06-17 08:43:56 -0700273 private LauncherAccessibilityDelegate mAccessibilityDelegate;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400274
Tony Wickham010d2552017-01-20 08:15:28 -0800275 private PopupDataProvider mPopupDataProvider;
Tony Wickhambfbf7f92016-05-19 11:19:39 -0700276
Sunny Goyalf4aceab2017-12-06 16:16:31 -0800277 private int mSynchronouslyBoundPage = PagedView.INVALID_PAGE;
Adam Cohen1462de32012-07-24 22:34:36 -0700278
Winson Chung46353de2012-02-16 14:05:10 -0800279 // We only want to get the SharedPreferences once since it does an FS stat each time we get
280 // it from the context.
281 private SharedPreferences mSharedPrefs;
282
Sunny Goyal2100c782016-08-22 16:00:03 -0700283 // Activity result which needs to be processed after workspace has loaded.
284 private ActivityResultInfo mPendingActivityResult;
285 /**
286 * Holds extra information required to handle a result from an external call, like
287 * {@link #startActivityForResult(Intent, int)} or {@link #requestPermissions(String[], int)}
288 */
289 private PendingRequestArgs mPendingRequestArgs;
Sunny Goyaldedda052019-05-14 15:23:48 -0700290 // Request id for any pending activity result
291 private int mPendingActivityRequestCode = -1;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800292
Sunny Goyal3333b0c2016-05-09 20:43:21 -0700293 public ViewGroupFocusHelper mFocusHandler;
Hyunyoung Song7fb3ccc2017-10-17 15:39:46 -0700294
Sunny Goyal623eddd2018-03-02 12:24:41 -0800295 private RotationHelper mRotationHelper;
Sunny Goyal5743f862019-03-28 15:35:32 -0700296 private Runnable mCancelTouchController;
Sunny Goyal7779d622015-06-11 16:18:39 -0700297
Sunny Goyal2db53422019-03-01 16:06:12 -0800298 final Handler mHandler = new Handler();
Sunny Goyala002c6c2019-02-12 16:20:10 -0800299 private final Runnable mHandleDeferredResume = this::handleDeferredResume;
Sunny Goyale9c6f4c2019-05-30 11:35:25 -0700300 private boolean mDeferredResumePending;
Hyunyoung Songbd6fba92018-05-16 15:54:31 -0700301
Govinda Wassermanc06e1512019-04-09 09:56:53 -0400302 private float mCurrentAssistantVisibility = 0f;
303
Sunny Goyalae6e3182019-04-30 12:04:37 -0700304 private DeviceProfile mStableDeviceProfile;
305 private RotationMode mRotationMode = RotationMode.NORMAL;
306
Sunny Goyalb1d7de22019-09-06 10:36:54 -0700307 protected LauncherOverlayManager mOverlayManager;
308 // If true, overlay callbacks are deferred
309 private boolean mDeferOverlayCallbacks;
310 private final Runnable mDeferredOverlayCallbacks = this::checkIfOverlayStillDeferred;
311
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800312 @Override
313 protected void onCreate(Bundle savedInstanceState) {
Sunny Goyal17c72fb2019-10-14 14:06:38 -0700314 TraceHelper.INSTANCE.beginSection(ON_CREATE_EVT, TraceHelper.FLAG_UI_EVENT);
Winson Chunga2413752012-04-03 14:22:34 -0700315 if (DEBUG_STRICT_MODE) {
316 StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
317 .detectDiskReads()
318 .detectDiskWrites()
319 .detectNetwork() // or .detectAll() for all detectable problems
320 .penaltyLog()
321 .build());
322 StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
323 .detectLeakedSqlLiteObjects()
324 .detectLeakedClosableObjects()
325 .penaltyLog()
326 .penaltyDeath()
327 .build());
328 }
329
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800330 super.onCreate(savedInstanceState);
Daniel Sandlere060b0b2013-06-27 21:47:55 -0400331
Sunny Goyal87f784c2017-01-11 10:48:34 -0800332 LauncherAppState app = LauncherAppState.getInstance(this);
Sunny Goyalf8d56fc2018-01-31 15:18:11 -0800333 mOldConfig = new Configuration(getResources().getConfiguration());
Sunny Goyal0e7724c2018-02-22 13:22:21 -0800334 mModel = app.setLauncher(this);
Sunny Goyal41d51a02019-05-14 09:44:34 -0700335 mRotationHelper = new RotationHelper(this);
Hyunyoung Song31971a32019-01-27 12:31:12 -0800336 InvariantDeviceProfile idp = app.getInvariantDeviceProfile();
337 initDeviceProfile(idp);
338 idp.addOnChangeListener(this);
Sunny Goyalf7258242015-10-19 16:59:07 -0700339 mSharedPrefs = Utilities.getPrefs(this);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800340 mIconCache = app.getIconCache();
Sunny Goyalae502842016-06-17 08:43:56 -0700341 mAccessibilityDelegate = new LauncherAccessibilityDelegate(this);
Adam Cohen2e6da152015-05-06 11:42:25 -0700342
Joe Onorato41a12d22009-10-31 18:30:00 -0400343 mDragController = new DragController(this);
Hyunyoung Song645764e2016-06-06 14:19:02 -0700344 mAllAppsController = new AllAppsTransitionController(this);
Sunny Goyalc4fa8c32017-11-07 12:23:58 -0800345 mStateManager = new LauncherStateManager(this);
Tracy Zhou8b23c6f2018-04-30 17:13:27 -0700346 UiFactory.onCreate(this);
Romain Guycbb89e42009-06-08 15:52:54 -0700347
Sunny Goyalffe83f12014-08-14 17:39:34 -0700348 mAppWidgetManager = AppWidgetManagerCompat.getInstance(this);
Samuel Fufa44043ec2019-08-26 15:00:30 -0700349 mAppWidgetHost = new LauncherAppWidgetHost(this,
350 appWidgetId -> getWorkspace().removeWidget(appWidgetId));
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700351 mAppWidgetHost.startListening();
Romain Guycbb89e42009-06-08 15:52:54 -0700352
Sunny Goyal60820d72017-05-09 12:40:11 -0700353 mLauncherView = LayoutInflater.from(this).inflate(R.layout.launcher, null);
Michael Jurka7267fa52013-09-26 15:29:57 -0700354
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800355 setupViews();
Tony Wickham010d2552017-01-20 08:15:28 -0800356 mPopupDataProvider = new PopupDataProvider(this);
357
Sunny Goyal90548432018-04-04 17:17:00 -0700358 mAppTransitionManager = LauncherAppTransitionManager.newInstance(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800359
Sunny Goyale84c5b82019-09-26 17:05:31 -0700360 boolean internalStateHandled = ACTIVITY_TRACKER.handleCreate(this);
Sunny Goyald3864fa2017-11-14 15:06:36 -0800361 if (internalStateHandled) {
Sunny Goyald3864fa2017-11-14 15:06:36 -0800362 if (savedInstanceState != null) {
363 // InternalStateHandler has already set the appropriate state.
364 // We dont need to do anything.
365 savedInstanceState.remove(RUNTIME_STATE);
366 }
367 }
368 restoreState(savedInstanceState);
Sunny Goyalbbece862019-03-01 13:13:52 -0800369 mStateManager.reapplyState();
Winson Chungb63b44c2017-11-10 17:54:44 -0800370
Sunny Goyal2100c782016-08-22 16:00:03 -0700371 // We only load the page synchronously if the user rotates (or triggers a
372 // configuration change) while launcher is in the foreground
Sunny Goyalfe770c92016-09-27 14:38:58 -0700373 int currentScreen = PagedView.INVALID_RESTORE_PAGE;
374 if (savedInstanceState != null) {
375 currentScreen = savedInstanceState.getInt(RUNTIME_STATE_CURRENT_SCREEN, currentScreen);
376 }
Sunny Goyald3864fa2017-11-14 15:06:36 -0800377
Sunny Goyalfe770c92016-09-27 14:38:58 -0700378 if (!mModel.startLoader(currentScreen)) {
Sunny Goyald3864fa2017-11-14 15:06:36 -0800379 if (!internalStateHandled) {
380 // If we are not binding synchronously, show a fade in animation when
381 // the first page bind completes.
Sunny Goyal6001ea22018-05-10 16:31:00 -0700382 mDragLayer.getAlphaProperty(ALPHA_INDEX_LAUNCHER_LOAD).setValue(0);
Sunny Goyald3864fa2017-11-14 15:06:36 -0800383 }
Sunny Goyal2100c782016-08-22 16:00:03 -0700384 } else {
Sunny Goyalfe770c92016-09-27 14:38:58 -0700385 // Pages bound synchronously.
386 mWorkspace.setCurrentPage(currentScreen);
387
Sunny Goyal2100c782016-08-22 16:00:03 -0700388 setWorkspaceLoading(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800389 }
390
391 // For handling default keys
Sunny Goyalf4aceab2017-12-06 16:16:31 -0800392 setDefaultKeyMode(DEFAULT_KEYS_SEARCH_LOCAL);
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800393
Sunny Goyal0bbd5542016-11-11 10:41:26 -0800394 setContentView(mLauncherView);
Sunny Goyalf8d56fc2018-01-31 15:18:11 -0800395 getRootView().dispatchInsets();
Mario Bertschlera6936942017-05-31 14:48:19 -0700396
Jon Miranda7fda2852017-07-19 16:07:01 -0700397 // Listen for broadcasts
Sunny Goyal5d1873a2018-05-08 11:10:44 -0700398 registerReceiver(mScreenOffReceiver, new IntentFilter(Intent.ACTION_SCREEN_OFF));
Sunny Goyala616d2b2017-06-12 13:54:01 -0700399
Sunny Goyal8392c822017-06-20 10:03:56 -0700400 getSystemUiController().updateUiState(SystemUiController.UI_STATE_BASE_WINDOW,
401 Themes.getAttrBoolean(this, R.attr.isWorkspaceDarkText));
Sunny Goyal14b32402017-07-31 10:03:28 -0700402
403 if (mLauncherCallbacks != null) {
404 mLauncherCallbacks.onCreate(savedInstanceState);
405 }
Sunny Goyalb1d7de22019-09-06 10:36:54 -0700406 mOverlayManager = getDefaultOverlay();
407 PluginManagerWrapper.INSTANCE.get(this).addPluginListener(this,
408 OverlayPlugin.class, false /* allowedMultiple */);
409
Sunny Goyal623eddd2018-03-02 12:24:41 -0800410 mRotationHelper.initialize();
Sunny Goyalfca6bc92017-09-28 16:28:34 -0700411
Govinda Wassermanc06e1512019-04-09 09:56:53 -0400412 mStateManager.addStateListener(new LauncherStateManager.StateListener() {
413 @Override
Samuel Fufaca37b8a2019-08-19 17:04:36 -0700414 public void onStateTransitionStart(LauncherState toState) {
415 }
Govinda Wassermanc06e1512019-04-09 09:56:53 -0400416
417 @Override
418 public void onStateTransitionComplete(LauncherState finalState) {
419 float alpha = 1f - mCurrentAssistantVisibility;
420 if (finalState == NORMAL) {
421 mAppsView.getAlphaProperty(APPS_VIEW_ALPHA_CHANNEL_INDEX).setValue(alpha);
422 } else if (finalState == OVERVIEW || finalState == OVERVIEW_PEEK) {
423 mAppsView.getAlphaProperty(APPS_VIEW_ALPHA_CHANNEL_INDEX).setValue(alpha);
424 mScrimView.getAlphaProperty(SCRIM_VIEW_ALPHA_CHANNEL_INDEX).setValue(alpha);
425 } else {
426 mAppsView.getAlphaProperty(APPS_VIEW_ALPHA_CHANNEL_INDEX).setValue(1f);
427 mScrimView.getAlphaProperty(SCRIM_VIEW_ALPHA_CHANNEL_INDEX).setValue(1f);
428 }
429 }
430 });
Sunny Goyal17c72fb2019-10-14 14:06:38 -0700431
432 TraceHelper.INSTANCE.endSection();
Adam Cohen9211d422014-10-07 18:14:53 -0700433 }
434
Sunny Goyalb1d7de22019-09-06 10:36:54 -0700435 protected LauncherOverlayManager getDefaultOverlay() {
436 return new LauncherOverlayManager() { };
437 }
438
439 @Override
440 public void onPluginConnected(OverlayPlugin overlayManager, Context context) {
441 switchOverlay(() -> overlayManager.createOverlayManager(this, this));
442 }
443
444 @Override
445 public void onPluginDisconnected(OverlayPlugin plugin) {
446 switchOverlay(this::getDefaultOverlay);
447 }
448
449 private void switchOverlay(Supplier<LauncherOverlayManager> overlaySupplier) {
450 if (mOverlayManager != null) {
451 mOverlayManager.onActivityDestroyed(this);
452 }
453 mOverlayManager = overlaySupplier.get();
454 if (getRootView().isAttachedToWindow()) {
455 mOverlayManager.onAttachedToWindow();
456 }
457 mDeferOverlayCallbacks = true;
458 checkIfOverlayStillDeferred();
459 }
460
461 @Override
462 protected void dispatchDeviceProfileChanged() {
463 super.dispatchDeviceProfileChanged();
464 mOverlayManager.onDeviceProvideChanged();
465 }
466
Sunny Goyal7779d622015-06-11 16:18:39 -0700467 @Override
Winson Chung8eb49e02018-07-16 13:33:31 -0700468 public void onEnterAnimationComplete() {
469 super.onEnterAnimationComplete();
470 UiFactory.onEnterAnimationComplete(this);
arangelovad783052018-08-17 14:46:45 +0100471 mAllAppsController.highlightWorkTabIfNecessary();
Sunny Goyalbe8c3402019-05-22 15:17:52 -0700472 mRotationHelper.setCurrentTransitionRequest(REQUEST_NONE);
Winson Chung8eb49e02018-07-16 13:33:31 -0700473 }
474
475 @Override
Sunny Goyalf8d56fc2018-01-31 15:18:11 -0800476 public void onConfigurationChanged(Configuration newConfig) {
477 int diff = newConfig.diff(mOldConfig);
Jon Mirandaaeb4dd02018-07-11 14:16:23 -0700478
Sunny Goyalf8d56fc2018-01-31 15:18:11 -0800479 if ((diff & (CONFIG_ORIENTATION | CONFIG_SCREEN_SIZE)) != 0) {
Sunny Goyal371ea052019-03-06 15:38:32 -0800480 onIdpChanged(mDeviceProfile.inv);
Sunny Goyalf8d56fc2018-01-31 15:18:11 -0800481 }
482
483 mOldConfig.setTo(newConfig);
Tracy Zhoua706f002018-03-28 13:55:19 -0700484 UiFactory.onLauncherStateOrResumeChanged(this);
Sunny Goyalf8d56fc2018-01-31 15:18:11 -0800485 super.onConfigurationChanged(newConfig);
486 }
487
Sunny Goyal3e195d72019-06-19 14:24:38 -0700488 public void reload() {
489 onIdpChanged(mDeviceProfile.inv);
490 }
491
Sunny Goyal41d51a02019-05-14 09:44:34 -0700492 private boolean supportsFakeLandscapeUI() {
493 return FeatureFlags.FAKE_LANDSCAPE_UI.get() && !mRotationHelper.homeScreenCanRotate();
494 }
495
Sunny Goyal605bcf32018-03-02 15:16:12 -0800496 @Override
Sunny Goyal41d51a02019-05-14 09:44:34 -0700497 public void reapplyUi() {
498 if (supportsFakeLandscapeUI()) {
Sunny Goyal7a39b1b2019-05-02 13:39:16 -0700499 mRotationMode = mStableDeviceProfile == null
500 ? RotationMode.NORMAL : UiFactory.getRotationMode(mDeviceProfile);
Sunny Goyalae6e3182019-04-30 12:04:37 -0700501 }
Sunny Goyal59d086c2018-05-07 17:31:40 -0700502 getRootView().dispatchInsets();
503 getStateManager().reapplyState(true /* cancelCurrentAnimation */);
504 }
505
506 @Override
Sunny Goyal605bcf32018-03-02 15:16:12 -0800507 public void rebindModel() {
508 int currentPage = mWorkspace.getNextPage();
509 if (mModel.startLoader(currentPage)) {
510 mWorkspace.setCurrentPage(currentPage);
511 setWorkspaceLoading(true);
512 }
513 }
514
Hyunyoung Song31971a32019-01-27 12:31:12 -0800515 @Override
516 public void onIdpChanged(int changeFlags, InvariantDeviceProfile idp) {
Sunny Goyal371ea052019-03-06 15:38:32 -0800517 onIdpChanged(idp);
518 }
519
520 private void onIdpChanged(InvariantDeviceProfile idp) {
521 mUserEventDispatcher = null;
522
Sunny Goyalc8502c12019-06-10 12:14:47 -0700523 DeviceProfile oldWallpaperProfile = getWallpaperDeviceProfile();
Hyunyoung Song31971a32019-01-27 12:31:12 -0800524 initDeviceProfile(idp);
Sunny Goyal371ea052019-03-06 15:38:32 -0800525 dispatchDeviceProfileChanged();
526 reapplyUi();
527 mDragLayer.recreateControllers();
528
Sunny Goyal76ba0a32019-06-10 11:56:11 -0700529 // Calling onSaveInstanceState ensures that static cache used by listWidgets is
530 // initialized properly.
531 onSaveInstanceState(new Bundle());
Sunny Goyalc8502c12019-06-10 12:14:47 -0700532 if (oldWallpaperProfile != getWallpaperDeviceProfile()) {
533 rebindModel();
534 }
Hyunyoung Song31971a32019-01-27 12:31:12 -0800535 }
536
Govinda Wassermanc06e1512019-04-09 09:56:53 -0400537 public void onAssistantVisibilityChanged(float visibility) {
538 mCurrentAssistantVisibility = visibility;
539 float alpha = 1f - visibility;
540 LauncherState state = mStateManager.getState();
541 if (state == NORMAL) {
542 mAppsView.getAlphaProperty(APPS_VIEW_ALPHA_CHANNEL_INDEX).setValue(alpha);
543 } else if (state == OVERVIEW || state == OVERVIEW_PEEK) {
544 mAppsView.getAlphaProperty(APPS_VIEW_ALPHA_CHANNEL_INDEX).setValue(alpha);
545 mScrimView.getAlphaProperty(SCRIM_VIEW_ALPHA_CHANNEL_INDEX).setValue(alpha);
546 }
547 }
548
Sunny Goyalf8d56fc2018-01-31 15:18:11 -0800549 private void initDeviceProfile(InvariantDeviceProfile idp) {
550 // Load configuration-specific DeviceProfile
Sunny Goyal59d086c2018-05-07 17:31:40 -0700551 mDeviceProfile = idp.getDeviceProfile(this);
Sunny Goyal8c48d8b2019-01-25 15:10:18 -0800552 if (isInMultiWindowMode()) {
Winson Chung13c1c2c2019-09-06 11:46:19 -0700553 // Note: Calls to getSize() can't rely on our cached DefaultDisplay since it can return
554 // the app window size
Sunny Goyal59d086c2018-05-07 17:31:40 -0700555 Display display = getWindowManager().getDefaultDisplay();
556 Point mwSize = new Point();
557 display.getSize(mwSize);
558 mDeviceProfile = mDeviceProfile.getMultiWindowProfile(this, mwSize);
559 }
Sunny Goyalae6e3182019-04-30 12:04:37 -0700560
Sunny Goyalda14cf82019-05-30 10:31:09 -0700561 if (supportsFakeLandscapeUI() && mDeviceProfile.isVerticalBarLayout()) {
Sunny Goyalae6e3182019-04-30 12:04:37 -0700562 mStableDeviceProfile = mDeviceProfile.inv.portraitProfile;
Sunny Goyal7a39b1b2019-05-02 13:39:16 -0700563 mRotationMode = UiFactory.getRotationMode(mDeviceProfile);
Sunny Goyalae6e3182019-04-30 12:04:37 -0700564 } else {
565 mStableDeviceProfile = null;
566 mRotationMode = RotationMode.NORMAL;
567 }
568
Sunny Goyalda14cf82019-05-30 10:31:09 -0700569 mRotationHelper.updateRotationAnimation();
Sunny Goyal59d086c2018-05-07 17:31:40 -0700570 onDeviceProfileInitiated();
Sunny Goyalae6e3182019-04-30 12:04:37 -0700571 mModelWriter = mModel.getWriter(getWallpaperDeviceProfile().isVerticalBarLayout(), true);
572 }
573
574 public void updateInsets(Rect insets) {
575 mDeviceProfile.updateInsets(insets);
576 if (mStableDeviceProfile != null) {
Sunny Goyal7a39b1b2019-05-02 13:39:16 -0700577 Rect r = mStableDeviceProfile.getInsets();
578 mRotationMode.mapInsets(this, insets, r);
579 mStableDeviceProfile.updateInsets(r);
Sunny Goyalae6e3182019-04-30 12:04:37 -0700580 }
581 }
582
583 @Override
584 public RotationMode getRotationMode() {
585 return mRotationMode;
586 }
587
588 /**
589 * Device profile to be used by UI elements which are shown directly on top of the wallpaper
590 * and whose presentation is tied to the wallpaper (and physical device) and not the activity
591 * configuration.
592 */
593 @Override
594 public DeviceProfile getWallpaperDeviceProfile() {
595 return mStableDeviceProfile == null ? mDeviceProfile : mStableDeviceProfile;
Sunny Goyalf8d56fc2018-01-31 15:18:11 -0800596 }
597
Sunny Goyal623eddd2018-03-02 12:24:41 -0800598 public RotationHelper getRotationHelper() {
599 return mRotationHelper;
600 }
601
Sunny Goyal3e3f44c2017-10-23 17:14:52 -0700602 public LauncherStateManager getStateManager() {
603 return mStateManager;
Sunny Goyalbe93f262017-10-20 17:05:27 -0700604 }
605
Mario Bertschler27288382017-05-24 15:35:09 -0700606 @Override
Sunny Goyalc7b8df82017-06-27 11:11:03 -0700607 public <T extends View> T findViewById(int id) {
Sunny Goyal0bbd5542016-11-11 10:41:26 -0800608 return mLauncherView.findViewById(id);
609 }
610
Adam Cohen9211d422014-10-07 18:14:53 -0700611 private LauncherCallbacks mLauncherCallbacks;
612
Sunny Goyal32554d12015-12-03 15:31:25 -0800613 /**
614 * Call this after onCreate to set or clear overlay.
615 */
Sunny Goyalb1d7de22019-09-06 10:36:54 -0700616 @Override
Sunny Goyal32554d12015-12-03 15:31:25 -0800617 public void setLauncherOverlay(LauncherOverlay overlay) {
618 if (overlay != null) {
619 overlay.setOverlayCallbacks(new LauncherOverlayCallbacksImpl());
620 }
621 mWorkspace.setLauncherOverlay(overlay);
622 }
623
Sunny Goyalb1d7de22019-09-06 10:36:54 -0700624 @Override
625 public void runOnOverlayHidden(Runnable runnable) {
626 getWorkspace().runOnOverlayHidden(runnable);
627 }
628
Adam Cohen9211d422014-10-07 18:14:53 -0700629 public boolean setLauncherCallbacks(LauncherCallbacks callbacks) {
630 mLauncherCallbacks = callbacks;
631 return true;
Adam Cohenf9426d52012-06-04 17:26:21 -0700632 }
633
Hyunyoung Song3f471442015-04-08 19:01:34 -0700634 public boolean isDraggingEnabled() {
Winson Chung36a62fe2012-05-06 18:04:42 -0700635 // We prevent dragging when we are loading the workspace as it is possible to pick up a view
636 // that is subsequently removed from the workspace in startBinding().
Sunny Goyal639e9062015-08-19 19:17:06 -0700637 return !isWorkspaceLoading();
Winson Chung36a62fe2012-05-06 18:04:42 -0700638 }
639
Tony Wickham010d2552017-01-20 08:15:28 -0800640 public PopupDataProvider getPopupDataProvider() {
641 return mPopupDataProvider;
642 }
643
Sunny Goyal0b0847b2018-03-14 12:30:11 -0700644 @Override
Tony Wickhamf34bee82018-12-03 18:11:39 -0800645 public DotInfo getDotInfoForItem(ItemInfo info) {
646 return mPopupDataProvider.getDotInfoForItem(info);
Sunny Goyal0b0847b2018-03-14 12:30:11 -0700647 }
648
649 @Override
650 public void invalidateParent(ItemInfo info) {
Jon Mirandae6f3fa42019-03-04 09:14:40 -0800651 if (info.container >= 0) {
Sunny Goyal0b0847b2018-03-14 12:30:11 -0700652 View folderIcon = getWorkspace().getHomescreenIconByItemId(info.container);
Jon Mirandae6f3fa42019-03-04 09:14:40 -0800653 if (folderIcon instanceof FolderIcon && folderIcon.getTag() instanceof FolderInfo) {
Sunny Goyal11a50742019-08-07 09:24:26 -0700654 if (new FolderGridOrganizer(getDeviceProfile().inv)
655 .setFolderInfo((FolderInfo) folderIcon.getTag())
656 .isItemInPreview(info.rank)) {
Jon Mirandae6f3fa42019-03-04 09:14:40 -0800657 folderIcon.invalidate();
658 }
Sunny Goyal0b0847b2018-03-14 12:30:11 -0700659 }
660 }
661 }
662
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000663 /**
Winson Chung557d6ed2011-07-08 15:34:52 -0700664 * Returns whether we should delay spring loaded mode -- for shortcuts and widgets that have
665 * a configuration step, this allows the proper animations to run after other transitions.
666 */
Sunny Goyalefb7e842018-10-04 15:11:00 -0700667 private int completeAdd(
Sunny Goyal2100c782016-08-22 16:00:03 -0700668 int requestCode, Intent intent, int appWidgetId, PendingRequestArgs info) {
Sunny Goyalefb7e842018-10-04 15:11:00 -0700669 int screenId = info.screenId;
Sunny Goyal2100c782016-08-22 16:00:03 -0700670 if (info.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
Adam Cohen83079e42014-09-19 17:43:08 -0700671 // When the screen id represents an actual screen (as opposed to a rank) we make sure
672 // that the drop page actually exists.
Sunny Goyal2100c782016-08-22 16:00:03 -0700673 screenId = ensurePendingDropLayoutExists(info.screenId);
Adam Cohen83079e42014-09-19 17:43:08 -0700674 }
Adam Cohendb364c32014-05-20 14:23:40 -0700675
Sunny Goyal2100c782016-08-22 16:00:03 -0700676 switch (requestCode) {
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800677 case REQUEST_CREATE_SHORTCUT:
Sunny Goyalfb5096d2016-09-08 14:32:06 -0700678 completeAddShortcut(intent, info.container, screenId, info.cellX, info.cellY, info);
Winson Chungb8472bb2011-08-05 13:49:21 -0700679 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800680 case REQUEST_CREATE_APPWIDGET:
Sunny Goyal2100c782016-08-22 16:00:03 -0700681 completeAddAppWidget(appWidgetId, info, null, null);
Winson Chungb8472bb2011-08-05 13:49:21 -0700682 break;
Sunny Goyalff572272014-07-23 13:58:07 -0700683 case REQUEST_RECONFIGURE_APPWIDGET:
Sunny Goyal2100c782016-08-22 16:00:03 -0700684 completeRestoreAppWidget(appWidgetId, LauncherAppWidgetInfo.RESTORE_COMPLETED);
Sunny Goyalff572272014-07-23 13:58:07 -0700685 break;
Sunny Goyald478c832016-04-01 12:04:16 -0700686 case REQUEST_BIND_PENDING_APPWIDGET: {
Sunny Goyal2100c782016-08-22 16:00:03 -0700687 int widgetId = appWidgetId;
688 LauncherAppWidgetInfo widgetInfo =
Sunny Goyald478c832016-04-01 12:04:16 -0700689 completeRestoreAppWidget(widgetId, LauncherAppWidgetInfo.FLAG_UI_NOT_READY);
Sunny Goyal2100c782016-08-22 16:00:03 -0700690 if (widgetInfo != null) {
Sunny Goyald478c832016-04-01 12:04:16 -0700691 // Since the view was just bound, also launch the configure activity if needed
692 LauncherAppWidgetProviderInfo provider = mAppWidgetManager
693 .getLauncherAppWidgetInfo(widgetId);
Sunny Goyal04a324a2017-01-20 21:08:59 -0800694 if (provider != null) {
695 new WidgetAddFlowHandler(provider)
Samuel Fufaca37b8a2019-08-19 17:04:36 -0700696 .startConfigActivity(this, widgetInfo,
697 REQUEST_RECONFIGURE_APPWIDGET);
Sunny Goyald478c832016-04-01 12:04:16 -0700698 }
699 }
700 break;
701 }
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800702 }
Sunny Goyal2100c782016-08-22 16:00:03 -0700703
Adam Cohendb364c32014-05-20 14:23:40 -0700704 return screenId;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800705 }
706
Adam Cohenc7cd2cb2014-11-17 17:45:34 -0800707 private void handleActivityResult(
Michael Jurka8b805b12012-04-18 14:23:14 -0700708 final int requestCode, final int resultCode, final Intent data) {
Sunny Goyal2100c782016-08-22 16:00:03 -0700709 if (isWorkspaceLoading()) {
710 // process the result once the workspace has loaded.
711 mPendingActivityResult = new ActivityResultInfo(requestCode, resultCode, data);
712 return;
713 }
714 mPendingActivityResult = null;
715
Winson Chunge341d302013-08-16 14:31:00 -0700716 // Reset the startActivity waiting flag
Sunny Goyal2100c782016-08-22 16:00:03 -0700717 final PendingRequestArgs requestArgs = mPendingRequestArgs;
718 setWaitingForResult(null);
719 if (requestArgs == null) {
720 return;
721 }
722
723 final int pendingAddWidgetId = requestArgs.getWidgetId();
Winson Chunge341d302013-08-16 14:31:00 -0700724
Adam Cohenad4e15c2013-10-17 16:21:35 -0700725 Runnable exitSpringLoaded = new Runnable() {
726 @Override
727 public void run() {
Sunny Goyal3e3f44c2017-10-23 17:14:52 -0700728 mStateManager.goToState(NORMAL, SPRING_LOADED_EXIT_DELAY);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700729 }
730 };
731
Michael Jurka8b805b12012-04-18 14:23:14 -0700732 if (requestCode == REQUEST_BIND_APPWIDGET) {
Winsona1f79d32015-08-05 14:00:45 -0700733 // This is called only if the user did not previously have permissions to bind widgets
Adam Cohenad4e15c2013-10-17 16:21:35 -0700734 final int appWidgetId = data != null ?
Michael Jurka8b805b12012-04-18 14:23:14 -0700735 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
736 if (resultCode == RESULT_CANCELED) {
Sunny Goyal2100c782016-08-22 16:00:03 -0700737 completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId, requestArgs);
Adam Cohen689ff162014-05-08 17:27:56 -0700738 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
Adam Cohenad4e15c2013-10-17 16:21:35 -0700739 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
Michael Jurka8b805b12012-04-18 14:23:14 -0700740 } else if (resultCode == RESULT_OK) {
Sunny Goyal2100c782016-08-22 16:00:03 -0700741 addAppWidgetImpl(
742 appWidgetId, requestArgs, null,
Sunny Goyal04a324a2017-01-20 21:08:59 -0800743 requestArgs.getWidgetHandler(),
Sunny Goyal2100c782016-08-22 16:00:03 -0700744 ON_ACTIVITY_RESULT_ANIMATION_DELAY);
Michael Jurka8b805b12012-04-18 14:23:14 -0700745 }
746 return;
747 }
Michael Jurka336fd4f2013-09-12 00:05:02 +0200748
Adam Cohened66b2b2012-01-23 17:28:51 -0800749 boolean isWidgetDrop = (requestCode == REQUEST_PICK_APPWIDGET ||
Sunny Goyal5c97f512015-05-19 16:03:28 -0700750 requestCode == REQUEST_CREATE_APPWIDGET);
Romain Guyaad5ef42009-06-10 02:48:37 -0700751
Adam Cohened66b2b2012-01-23 17:28:51 -0800752 // We have special handling for widgets
753 if (isWidgetDrop) {
Adam Cohen4637b5a2013-11-04 18:21:24 -0800754 final int appWidgetId;
755 int widgetId = data != null ? data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1)
756 : -1;
757 if (widgetId < 0) {
758 appWidgetId = pendingAddWidgetId;
759 } else {
760 appWidgetId = widgetId;
761 }
762
Adam Cohenad4e15c2013-10-17 16:21:35 -0700763 final int result;
Adam Cohenf0129b12013-11-04 17:57:36 -0800764 if (appWidgetId < 0 || resultCode == RESULT_CANCELED) {
Adam Cohendb364c32014-05-20 14:23:40 -0700765 Log.e(TAG, "Error: appWidgetId (EXTRA_APPWIDGET_ID) was not " +
766 "returned from the widget configuration activity.");
Adam Cohenad4e15c2013-10-17 16:21:35 -0700767 result = RESULT_CANCELED;
Sunny Goyal2100c782016-08-22 16:00:03 -0700768 completeTwoStageWidgetDrop(result, appWidgetId, requestArgs);
Adam Cohendb364c32014-05-20 14:23:40 -0700769 final Runnable onComplete = new Runnable() {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700770 @Override
771 public void run() {
Sunny Goyal3e3f44c2017-10-23 17:14:52 -0700772 getStateManager().goToState(NORMAL);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700773 }
774 };
Adam Cohendb364c32014-05-20 14:23:40 -0700775
Sunny Goyal2100c782016-08-22 16:00:03 -0700776 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete,
777 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
778 } else {
779 if (requestArgs.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
780 // When the screen id represents an actual screen (as opposed to a rank)
781 // we make sure that the drop page actually exists.
782 requestArgs.screenId =
783 ensurePendingDropLayoutExists(requestArgs.screenId);
Adam Cohendb364c32014-05-20 14:23:40 -0700784 }
Sunny Goyal2100c782016-08-22 16:00:03 -0700785 final CellLayout dropLayout =
786 mWorkspace.getScreenWithId(requestArgs.screenId);
787
788 dropLayout.setDropPending(true);
789 final Runnable onComplete = new Runnable() {
790 @Override
791 public void run() {
792 completeTwoStageWidgetDrop(resultCode, appWidgetId, requestArgs);
793 dropLayout.setDropPending(false);
794 }
795 };
796 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete,
797 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
Winson Chung5aaab772012-04-27 15:24:02 -0700798 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800799 return;
800 }
801
Sunny Goyald478c832016-04-01 12:04:16 -0700802 if (requestCode == REQUEST_RECONFIGURE_APPWIDGET
803 || requestCode == REQUEST_BIND_PENDING_APPWIDGET) {
Sunny Goyalff572272014-07-23 13:58:07 -0700804 if (resultCode == RESULT_OK) {
805 // Update the widget view.
Sunny Goyal2100c782016-08-22 16:00:03 -0700806 completeAdd(requestCode, data, pendingAddWidgetId, requestArgs);
Sunny Goyalff572272014-07-23 13:58:07 -0700807 }
808 // Leave the widget in the pending state if the user canceled the configure.
809 return;
810 }
811
Sunny Goyalaad90582015-07-09 14:22:50 -0700812 if (requestCode == REQUEST_CREATE_SHORTCUT) {
813 // Handle custom shortcuts created using ACTION_CREATE_SHORTCUT.
Sunny Goyal2100c782016-08-22 16:00:03 -0700814 if (resultCode == RESULT_OK && requestArgs.container != ItemInfo.NO_ID) {
815 completeAdd(requestCode, data, -1, requestArgs);
816 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
817 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
818
Sunny Goyalaad90582015-07-09 14:22:50 -0700819 } else if (resultCode == RESULT_CANCELED) {
Adam Cohendb364c32014-05-20 14:23:40 -0700820 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
821 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800822 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800823 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800824 mDragLayer.clearAnimatedView();
Adam Cohenc7cd2cb2014-11-17 17:45:34 -0800825 }
826
827 @Override
Sunny Goyal64a75aa2017-07-03 13:50:52 -0700828 public void onActivityResult(
Adam Cohenc7cd2cb2014-11-17 17:45:34 -0800829 final int requestCode, final int resultCode, final Intent data) {
Sunny Goyaldedda052019-05-14 15:23:48 -0700830 mPendingActivityRequestCode = -1;
Adam Cohenc7cd2cb2014-11-17 17:45:34 -0800831 handleActivityResult(requestCode, resultCode, data);
Adam Cohened66b2b2012-01-23 17:28:51 -0800832 }
833
Sunny Goyal7ce471b2017-08-02 03:37:39 -0700834 @Override
Sunny Goyaldd2e6df2015-07-07 10:57:57 -0700835 public void onRequestPermissionsResult(int requestCode, String[] permissions,
Dave Hawkey3a43ed62015-06-26 10:27:47 -0600836 int[] grantResults) {
Sunny Goyal2100c782016-08-22 16:00:03 -0700837 PendingRequestArgs pendingArgs = mPendingRequestArgs;
838 if (requestCode == REQUEST_PERMISSION_CALL_PHONE && pendingArgs != null
839 && pendingArgs.getRequestCode() == REQUEST_PERMISSION_CALL_PHONE) {
840 setWaitingForResult(null);
841
Sunny Goyal28c6b962015-10-12 11:42:05 -0700842 View v = null;
Sunny Goyal2100c782016-08-22 16:00:03 -0700843 CellLayout layout = getCellLayout(pendingArgs.container, pendingArgs.screenId);
Sunny Goyal28c6b962015-10-12 11:42:05 -0700844 if (layout != null) {
Sunny Goyal2100c782016-08-22 16:00:03 -0700845 v = layout.getChildAt(pendingArgs.cellX, pendingArgs.cellY);
Sunny Goyal28c6b962015-10-12 11:42:05 -0700846 }
Sunny Goyal2100c782016-08-22 16:00:03 -0700847 Intent intent = pendingArgs.getPendingIntent();
848
Sunny Goyal28c6b962015-10-12 11:42:05 -0700849 if (grantResults.length > 0
850 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
Sunny Goyal369212a2019-03-26 15:03:57 -0700851 startActivitySafely(v, intent, null, null);
Sunny Goyal28c6b962015-10-12 11:42:05 -0700852 } else {
853 // TODO: Show a snack bar with link to settings
854 Toast.makeText(this, getString(R.string.msg_no_phone_permission,
Sunny Goyal112ce422016-08-22 16:45:29 -0700855 getString(R.string.derived_app_name)), Toast.LENGTH_SHORT).show();
Sunny Goyal28c6b962015-10-12 11:42:05 -0700856 }
857 }
Dave Hawkey3a43ed62015-06-26 10:27:47 -0600858 }
859
Adam Cohendb364c32014-05-20 14:23:40 -0700860 /**
861 * Check to see if a given screen id exists. If not, create it at the end, return the new id.
862 *
863 * @param screenId the screen id to check
864 * @return the new screen, or screenId if it exists
865 */
Sunny Goyalefb7e842018-10-04 15:11:00 -0700866 private int ensurePendingDropLayoutExists(int screenId) {
Sunny Goyal32554d12015-12-03 15:31:25 -0800867 CellLayout dropLayout = mWorkspace.getScreenWithId(screenId);
Adam Cohendb364c32014-05-20 14:23:40 -0700868 if (dropLayout == null) {
869 // it's possible that the add screen was removed because it was
870 // empty and a re-bind occurred
871 mWorkspace.addExtraEmptyScreen();
872 return mWorkspace.commitExtraEmptyScreen();
873 } else {
874 return screenId;
875 }
876 }
877
Samuel Fufaca37b8a2019-08-19 17:04:36 -0700878 @Thunk
879 void completeTwoStageWidgetDrop(
Sunny Goyal2100c782016-08-22 16:00:03 -0700880 final int resultCode, final int appWidgetId, final PendingRequestArgs requestArgs) {
881 CellLayout cellLayout = mWorkspace.getScreenWithId(requestArgs.screenId);
Adam Cohened66b2b2012-01-23 17:28:51 -0800882 Runnable onCompleteRunnable = null;
883 int animationType = 0;
884
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700885 AppWidgetHostView boundWidget = null;
Adam Cohened66b2b2012-01-23 17:28:51 -0800886 if (resultCode == RESULT_OK) {
887 animationType = Workspace.COMPLETE_TWO_STAGE_WIDGET_DROP_ANIMATION;
888 final AppWidgetHostView layout = mAppWidgetHost.createView(this, appWidgetId,
Sunny Goyal04a324a2017-01-20 21:08:59 -0800889 requestArgs.getWidgetHandler().getProviderInfo(this));
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700890 boundWidget = layout;
Adam Cohened66b2b2012-01-23 17:28:51 -0800891 onCompleteRunnable = new Runnable() {
892 @Override
893 public void run() {
Sunny Goyal2100c782016-08-22 16:00:03 -0700894 completeAddAppWidget(appWidgetId, requestArgs, layout, null);
Sunny Goyal3e3f44c2017-10-23 17:14:52 -0700895 mStateManager.goToState(NORMAL, SPRING_LOADED_EXIT_DELAY);
Adam Cohened66b2b2012-01-23 17:28:51 -0800896 }
897 };
898 } else if (resultCode == RESULT_CANCELED) {
Adam Cohen4637b5a2013-11-04 18:21:24 -0800899 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
Adam Cohened66b2b2012-01-23 17:28:51 -0800900 animationType = Workspace.CANCEL_TWO_STAGE_WIDGET_DROP_ANIMATION;
Adam Cohened66b2b2012-01-23 17:28:51 -0800901 }
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700902 if (mDragLayer.getAnimatedView() != null) {
Sunny Goyal2100c782016-08-22 16:00:03 -0700903 mWorkspace.animateWidgetDrop(requestArgs, cellLayout,
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700904 (DragView) mDragLayer.getAnimatedView(), onCompleteRunnable,
905 animationType, boundWidget, true);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700906 } else if (onCompleteRunnable != null) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700907 // The animated view may be null in the case of a rotation during widget configuration
908 onCompleteRunnable.run();
909 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800910 }
911
912 @Override
Michael Jurkacd496d72013-04-11 11:32:45 -0700913 protected void onStop() {
914 super.onStop();
Winson Chung0b70cd42019-06-17 22:34:33 -0700915
Sunny Goyalb1d7de22019-09-06 10:36:54 -0700916 if (mDeferOverlayCallbacks) {
917 checkIfOverlayStillDeferred();
918 } else {
919 mOverlayManager.onActivityStopped(this);
Adam Cohen9211d422014-10-07 18:14:53 -0700920 }
Sunny Goyalb1d7de22019-09-06 10:36:54 -0700921
Becky Qiubfc2da12019-08-01 11:09:38 -0700922 logStopAndResume(Action.Command.STOP);
Hyunyoung Songbd6fba92018-05-16 15:54:31 -0700923
924 mAppWidgetHost.setListenIfResumed(false);
925
Tony Wickham010d2552017-01-20 08:15:28 -0800926 NotificationListener.removeNotificationsChangedListener();
Sunny Goyalaf161fd2018-02-05 16:34:57 -0800927 getStateManager().moveToRestState();
Winson Chungedb0d6b2018-03-21 17:32:55 -0700928
Tracy Zhou62646712018-06-26 14:19:02 -0700929 UiFactory.onLauncherStateOrResumeChanged(this);
930
Winson Chungdea51352018-04-24 13:02:10 -0700931 // Workaround for b/78520668, explicitly trim memory once UI is hidden
Winson Chung473730f2018-04-26 11:54:22 -0700932 onTrimMemory(TRIM_MEMORY_UI_HIDDEN);
Michael Jurkacd496d72013-04-11 11:32:45 -0700933 }
934
935 @Override
936 protected void onStart() {
Sunny Goyal17c72fb2019-10-14 14:06:38 -0700937 TraceHelper.INSTANCE.beginSection(ON_START_EVT, TraceHelper.FLAG_UI_EVENT);
Michael Jurkacd496d72013-04-11 11:32:45 -0700938 super.onStart();
Sunny Goyalb1d7de22019-09-06 10:36:54 -0700939 if (!mDeferOverlayCallbacks) {
940 mOverlayManager.onActivityStarted(this);
Adam Cohen9211d422014-10-07 18:14:53 -0700941 }
Sunny Goyalb1d7de22019-09-06 10:36:54 -0700942
Sunny Goyal67419a12017-11-14 16:55:22 -0800943 mAppWidgetHost.setListenIfResumed(true);
Sunny Goyal17c72fb2019-10-14 14:06:38 -0700944 TraceHelper.INSTANCE.endSection();
Michael Jurkacd496d72013-04-11 11:32:45 -0700945 }
946
Sunny Goyala002c6c2019-02-12 16:20:10 -0800947 private void handleDeferredResume() {
Sunny Goyale9c6f4c2019-05-30 11:35:25 -0700948 if (hasBeenResumed() && !mStateManager.getState().disableInteraction) {
Becky Qiubfc2da12019-08-01 11:09:38 -0700949 logStopAndResume(Action.Command.RESUME);
Hyunyoung Songbd6fba92018-05-16 15:54:31 -0700950 getUserEventDispatcher().startSession();
Sunny Goyala002c6c2019-02-12 16:20:10 -0800951
952 UiFactory.onLauncherStateOrResumeChanged(this);
Sunny Goyal369212a2019-03-26 15:03:57 -0700953 AppLaunchTracker.INSTANCE.get(this).onReturnedToHome();
Hyunyoung Songbd6fba92018-05-16 15:54:31 -0700954
Sunny Goyale9c6f4c2019-05-30 11:35:25 -0700955 // Process any items that were added while Launcher was away.
956 InstallShortcutReceiver.disableAndFlushInstallQueue(
957 InstallShortcutReceiver.FLAG_ACTIVITY_PAUSED, this);
958
959 // Refresh shortcuts if the permission changed.
960 mModel.refreshShortcutsIfRequired();
961
Winson Chung87583112019-06-10 14:20:58 -0700962 // Set the notification listener and fetch updated notifications when we resume
963 NotificationListener.setNotificationsChangedListener(mPopupDataProvider);
964
Sunny Goyale9c6f4c2019-05-30 11:35:25 -0700965 DiscoveryBounce.showForHomeIfNeeded(this);
966
967 if (mPendingActivityRequestCode != -1 && isInState(NORMAL)) {
968 UiFactory.resetPendingActivityResults(this, mPendingActivityRequestCode);
969 }
970 mDeferredResumePending = false;
971 } else {
972 mDeferredResumePending = true;
Sunny Goyaldedda052019-05-14 15:23:48 -0700973 }
974 }
975
Becky Qiubfc2da12019-08-01 11:09:38 -0700976 private void logStopAndResume(int command) {
977 int containerType = mStateManager.getState().containerType;
978 if (containerType == ContainerType.WORKSPACE && mWorkspace != null) {
979 getUserEventDispatcher().logActionCommand(command,
Samuel Fufaca37b8a2019-08-19 17:04:36 -0700980 containerType, -1, mWorkspace.isOverlayShown() ? -1 : 0);
Becky Qiubfc2da12019-08-01 11:09:38 -0700981 } else {
982 getUserEventDispatcher().logActionCommand(command, containerType, -1);
983 }
Sunny Goyalb1d7de22019-09-06 10:36:54 -0700984 }
Becky Qiubfc2da12019-08-01 11:09:38 -0700985
Sunny Goyalb1d7de22019-09-06 10:36:54 -0700986 private void scheduleDeferredCheck() {
987 mHandler.removeCallbacks(mDeferredOverlayCallbacks);
988 postAsyncCallback(mHandler, mDeferredOverlayCallbacks);
989 }
990
991 private void checkIfOverlayStillDeferred() {
992 if (!mDeferOverlayCallbacks) {
993 return;
994 }
995 if (isStarted() && (!hasBeenResumed() || mStateManager.getState().disableInteraction)) {
996 return;
997 }
998 mDeferOverlayCallbacks = false;
999
1000 // Move the client to the correct state. Calling the same method twice is no-op.
1001 if (isStarted()) {
1002 mOverlayManager.onActivityStarted(this);
1003 }
1004 if (hasBeenResumed()) {
1005 mOverlayManager.onActivityResumed(this);
1006 } else {
1007 mOverlayManager.onActivityPaused(this);
1008 }
1009 if (!isStarted()) {
1010 mOverlayManager.onActivityStopped(this);
1011 }
1012 }
1013
1014 public void deferOverlayCallbacksUntilNextResumeOrStop() {
1015 mDeferOverlayCallbacks = true;
1016 }
1017
1018 public LauncherOverlayManager getOverlayManager() {
1019 return mOverlayManager;
Becky Qiubfc2da12019-08-01 11:09:38 -07001020 }
1021
Winson Chungef528762019-09-06 12:05:52 -07001022 public void onStateSetStart(LauncherState state) {
Sunny Goyale9c6f4c2019-05-30 11:35:25 -07001023 if (mDeferredResumePending) {
1024 handleDeferredResume();
1025 }
Sunny Goyalb1d7de22019-09-06 10:36:54 -07001026 if (mDeferOverlayCallbacks) {
1027 scheduleDeferredCheck();
Sunny Goyale9c6f4c2019-05-30 11:35:25 -07001028 }
Sunny Goyaldedda052019-05-14 15:23:48 -07001029 }
1030
Winson Chungef528762019-09-06 12:05:52 -07001031 public void onStateSetEnd(LauncherState state) {
1032 getAppWidgetHost().setResumed(state == LauncherState.NORMAL);
1033 getWorkspace().setClipChildren(!state.disablePageClipping);
1034 finishAutoCancelActionMode();
1035 }
1036
Michael Jurkacd496d72013-04-11 11:32:45 -07001037 @Override
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001038 protected void onResume() {
Sunny Goyal17c72fb2019-10-14 14:06:38 -07001039 TraceHelper.INSTANCE.beginSection(ON_RESUME_EVT, TraceHelper.FLAG_UI_EVENT);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001040 super.onResume();
Sunny Goyalfca6bc92017-09-28 16:28:34 -07001041
Sunny Goyala002c6c2019-02-12 16:20:10 -08001042 mHandler.removeCallbacks(mHandleDeferredResume);
1043 Utilities.postAsyncCallback(mHandler, mHandleDeferredResume);
Hyunyoung Songbd6fba92018-05-16 15:54:31 -07001044
Winson Chung940b0ac2019-07-09 11:33:50 -07001045 if (!mOnResumeCallbacks.isEmpty()) {
1046 final ArrayList<OnResumeCallback> resumeCallbacks = new ArrayList<>(mOnResumeCallbacks);
1047 mOnResumeCallbacks.clear();
1048 for (int i = resumeCallbacks.size() - 1; i >= 0; i--) {
1049 resumeCallbacks.get(i).onLauncherResume();
1050 }
1051 resumeCallbacks.clear();
Winson Chung0b70cd42019-06-17 22:34:33 -07001052 }
Sunny Goyal95f3d6b2016-08-10 16:09:29 -07001053
Sunny Goyalb1d7de22019-09-06 10:36:54 -07001054 if (mDeferOverlayCallbacks) {
1055 scheduleDeferredCheck();
1056 } else {
1057 mOverlayManager.onActivityResumed(this);
Adam Cohen9211d422014-10-07 18:14:53 -07001058 }
Mario Bertschler0fc6f682017-02-17 12:16:13 -08001059
Sunny Goyal17c72fb2019-10-14 14:06:38 -07001060 TraceHelper.INSTANCE.endSection();
Adam Cohen06dff352012-06-01 17:17:08 -07001061 }
1062
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001063 @Override
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001064 protected void onPause() {
Winson Chung997a9232013-07-24 15:33:46 -07001065 // Ensure that items added to Launcher are queued until Launcher returns
Sunny Goyala474a9b2017-05-04 16:47:11 -07001066 InstallShortcutReceiver.enableInstallQueue(InstallShortcutReceiver.FLAG_ACTIVITY_PAUSED);
Winson Chung997a9232013-07-24 15:33:46 -07001067
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001068 super.onPause();
Joe Onorato24b6fd82009-11-12 13:47:09 -08001069 mDragController.cancelDrag();
Winson Chunga2413752012-04-03 14:22:34 -07001070 mDragController.resetLastGestureUpTime();
Hyunyoung Song497708c2019-05-01 16:16:53 -07001071 mDropTargetBar.animateToVisibility(false);
Sunny Goyalb1d7de22019-09-06 10:36:54 -07001072
1073 if (!mDeferOverlayCallbacks) {
1074 mOverlayManager.onActivityPaused(this);
Adam Cohenbffe7452013-07-22 18:21:45 -07001075 }
Adam Cohenbffe7452013-07-22 18:21:45 -07001076 }
1077
Winson Chungd7823942018-02-16 03:23:47 +00001078 @Override
Tracy Zhoua706f002018-03-28 13:55:19 -07001079 protected void onUserLeaveHint() {
1080 super.onUserLeaveHint();
1081 UiFactory.onLauncherStateOrResumeChanged(this);
1082 }
1083
1084 @Override
Winson Chungd7823942018-02-16 03:23:47 +00001085 public void onWindowFocusChanged(boolean hasFocus) {
1086 super.onWindowFocusChanged(hasFocus);
1087 mStateManager.onWindowFocusChanged();
1088 }
1089
Adam Cohenc2d6e892014-10-16 09:49:24 -07001090 class LauncherOverlayCallbacksImpl implements LauncherOverlayCallbacks {
1091
Sunny Goyalc86df472016-02-25 09:19:38 -08001092 public void onScrollChanged(float progress) {
1093 if (mWorkspace != null) {
1094 mWorkspace.onOverlayScrollChanged(progress);
1095 }
1096 }
Adam Cohenc2d6e892014-10-16 09:49:24 -07001097 }
1098
Sunny Goyalf9403d92017-10-18 10:55:56 -07001099 public boolean isInState(LauncherState state) {
Sunny Goyalea609262017-10-25 15:47:38 -07001100 return mStateManager.getState() == state;
Sunny Goyalf9403d92017-10-18 10:55:56 -07001101 }
1102
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001103 /**
1104 * Restores the previous state, if it exists.
1105 *
1106 * @param savedState The previous state.
1107 */
1108 private void restoreState(Bundle savedState) {
1109 if (savedState == null) {
1110 return;
1111 }
1112
Sunny Goyal3e3f44c2017-10-23 17:14:52 -07001113 int stateOrdinal = savedState.getInt(RUNTIME_STATE, NORMAL.ordinal);
Sunny Goyalf9403d92017-10-18 10:55:56 -07001114 LauncherState[] stateValues = LauncherState.values();
1115 LauncherState state = stateValues[stateOrdinal];
Sunny Goyalbc683e92017-12-06 10:25:07 -08001116 if (!state.disableRestore) {
Sunny Goyal3e3f44c2017-10-23 17:14:52 -07001117 mStateManager.goToState(state, false /* animated */);
Joe Onorato3a8820b2009-11-10 15:06:42 -08001118 }
1119
Samuel Fufaca37b8a2019-08-19 17:04:36 -07001120 PendingRequestArgs requestArgs = savedState.getParcelable(
1121 RUNTIME_STATE_PENDING_REQUEST_ARGS);
Sunny Goyal2100c782016-08-22 16:00:03 -07001122 if (requestArgs != null) {
1123 setWaitingForResult(requestArgs);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001124 }
Sunny Goyaldedda052019-05-14 15:23:48 -07001125 mPendingActivityRequestCode = savedState.getInt(RUNTIME_STATE_PENDING_REQUEST_CODE);
Sunny Goyal2100c782016-08-22 16:00:03 -07001126
1127 mPendingActivityResult = savedState.getParcelable(RUNTIME_STATE_PENDING_ACTIVITY_RESULT);
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -07001128
1129 SparseArray<Parcelable> widgetsState =
1130 savedState.getSparseParcelableArray(RUNTIME_STATE_WIDGET_PANEL);
1131 if (widgetsState != null) {
1132 WidgetsFullSheet.show(this, false).restoreHierarchyState(widgetsState);
1133 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001134 }
1135
1136 /**
1137 * Finds all the views we need and configure them properly.
1138 */
1139 private void setupViews() {
Sunny Goyalcc96aa12018-01-11 09:56:07 -08001140 mDragLayer = findViewById(R.id.drag_layer);
Sunny Goyal3333b0c2016-05-09 20:43:21 -07001141 mFocusHandler = mDragLayer.getFocusIndicatorHelper();
Sunny Goyal966d9012017-06-06 16:43:59 -07001142 mWorkspace = mDragLayer.findViewById(R.id.workspace);
Sunny Goyald0a6ae72016-06-16 12:29:03 -07001143 mWorkspace.initParentViews(mDragLayer);
Sunny Goyal16764582017-11-06 16:00:34 -08001144 mOverviewPanel = findViewById(R.id.overview_panel);
Sunny Goyal7c7be8c2018-03-07 19:58:07 -08001145 mHotseat = findViewById(R.id.hotseat);
Craig Mautner360310b2012-10-26 15:13:08 -07001146
Sunny Goyal784f9c32016-03-23 16:56:54 -07001147 mLauncherView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
1148 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
1149 | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001150
Winson Chung4c98d922011-05-31 16:50:48 -07001151 // Setup the drag layer
Sunny Goyal5d1873a2018-05-08 11:10:44 -07001152 mDragLayer.setup(mDragController, mWorkspace);
Sunny Goyal0b1cb752019-06-05 15:18:39 -07001153 mCancelTouchController = UiFactory.enableLiveUIChanges(this);
Winson Chung4c98d922011-05-31 16:50:48 -07001154
Hyunyoung Song645764e2016-06-06 14:19:02 -07001155 mWorkspace.setup(mDragController);
Winsonc7d2e832016-07-28 12:24:55 -07001156 // Until the workspace is bound, ensure that we keep the wallpaper offset locked to the
1157 // default state, otherwise we will update to the wrong offsets in RTL
1158 mWorkspace.lockWallpaperToDefaultPage();
Sunny Goyalda4fe1a2016-05-26 16:05:17 -07001159 mWorkspace.bindAndInitFirstWorkspaceScreen(null /* recycled qsb */);
Hyunyoung Song645764e2016-06-06 14:19:02 -07001160 mDragController.addDragListener(mWorkspace);
Winson Chung4c98d922011-05-31 16:50:48 -07001161
Tony Wickham34d2c912015-09-11 09:27:58 -07001162 // Get the search/delete/uninstall bar
Rajeev Kumar43c0f582017-06-23 15:34:55 -07001163 mDropTargetBar = mDragLayer.findViewById(R.id.drop_target_bar);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07001164
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -07001165 // Setup Apps
1166 mAppsView = findViewById(R.id.apps_view);
Craig Mautner360310b2012-10-26 15:13:08 -07001167
Govinda Wassermanc06e1512019-04-09 09:56:53 -04001168 // Setup Scrim
1169 mScrimView = findViewById(R.id.scrim_view);
1170
Winson Chung3d503fb2011-07-13 17:25:49 -07001171 // Setup the drag controller (drop targets have to be added in reverse order in priority)
Hyunyoung Song645764e2016-06-06 14:19:02 -07001172 mDragController.setMoveTarget(mWorkspace);
Sunny Goyal47328fd2016-05-25 18:56:41 -07001173 mDropTargetBar.setup(mDragController);
Daniel Sandler924b9932013-06-12 00:38:25 -04001174
Sunny Goyal7185dd62018-03-14 17:51:49 -07001175 mAllAppsController.setupViews(mAppsView);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001176 }
1177
1178 /**
1179 * Creates a view representing a shortcut.
1180 *
1181 * @param info The data structure describing the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001182 */
Sunny Goyal95899162019-03-27 16:03:06 -07001183 View createShortcut(WorkspaceItemInfo info) {
Sunny Goyaldfaccf62015-05-11 16:30:44 -07001184 return createShortcut((ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001185 }
1186
1187 /**
1188 * Creates a view representing a shortcut inflated from the specified resource.
1189 *
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001190 * @param parent The group the shortcut belongs to.
Samuel Fufaca37b8a2019-08-19 17:04:36 -07001191 * @param info The data structure describing the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001192 * @return A View inflated from layoutResId.
1193 */
Sunny Goyal95899162019-03-27 16:03:06 -07001194 public View createShortcut(ViewGroup parent, WorkspaceItemInfo info) {
Sunny Goyal9b29ca52017-02-17 10:39:44 -08001195 BubbleTextView favorite = (BubbleTextView) LayoutInflater.from(parent.getContext())
1196 .inflate(R.layout.app_icon, parent, false);
Sunny Goyal95899162019-03-27 16:03:06 -07001197 favorite.applyFromWorkspaceItem(info);
Sunny Goyal8a2a63b2018-03-06 22:15:18 -08001198 favorite.setOnClickListener(ItemClickHandler.INSTANCE);
Sunny Goyaldcbcc862014-08-12 15:58:36 -07001199 favorite.setOnFocusChangeListener(mFocusHandler);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001200 return favorite;
1201 }
1202
1203 /**
Jon Mirandac476d6e2017-05-04 16:30:01 -07001204 * Add a shortcut to the workspace or to a Folder.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001205 *
1206 * @param data The intent describing the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001207 */
Sunny Goyalefb7e842018-10-04 15:11:00 -07001208 private void completeAddShortcut(Intent data, int container, int screenId, int cellX,
Sunny Goyalfb5096d2016-09-08 14:32:06 -07001209 int cellY, PendingRequestArgs args) {
Jon Mirandac476d6e2017-05-04 16:30:01 -07001210 if (args.getRequestCode() != REQUEST_CREATE_SHORTCUT
1211 || args.getPendingIntent().getComponent() == null) {
Sunny Goyalfb5096d2016-09-08 14:32:06 -07001212 return;
1213 }
Adam Cohen558baaf2011-08-15 15:22:57 -07001214
Jon Mirandac476d6e2017-05-04 16:30:01 -07001215 int[] cellXY = mTmpAddItemCellCoordinates;
1216 CellLayout layout = getCellLayout(container, screenId);
1217
Sunny Goyal95899162019-03-27 16:03:06 -07001218 WorkspaceItemInfo info = null;
Hyunyoung Songe24cb632017-09-11 11:18:03 -07001219 if (Utilities.ATLEAST_OREO) {
Sunny Goyale7b00122019-10-02 16:13:34 -07001220 info = PinRequestHelper.createWorkspaceItemFromPinItemRequest(
1221 this, PinRequestHelper.getPinItemRequest(data), 0);
Sunny Goyal782f0c92017-01-19 10:27:54 -08001222 }
1223
1224 if (info == null) {
Sunny Goyalb57645f2017-03-20 13:57:28 -07001225 // Legacy shortcuts are only supported for primary profile.
1226 info = Process.myUserHandle().equals(args.user)
1227 ? InstallShortcutReceiver.fromShortcutIntent(this, data) : null;
Sunny Goyal782f0c92017-01-19 10:27:54 -08001228
Sunny Goyalb57645f2017-03-20 13:57:28 -07001229 if (info == null) {
1230 Log.e(TAG, "Unable to parse a valid custom shortcut result");
1231 return;
1232 } else if (!new PackageManagerHelper(this).hasPermissionForActivity(
Sunny Goyal342e4662017-02-02 15:21:08 -08001233 info.intent, args.getPendingIntent().getComponent().getPackageName())) {
Sunny Goyal782f0c92017-01-19 10:27:54 -08001234 // The app is trying to add a shortcut without sufficient permissions
1235 Log.e(TAG, "Ignoring malicious intent " + info.intent.toUri(0));
1236 return;
1237 }
1238 }
1239
Jon Mirandac476d6e2017-05-04 16:30:01 -07001240 if (container < 0) {
1241 // Adding a shortcut to the Workspace.
1242 final View view = createShortcut(info);
1243 boolean foundCellSpan = false;
1244 // First we check if we already know the exact location where we want to add this item.
1245 if (cellX >= 0 && cellY >= 0) {
1246 cellXY[0] = cellX;
1247 cellXY[1] = cellY;
1248 foundCellSpan = true;
Adam Cohen558baaf2011-08-15 15:22:57 -07001249
Jon Mirandac476d6e2017-05-04 16:30:01 -07001250 // If appropriate, either create a folder or add to an existing folder
1251 if (mWorkspace.createUserFolderIfNecessary(view, container, layout, cellXY, 0,
Sunny Goyal1797af42017-10-06 13:29:57 -07001252 true, null)) {
Jon Mirandac476d6e2017-05-04 16:30:01 -07001253 return;
1254 }
1255 DragObject dragObject = new DragObject();
1256 dragObject.dragInfo = info;
1257 if (mWorkspace.addToExistingFolderIfNecessary(view, layout, cellXY, 0, dragObject,
1258 true)) {
1259 return;
1260 }
1261 } else {
1262 foundCellSpan = layout.findCellForSpan(cellXY, 1, 1);
1263 }
1264
1265 if (!foundCellSpan) {
1266 mWorkspace.onNoCellFound(layout);
Adam Cohen558baaf2011-08-15 15:22:57 -07001267 return;
1268 }
Jon Mirandac476d6e2017-05-04 16:30:01 -07001269
1270 getModelWriter().addItemToDatabase(info, container, screenId, cellXY[0], cellXY[1]);
1271 mWorkspace.addInScreen(view, info);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001272 } else {
Jon Mirandac476d6e2017-05-04 16:30:01 -07001273 // Adding a shortcut to a Folder.
Sunny Goyale29897f52017-07-20 10:09:42 -07001274 FolderIcon folderIcon = findFolderIcon(container);
Jon Mirandac476d6e2017-05-04 16:30:01 -07001275 if (folderIcon != null) {
1276 FolderInfo folderInfo = (FolderInfo) folderIcon.getTag();
1277 folderInfo.add(info, args.rank, false);
1278 } else {
Sunny Goyale29897f52017-07-20 10:09:42 -07001279 Log.e(TAG, "Could not find folder with id " + container + " to add shortcut.");
Jon Mirandac476d6e2017-05-04 16:30:01 -07001280 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001281 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001282 }
1283
Sunny Goyalefb7e842018-10-04 15:11:00 -07001284 public FolderIcon findFolderIcon(final int folderIconId) {
Sunny Goyal83fd25e2018-07-09 16:47:01 -07001285 return (FolderIcon) mWorkspace.getHomescreenIconByItemId(folderIconId);
Sunny Goyale29897f52017-07-20 10:09:42 -07001286 }
1287
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001288 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001289 * Add a widget to the workspace.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001290 *
Romain Guy5bbc91b2010-08-18 11:38:46 -07001291 * @param appWidgetId The app widget id
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001292 */
Samuel Fufaca37b8a2019-08-19 17:04:36 -07001293 @Thunk
1294 void completeAddAppWidget(int appWidgetId, ItemInfo itemInfo,
Adam Cohen59400422014-03-05 18:07:04 -08001295 AppWidgetHostView hostView, LauncherAppWidgetProviderInfo appWidgetInfo) {
1296
Adam Cohened66b2b2012-01-23 17:28:51 -08001297 if (appWidgetInfo == null) {
Sunny Goyal2e1efb42016-03-03 16:58:55 -08001298 appWidgetInfo = mAppWidgetManager.getLauncherAppWidgetInfo(appWidgetId);
Adam Cohened66b2b2012-01-23 17:28:51 -08001299 }
Romain Guycbb89e42009-06-08 15:52:54 -07001300
Adam Cohen59400422014-03-05 18:07:04 -08001301 LauncherAppWidgetInfo launcherInfo;
1302 launcherInfo = new LauncherAppWidgetInfo(appWidgetId, appWidgetInfo.provider);
Sunny Goyal2100c782016-08-22 16:00:03 -07001303 launcherInfo.spanX = itemInfo.spanX;
1304 launcherInfo.spanY = itemInfo.spanY;
1305 launcherInfo.minSpanX = itemInfo.minSpanX;
1306 launcherInfo.minSpanY = itemInfo.minSpanY;
Sunny Goyal952e63d2017-08-16 04:59:08 -07001307 launcherInfo.user = appWidgetInfo.getProfile();
Romain Guycbb89e42009-06-08 15:52:54 -07001308
Sunny Goyal43bf11d2017-02-02 13:52:53 -08001309 getModelWriter().addItemToDatabase(launcherInfo,
Sunny Goyal2100c782016-08-22 16:00:03 -07001310 itemInfo.container, itemInfo.screenId, itemInfo.cellX, itemInfo.cellY);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001311
Sunny Goyal2100c782016-08-22 16:00:03 -07001312 if (hostView == null) {
1313 // Perform actual inflation because we're live
1314 hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001315 }
Sunny Goyal2100c782016-08-22 16:00:03 -07001316 hostView.setVisibility(View.VISIBLE);
Sunny Goyald5462aa2016-11-22 16:52:39 +05301317 prepareAppWidget(hostView, launcherInfo);
1318 mWorkspace.addInScreen(hostView, launcherInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001319 }
Romain Guycbb89e42009-06-08 15:52:54 -07001320
Sunny Goyald5462aa2016-11-22 16:52:39 +05301321 private void prepareAppWidget(AppWidgetHostView hostView, LauncherAppWidgetInfo item) {
Sunny Goyal87af0fd2016-05-16 14:56:02 -07001322 hostView.setTag(item);
1323 item.onBindAppWidget(this, hostView);
Sunny Goyal87af0fd2016-05-16 14:56:02 -07001324 hostView.setFocusable(true);
1325 hostView.setOnFocusChangeListener(mFocusHandler);
Sunny Goyal25c2e3e2015-10-28 23:28:21 -07001326 }
1327
Sunny Goyal5d1873a2018-05-08 11:10:44 -07001328 private final BroadcastReceiver mScreenOffReceiver = new BroadcastReceiver() {
Adam Cohended9f8d2010-11-03 13:25:16 -07001329 @Override
1330 public void onReceive(Context context, Intent intent) {
Sunny Goyal5d1873a2018-05-08 11:10:44 -07001331 // Reset AllApps to its initial state only if we are not in the middle of
1332 // processing a multi-step drop
1333 if (mPendingRequestArgs == null) {
1334 mStateManager.goToState(NORMAL);
Adam Cohended9f8d2010-11-03 13:25:16 -07001335 }
1336 }
1337 };
1338
Sunny Goyalaae6fbb2019-01-31 16:05:58 -08001339 public void updateNotificationDots(Predicate<PackageUserKey> updatedDots) {
Tony Wickhamf34bee82018-12-03 18:11:39 -08001340 mWorkspace.updateNotificationDots(updatedDots);
1341 mAppsView.getAppsStore().updateNotificationDots(updatedDots);
Tony Wickham010d2552017-01-20 08:15:28 -08001342 }
1343
Adam Cohended9f8d2010-11-03 13:25:16 -07001344 @Override
1345 public void onAttachedToWindow() {
1346 super.onAttachedToWindow();
Sunny Goyalb1d7de22019-09-06 10:36:54 -07001347 mOverlayManager.onAttachedToWindow();
Adam Cohended9f8d2010-11-03 13:25:16 -07001348 }
1349
1350 @Override
1351 public void onDetachedFromWindow() {
1352 super.onDetachedFromWindow();
Sunny Goyalb1d7de22019-09-06 10:36:54 -07001353 mOverlayManager.onDetachedFromWindow();
1354 closeContextMenu();
Adam Cohended9f8d2010-11-03 13:25:16 -07001355 }
1356
Sunny Goyalc4fa8c32017-11-07 12:23:58 -08001357 public AllAppsTransitionController getAllAppsController() {
1358 return mAllAppsController;
1359 }
1360
Sunny Goyal9d69c8d2018-03-19 13:41:31 -07001361 @Override
Winson Chung1a341002018-01-17 10:00:23 -08001362 public LauncherRootView getRootView() {
1363 return (LauncherRootView) mLauncherView;
1364 }
1365
Sunny Goyal0b0847b2018-03-14 12:30:11 -07001366 @Override
Winson Chunga6945242014-01-08 14:04:34 -08001367 public DragLayer getDragLayer() {
1368 return mDragLayer;
1369 }
1370
Winson Chung5f4e0fd2015-05-22 11:12:27 -07001371 public AllAppsContainerView getAppsView() {
Winson Chungb745afb2015-03-02 11:51:23 -08001372 return mAppsView;
1373 }
1374
Winson Chunga6945242014-01-08 14:04:34 -08001375 public Workspace getWorkspace() {
1376 return mWorkspace;
1377 }
1378
1379 public Hotseat getHotseat() {
1380 return mHotseat;
1381 }
1382
Sunny Goyal7c7be8c2018-03-07 19:58:07 -08001383 public <T extends View> T getOverviewPanel() {
Winson Chung8ae41982017-11-10 11:42:13 -08001384 return (T) mOverviewPanel;
Winson Chunga6945242014-01-08 14:04:34 -08001385 }
1386
Sunny Goyal47328fd2016-05-25 18:56:41 -07001387 public DropTargetBar getDropTargetBar() {
1388 return mDropTargetBar;
Tony Wickham34d2c912015-09-11 09:27:58 -07001389 }
1390
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001391 public LauncherAppWidgetHost getAppWidgetHost() {
1392 return mAppWidgetHost;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001393 }
Romain Guycbb89e42009-06-08 15:52:54 -07001394
Winson Chunga9abd0e2010-10-27 17:18:37 -07001395 public LauncherModel getModel() {
1396 return mModel;
1397 }
1398
Sunny Goyal43bf11d2017-02-02 13:52:53 -08001399 public ModelWriter getModelWriter() {
1400 return mModelWriter;
1401 }
1402
Sunny Goyalb1d7de22019-09-06 10:36:54 -07001403 @Override
Adam Cohen79d90c52016-04-22 13:29:20 -07001404 public SharedPreferences getSharedPrefs() {
Winson Chunga6945242014-01-08 14:04:34 -08001405 return mSharedPrefs;
1406 }
1407
Sunny Goyalb1d7de22019-09-06 10:36:54 -07001408 @Override
1409 public SharedPreferences getDevicePrefs() {
1410 return Utilities.getDevicePrefs(this);
1411 }
1412
Samuel Fufaca37b8a2019-08-19 17:04:36 -07001413 public int getOrientation() {
1414 return mOldConfig.orientation;
1415 }
Jon Miranda6bed3502017-09-19 14:43:17 -07001416
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001417 @Override
1418 protected void onNewIntent(Intent intent) {
Sunny Goyal17c72fb2019-10-14 14:06:38 -07001419 TraceHelper.INSTANCE.beginSection(ON_NEW_INTENT_EVT);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001420 super.onNewIntent(intent);
1421
Sunny Goyalf4aceab2017-12-06 16:16:31 -08001422 boolean alreadyOnHome = hasWindowFocus() && ((intent.getFlags() &
Winson15f8b172015-08-19 11:02:39 -07001423 Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
1424 != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
Sunny Goyal85313732016-09-28 12:00:07 -07001425
1426 // Check this condition before handling isActionMain, as this will get reset.
Sunny Goyal3e3f44c2017-10-23 17:14:52 -07001427 boolean shouldMoveToDefaultScreen = alreadyOnHome && isInState(NORMAL)
Sunny Goyalf9403d92017-10-18 10:55:56 -07001428 && AbstractFloatingView.getTopOpenView(this) == null;
Winson15f8b172015-08-19 11:02:39 -07001429 boolean isActionMain = Intent.ACTION_MAIN.equals(intent.getAction());
Sunny Goyale84c5b82019-09-26 17:05:31 -07001430 boolean internalStateHandled = ACTIVITY_TRACKER.handleNewIntent(this, intent);
Sunny Goyald3864fa2017-11-14 15:06:36 -08001431
Winson15f8b172015-08-19 11:02:39 -07001432 if (isActionMain) {
Sunny Goyald3864fa2017-11-14 15:06:36 -08001433 if (!internalStateHandled) {
Sunny Goyald3864fa2017-11-14 15:06:36 -08001434 // In all these cases, only animate if we're already on home
Sunny Goyalcc96aa12018-01-11 09:56:07 -08001435 AbstractFloatingView.closeAllOpenViews(this, isStarted());
Jon Mirandafeba90f2016-10-06 10:53:29 -07001436
Sunny Goyala2467272018-03-16 14:53:05 -07001437 if (!isInState(NORMAL)) {
1438 // Only change state, if not already the same. This prevents cancelling any
1439 // animations running as part of resume
1440 mStateManager.goToState(NORMAL);
1441 }
Sunny Goyald3864fa2017-11-14 15:06:36 -08001442
1443 // Reset the apps view
Sunny Goyal5d1873a2018-05-08 11:10:44 -07001444 if (!alreadyOnHome) {
Sunny Goyal7185dd62018-03-14 17:51:49 -07001445 mAppsView.reset(isStarted() /* animate */);
Sunny Goyald3864fa2017-11-14 15:06:36 -08001446 }
1447
Sunny Goyalaad33592018-08-07 17:20:35 -07001448 if (shouldMoveToDefaultScreen && !mWorkspace.isHandlingTouch()) {
Sunny Goyald3864fa2017-11-14 15:06:36 -08001449 mWorkspace.post(mWorkspace::moveToDefaultScreen);
1450 }
1451 }
Adam Cohen6fecd412013-10-02 17:41:50 -07001452
Hyunyoung Song2a70b3d2019-06-11 12:47:07 -07001453 // Handle HOME_INTENT
1454 UserEventDispatcher ued = getUserEventDispatcher();
1455 Target target = newContainerTarget(mStateManager.getState().containerType);
1456 target.pageIndex = mWorkspace.getCurrentPage();
1457 ued.logActionCommand(Action.Command.HOME_INTENT, target,
1458 newContainerTarget(ContainerType.WORKSPACE));
1459
Adam Cohen6fecd412013-10-02 17:41:50 -07001460 final View v = getWindow().peekDecorView();
1461 if (v != null && v.getWindowToken() != null) {
Sunny Goyal326403e2017-10-02 12:45:10 -07001462 UiThreadHelper.hideKeyboardAsync(this, v.getWindowToken());
Adam Cohen6fecd412013-10-02 17:41:50 -07001463 }
1464
Adam Cohen9211d422014-10-07 18:14:53 -07001465 if (mLauncherCallbacks != null) {
Sunny Goyal85462132018-04-24 11:39:37 -07001466 mLauncherCallbacks.onHomeIntent(internalStateHandled);
Adam Cohen9211d422014-10-07 18:14:53 -07001467 }
Sunny Goyalb1d7de22019-09-06 10:36:54 -07001468 mOverlayManager.hideOverlay(isStarted() && !isForceInvisible());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001469 }
Winson15f8b172015-08-19 11:02:39 -07001470
Sunny Goyal17c72fb2019-10-14 14:06:38 -07001471 TraceHelper.INSTANCE.endSection();
Adam Coppa120b8e2013-11-12 16:26:04 +00001472 }
1473
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001474 @Override
Adam Cohen1462de32012-07-24 22:34:36 -07001475 public void onRestoreInstanceState(Bundle state) {
1476 super.onRestoreInstanceState(state);
Sunny Goyalf4aceab2017-12-06 16:16:31 -08001477 mWorkspace.restoreInstanceStateForChild(mSynchronouslyBoundPage);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001478 }
1479
1480 @Override
1481 protected void onSaveInstanceState(Bundle outState) {
Adam Cohen21cd0022013-10-09 18:57:02 -07001482 if (mWorkspace.getChildCount() > 0) {
Sunny Goyal7ce471b2017-08-02 03:37:39 -07001483 outState.putInt(RUNTIME_STATE_CURRENT_SCREEN, mWorkspace.getNextPage());
Hyunyoung Song645764e2016-06-06 14:19:02 -07001484
Adam Cohen21cd0022013-10-09 18:57:02 -07001485 }
Sunny Goyalea609262017-10-25 15:47:38 -07001486 outState.putInt(RUNTIME_STATE, mStateManager.getState().ordinal);
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -07001487
1488
1489 AbstractFloatingView widgets = AbstractFloatingView
1490 .getOpenView(this, AbstractFloatingView.TYPE_WIDGETS_FULL_SHEET);
1491 if (widgets != null) {
1492 SparseArray<Parcelable> widgetsState = new SparseArray<>();
1493 widgets.saveHierarchyState(widgetsState);
1494 outState.putSparseParcelableArray(RUNTIME_STATE_WIDGET_PANEL, widgetsState);
1495 } else {
1496 outState.remove(RUNTIME_STATE_WIDGET_PANEL);
1497 }
1498
Pinyao Tinga74b63a2019-07-17 23:26:06 -07001499 // We close any open folders and shortcut containers that are not safe for rebind,
Sunny Goyal740ac7f2016-09-28 16:47:32 -07001500 // and we need to make sure this state is reflected.
Pinyao Tinga74b63a2019-07-17 23:26:06 -07001501 AbstractFloatingView.closeOpenViews(this, false, TYPE_ALL & ~TYPE_REBIND_SAFE);
1502 finishAutoCancelActionMode();
Tony Wickham49c8d292016-07-01 11:44:34 -07001503
Sunny Goyal2100c782016-08-22 16:00:03 -07001504 if (mPendingRequestArgs != null) {
1505 outState.putParcelable(RUNTIME_STATE_PENDING_REQUEST_ARGS, mPendingRequestArgs);
1506 }
Sunny Goyaldedda052019-05-14 15:23:48 -07001507 outState.putInt(RUNTIME_STATE_PENDING_REQUEST_CODE, mPendingActivityRequestCode);
1508
Sunny Goyal2100c782016-08-22 16:00:03 -07001509 if (mPendingActivityResult != null) {
1510 outState.putParcelable(RUNTIME_STATE_PENDING_ACTIVITY_RESULT, mPendingActivityResult);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001511 }
1512
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -07001513 super.onSaveInstanceState(outState);
Sunny Goyalb1d7de22019-09-06 10:36:54 -07001514 mOverlayManager.onActivitySaveInstanceState(this, outState);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001515 }
1516
1517 @Override
1518 public void onDestroy() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001519 super.onDestroy();
Sunny Goyale84c5b82019-09-26 17:05:31 -07001520 ACTIVITY_TRACKER.onActivityDestroyed(this);
Romain Guycbb89e42009-06-08 15:52:54 -07001521
Sunny Goyal5d1873a2018-05-08 11:10:44 -07001522 unregisterReceiver(mScreenOffReceiver);
Sunny Goyalaaf7d1d2016-05-17 13:38:54 -07001523 mWorkspace.removeFolderListeners();
Sunny Goyalb1d7de22019-09-06 10:36:54 -07001524 PluginManagerWrapper.INSTANCE.get(this).removePluginListener(this);
Winson Chunge7a03942011-08-05 15:05:12 -07001525
Sunny Goyal5743f862019-03-28 15:35:32 -07001526 if (mCancelTouchController != null) {
1527 mCancelTouchController.run();
1528 mCancelTouchController = null;
1529 }
Tony Wickhama0068302018-04-11 16:16:11 -07001530
Winson Chungcd2b0142011-06-08 16:02:26 -07001531 // Stop callbacks from LauncherModel
Adam Cohen1a85c582014-09-30 09:48:49 -07001532 // It's possible to receive onDestroy after a new Launcher activity has
1533 // been created. In this case, don't interfere with the new Launcher.
1534 if (mModel.isCurrentCallbacks(this)) {
1535 mModel.stopLoader();
Sunny Goyal87f784c2017-01-11 10:48:34 -08001536 LauncherAppState.getInstance(this).setLauncher(null);
Adam Cohen1a85c582014-09-30 09:48:49 -07001537 }
Sunny Goyal623eddd2018-03-02 12:24:41 -08001538 mRotationHelper.destroy();
Sunny Goyal745bad92016-05-02 10:54:12 -07001539
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001540 try {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001541 mAppWidgetHost.stopListening();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001542 } catch (NullPointerException ex) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001543 Log.w(TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001544 }
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001545
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001546 TextKeyListener.getInstance().release();
Tony2917a8b2017-07-31 23:29:42 -07001547 clearPendingBinds();
Hyunyoung Song31971a32019-01-27 12:31:12 -08001548 LauncherAppState.getIDP(this).removeOnChangeListener(this);
Sunny Goyalb1d7de22019-09-06 10:36:54 -07001549
1550 mOverlayManager.onActivityDestroyed(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001551 }
1552
Sunny Goyalae502842016-06-17 08:43:56 -07001553 public LauncherAccessibilityDelegate getAccessibilityDelegate() {
1554 return mAccessibilityDelegate;
1555 }
1556
Adam Cohena9cf38f2011-05-02 15:36:58 -07001557 public DragController getDragController() {
1558 return mDragController;
1559 }
1560
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001561 @Override
Sunny Goyal0eca4e22016-07-20 11:43:06 -07001562 public void startActivityForResult(Intent intent, int requestCode, Bundle options) {
Sunny Goyaldedda052019-05-14 15:23:48 -07001563 if (requestCode != -1) {
1564 mPendingActivityRequestCode = requestCode;
1565 }
1566 if (requestCode == -1
1567 || !UiFactory.startActivityForResult(this, intent, requestCode, options)) {
1568 super.startActivityForResult(intent, requestCode, options);
1569 }
Adam Cohen173f7112015-03-27 15:14:00 -07001570 }
1571
1572 @Override
Sunny Goyaldedda052019-05-14 15:23:48 -07001573 public void startIntentSenderForResult(IntentSender intent, int requestCode,
Adam Cohen173f7112015-03-27 15:14:00 -07001574 Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags, Bundle options) {
Sunny Goyaldedda052019-05-14 15:23:48 -07001575 if (requestCode != -1) {
1576 mPendingActivityRequestCode = requestCode;
1577 }
1578 if (requestCode == -1 || !UiFactory.startIntentSenderForResult(this, intent, requestCode,
1579 fillInIntent, flagsMask, flagsValues, extraFlags, options)) {
1580 try {
1581 super.startIntentSenderForResult(intent, requestCode,
1582 fillInIntent, flagsMask, flagsValues, extraFlags, options);
1583 } catch (IntentSender.SendIntentException e) {
1584 throw new ActivityNotFoundException();
1585 }
Adam Cohen173f7112015-03-27 15:14:00 -07001586 }
1587 }
1588
Winson Chung70d72102011-08-12 11:24:35 -07001589 /**
1590 * Indicates that we want global search for this activity by setting the globalSearch
1591 * argument for {@link #startSearch} to true.
1592 */
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001593 @Override
Romain Guycbb89e42009-06-08 15:52:54 -07001594 public void startSearch(String initialQuery, boolean selectInitialQuery,
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001595 Bundle appSearchData, boolean globalSearch) {
1596 if (appSearchData == null) {
1597 appSearchData = new Bundle();
Bjorn Bringert32b12d22013-06-06 13:00:41 +01001598 appSearchData.putString("source", "launcher-search");
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001599 }
Sunny Goyalda4fe1a2016-05-26 16:05:17 -07001600
Sunny Goyal6f28e712016-09-13 14:19:29 -07001601 if (mLauncherCallbacks == null ||
1602 !mLauncherCallbacks.startSearch(initialQuery, selectInitialQuery, appSearchData)) {
1603 // Starting search from the callbacks failed. Start the default global search.
Sunny Goyalf4aceab2017-12-06 16:16:31 -08001604 super.startSearch(initialQuery, selectInitialQuery, appSearchData, true);
Ian Parkinson047036e2014-09-01 15:40:53 +01001605 }
Winson Chungcd99cd32015-04-29 11:03:24 -07001606
1607 // We need to show the workspace after starting the search
Sunny Goyal3e3f44c2017-10-23 17:14:52 -07001608 mStateManager.goToState(NORMAL);
Bjorn Bringertc459e522013-06-07 19:36:01 +01001609 }
1610
Joe Onorato9c1289c2009-08-17 11:03:03 -04001611 public boolean isWorkspaceLocked() {
Sunny Goyal2100c782016-08-22 16:00:03 -07001612 return mWorkspaceLoading || mPendingRequestArgs != null;
Joe Onorato9c1289c2009-08-17 11:03:03 -04001613 }
1614
Adam Cohen517a7f52014-03-01 12:12:59 -08001615 public boolean isWorkspaceLoading() {
1616 return mWorkspaceLoading;
1617 }
1618
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001619 private void setWorkspaceLoading(boolean value) {
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001620 mWorkspaceLoading = value;
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001621 }
1622
Sunny Goyal04a324a2017-01-20 21:08:59 -08001623 public void setWaitingForResult(PendingRequestArgs args) {
Sunny Goyal2100c782016-08-22 16:00:03 -07001624 mPendingRequestArgs = args;
Adam Cohen9211d422014-10-07 18:14:53 -07001625 }
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001626
Sunny Goyal2100c782016-08-22 16:00:03 -07001627 void addAppWidgetFromDropImpl(int appWidgetId, ItemInfo info, AppWidgetHostView boundWidget,
Sunny Goyal04a324a2017-01-20 21:08:59 -08001628 WidgetAddFlowHandler addFlowHandler) {
Tony Wickhama0628cc2015-10-14 15:23:04 -07001629 if (LOGD) {
1630 Log.d(TAG, "Adding widget from drop");
1631 }
Sunny Goyal04a324a2017-01-20 21:08:59 -08001632 addAppWidgetImpl(appWidgetId, info, boundWidget, addFlowHandler, 0);
Adam Cohenad4e15c2013-10-17 16:21:35 -07001633 }
1634
Sunny Goyal2100c782016-08-22 16:00:03 -07001635 void addAppWidgetImpl(int appWidgetId, ItemInfo info,
Sunny Goyal04a324a2017-01-20 21:08:59 -08001636 AppWidgetHostView boundWidget, WidgetAddFlowHandler addFlowHandler, int delay) {
Samuel Fufaca37b8a2019-08-19 17:04:36 -07001637 if (!addFlowHandler.startConfigActivity(this, appWidgetId, info,
1638 REQUEST_CREATE_APPWIDGET)) {
Sunny Goyal04a324a2017-01-20 21:08:59 -08001639 // If the configuration flow was not started, add the widget
Michael Jurkaaf442092010-06-10 17:01:57 -07001640
Adam Cohenad4e15c2013-10-17 16:21:35 -07001641 Runnable onComplete = new Runnable() {
1642 @Override
1643 public void run() {
1644 // Exit spring loaded mode if necessary after adding the widget
Sunny Goyal3e3f44c2017-10-23 17:14:52 -07001645 mStateManager.goToState(NORMAL, SPRING_LOADED_EXIT_DELAY);
Adam Cohenad4e15c2013-10-17 16:21:35 -07001646 }
1647 };
Samuel Fufaca37b8a2019-08-19 17:04:36 -07001648 completeAddAppWidget(appWidgetId, info, boundWidget,
1649 addFlowHandler.getProviderInfo(this));
Adam Cohen689ff162014-05-08 17:27:56 -07001650 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete, delay, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001651 }
1652 }
Romain Guycbb89e42009-06-08 15:52:54 -07001653
Sunny Goyalefb7e842018-10-04 15:11:00 -07001654 public void addPendingItem(PendingAddItemInfo info, int container, int screenId,
Sunny Goyal71b5c0b2015-01-08 16:59:04 -08001655 int[] cell, int spanX, int spanY) {
Sunny Goyal2100c782016-08-22 16:00:03 -07001656 info.container = container;
1657 info.screenId = screenId;
1658 if (cell != null) {
1659 info.cellX = cell[0];
1660 info.cellY = cell[1];
1661 }
1662 info.spanX = spanX;
1663 info.spanY = spanY;
1664
Sunny Goyal71b5c0b2015-01-08 16:59:04 -08001665 switch (info.itemType) {
1666 case LauncherSettings.Favorites.ITEM_TYPE_CUSTOM_APPWIDGET:
1667 case LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET:
Sunny Goyal2100c782016-08-22 16:00:03 -07001668 addAppWidgetFromDrop((PendingAddWidgetInfo) info);
Sunny Goyal71b5c0b2015-01-08 16:59:04 -08001669 break;
1670 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Sunny Goyal782f0c92017-01-19 10:27:54 -08001671 processShortcutFromDrop((PendingAddShortcutInfo) info);
Sunny Goyal71b5c0b2015-01-08 16:59:04 -08001672 break;
1673 default:
1674 throw new IllegalStateException("Unknown item type: " + info.itemType);
Samuel Fufaca37b8a2019-08-19 17:04:36 -07001675 }
Sunny Goyal71b5c0b2015-01-08 16:59:04 -08001676 }
1677
Adam Cohenfbba09b2011-07-18 21:43:05 -07001678 /**
1679 * Process a shortcut drop.
Adam Cohenfbba09b2011-07-18 21:43:05 -07001680 */
Sunny Goyal782f0c92017-01-19 10:27:54 -08001681 private void processShortcutFromDrop(PendingAddShortcutInfo info) {
Sunny Goyalfb5096d2016-09-08 14:32:06 -07001682 Intent intent = new Intent(Intent.ACTION_CREATE_SHORTCUT).setComponent(info.componentName);
1683 setWaitingForResult(PendingRequestArgs.forIntent(REQUEST_CREATE_SHORTCUT, intent, info));
Sunny Goyal782f0c92017-01-19 10:27:54 -08001684 if (!info.activityInfo.startConfigActivity(this, REQUEST_CREATE_SHORTCUT)) {
1685 handleActivityResult(REQUEST_CREATE_SHORTCUT, RESULT_CANCELED, null);
1686 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001687 }
1688
Adam Cohenfbba09b2011-07-18 21:43:05 -07001689 /**
1690 * Process a widget drop.
Adam Cohenfbba09b2011-07-18 21:43:05 -07001691 */
Sunny Goyal2100c782016-08-22 16:00:03 -07001692 private void addAppWidgetFromDrop(PendingAddWidgetInfo info) {
Adam Cohened66b2b2012-01-23 17:28:51 -08001693 AppWidgetHostView hostView = info.boundWidget;
Sunny Goyal952e63d2017-08-16 04:59:08 -07001694 final int appWidgetId;
Sunny Goyal8a0dc382017-01-25 11:30:06 -08001695 WidgetAddFlowHandler addFlowHandler = info.getHandler();
Adam Cohened66b2b2012-01-23 17:28:51 -08001696 if (hostView != null) {
Tony Wickhama0628cc2015-10-14 15:23:04 -07001697 // In the case where we've prebound the widget, we remove it from the DragLayer
1698 if (LOGD) {
1699 Log.d(TAG, "Removing widget view from drag layer and setting boundWidget to null");
1700 }
1701 getDragLayer().removeView(hostView);
1702
Adam Cohened66b2b2012-01-23 17:28:51 -08001703 appWidgetId = hostView.getAppWidgetId();
Sunny Goyal04a324a2017-01-20 21:08:59 -08001704 addAppWidgetFromDropImpl(appWidgetId, info, hostView, addFlowHandler);
Sunny Goyal5b9ebca2015-06-01 18:37:32 -07001705
1706 // Clear the boundWidget so that it doesn't get destroyed.
1707 info.boundWidget = null;
Adam Cohened66b2b2012-01-23 17:28:51 -08001708 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001709 // In this case, we either need to start an activity to get permission to bind
1710 // the widget, or we need to start an activity to configure the widget, or both.
Pinyao Tingc7a6c292019-08-26 14:36:02 -07001711 if (info.itemType == LauncherSettings.Favorites.ITEM_TYPE_CUSTOM_APPWIDGET) {
1712 appWidgetId = CustomWidgetManager.INSTANCE.get(this).getWidgetIdForCustomProvider(
1713 info.componentName);
Sunny Goyal952e63d2017-08-16 04:59:08 -07001714 } else {
1715 appWidgetId = getAppWidgetHost().allocateAppWidgetId();
1716 }
Adam Cohendd70d662012-10-04 16:53:44 -07001717 Bundle options = info.bindOptions;
1718
Sunny Goyalffe83f12014-08-14 17:39:34 -07001719 boolean success = mAppWidgetManager.bindAppWidgetIdIfAllowed(
1720 appWidgetId, info.info, options);
Adam Cohendd70d662012-10-04 16:53:44 -07001721 if (success) {
Sunny Goyal04a324a2017-01-20 21:08:59 -08001722 addAppWidgetFromDropImpl(appWidgetId, info, null, addFlowHandler);
Michael Jurka8b805b12012-04-18 14:23:14 -07001723 } else {
Sunny Goyal04a324a2017-01-20 21:08:59 -08001724 addFlowHandler.startBindFlow(this, appWidgetId, info, REQUEST_BIND_APPWIDGET);
Michael Jurka8b805b12012-04-18 14:23:14 -07001725 }
Adam Cohened66b2b2012-01-23 17:28:51 -08001726 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001727 }
1728
Sunny Goyalefb7e842018-10-04 15:11:00 -07001729 FolderIcon addFolder(CellLayout layout, int container, final int screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07001730 int cellY) {
Michael Jurkac9d95c52011-08-29 14:03:34 -07001731 final FolderInfo folderInfo = new FolderInfo();
Samuel Fufa84245e82019-08-14 13:44:12 -07001732 folderInfo.title = "";
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001733
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001734 // Update the model
Sunny Goyal43bf11d2017-02-02 13:52:53 -08001735 getModelWriter().addItemToDatabase(folderInfo, container, screenId, cellX, cellY);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001736
1737 // Create the view
Sunny Goyal1cd01b02016-11-09 10:43:58 -08001738 FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this, layout, folderInfo);
Sunny Goyald5462aa2016-11-22 16:52:39 +05301739 mWorkspace.addInScreen(newFolder, folderInfo);
Winson Chung5f8afe62013-08-12 16:19:28 -07001740 // Force measure the new folder icon
1741 CellLayout parent = mWorkspace.getParentCellLayoutForView(newFolder);
1742 parent.getShortcutsAndWidgets().measureChild(newFolder);
Adam Cohendf035382011-04-11 17:22:04 -07001743 return newFolder;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001744 }
Romain Guycbb89e42009-06-08 15:52:54 -07001745
Winsonc0b52fe2015-09-09 16:38:15 -07001746 /**
Winsonfa56b3f2015-09-14 12:01:13 -07001747 * Unbinds the view for the specified item, and removes the item and all its children.
1748 *
1749 * @param v the view being removed.
Winsonfa56b3f2015-09-14 12:01:13 -07001750 * @param itemInfo the {@link ItemInfo} for this view.
1751 * @param deleteFromDb whether or not to delete this item from the db.
Winsonc0b52fe2015-09-09 16:38:15 -07001752 */
Tony Wickhambfbf7f92016-05-19 11:19:39 -07001753 public boolean removeItem(View v, final ItemInfo itemInfo, boolean deleteFromDb) {
Sunny Goyal95899162019-03-27 16:03:06 -07001754 if (itemInfo instanceof WorkspaceItemInfo) {
Winsonfa56b3f2015-09-14 12:01:13 -07001755 // Remove the shortcut from the folder before removing it from launcher
Sunny Goyal44c06432016-04-02 10:56:02 -07001756 View folderIcon = mWorkspace.getHomescreenIconByItemId(itemInfo.container);
1757 if (folderIcon instanceof FolderIcon) {
Sunny Goyal95899162019-03-27 16:03:06 -07001758 ((FolderInfo) folderIcon.getTag()).remove((WorkspaceItemInfo) itemInfo, true);
Winsonfa56b3f2015-09-14 12:01:13 -07001759 } else {
1760 mWorkspace.removeWorkspaceItem(v);
1761 }
Winsonc0b52fe2015-09-09 16:38:15 -07001762 if (deleteFromDb) {
Sunny Goyal43bf11d2017-02-02 13:52:53 -08001763 getModelWriter().deleteItemFromDatabase(itemInfo);
Winsonc0b52fe2015-09-09 16:38:15 -07001764 }
1765 } else if (itemInfo instanceof FolderInfo) {
1766 final FolderInfo folderInfo = (FolderInfo) itemInfo;
Sunny Goyalaaf7d1d2016-05-17 13:38:54 -07001767 if (v instanceof FolderIcon) {
1768 ((FolderIcon) v).removeListeners();
1769 }
Winsonc0b52fe2015-09-09 16:38:15 -07001770 mWorkspace.removeWorkspaceItem(v);
1771 if (deleteFromDb) {
Sunny Goyal43bf11d2017-02-02 13:52:53 -08001772 getModelWriter().deleteFolderAndContentsFromDatabase(folderInfo);
Winsonc0b52fe2015-09-09 16:38:15 -07001773 }
1774 } else if (itemInfo instanceof LauncherAppWidgetInfo) {
1775 final LauncherAppWidgetInfo widgetInfo = (LauncherAppWidgetInfo) itemInfo;
Winson44818e02015-10-02 11:25:46 -07001776 mWorkspace.removeWorkspaceItem(v);
Winsonc0b52fe2015-09-09 16:38:15 -07001777 if (deleteFromDb) {
Tony Wickham6a71a5b2018-08-21 11:40:23 -07001778 getModelWriter().deleteWidgetInfo(widgetInfo, getAppWidgetHost());
Winsonc0b52fe2015-09-09 16:38:15 -07001779 }
1780 } else {
1781 return false;
1782 }
1783 return true;
1784 }
1785
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001786 @Override
1787 public boolean dispatchKeyEvent(KeyEvent event) {
Hyunyoung Song3c7d9cb2017-01-30 15:11:27 -08001788 return (event.getKeyCode() == KeyEvent.KEYCODE_HOME) || super.dispatchKeyEvent(event);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001789 }
1790
Joe Onorato88ec0992009-11-19 13:16:06 -08001791 @Override
1792 public void onBackPressed() {
Sunny Goyal7c8a65e2017-12-22 11:11:33 -08001793 if (finishAutoCancelActionMode()) {
1794 return;
1795 }
Adam Cohen9211d422014-10-07 18:14:53 -07001796
Sunny Goyal45478022015-06-08 16:52:41 -07001797 if (mDragController.isDragging()) {
1798 mDragController.cancelDrag();
Adam Cohenc9735cf2015-01-23 16:11:55 -08001799 return;
1800 }
1801
Jon Mirandafeba90f2016-10-06 10:53:29 -07001802 // Note: There should be at most one log per method call. This is enforced implicitly
1803 // by using if-else statements.
1804 UserEventDispatcher ued = getUserEventDispatcher();
Sunny Goyal740ac7f2016-09-28 16:47:32 -07001805 AbstractFloatingView topView = AbstractFloatingView.getTopOpenView(this);
Tony Wickham52c1b662018-05-21 13:13:58 -07001806 if (topView != null && topView.onBackPressed()) {
1807 // Handled by the floating view.
Patrick Dubroy94f78a52011-02-28 17:39:16 -08001808 } else {
Sunny Goyale39690b2018-08-02 13:35:07 -07001809 mStateManager.getState().onBackPressed(this);
Michael Jurkaaf442092010-06-10 17:01:57 -07001810 }
Joe Onorato88ec0992009-11-19 13:16:06 -08001811 }
1812
Sunny Goyalfe770c92016-09-27 14:38:58 -07001813 @TargetApi(Build.VERSION_CODES.M)
Sunny Goyal0b0847b2018-03-14 12:30:11 -07001814 @Override
Jon Miranda73c27ec2018-05-16 18:06:23 -07001815 public ActivityOptions getActivityLaunchOptions(View v) {
1816 return mAppTransitionManager.getActivityLaunchOptions(this, v);
Sunny Goyala7ce1662016-05-31 15:01:35 -07001817 }
1818
Tony Wickham3a6746a2018-03-29 09:39:56 -07001819 public LauncherAppTransitionManager getAppTransitionManager() {
1820 return mAppTransitionManager;
1821 }
1822
Sunny Goyal0b0847b2018-03-14 12:30:11 -07001823 @TargetApi(Build.VERSION_CODES.M)
1824 @Override
1825 protected boolean onErrorStartingShortcut(Intent intent, ItemInfo info) {
1826 // Due to legacy reasons, direct call shortcuts require Launchers to have the
1827 // corresponding permission. Show the appropriate permission prompt if that
1828 // is the case.
1829 if (intent.getComponent() == null
1830 && Intent.ACTION_CALL.equals(intent.getAction())
1831 && checkSelfPermission(android.Manifest.permission.CALL_PHONE) !=
1832 PackageManager.PERMISSION_GRANTED) {
1833
1834 setWaitingForResult(PendingRequestArgs
1835 .forIntent(REQUEST_PERMISSION_CALL_PHONE, intent, info));
1836 requestPermissions(new String[]{android.Manifest.permission.CALL_PHONE},
1837 REQUEST_PERMISSION_CALL_PHONE);
1838 return true;
1839 } else {
1840 return false;
1841 }
Sunny Goyal0eca4e22016-07-20 11:43:06 -07001842 }
1843
Hyunyoung Song46d07f72018-05-22 15:41:25 -07001844 @Override
Hyunyoung Songfc007472018-10-25 14:09:50 -07001845 public int getCurrentState() {
Samuel Fufaca37b8a2019-08-19 17:04:36 -07001846 if (mStateManager.getState() == LauncherState.ALL_APPS) {
Hyunyoung Songfc007472018-10-25 14:09:50 -07001847 return StatsLogUtils.LAUNCHER_STATE_ALLAPPS;
Govinda Wassermanc06e1512019-04-09 09:56:53 -04001848 } else if (mStateManager.getState() == OVERVIEW) {
Hyunyoung Songfc007472018-10-25 14:09:50 -07001849 return StatsLogUtils.LAUNCHER_STATE_OVERVIEW;
1850 }
Hyunyoung Song0ae38882018-11-05 14:45:19 -08001851 return StatsLogUtils.LAUNCHER_STATE_HOME;
Hyunyoung Songfc007472018-10-25 14:09:50 -07001852 }
1853
1854 @Override
Hyunyoung Song46d07f72018-05-22 15:41:25 -07001855 public void modifyUserEvent(LauncherLogProto.LauncherEvent event) {
1856 if (event.srcTarget != null && event.srcTarget.length > 0 &&
1857 event.srcTarget[1].containerType == ContainerType.PREDICTION) {
1858 Target[] targets = new Target[3];
1859 targets[0] = event.srcTarget[0];
1860 targets[1] = event.srcTarget[1];
1861 targets[2] = newTarget(Target.Type.CONTAINER);
1862 event.srcTarget = targets;
1863 LauncherState state = mStateManager.getState();
1864 if (state == LauncherState.ALL_APPS) {
1865 event.srcTarget[2].containerType = ContainerType.ALLAPPS;
Govinda Wassermanc06e1512019-04-09 09:56:53 -04001866 } else if (state == OVERVIEW) {
Hyunyoung Song46d07f72018-05-22 15:41:25 -07001867 event.srcTarget[2].containerType = ContainerType.TASKSWITCHER;
1868 }
1869 }
1870 }
1871
Sunny Goyal369212a2019-03-26 15:03:57 -07001872 public boolean startActivitySafely(View v, Intent intent, ItemInfo item,
1873 @Nullable String sourceContainer) {
Winson Chung0b70cd42019-06-17 22:34:33 -07001874 if (!hasBeenResumed()) {
1875 // Workaround an issue where the WM launch animation is clobbered when finishing the
1876 // recents animation into launcher. Defer launching the activity until Launcher is
1877 // next resumed.
1878 addOnResumeCallback(() -> startActivitySafely(v, intent, item, sourceContainer));
Tracy Zhou387279d2019-08-14 15:01:53 -07001879 UiFactory.clearSwipeSharedState(this, true /* finishAnimation */);
Winson Chung0b70cd42019-06-17 22:34:33 -07001880 return true;
1881 }
1882
Sunny Goyal369212a2019-03-26 15:03:57 -07001883 boolean success = super.startActivitySafely(v, intent, item, sourceContainer);
Hyunyoung Song1241e612018-05-15 21:46:51 -07001884 if (success && v instanceof BubbleTextView) {
Sunny Goyal0b0847b2018-03-14 12:30:11 -07001885 // This is set to the view that launched the activity that navigated the user away
1886 // from launcher. Since there is no callback for when the activity has finished
1887 // launching, enable the press state and keep this reference to reset the press
1888 // state when we return to launcher.
1889 BubbleTextView btv = (BubbleTextView) v;
1890 btv.setStayPressed(true);
Winson Chung0b70cd42019-06-17 22:34:33 -07001891 addOnResumeCallback(btv);
Sunny Goyala7ce1662016-05-31 15:01:35 -07001892 }
Hyunyoung Song1241e612018-05-15 21:46:51 -07001893 return success;
Michael Jurka86a720e2012-05-09 11:23:23 -07001894 }
1895
Winson Chung3d503fb2011-07-13 17:25:49 -07001896 boolean isHotseatLayout(View layout) {
Sunny Goyalc13403c2016-11-18 23:44:48 -08001897 // TODO: Remove this method
Sunny Goyal876e4622018-11-02 13:50:40 -07001898 return mHotseat != null && (layout == mHotseat);
Winson Chung3d503fb2011-07-13 17:25:49 -07001899 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08001900
Winson Chung3d503fb2011-07-13 17:25:49 -07001901 /**
1902 * Returns the CellLayout of the specified container at the specified screen.
1903 */
Sunny Goyalefb7e842018-10-04 15:11:00 -07001904 public CellLayout getCellLayout(int container, int screenId) {
Sunny Goyal876e4622018-11-02 13:50:40 -07001905 return (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT)
1906 ? mHotseat : mWorkspace.getScreenWithId(screenId);
Romain Guya6abce82009-11-10 02:54:41 -08001907 }
1908
Michael Jurkae326f182011-11-21 14:05:46 -08001909 @Override
1910 public void onTrimMemory(int level) {
1911 super.onTrimMemory(level);
Adam Cohen3f9c9712014-10-31 11:48:25 -07001912 if (level >= ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN) {
1913 // The widget preview db can result in holding onto over
1914 // 3MB of memory for caching which isn't necessary.
1915 SQLiteDatabase.releaseMemory();
1916
Adam Cohenc8f4e1b2014-11-19 16:03:20 -08001917 // This clears all widget bitmaps from the widget tray
Hyunyoung Song3f471442015-04-08 19:01:34 -07001918 // TODO(hyunyoungs)
Michael Jurkae326f182011-11-21 14:05:46 -08001919 }
Winson Chung62a70be2018-02-23 15:10:05 -08001920 UiFactory.onTrimMemory(this, level);
Michael Jurkae326f182011-11-21 14:05:46 -08001921 }
1922
Michael Jurkad7c28052012-04-27 15:43:36 -07001923 @Override
1924 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
alanv1d4fde62012-10-17 13:15:47 -07001925 final boolean result = super.dispatchPopulateAccessibilityEvent(event);
Michael Jurkad7c28052012-04-27 15:43:36 -07001926 final List<CharSequence> text = event.getText();
1927 text.clear();
alanv1d4fde62012-10-17 13:15:47 -07001928 // Populate event with a fake title based on the current state.
Sunny Goyal3e3f44c2017-10-23 17:14:52 -07001929 // TODO: When can workspace be null?
1930 text.add(mWorkspace == null
1931 ? getString(R.string.all_apps_home_button_label)
Sunny Goyalea609262017-10-25 15:47:38 -07001932 : mStateManager.getState().getDescription(this));
Michael Jurkad7c28052012-04-27 15:43:36 -07001933 return result;
1934 }
1935
Winson Chung0b70cd42019-06-17 22:34:33 -07001936 public void addOnResumeCallback(OnResumeCallback callback) {
1937 mOnResumeCallbacks.add(callback);
Michael Jurka1e2f4652013-07-08 18:03:46 -07001938 }
1939
Michael Jurka7607c2f2013-04-03 14:33:19 -07001940 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04001941 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001942 */
Sunny Goyal93f878c2016-03-30 17:31:24 -07001943 @Override
Joe Onorato9c1289c2009-08-17 11:03:03 -04001944 public int getCurrentWorkspaceScreen() {
Joe Onoratod0afc872010-06-11 00:03:15 -07001945 if (mWorkspace != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07001946 return mWorkspace.getCurrentPage();
Joe Onoratod0afc872010-06-11 00:03:15 -07001947 } else {
Winson Chung882a52e2015-07-08 14:32:26 -07001948 return 0;
Joe Onoratod0afc872010-06-11 00:03:15 -07001949 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04001950 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07001951
Joe Onorato9c1289c2009-08-17 11:03:03 -04001952 /**
Sunny Goyal527c7d32015-08-28 15:19:36 -07001953 * Clear any pending bind callbacks. This is called when is loader is planning to
1954 * perform a full rebind from scratch.
1955 */
1956 @Override
1957 public void clearPendingBinds() {
Sunny Goyal527c7d32015-08-28 15:19:36 -07001958 if (mPendingExecutor != null) {
1959 mPendingExecutor.markCompleted();
1960 mPendingExecutor = null;
Sunny Goyal6b6d0a32019-08-05 17:19:32 -07001961
1962 // We might have set this flag previously and forgot to clear it.
1963 mAppsView.getAppsStore()
1964 .disableDeferUpdatesSilently(AllAppsStore.DEFER_UPDATES_NEXT_DRAW);
Sunny Goyal527c7d32015-08-28 15:19:36 -07001965 }
1966 }
1967
1968 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04001969 * Refreshes the shortcuts shown on the workspace.
1970 *
1971 * Implementation of the method from LauncherModel.Callbacks.
1972 */
1973 public void startBinding() {
Sunny Goyal17c72fb2019-10-14 14:06:38 -07001974 TraceHelper.INSTANCE.beginSection("startBinding");
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -07001975 // Floating panels (except the full widget sheet) are associated with individual icons. If
1976 // we are starting a fresh bind, close all such panels as all the icons are about
1977 // to go away.
Pinyao Tinga74b63a2019-07-17 23:26:06 -07001978 AbstractFloatingView.closeOpenViews(this, true, TYPE_ALL & ~TYPE_REBIND_SAFE);
Jon Miranda6dc7f1e2017-02-21 12:37:51 -08001979
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001980 setWorkspaceLoading(true);
Adam Cohen517a7f52014-03-01 12:12:59 -08001981
Winson Chungd64d1762013-08-20 14:37:16 -07001982 // Clear the workspace because it's going to be rebound
Sunny Goyal2db53422019-03-01 16:06:12 -08001983 mDragController.cancelDrag();
1984
Adam Cohendf035382011-04-11 17:22:04 -07001985 mWorkspace.clearDropTargets();
Winson Chung9e6a0a22013-08-27 11:58:12 -07001986 mWorkspace.removeAllWorkspaceScreens();
Sunny Goyalc11fac32018-02-27 19:20:15 -08001987 mAppWidgetHost.clearViews();
Winson Chungd64d1762013-08-20 14:37:16 -07001988
Winson Chung3d503fb2011-07-13 17:25:49 -07001989 if (mHotseat != null) {
Sunny Goyalae6e3182019-04-30 12:04:37 -07001990 mHotseat.resetLayout(getWallpaperDeviceProfile().isVerticalBarLayout());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001991 }
Sunny Goyal17c72fb2019-10-14 14:06:38 -07001992 TraceHelper.INSTANCE.endSection();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001993 }
1994
Adam Cohendcd297f2013-06-18 13:13:40 -07001995 @Override
Sunny Goyalefb7e842018-10-04 15:11:00 -07001996 public void bindScreens(IntArray orderedScreenIds) {
Sunny Goyalda4fe1a2016-05-26 16:05:17 -07001997 // Make sure the first screen is always at the start.
Jon Miranda7143ba62019-03-15 09:00:05 -07001998 if (FeatureFlags.QSB_ON_FIRST_SCREEN &&
Sunny Goyala9e2f5a2016-06-10 12:22:04 -07001999 orderedScreenIds.indexOf(Workspace.FIRST_SCREEN_ID) != 0) {
Sunny Goyalefb7e842018-10-04 15:11:00 -07002000 orderedScreenIds.removeValue(Workspace.FIRST_SCREEN_ID);
Sunny Goyalda4fe1a2016-05-26 16:05:17 -07002001 orderedScreenIds.add(0, Workspace.FIRST_SCREEN_ID);
Jon Miranda7143ba62019-03-15 09:00:05 -07002002 } else if (!FeatureFlags.QSB_ON_FIRST_SCREEN && orderedScreenIds.isEmpty()) {
Sunny Goyala9e2f5a2016-06-10 12:22:04 -07002003 // If there are no screens, we need to have an empty screen
2004 mWorkspace.addExtraEmptyScreen();
Adam Cohen5084cba2013-09-03 12:01:16 -07002005 }
Sunny Goyalda4fe1a2016-05-26 16:05:17 -07002006 bindAddScreens(orderedScreenIds);
Winson Chung0e6a7132013-08-23 12:55:10 -07002007
Winsonc7d2e832016-07-28 12:24:55 -07002008 // After we have added all the screens, if the wallpaper was locked to the default state,
2009 // then notify to indicate that it can be released and a proper wallpaper offset can be
2010 // computed before the next layout
2011 mWorkspace.unlockWallpaperFromDefaultPageOnNextLayout();
Winson Chung64359a52013-07-08 17:17:08 -07002012 }
2013
Sunny Goyalefb7e842018-10-04 15:11:00 -07002014 private void bindAddScreens(IntArray orderedScreenIds) {
Adam Cohendcd297f2013-06-18 13:13:40 -07002015 int count = orderedScreenIds.size();
2016 for (int i = 0; i < count; i++) {
Sunny Goyalefb7e842018-10-04 15:11:00 -07002017 int screenId = orderedScreenIds.get(i);
Jon Miranda7143ba62019-03-15 09:00:05 -07002018 if (!FeatureFlags.QSB_ON_FIRST_SCREEN || screenId != Workspace.FIRST_SCREEN_ID) {
Sunny Goyalda4fe1a2016-05-26 16:05:17 -07002019 // No need to bind the first screen, as its always bound.
2020 mWorkspace.insertNewWorkspaceScreenBeforeEmptyScreen(screenId);
2021 }
Adam Cohendcd297f2013-06-18 13:13:40 -07002022 }
Adam Cohendcd297f2013-06-18 13:13:40 -07002023 }
2024
Sunny Goyalb23980c2017-08-17 07:45:25 -07002025 @Override
Tony Wickham6a71a5b2018-08-21 11:40:23 -07002026 public void preAddApps() {
2027 // If there's an undo snackbar, force it to complete to ensure empty screens are removed
2028 // before trying to add new items.
2029 mModelWriter.commitDelete();
2030 AbstractFloatingView snackbar = AbstractFloatingView.getOpenView(this, TYPE_SNACKBAR);
2031 if (snackbar != null) {
2032 snackbar.post(() -> snackbar.close(true));
2033 }
2034 }
2035
2036 @Override
Sunny Goyalefb7e842018-10-04 15:11:00 -07002037 public void bindAppsAdded(IntArray newScreens, ArrayList<ItemInfo> addNotAnimated,
Sunny Goyal29947f02017-12-18 13:49:44 -08002038 ArrayList<ItemInfo> addAnimated) {
Winson Chungd64d1762013-08-20 14:37:16 -07002039 // Add the new screens
Adam Cohen76a47a12014-02-05 11:47:43 -08002040 if (newScreens != null) {
2041 bindAddScreens(newScreens);
2042 }
Winson Chungd64d1762013-08-20 14:37:16 -07002043
2044 // We add the items without animation on non-visible pages, and with
2045 // animations on the new page (which we will try and snap to).
Adam Cohen76a47a12014-02-05 11:47:43 -08002046 if (addNotAnimated != null && !addNotAnimated.isEmpty()) {
Sunny Goyalb23980c2017-08-17 07:45:25 -07002047 bindItems(addNotAnimated, false);
Winson Chungd64d1762013-08-20 14:37:16 -07002048 }
Adam Cohen76a47a12014-02-05 11:47:43 -08002049 if (addAnimated != null && !addAnimated.isEmpty()) {
Sunny Goyalb23980c2017-08-17 07:45:25 -07002050 bindItems(addAnimated, true);
Winson Chungd64d1762013-08-20 14:37:16 -07002051 }
Winson Chungc58497e2013-09-03 17:48:37 -07002052
Winson Chung87412982013-10-03 18:34:14 -07002053 // Remove the extra empty screen
Adam Cohen689ff162014-05-08 17:27:56 -07002054 mWorkspace.removeExtraEmptyScreen(false, false);
Winson Chungd64d1762013-08-20 14:37:16 -07002055 }
2056
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002057 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04002058 * Bind the items start-end from the list.
2059 *
2060 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002061 */
Tony Wickham0bb211a2015-10-02 16:22:08 -07002062 @Override
Sunny Goyalb23980c2017-08-17 07:45:25 -07002063 public void bindItems(final List<ItemInfo> items, final boolean forceAnimateIcons) {
Sunny Goyal3be633b2016-12-08 09:59:25 -08002064 // Get the list of added items and intersect them with the set of items here
Rajeev Kumar43c0f582017-06-23 15:34:55 -07002065 final Collection<Animator> bounceAnims = new ArrayList<>();
Winson Chung997a9232013-07-24 15:33:46 -07002066 final boolean animateIcons = forceAnimateIcons && canRunNewAppsAnimation();
Winson Chungf0c6ae02012-03-21 16:10:31 -07002067 Workspace workspace = mWorkspace;
Sunny Goyalefb7e842018-10-04 15:11:00 -07002068 int newItemsScreenId = -1;
Sunny Goyalb23980c2017-08-17 07:45:25 -07002069 int end = items.size();
2070 for (int i = 0; i < end; i++) {
Sunny Goyal3be633b2016-12-08 09:59:25 -08002071 final ItemInfo item = items.get(i);
Winson Chung4d279d92011-07-21 11:46:32 -07002072
2073 // Short circuit if we are loading dock items for a configuration which has no dock
2074 if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT &&
2075 mHotseat == null) {
2076 continue;
2077 }
2078
Sunny Goyal639e9062015-08-19 19:17:06 -07002079 final View view;
Joe Onorato9c1289c2009-08-17 11:03:03 -04002080 switch (item.itemType) {
2081 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
2082 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Sunny Goyal3be633b2016-12-08 09:59:25 -08002083 case LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT: {
Sunny Goyal95899162019-03-27 16:03:06 -07002084 WorkspaceItemInfo info = (WorkspaceItemInfo) item;
Sunny Goyal639e9062015-08-19 19:17:06 -07002085 view = createShortcut(info);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002086 break;
Sunny Goyal3be633b2016-12-08 09:59:25 -08002087 }
2088 case LauncherSettings.Favorites.ITEM_TYPE_FOLDER: {
Sunny Goyal639e9062015-08-19 19:17:06 -07002089 view = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07002090 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Sunny Goyal1cd01b02016-11-09 10:43:58 -08002091 (FolderInfo) item);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002092 break;
Sunny Goyal3be633b2016-12-08 09:59:25 -08002093 }
Sunny Goyal952e63d2017-08-16 04:59:08 -07002094 case LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET:
2095 case LauncherSettings.Favorites.ITEM_TYPE_CUSTOM_APPWIDGET: {
Sunny Goyala9a1a212017-08-18 01:03:21 -07002096 view = inflateAppWidget((LauncherAppWidgetInfo) item);
Sunny Goyalb23980c2017-08-17 07:45:25 -07002097 if (view == null) {
2098 continue;
Sunny Goyal3be633b2016-12-08 09:59:25 -08002099 }
Sunny Goyal3be633b2016-12-08 09:59:25 -08002100 break;
2101 }
Winson Chungc763c4e2013-07-19 13:49:06 -07002102 default:
2103 throw new RuntimeException("Invalid Item Type");
Joe Onorato9c1289c2009-08-17 11:03:03 -04002104 }
Sunny Goyal639e9062015-08-19 19:17:06 -07002105
Samuel Fufaca37b8a2019-08-19 17:04:36 -07002106 /*
Sunny Goyalda4fe1a2016-05-26 16:05:17 -07002107 * Remove colliding items.
2108 */
2109 if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
2110 CellLayout cl = mWorkspace.getScreenWithId(item.screenId);
2111 if (cl != null && cl.isOccupied(item.cellX, item.cellY)) {
2112 View v = cl.getChildAt(item.cellX, item.cellY);
2113 Object tag = v.getTag();
2114 String desc = "Collision while binding workspace item: " + item
2115 + ". Collides with " + tag;
Sunny Goyal3d706ad2017-03-06 16:56:39 -08002116 if (FeatureFlags.IS_DOGFOOD_BUILD) {
Sunny Goyalda4fe1a2016-05-26 16:05:17 -07002117 throw (new RuntimeException(desc));
2118 } else {
2119 Log.d(TAG, desc);
Sunny Goyal43bf11d2017-02-02 13:52:53 -08002120 getModelWriter().deleteItemFromDatabase(item);
Sunny Goyalda4fe1a2016-05-26 16:05:17 -07002121 continue;
2122 }
2123 }
2124 }
Sunny Goyald5462aa2016-11-22 16:52:39 +05302125 workspace.addInScreenFromBind(view, item);
Sunny Goyal639e9062015-08-19 19:17:06 -07002126 if (animateIcons) {
2127 // Animate all the applications up now
2128 view.setAlpha(0f);
2129 view.setScaleX(0f);
2130 view.setScaleY(0f);
2131 bounceAnims.add(createNewAppBounceAnimation(view, i));
Sunny Goyal3be633b2016-12-08 09:59:25 -08002132 newItemsScreenId = item.screenId;
Sunny Goyal639e9062015-08-19 19:17:06 -07002133 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002134 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07002135
Sunny Goyalf0b6db72018-08-13 16:10:14 -07002136 // Animate to the correct page
2137 if (animateIcons && newItemsScreenId > -1) {
2138 AnimatorSet anim = new AnimatorSet();
2139 anim.playTogether(bounceAnims);
Jon Miranda64eb8ea2018-03-29 11:43:58 -07002140
Sunny Goyalefb7e842018-10-04 15:11:00 -07002141 int currentScreenId = mWorkspace.getScreenIdForPageIndex(mWorkspace.getNextPage());
Sunny Goyalf0b6db72018-08-13 16:10:14 -07002142 final int newScreenIndex = mWorkspace.getPageIndexForScreenId(newItemsScreenId);
2143 final Runnable startBounceAnimRunnable = anim::start;
2144
2145 if (newItemsScreenId != currentScreenId) {
2146 // We post the animation slightly delayed to prevent slowdowns
2147 // when we are loading right after we return to launcher.
2148 mWorkspace.postDelayed(new Runnable() {
2149 public void run() {
2150 if (mWorkspace != null) {
2151 AbstractFloatingView.closeAllOpenViews(Launcher.this, false);
2152
2153 mWorkspace.snapToPage(newScreenIndex);
2154 mWorkspace.postDelayed(startBounceAnimRunnable,
2155 NEW_APPS_ANIMATION_DELAY);
Winson Chung94d67682013-09-25 16:29:40 -07002156 }
Sunny Goyalf0b6db72018-08-13 16:10:14 -07002157 }
2158 }, NEW_APPS_PAGE_MOVE_DELAY);
2159 } else {
2160 mWorkspace.postDelayed(startBounceAnimRunnable, NEW_APPS_ANIMATION_DELAY);
Winson Chung997a9232013-07-24 15:33:46 -07002161 }
Winson Chung64359a52013-07-08 17:17:08 -07002162 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04002163 workspace.requestLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002164 }
2165
Joe Onorato9c1289c2009-08-17 11:03:03 -04002166 /**
2167 * Add the views for a widget to the workspace.
Joe Onorato9c1289c2009-08-17 11:03:03 -04002168 */
Sunny Goyala9a1a212017-08-18 01:03:21 -07002169 public void bindAppWidget(LauncherAppWidgetInfo item) {
2170 View view = inflateAppWidget(item);
2171 if (view != null) {
2172 mWorkspace.addInScreen(view, item);
2173 mWorkspace.requestLayout();
2174 }
2175 }
2176
2177 private View inflateAppWidget(LauncherAppWidgetInfo item) {
Samuel Fufaca37b8a2019-08-19 17:04:36 -07002178 if (item.hasOptionFlag(LauncherAppWidgetInfo.OPTION_SEARCH_WIDGET)) {
2179 item.providerName = QsbContainerView.getSearchComponentName(this);
2180 if (item.providerName == null) {
2181 getModelWriter().deleteItemFromDatabase(item);
2182 return null;
2183 }
2184 }
Sunny Goyal17c72fb2019-10-14 14:06:38 -07002185 final AppWidgetHostView view;
Sunny Goyal2e1efb42016-03-03 16:58:55 -08002186 if (mIsSafeModeEnabled) {
Sunny Goyal17c72fb2019-10-14 14:06:38 -07002187 view = new PendingAppWidgetHostView(this, item, mIconCache, true);
Sunny Goyald5462aa2016-11-22 16:52:39 +05302188 prepareAppWidget(view, item);
Sunny Goyalb23980c2017-08-17 07:45:25 -07002189 return view;
Sunny Goyal2e1efb42016-03-03 16:58:55 -08002190 }
2191
Sunny Goyal17c72fb2019-10-14 14:06:38 -07002192 TraceHelper.INSTANCE.beginSection("BIND_WIDGET_id=" + item.appWidgetId);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002193
Sunny Goyal17c72fb2019-10-14 14:06:38 -07002194 try {
2195 final LauncherAppWidgetProviderInfo appWidgetInfo;
Adam Cohen59400422014-03-05 18:07:04 -08002196
Sunny Goyal17c72fb2019-10-14 14:06:38 -07002197 if (item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_PROVIDER_NOT_READY)) {
2198 // If the provider is not ready, bind as a pending widget.
2199 appWidgetInfo = null;
2200 } else if (item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_ID_NOT_VALID)) {
2201 // The widget id is not valid. Try to find the widget based on the provider info.
2202 appWidgetInfo = mAppWidgetManager.findProvider(item.providerName, item.user);
2203 } else {
2204 appWidgetInfo = mAppWidgetManager.getLauncherAppWidgetInfo(item.appWidgetId);
Sunny Goyalff572272014-07-23 13:58:07 -07002205 }
Sunny Goyalff572272014-07-23 13:58:07 -07002206
Sunny Goyal17c72fb2019-10-14 14:06:38 -07002207 // If the provider is ready, but the width is not yet restored, try to restore it.
2208 if (!item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_PROVIDER_NOT_READY)
2209 && (item.restoreStatus != LauncherAppWidgetInfo.RESTORE_COMPLETED)) {
2210 if (appWidgetInfo == null) {
2211 Log.d(TAG, "Removing restored widget: id=" + item.appWidgetId
2212 + " belongs to component " + item.providerName
2213 + ", as the provider is null");
2214 getModelWriter().deleteItemFromDatabase(item);
2215 return null;
2216 }
Sunny Goyalff572272014-07-23 13:58:07 -07002217
Sunny Goyal17c72fb2019-10-14 14:06:38 -07002218 // If we do not have a valid id, try to bind an id.
2219 if (item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_ID_NOT_VALID)) {
2220 if (!item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_ID_ALLOCATED)) {
2221 // Id has not been allocated yet. Allocate a new id.
2222 item.appWidgetId = mAppWidgetHost.allocateAppWidgetId();
2223 item.restoreStatus |= LauncherAppWidgetInfo.FLAG_ID_ALLOCATED;
Sunny Goyal86df1382016-08-10 15:03:22 -07002224
Sunny Goyal17c72fb2019-10-14 14:06:38 -07002225 // Also try to bind the widget. If the bind fails, the user will be shown
2226 // a click to setup UI, which will ask for the bind permission.
2227 PendingAddWidgetInfo pendingInfo = new PendingAddWidgetInfo(appWidgetInfo);
2228 pendingInfo.spanX = item.spanX;
2229 pendingInfo.spanY = item.spanY;
2230 pendingInfo.minSpanX = item.minSpanX;
2231 pendingInfo.minSpanY = item.minSpanY;
2232 Bundle options = WidgetHostViewLoader.getDefaultOptionsForWidget(this,
2233 pendingInfo);
2234
2235 boolean isDirectConfig =
2236 item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_DIRECT_CONFIG);
2237 if (isDirectConfig && item.bindOptions != null) {
2238 Bundle newOptions = item.bindOptions.getExtras();
2239 if (options != null) {
2240 newOptions.putAll(options);
2241 }
2242 options = newOptions;
Sunny Goyal86df1382016-08-10 15:03:22 -07002243 }
Sunny Goyal17c72fb2019-10-14 14:06:38 -07002244 boolean success = mAppWidgetManager.bindAppWidgetIdIfAllowed(
2245 item.appWidgetId, appWidgetInfo, options);
2246
2247 // We tried to bind once. If we were not able to bind, we would need to
2248 // go through the permission dialog, which means we cannot skip the config
2249 // activity.
2250 item.bindOptions = null;
2251 item.restoreStatus &= ~LauncherAppWidgetInfo.FLAG_DIRECT_CONFIG;
2252
2253 // Bind succeeded
2254 if (success) {
2255 // If the widget has a configure activity, it is still needs to set it
2256 // up, otherwise the widget is ready to go.
2257 item.restoreStatus = (appWidgetInfo.configure == null) || isDirectConfig
2258 ? LauncherAppWidgetInfo.RESTORE_COMPLETED
2259 : LauncherAppWidgetInfo.FLAG_UI_NOT_READY;
2260 }
2261
2262 getModelWriter().updateItemInDatabase(item);
Sunny Goyal86df1382016-08-10 15:03:22 -07002263 }
Sunny Goyal17c72fb2019-10-14 14:06:38 -07002264 } else if (item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_UI_NOT_READY)
2265 && (appWidgetInfo.configure == null)) {
2266 // The widget was marked as UI not ready, but there is no configure activity to
2267 // update the UI.
2268 item.restoreStatus = LauncherAppWidgetInfo.RESTORE_COMPLETED;
Sunny Goyal43bf11d2017-02-02 13:52:53 -08002269 getModelWriter().updateItemInDatabase(item);
Sunny Goyalff572272014-07-23 13:58:07 -07002270 }
Sunny Goyal56c73602015-09-25 12:55:01 -07002271 }
2272
Sunny Goyal17c72fb2019-10-14 14:06:38 -07002273 if (item.restoreStatus == LauncherAppWidgetInfo.RESTORE_COMPLETED) {
2274 // Verify that we own the widget
2275 if (appWidgetInfo == null) {
2276 FileLog.e(TAG, "Removing invalid widget: id=" + item.appWidgetId);
2277 getModelWriter().deleteWidgetInfo(item, getAppWidgetHost());
2278 return null;
2279 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04002280
Sunny Goyal17c72fb2019-10-14 14:06:38 -07002281 item.minSpanX = appWidgetInfo.minSpanX;
2282 item.minSpanY = appWidgetInfo.minSpanY;
2283 view = mAppWidgetHost.createView(this, item.appWidgetId, appWidgetInfo);
2284 } else {
2285 view = new PendingAppWidgetHostView(this, item, mIconCache, false);
2286 }
2287 prepareAppWidget(view, item);
2288 } finally {
2289 TraceHelper.INSTANCE.endSection();
2290 }
2291
Sunny Goyalb23980c2017-08-17 07:45:25 -07002292 return view;
Joe Onorato9c1289c2009-08-17 11:03:03 -04002293 }
2294
Sunny Goyalff572272014-07-23 13:58:07 -07002295 /**
2296 * Restores a pending widget.
2297 *
2298 * @param appWidgetId The app widget id
Sunny Goyalff572272014-07-23 13:58:07 -07002299 */
Sunny Goyald478c832016-04-01 12:04:16 -07002300 private LauncherAppWidgetInfo completeRestoreAppWidget(int appWidgetId, int finalRestoreFlag) {
Sunny Goyalff572272014-07-23 13:58:07 -07002301 LauncherAppWidgetHostView view = mWorkspace.getWidgetForAppWidgetId(appWidgetId);
2302 if ((view == null) || !(view instanceof PendingAppWidgetHostView)) {
2303 Log.e(TAG, "Widget update called, when the widget no longer exists.");
Sunny Goyald478c832016-04-01 12:04:16 -07002304 return null;
Sunny Goyalff572272014-07-23 13:58:07 -07002305 }
2306
Sunny Goyal0fc1be12014-08-11 17:05:23 -07002307 LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) view.getTag();
Sunny Goyald478c832016-04-01 12:04:16 -07002308 info.restoreStatus = finalRestoreFlag;
Jon Miranda2b823f42017-05-02 18:36:18 -07002309 if (info.restoreStatus == LauncherAppWidgetInfo.RESTORE_COMPLETED) {
2310 info.pendingItemInfo = null;
2311 }
Sunny Goyalff572272014-07-23 13:58:07 -07002312
Sunny Goyalba47faa2017-10-04 16:50:57 -07002313 if (((PendingAppWidgetHostView) view).isReinflateIfNeeded()) {
Sunny Goyal29947f02017-12-18 13:49:44 -08002314 view.reInflate();
Sunny Goyalba47faa2017-10-04 16:50:57 -07002315 }
2316
Sunny Goyal43bf11d2017-02-02 13:52:53 -08002317 getModelWriter().updateItemInDatabase(info);
Sunny Goyald478c832016-04-01 12:04:16 -07002318 return info;
Sunny Goyalff572272014-07-23 13:58:07 -07002319 }
2320
Adam Cohen1462de32012-07-24 22:34:36 -07002321 public void onPageBoundSynchronously(int page) {
Sunny Goyalf4aceab2017-12-06 16:16:31 -08002322 mSynchronouslyBoundPage = page;
Adam Cohen1462de32012-07-24 22:34:36 -07002323 }
2324
Sunny Goyal527c7d32015-08-28 15:19:36 -07002325 @Override
2326 public void executeOnNextDraw(ViewOnDrawExecutor executor) {
Sunny Goyal6b6d0a32019-08-05 17:19:32 -07002327 clearPendingBinds();
Sunny Goyal527c7d32015-08-28 15:19:36 -07002328 mPendingExecutor = executor;
Sunny Goyal60180b02018-02-07 12:56:30 -08002329 if (!isInState(ALL_APPS)) {
vadimtd4c90e12019-06-04 13:59:43 -07002330 mAppsView.getAppsStore().enableDeferUpdates(AllAppsStore.DEFER_UPDATES_NEXT_DRAW);
2331 mPendingExecutor.execute(() -> mAppsView.getAppsStore().disableDeferUpdates(
2332 AllAppsStore.DEFER_UPDATES_NEXT_DRAW));
Sunny Goyal60180b02018-02-07 12:56:30 -08002333 }
2334
Sunny Goyal527c7d32015-08-28 15:19:36 -07002335 executor.attachTo(this);
2336 }
2337
2338 public void clearPendingExecutor(ViewOnDrawExecutor executor) {
2339 if (mPendingExecutor == executor) {
2340 mPendingExecutor = null;
2341 }
2342 }
2343
Sunny Goyalb5b9ad62016-04-02 11:23:39 -07002344 @Override
2345 public void finishFirstPageBind(final ViewOnDrawExecutor executor) {
Sunny Goyal6001ea22018-05-10 16:31:00 -07002346 AlphaProperty property = mDragLayer.getAlphaProperty(ALPHA_INDEX_LAUNCHER_LOAD);
2347 if (property.getValue() < 1) {
2348 ObjectAnimator anim = ObjectAnimator.ofFloat(property, MultiValueAlpha.VALUE, 1);
2349 if (executor != null) {
2350 anim.addListener(new AnimatorListenerAdapter() {
2351 @Override
2352 public void onAnimationEnd(Animator animation) {
2353 executor.onLoadAnimationCompleted();
2354 }
2355 });
2356 }
2357 anim.start();
Sunny Goyal29947f02017-12-18 13:49:44 -08002358 } else if (executor != null) {
2359 executor.onLoadAnimationCompleted();
Sunny Goyalb5b9ad62016-04-02 11:23:39 -07002360 }
2361 }
2362
Joe Onorato9c1289c2009-08-17 11:03:03 -04002363 /**
2364 * Callback saying that there aren't any more items to bind.
2365 *
2366 * Implementation of the method from LauncherModel.Callbacks.
2367 */
Tonyf80e8932018-12-21 11:58:04 -08002368 public void finishBindingItems(int pageBoundFirst) {
Sunny Goyal17c72fb2019-10-14 14:06:38 -07002369 TraceHelper.INSTANCE.beginSection("finishBindingItems");
Adam Cohen1462de32012-07-24 22:34:36 -07002370 mWorkspace.restoreInstanceStateForRemainingPages();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002371
Anjali Koppalff7ceff2014-05-01 18:26:37 -07002372 setWorkspaceLoading(false);
Adam Cohendb364c32014-05-20 14:23:40 -07002373
Sunny Goyal2100c782016-08-22 16:00:03 -07002374 if (mPendingActivityResult != null) {
2375 handleActivityResult(mPendingActivityResult.requestCode,
2376 mPendingActivityResult.resultCode, mPendingActivityResult.data);
2377 mPendingActivityResult = null;
Adam Cohendb364c32014-05-20 14:23:40 -07002378 }
2379
Sunny Goyala474a9b2017-05-04 16:47:11 -07002380 InstallShortcutReceiver.disableAndFlushInstallQueue(
2381 InstallShortcutReceiver.FLAG_LOADER_RUNNING, this);
Adam Cohen9211d422014-10-07 18:14:53 -07002382
Tonyf80e8932018-12-21 11:58:04 -08002383 // When undoing the removal of the last item on a page, return to that page.
Tony Wickham03f27012019-04-25 14:22:54 -07002384 // Since we are just resetting the current page without user interaction,
2385 // override the previous page so we don't log the page switch.
2386 mWorkspace.setCurrentPage(pageBoundFirst, pageBoundFirst /* overridePrevPage */);
Tony Wickham6a71a5b2018-08-21 11:40:23 -07002387
Sunny Goyalac6f69f2019-08-16 11:59:55 -07002388 // Cache one page worth of icons
2389 getViewCache().setCacheSize(R.layout.folder_application,
2390 mDeviceProfile.inv.numFolderColumns * mDeviceProfile.inv.numFolderRows);
2391 getViewCache().setCacheSize(R.layout.folder_page, 2);
2392
Sunny Goyal17c72fb2019-10-14 14:06:38 -07002393 TraceHelper.INSTANCE.endSection();
Winson Chungf0c6ae02012-03-21 16:10:31 -07002394 }
2395
Winson Chunga2413752012-04-03 14:22:34 -07002396 private boolean canRunNewAppsAnimation() {
2397 long diff = System.currentTimeMillis() - mDragController.getLastGestureUpTime();
Andrew Sapperstein932eb832016-06-30 18:10:09 -07002398 return diff > (NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS * 1000);
Winson Chunga2413752012-04-03 14:22:34 -07002399 }
2400
Winson Chungc9168342013-06-26 14:54:55 -07002401 private ValueAnimator createNewAppBounceAnimation(View v, int i) {
Sunny Goyalf0b6db72018-08-13 16:10:14 -07002402 ValueAnimator bounceAnim = new PropertyListBuilder().alpha(1).scale(1).build(v)
2403 .setDuration(InstallShortcutReceiver.NEW_SHORTCUT_BOUNCE_DURATION);
Winson Chungc9168342013-06-26 14:54:55 -07002404 bounceAnim.setStartDelay(i * InstallShortcutReceiver.NEW_SHORTCUT_STAGGER_DELAY);
Sunny Goyal5a1f53b2015-05-27 10:24:24 -07002405 bounceAnim.setInterpolator(new OvershootInterpolator(BOUNCE_ANIMATION_TENSION));
Winson Chungc9168342013-06-26 14:54:55 -07002406 return bounceAnim;
2407 }
2408
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002409 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04002410 * Add the icons for all apps.
2411 *
2412 * Implementation of the method from LauncherModel.Callbacks.
2413 */
Sunny Goyal87dcde62019-07-17 20:35:56 -07002414 public void bindAllApplications(AppInfo[] apps) {
Sunny Goyal60180b02018-02-07 12:56:30 -08002415 mAppsView.getAppsStore().setApps(apps);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002416 }
2417
2418 /**
Zak Cohen658c67a2018-10-19 14:21:05 -07002419 * Copies LauncherModel's map of activities to shortcut counts to Launcher's. This is necessary
Tony Wickhambfbf7f92016-05-19 11:19:39 -07002420 * because LauncherModel's map is updated in the background, while Launcher runs on the UI.
2421 */
2422 @Override
Zak Cohen658c67a2018-10-19 14:21:05 -07002423 public void bindDeepShortcutMap(HashMap<ComponentKey, Integer> deepShortcutMapCopy) {
Tony Wickham010d2552017-01-20 08:15:28 -08002424 mPopupDataProvider.setDeepShortcutMap(deepShortcutMapCopy);
Tony Wickham1bce7fd2016-04-28 17:39:03 -07002425 }
2426
Sunny Goyal4390ace2014-10-13 11:33:11 -07002427 @Override
Sunny Goyal29947f02017-12-18 13:49:44 -08002428 public void bindPromiseAppProgressUpdated(PromiseAppInfo app) {
Sunny Goyal60180b02018-02-07 12:56:30 -08002429 mAppsView.getAppsStore().updatePromiseAppProgress(app);
Mario Bertschler08ffaae2017-03-20 11:30:27 -07002430 }
2431
2432 @Override
Sunny Goyal29947f02017-12-18 13:49:44 -08002433 public void bindWidgetsRestored(ArrayList<LauncherAppWidgetInfo> widgets) {
Sunny Goyal4390ace2014-10-13 11:33:11 -07002434 mWorkspace.widgetsRestored(widgets);
2435 }
2436
Joe Onorato9c1289c2009-08-17 11:03:03 -04002437 /**
Sunny Goyalb50cc8c2014-10-06 16:23:56 -07002438 * Some shortcuts were updated in the background.
Sunny Goyalb50cc8c2014-10-06 16:23:56 -07002439 * Implementation of the method from LauncherModel.Callbacks.
Sunny Goyald3b87ef2016-07-28 12:11:54 -07002440 *
2441 * @param updated list of shortcuts which have changed.
Sunny Goyalb50cc8c2014-10-06 16:23:56 -07002442 */
Sunny Goyal4390ace2014-10-13 11:33:11 -07002443 @Override
Sunny Goyal95899162019-03-27 16:03:06 -07002444 public void bindWorkspaceItemsChanged(ArrayList<WorkspaceItemInfo> updated) {
Sunny Goyal4390ace2014-10-13 11:33:11 -07002445 if (!updated.isEmpty()) {
2446 mWorkspace.updateShortcuts(updated);
2447 }
Sunny Goyalb50cc8c2014-10-06 16:23:56 -07002448 }
2449
2450 /**
Chris Wrenaeff7ea2014-02-14 16:59:24 -05002451 * Update the state of a package, typically related to install state.
2452 *
2453 * Implementation of the method from LauncherModel.Callbacks.
2454 */
Sunny Goyale755d462014-07-22 13:48:29 -07002455 @Override
Sunny Goyal29947f02017-12-18 13:49:44 -08002456 public void bindRestoreItemsChange(HashSet<ItemInfo> updates) {
Sunny Goyal756adbc2015-04-16 15:20:51 -07002457 mWorkspace.updateRestoreItems(updates);
Sunny Goyala22666f2014-09-18 13:25:15 -07002458 }
2459
2460 /**
Sunny Goyal3bbbabc2016-03-15 09:16:30 -07002461 * A package was uninstalled/updated. We take both the super set of packageNames
Winson Chung83892cc2013-05-01 16:53:33 -07002462 * in addition to specific applications to remove, the reason being that
2463 * this can be called when a package is updated as well. In that scenario,
Sunny Goyal3bbbabc2016-03-15 09:16:30 -07002464 * we only remove specific components from the workspace and hotseat, where as
Winson Chung83892cc2013-05-01 16:53:33 -07002465 * package-removal should clear all items by package name.
Joe Onorato9c1289c2009-08-17 11:03:03 -04002466 */
Sunny Goyal1a745e82014-10-02 15:58:31 -07002467 @Override
Sunny Goyal6e13dd32017-08-17 03:01:19 -07002468 public void bindWorkspaceComponentsRemoved(final ItemInfoMatcher matcher) {
Sunny Goyal6e13dd32017-08-17 03:01:19 -07002469 mWorkspace.removeItemsByMatcher(matcher);
2470 mDragController.onAppsRemoved(matcher);
Sunny Goyal3bbbabc2016-03-15 09:16:30 -07002471 }
Sunny Goyal4390ace2014-10-13 11:33:11 -07002472
Sunny Goyal3bbbabc2016-03-15 09:16:30 -07002473 @Override
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -07002474 public void bindAllWidgets(final ArrayList<WidgetListRowEntry> allWidgets) {
2475 mPopupDataProvider.setAllWidgets(allWidgets);
Tony Wickham26b17462017-03-20 17:12:24 -07002476 }
2477
Tony Wickham86222d22017-03-29 15:30:43 -07002478 /**
2479 * @param packageUser if null, refreshes all widgets and shortcuts, otherwise only
2480 * refreshes the widgets and shortcuts associated with the given package/user
2481 */
2482 public void refreshAndBindWidgetsForPackageUser(@Nullable PackageUserKey packageUser) {
Sunny Goyalc6e97692017-06-02 13:46:55 -07002483 mModel.refreshAndBindWidgetsAndShortcuts(packageUser);
Sunny Goyal2e1efb42016-03-03 16:58:55 -08002484 }
2485
Winson Chung80baf5a2010-08-09 16:03:15 -07002486 /**
Hyunyoung Song3c7d9cb2017-01-30 15:11:27 -08002487 * $ adb shell dumpsys activity com.android.launcher3.Launcher [--all]
Joe Onoratobe386092009-11-17 17:32:16 -08002488 */
Adam Cohen16d7ffc2011-10-05 17:49:14 -07002489 @Override
2490 public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
2491 super.dump(prefix, fd, writer, args);
Sunny Goyala1365452015-10-01 15:46:24 -07002492
Hyunyoung Song3c7d9cb2017-01-30 15:11:27 -08002493 if (args.length > 0 && TextUtils.equals(args[0], "--all")) {
2494 writer.println(prefix + "Workspace Items");
Sunny Goyal7ce471b2017-08-02 03:37:39 -07002495 for (int i = 0; i < mWorkspace.getPageCount(); i++) {
Hyunyoung Song3c7d9cb2017-01-30 15:11:27 -08002496 writer.println(prefix + " Homescreen " + i);
2497
2498 ViewGroup layout = ((CellLayout) mWorkspace.getPageAt(i)).getShortcutsAndWidgets();
2499 for (int j = 0; j < layout.getChildCount(); j++) {
2500 Object tag = layout.getChildAt(j).getTag();
2501 if (tag != null) {
2502 writer.println(prefix + " " + tag.toString());
2503 }
2504 }
2505 }
2506
2507 writer.println(prefix + " Hotseat");
Sunny Goyal876e4622018-11-02 13:50:40 -07002508 ViewGroup layout = mHotseat.getShortcutsAndWidgets();
Sunny Goyala1365452015-10-01 15:46:24 -07002509 for (int j = 0; j < layout.getChildCount(); j++) {
2510 Object tag = layout.getChildAt(j).getTag();
2511 if (tag != null) {
2512 writer.println(prefix + " " + tag.toString());
2513 }
Adam Cohen4caf2982013-08-20 18:54:31 -07002514 }
Sunny Goyala1365452015-10-01 15:46:24 -07002515 }
2516
Hyunyoung Song3c7d9cb2017-01-30 15:11:27 -08002517 writer.println(prefix + "Misc:");
Winson Chungef528762019-09-06 12:05:52 -07002518 dumpMisc(prefix + "\t", writer);
2519 writer.println(prefix + "\tmWorkspaceLoading=" + mWorkspaceLoading);
2520 writer.println(prefix + "\tmPendingRequestArgs=" + mPendingRequestArgs
2521 + " mPendingActivityResult=" + mPendingActivityResult);
2522 writer.println(prefix + "\tmRotationHelper: " + mRotationHelper);
2523 writer.println(prefix + "\tmAppWidgetHost.isListening: " + mAppWidgetHost.isListening());
2524
Sunny Goyalcb2c5052018-10-15 12:30:29 -07002525 // Extra logging for b/116853349
Hyunyoung Songa310a802019-04-25 13:57:16 -07002526 mDragLayer.dump(prefix, writer);
2527 mStateManager.dump(prefix, writer);
Sunny Goyal2bba1902018-02-27 12:20:50 -08002528
2529 try {
2530 FileLog.flushAll(writer);
2531 } catch (Exception e) {
2532 // Ignore
2533 }
Hyunyoung Song3c7d9cb2017-01-30 15:11:27 -08002534
2535 mModel.dumpState(prefix, fd, writer, args);
Sunny Goyala1365452015-10-01 15:46:24 -07002536
Adam Cohen9211d422014-10-07 18:14:53 -07002537 if (mLauncherCallbacks != null) {
2538 mLauncherCallbacks.dump(prefix, fd, writer, args);
2539 }
Sunny Goyalb1d7de22019-09-06 10:36:54 -07002540 mOverlayManager.dump(prefix, writer);
Adam Cohen16d7ffc2011-10-05 17:49:14 -07002541 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07002542
Sunny Goyal66b24572016-09-21 15:57:55 -07002543 @Override
Sunny Goyal66b24572016-09-21 15:57:55 -07002544 public void onProvideKeyboardShortcuts(
2545 List<KeyboardShortcutGroup> data, Menu menu, int deviceId) {
2546
2547 ArrayList<KeyboardShortcutInfo> shortcutInfos = new ArrayList<>();
Sunny Goyal3e3f44c2017-10-23 17:14:52 -07002548 if (isInState(NORMAL)) {
Sunny Goyal66b24572016-09-21 15:57:55 -07002549 shortcutInfos.add(new KeyboardShortcutInfo(getString(R.string.all_apps_button_label),
2550 KeyEvent.KEYCODE_A, KeyEvent.META_CTRL_ON));
Vadim Tryshev74c261c2018-06-12 13:44:43 -07002551 shortcutInfos.add(new KeyboardShortcutInfo(getString(R.string.widget_button_text),
2552 KeyEvent.KEYCODE_W, KeyEvent.META_CTRL_ON));
Sunny Goyal66b24572016-09-21 15:57:55 -07002553 }
Vadim Tryshev3455f8d2018-05-11 20:02:20 -07002554 final View currentFocus = getCurrentFocus();
2555 if (currentFocus != null) {
2556 if (new CustomActionsPopup(this, currentFocus).canShow()) {
2557 shortcutInfos.add(new KeyboardShortcutInfo(getString(R.string.custom_actions),
2558 KeyEvent.KEYCODE_O, KeyEvent.META_CTRL_ON));
2559 }
2560 if (currentFocus.getTag() instanceof ItemInfo
Pinyao Ting49a3e692019-07-26 12:28:38 -07002561 && ShortcutUtil.supportsShortcuts((ItemInfo) currentFocus.getTag())) {
Vadim Tryshev3455f8d2018-05-11 20:02:20 -07002562 shortcutInfos.add(new KeyboardShortcutInfo(
2563 getString(R.string.shortcuts_menu_with_notifications_description),
2564 KeyEvent.KEYCODE_S, KeyEvent.META_CTRL_ON));
2565 }
Sunny Goyal66b24572016-09-21 15:57:55 -07002566 }
2567 if (!shortcutInfos.isEmpty()) {
2568 data.add(new KeyboardShortcutGroup(getString(R.string.home_screen), shortcutInfos));
2569 }
2570
2571 super.onProvideKeyboardShortcuts(data, menu, deviceId);
2572 }
2573
2574 @Override
2575 public boolean onKeyShortcut(int keyCode, KeyEvent event) {
2576 if (event.hasModifiers(KeyEvent.META_CTRL_ON)) {
2577 switch (keyCode) {
2578 case KeyEvent.KEYCODE_A:
Sunny Goyal3e3f44c2017-10-23 17:14:52 -07002579 if (isInState(NORMAL)) {
2580 getStateManager().goToState(ALL_APPS);
Sunny Goyal66b24572016-09-21 15:57:55 -07002581 return true;
2582 }
2583 break;
2584 case KeyEvent.KEYCODE_S: {
2585 View focusedView = getCurrentFocus();
2586 if (focusedView instanceof BubbleTextView
2587 && focusedView.getTag() instanceof ItemInfo
2588 && mAccessibilityDelegate.performAction(focusedView,
Samuel Fufaca37b8a2019-08-19 17:04:36 -07002589 (ItemInfo) focusedView.getTag(),
2590 LauncherAccessibilityDelegate.DEEP_SHORTCUTS)) {
Sunny Goyal00ac9202017-11-09 15:24:06 -08002591 PopupContainerWithArrow.getOpen(this).requestFocus();
Sunny Goyal66b24572016-09-21 15:57:55 -07002592 return true;
2593 }
2594 break;
2595 }
2596 case KeyEvent.KEYCODE_O:
2597 if (new CustomActionsPopup(this, getCurrentFocus()).show()) {
2598 return true;
2599 }
2600 break;
Vadim Tryshev74c261c2018-06-12 13:44:43 -07002601 case KeyEvent.KEYCODE_W:
2602 if (isInState(NORMAL)) {
2603 OptionsPopupView.openWidgets(this);
2604 return true;
2605 }
2606 break;
Sunny Goyal66b24572016-09-21 15:57:55 -07002607 }
2608 }
2609 return super.onKeyShortcut(keyCode, event);
2610 }
2611
Vadim Tryshev646a0dd2018-02-05 16:27:50 -08002612 @Override
2613 public boolean onKeyUp(int keyCode, KeyEvent event) {
2614 if (keyCode == KeyEvent.KEYCODE_MENU) {
2615 // KEYCODE_MENU is sent by some tests, for example
2616 // LauncherJankTests#testWidgetsContainerFling. Don't just remove its handling.
2617 if (!mDragController.isDragging() && !mWorkspace.isSwitchingState() &&
2618 isInState(NORMAL)) {
2619 // Close any open floating views.
2620 AbstractFloatingView.closeAllOpenViews(this);
2621
2622 // Setting the touch point to (-1, -1) will show the options popup in the center of
2623 // the screen.
Sunny Goyal2fd7a8b2018-03-30 17:10:13 -07002624 OptionsPopupView.showDefaultOptions(this, -1, -1);
Vadim Tryshev646a0dd2018-02-05 16:27:50 -08002625 }
2626 return true;
2627 }
2628 return super.onKeyUp(keyCode, event);
2629 }
2630
Andrew Sappersteinabef55a2016-06-19 12:49:00 -07002631 public static Launcher getLauncher(Context context) {
Sunny Goyal87b5eb62018-07-03 15:53:39 -07002632 return (Launcher) fromContext(context);
Andrew Sappersteinabef55a2016-06-19 12:49:00 -07002633 }
2634
Vinit Nayakf9b585b2019-07-10 14:25:32 -07002635 @Override
2636 public void returnToHomescreen() {
2637 super.returnToHomescreen();
2638 getStateManager().goToState(LauncherState.NORMAL);
2639 }
2640
Sunny Goyal3dce5f32017-10-05 11:40:05 -07002641 /**
Sunny Goyalab770a12018-11-14 15:17:26 -08002642 * Just a wrapper around the type cast to allow easier tracking of calls.
2643 */
2644 public static <T extends Launcher> T cast(ActivityContext activityContext) {
2645 return (T) activityContext;
2646 }
2647
2648 /**
Sunny Goyal3dce5f32017-10-05 11:40:05 -07002649 * Callback for listening for onResume
2650 */
2651 public interface OnResumeCallback {
2652
2653 void onLauncherResume();
2654 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002655}