blob: 559b55fa690ecb73ad7996c80332a1922a2ee671 [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 Goyal6001ea22018-05-10 16:31:00 -070030import static com.android.launcher3.dragndrop.DragLayer.ALPHA_INDEX_LAUNCHER_LOAD;
Sunny Goyalaeb16432017-10-16 11:46:41 -070031import static com.android.launcher3.logging.LoggerUtils.newContainerTarget;
Hyunyoung Song46d07f72018-05-22 15:41:25 -070032import static com.android.launcher3.logging.LoggerUtils.newTarget;
Sunny Goyalbe8c3402019-05-22 15:17:52 -070033import static com.android.launcher3.states.RotationHelper.REQUEST_NONE;
vadimt00d42552018-12-11 17:59:36 -080034import static com.android.launcher3.util.RaceConditionTracker.ENTER;
35import static com.android.launcher3.util.RaceConditionTracker.EXIT;
Sunny Goyal326403e2017-10-02 12:45:10 -070036
Gilles Debunnedd6c9922010-10-25 11:23:41 -070037import android.animation.Animator;
Sunny Goyal6001ea22018-05-10 16:31:00 -070038import android.animation.AnimatorListenerAdapter;
Gilles Debunnedd6c9922010-10-25 11:23:41 -070039import android.animation.AnimatorSet;
Sunny Goyal6001ea22018-05-10 16:31:00 -070040import android.animation.ObjectAnimator;
Gilles Debunnedd6c9922010-10-25 11:23:41 -070041import android.animation.ValueAnimator;
Adam Cohen0b395352014-06-09 22:54:36 +000042import android.annotation.TargetApi;
Tony Wickham005df0b2018-02-13 11:28:12 -080043import android.app.ActivityOptions;
Adam Cohen0cf2a7c2011-11-08 15:07:01 -080044import android.appwidget.AppWidgetHostView;
Michael Jurkaaf442092010-06-10 17:01:57 -070045import android.appwidget.AppWidgetManager;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080046import android.content.ActivityNotFoundException;
Joe Onorato2ca0ae72009-11-10 13:14:13 -080047import android.content.BroadcastReceiver;
Michael Jurkae326f182011-11-21 14:05:46 -080048import android.content.ComponentCallbacks2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080049import android.content.Context;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080050import android.content.Intent;
Winson Chungf0ea4d32011-06-06 14:27:16 -070051import android.content.IntentFilter;
Adam Cohen173f7112015-03-27 15:14:00 -070052import android.content.IntentSender;
Winson Chung82f55532011-08-09 14:14:23 -070053import android.content.SharedPreferences;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080054import android.content.pm.PackageManager;
Sunny Goyalf8d56fc2018-01-31 15:18:11 -080055import android.content.res.Configuration;
Adam Cohen3f9c9712014-10-31 11:48:25 -070056import android.database.sqlite.SQLiteDatabase;
Sunny Goyal59d086c2018-05-07 17:31:40 -070057import android.graphics.Point;
Sunny Goyalae6e3182019-04-30 12:04:37 -070058import android.graphics.Rect;
Adam Cohen0f668f32014-09-08 19:54:17 +020059import android.os.Build;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080060import android.os.Bundle;
Hyunyoung Songbd6fba92018-05-16 15:54:31 -070061import android.os.Handler;
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -070062import android.os.Parcelable;
Sunny Goyal7c74e4a2016-12-15 15:53:17 -080063import android.os.Process;
Winson Chunga2413752012-04-03 14:22:34 -070064import android.os.StrictMode;
Michael Jurkaa33411c2012-06-14 16:18:21 -070065import android.text.TextUtils;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080066import android.text.method.TextKeyListener;
Joe Onorato7c312c12009-08-13 21:36:53 -070067import android.util.Log;
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -070068import android.util.SparseArray;
Sunny Goyal59d086c2018-05-07 17:31:40 -070069import android.view.Display;
Adam Cohen96d30a12013-07-16 18:13:21 -070070import android.view.KeyEvent;
Sunny Goyal66b24572016-09-21 15:57:55 -070071import android.view.KeyboardShortcutGroup;
72import android.view.KeyboardShortcutInfo;
Sunny Goyal9b29ca52017-02-17 10:39:44 -080073import android.view.LayoutInflater;
Adam Cohen96d30a12013-07-16 18:13:21 -070074import android.view.Menu;
Adam Cohen96d30a12013-07-16 18:13:21 -070075import android.view.View;
Adam Cohen96d30a12013-07-16 18:13:21 -070076import android.view.ViewGroup;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -080077import android.view.accessibility.AccessibilityEvent;
Sunny Goyal5a1f53b2015-05-27 10:24:24 -070078import android.view.animation.OvershootInterpolator;
Adam Cohen96d30a12013-07-16 18:13:21 -070079import android.widget.Toast;
Sunny Goyala1d1bf32015-06-26 13:24:53 -070080
Sunny Goyal11a50742019-08-07 09:24:26 -070081import androidx.annotation.Nullable;
82
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;
Sunny Goyal22ca9ec2017-05-18 15:03:13 -070091import com.android.launcher3.compat.LauncherAppsCompatVO;
Tony Wickhame0c33232016-02-08 11:37:04 -080092import com.android.launcher3.config.FeatureFlags;
vadimt00d42552018-12-11 17:59:36 -080093import com.android.launcher3.dot.DotInfo;
Vadim Tryshevfedca432015-08-19 17:55:02 -070094import com.android.launcher3.dragndrop.DragController;
95import com.android.launcher3.dragndrop.DragLayer;
96import com.android.launcher3.dragndrop.DragView;
Sunny Goyal11a50742019-08-07 09:24:26 -070097import com.android.launcher3.folder.FolderGridOrganizer;
Sunny Goyal26119432016-02-18 22:09:23 +000098import com.android.launcher3.folder.FolderIcon;
Sunny Goyalae6e3182019-04-30 12:04:37 -070099import com.android.launcher3.graphics.RotationMode;
Sunny Goyalf840f102018-09-21 14:41:05 -0700100import com.android.launcher3.icons.IconCache;
Sunny Goyal66b24572016-09-21 15:57:55 -0700101import com.android.launcher3.keyboard.CustomActionsPopup;
Sunny Goyal3333b0c2016-05-09 20:43:21 -0700102import com.android.launcher3.keyboard.ViewGroupFocusHelper;
Sunny Goyala7ce1662016-05-31 15:01:35 -0700103import com.android.launcher3.logging.FileLog;
Hyunyoung Songfc007472018-10-25 14:09:50 -0700104import com.android.launcher3.logging.StatsLogUtils;
Hyunyoung Songaa953652016-04-19 18:30:24 -0700105import com.android.launcher3.logging.UserEventDispatcher;
Hyunyoung Song46d07f72018-05-22 15:41:25 -0700106import com.android.launcher3.logging.UserEventDispatcher.UserEventDelegate;
Sunny Goyal369212a2019-03-26 15:03:57 -0700107import com.android.launcher3.model.AppLaunchTracker;
Sunny Goyal87dcde62019-07-17 20:35:56 -0700108import com.android.launcher3.model.BgDataModel.Callbacks;
Sunny Goyala535ae42017-02-27 10:07:13 -0800109import com.android.launcher3.model.ModelWriter;
Sunny Goyala535ae42017-02-27 10:07:13 -0800110import com.android.launcher3.notification.NotificationListener;
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 Goyalf8088ee2017-11-10 14:52:00 -0800114import com.android.launcher3.states.InternalStateHandler;
Sunny Goyal623eddd2018-03-02 12:24:41 -0800115import com.android.launcher3.states.RotationHelper;
Sunny Goyal8a2a63b2018-03-06 22:15:18 -0800116import com.android.launcher3.touch.ItemClickHandler;
Sunny Goyala5ace712017-11-15 17:12:51 -0800117import com.android.launcher3.uioverrides.UiFactory;
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;
Winson Chung6b1c73f2015-06-18 11:38:42 -0700123import com.android.launcher3.util.ComponentKey;
Sunny Goyalefb7e842018-10-04 15:11:00 -0700124import com.android.launcher3.util.IntArray;
Sunny Goyald3b87ef2016-07-28 12:11:54 -0700125import com.android.launcher3.util.ItemInfoMatcher;
Sunny Goyal6001ea22018-05-10 16:31:00 -0700126import com.android.launcher3.util.MultiValueAlpha;
127import com.android.launcher3.util.MultiValueAlpha.AlphaProperty;
Sunny Goyal04cc3a72016-05-17 10:32:43 -0700128import com.android.launcher3.util.PackageManagerHelper;
Tony Wickham010d2552017-01-20 08:15:28 -0800129import com.android.launcher3.util.PackageUserKey;
Sunny Goyal2100c782016-08-22 16:00:03 -0700130import com.android.launcher3.util.PendingRequestArgs;
vadimt00d42552018-12-11 17:59:36 -0800131import com.android.launcher3.util.RaceConditionTracker;
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;
Adam Cohen6c5891a2014-07-09 23:53:15 -0700151
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700152import java.io.FileDescriptor;
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700153import java.io.PrintWriter;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700154import java.util.ArrayList;
Winson Chungf0c6ae02012-03-21 16:10:31 -0700155import java.util.Collection;
Zak Cohen658c67a2018-10-19 14:21:05 -0700156import java.util.HashMap;
Sunny Goyal4390ace2014-10-13 11:33:11 -0700157import java.util.HashSet;
Michael Jurkad7c28052012-04-27 15:43:36 -0700158import java.util.List;
Sunny Goyalaae6fbb2019-01-31 16:05:58 -0800159import java.util.function.Predicate;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700160
Jon Mirandaf5197fc2019-09-04 16:55:41 -0700161import androidx.annotation.Nullable;
162import androidx.annotation.VisibleForTesting;
163
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800164/**
165 * Default launcher application.
166 */
Hyunyoung Song46d07f72018-05-22 15:41:25 -0700167public class Launcher extends BaseDraggingActivity implements LauncherExterns,
Sunny Goyal87dcde62019-07-17 20:35:56 -0700168 Callbacks, LauncherProviderChangeListener, UserEventDelegate,
Hyunyoung Song31971a32019-01-27 12:31:12 -0800169 InvariantDeviceProfile.OnIDPChangeListener {
Vadim Tryshevfedca432015-08-19 17:55:02 -0700170 public static final String TAG = "Launcher";
Sunny Goyal2bba4c32015-05-18 15:42:48 -0700171 static final boolean LOGD = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800172
Winson Chunga2413752012-04-03 14:22:34 -0700173 static final boolean DEBUG_STRICT_MODE = false;
Romain Guy6fefcf12009-06-11 13:07:43 -0700174
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800175 private static final int REQUEST_CREATE_SHORTCUT = 1;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700176 private static final int REQUEST_CREATE_APPWIDGET = 5;
Jon Mirandac476d6e2017-05-04 16:30:01 -0700177
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700178 private static final int REQUEST_PICK_APPWIDGET = 9;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800179
Michael Jurka8b805b12012-04-18 14:23:14 -0700180 private static final int REQUEST_BIND_APPWIDGET = 11;
Sunny Goyal8a2a63b2018-03-06 22:15:18 -0800181 public static final int REQUEST_BIND_PENDING_APPWIDGET = 12;
182 public static final int REQUEST_RECONFIGURE_APPWIDGET = 13;
Michael Jurka8b805b12012-04-18 14:23:14 -0700183
Jon Mirandac476d6e2017-05-04 16:30:01 -0700184 private static final int REQUEST_PERMISSION_CALL_PHONE = 14;
Sunny Goyal28c6b962015-10-12 11:42:05 -0700185
Sunny Goyal5a1f53b2015-05-27 10:24:24 -0700186 private static final float BOUNCE_ANIMATION_TENSION = 1.3f;
187
Mathew Inwood876a8462013-06-14 14:12:41 +0100188 /**
189 * IntentStarter uses request codes starting with this. This must be greater than all activity
190 * request codes used internally.
191 */
192 protected static final int REQUEST_LAST = 100;
193
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800194 // Type: int
195 private static final String RUNTIME_STATE_CURRENT_SCREEN = "launcher.current_screen";
Michael Jurka883f55b2010-10-21 15:47:14 -0700196 // Type: int
197 private static final String RUNTIME_STATE = "launcher.state";
Sunny Goyal2100c782016-08-22 16:00:03 -0700198 // Type: PendingRequestArgs
199 private static final String RUNTIME_STATE_PENDING_REQUEST_ARGS = "launcher.request_args";
Sunny Goyaldedda052019-05-14 15:23:48 -0700200 // Type: int
201 private static final String RUNTIME_STATE_PENDING_REQUEST_CODE = "launcher.request_code";
Sunny Goyal2100c782016-08-22 16:00:03 -0700202 // Type: ActivityResultInfo
203 private static final String RUNTIME_STATE_PENDING_ACTIVITY_RESULT = "launcher.activity_result";
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -0700204 // Type: SparseArray<Parcelable>
205 private static final String RUNTIME_STATE_WIDGET_PANEL = "launcher.widget_panel";
vadimt00d42552018-12-11 17:59:36 -0800206 public static final String ON_CREATE_EVT = "Launcher.onCreate";
vadimtcb863752018-12-19 17:44:57 -0800207 private static final String ON_START_EVT = "Launcher.onStart";
208 private static final String ON_RESUME_EVT = "Launcher.onResume";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800209
Sunny Goyal3e3f44c2017-10-23 17:14:52 -0700210 private LauncherStateManager mStateManager;
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700211
Adam Cohenad4e15c2013-10-17 16:21:35 -0700212 private static final int ON_ACTIVITY_RESULT_ANIMATION_DELAY = 500;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800213
Winson Chunga2413752012-04-03 14:22:34 -0700214 // How long to wait before the new-shortcut animation automatically pans the workspace
Jon Mirandaf5197fc2019-09-04 16:55:41 -0700215 @VisibleForTesting public static final int NEW_APPS_PAGE_MOVE_DELAY = 500;
Rajeev Kumar43c0f582017-06-23 15:34:55 -0700216 private static final int NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS = 5;
Jon Mirandaf5197fc2019-09-04 16:55:41 -0700217 @Thunk @VisibleForTesting public static final int NEW_APPS_ANIMATION_DELAY = 500;
Winson Chunga2413752012-04-03 14:22:34 -0700218
Govinda Wassermanc06e1512019-04-09 09:56:53 -0400219 private static final int APPS_VIEW_ALPHA_CHANNEL_INDEX = 1;
220 private static final int SCRIM_VIEW_ALPHA_CHANNEL_INDEX = 0;
221
Jon Miranda54441f52018-01-24 15:38:25 -0800222 private LauncherAppTransitionManager mAppTransitionManager;
Sunny Goyalf8d56fc2018-01-31 15:18:11 -0800223 private Configuration mOldConfig;
Jon Miranda54441f52018-01-24 15:38:25 -0800224
Samuel Fufaca37b8a2019-08-19 17:04:36 -0700225 @Thunk
226 Workspace mWorkspace;
Craig Mautner360310b2012-10-26 15:13:08 -0700227 private View mLauncherView;
Samuel Fufaca37b8a2019-08-19 17:04:36 -0700228 @Thunk
229 DragLayer mDragLayer;
Michael Jurkab737ee62011-11-15 15:57:22 -0800230 private DragController mDragController;
Sunny Goyal322d5562015-06-25 19:35:49 -0700231
Sunny Goyalffe83f12014-08-14 17:39:34 -0700232 private AppWidgetManagerCompat mAppWidgetManager;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700233 private LauncherAppWidgetHost mAppWidgetHost;
Romain Guycbb89e42009-06-08 15:52:54 -0700234
Rajeev Kumar43c0f582017-06-23 15:34:55 -0700235 private final int[] mTmpAddItemCellCoordinates = new int[2];
Michael Jurka0280c3b2010-09-17 15:00:07 -0700236
Samuel Fufaca37b8a2019-08-19 17:04:36 -0700237 @Thunk
238 Hotseat mHotseat;
Adam Cohenf358a4b2013-07-23 16:47:31 -0700239
Sunny Goyal47328fd2016-05-25 18:56:41 -0700240 private DropTargetBar mDropTargetBar;
Hyunyoung Song3f471442015-04-08 19:01:34 -0700241
242 // Main container view for the all apps screen.
Samuel Fufaca37b8a2019-08-19 17:04:36 -0700243 @Thunk
244 AllAppsContainerView mAppsView;
Hyunyoung Song645764e2016-06-06 14:19:02 -0700245 AllAppsTransitionController mAllAppsController;
Hyunyoung Song3f471442015-04-08 19:01:34 -0700246
Govinda Wassermanc06e1512019-04-09 09:56:53 -0400247 // Scrim view for the all apps and overview state.
Samuel Fufaca37b8a2019-08-19 17:04:36 -0700248 @Thunk
249 ScrimView mScrimView;
Govinda Wassermanc06e1512019-04-09 09:56:53 -0400250
Winson Chung8ae41982017-11-10 11:42:13 -0800251 // UI and state for the overview panel
Sunny Goyal7c7be8c2018-03-07 19:58:07 -0800252 private View mOverviewPanel;
Winson Chung8ae41982017-11-10 11:42:13 -0800253
Samuel Fufaca37b8a2019-08-19 17:04:36 -0700254 @Thunk
255 boolean mWorkspaceLoading = true;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400256
Winson Chung0b70cd42019-06-17 22:34:33 -0700257 private ArrayList<OnResumeCallback> mOnResumeCallbacks = new ArrayList<>();
Sunny Goyal3dce5f32017-10-05 11:40:05 -0700258
Sunny Goyal527c7d32015-08-28 15:19:36 -0700259 private ViewOnDrawExecutor mPendingExecutor;
Michael Jurka7607c2f2013-04-03 14:33:19 -0700260
Joe Onorato9c1289c2009-08-17 11:03:03 -0400261 private LauncherModel mModel;
Sunny Goyal43bf11d2017-02-02 13:52:53 -0800262 private ModelWriter mModelWriter;
Joe Onorato0589f0f2010-02-08 13:44:00 -0800263 private IconCache mIconCache;
Sunny Goyalae502842016-06-17 08:43:56 -0700264 private LauncherAccessibilityDelegate mAccessibilityDelegate;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400265
Tony Wickham010d2552017-01-20 08:15:28 -0800266 private PopupDataProvider mPopupDataProvider;
Tony Wickhambfbf7f92016-05-19 11:19:39 -0700267
Sunny Goyalf4aceab2017-12-06 16:16:31 -0800268 private int mSynchronouslyBoundPage = PagedView.INVALID_PAGE;
Adam Cohen1462de32012-07-24 22:34:36 -0700269
Winson Chung46353de2012-02-16 14:05:10 -0800270 // We only want to get the SharedPreferences once since it does an FS stat each time we get
271 // it from the context.
272 private SharedPreferences mSharedPrefs;
273
Sunny Goyal2100c782016-08-22 16:00:03 -0700274 // Activity result which needs to be processed after workspace has loaded.
275 private ActivityResultInfo mPendingActivityResult;
276 /**
277 * Holds extra information required to handle a result from an external call, like
278 * {@link #startActivityForResult(Intent, int)} or {@link #requestPermissions(String[], int)}
279 */
280 private PendingRequestArgs mPendingRequestArgs;
Sunny Goyaldedda052019-05-14 15:23:48 -0700281 // Request id for any pending activity result
282 private int mPendingActivityRequestCode = -1;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800283
Sunny Goyal3333b0c2016-05-09 20:43:21 -0700284 public ViewGroupFocusHelper mFocusHandler;
Hyunyoung Song7fb3ccc2017-10-17 15:39:46 -0700285
Sunny Goyal623eddd2018-03-02 12:24:41 -0800286 private RotationHelper mRotationHelper;
Sunny Goyal5743f862019-03-28 15:35:32 -0700287 private Runnable mCancelTouchController;
Sunny Goyal7779d622015-06-11 16:18:39 -0700288
Sunny Goyal2db53422019-03-01 16:06:12 -0800289 final Handler mHandler = new Handler();
Sunny Goyala002c6c2019-02-12 16:20:10 -0800290 private final Runnable mHandleDeferredResume = this::handleDeferredResume;
Sunny Goyale9c6f4c2019-05-30 11:35:25 -0700291 private boolean mDeferredResumePending;
Hyunyoung Songbd6fba92018-05-16 15:54:31 -0700292
Govinda Wassermanc06e1512019-04-09 09:56:53 -0400293 private float mCurrentAssistantVisibility = 0f;
294
Sunny Goyalae6e3182019-04-30 12:04:37 -0700295 private DeviceProfile mStableDeviceProfile;
296 private RotationMode mRotationMode = RotationMode.NORMAL;
297
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800298 @Override
299 protected void onCreate(Bundle savedInstanceState) {
vadimt00d42552018-12-11 17:59:36 -0800300 RaceConditionTracker.onEvent(ON_CREATE_EVT, ENTER);
Winson Chunga2413752012-04-03 14:22:34 -0700301 if (DEBUG_STRICT_MODE) {
302 StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
303 .detectDiskReads()
304 .detectDiskWrites()
305 .detectNetwork() // or .detectAll() for all detectable problems
306 .penaltyLog()
307 .build());
308 StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
309 .detectLeakedSqlLiteObjects()
310 .detectLeakedClosableObjects()
311 .penaltyLog()
312 .penaltyDeath()
313 .build());
314 }
Sunny Goyalfca6bc92017-09-28 16:28:34 -0700315 TraceHelper.beginSection("Launcher-onCreate");
Winson Chunga2413752012-04-03 14:22:34 -0700316
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800317 super.onCreate(savedInstanceState);
Sunny Goyalfca6bc92017-09-28 16:28:34 -0700318 TraceHelper.partitionSection("Launcher-onCreate", "super call");
Daniel Sandlere060b0b2013-06-27 21:47:55 -0400319
Sunny Goyal87f784c2017-01-11 10:48:34 -0800320 LauncherAppState app = LauncherAppState.getInstance(this);
Sunny Goyalf8d56fc2018-01-31 15:18:11 -0800321 mOldConfig = new Configuration(getResources().getConfiguration());
Sunny Goyal0e7724c2018-02-22 13:22:21 -0800322 mModel = app.setLauncher(this);
Sunny Goyal41d51a02019-05-14 09:44:34 -0700323 mRotationHelper = new RotationHelper(this);
Hyunyoung Song31971a32019-01-27 12:31:12 -0800324 InvariantDeviceProfile idp = app.getInvariantDeviceProfile();
325 initDeviceProfile(idp);
326 idp.addOnChangeListener(this);
Sunny Goyalf7258242015-10-19 16:59:07 -0700327 mSharedPrefs = Utilities.getPrefs(this);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800328 mIconCache = app.getIconCache();
Sunny Goyalae502842016-06-17 08:43:56 -0700329 mAccessibilityDelegate = new LauncherAccessibilityDelegate(this);
Adam Cohen2e6da152015-05-06 11:42:25 -0700330
Joe Onorato41a12d22009-10-31 18:30:00 -0400331 mDragController = new DragController(this);
Hyunyoung Song645764e2016-06-06 14:19:02 -0700332 mAllAppsController = new AllAppsTransitionController(this);
Sunny Goyalc4fa8c32017-11-07 12:23:58 -0800333 mStateManager = new LauncherStateManager(this);
Tracy Zhou8b23c6f2018-04-30 17:13:27 -0700334 UiFactory.onCreate(this);
Romain Guycbb89e42009-06-08 15:52:54 -0700335
Sunny Goyalffe83f12014-08-14 17:39:34 -0700336 mAppWidgetManager = AppWidgetManagerCompat.getInstance(this);
Adam Cohen53805212013-10-01 10:39:23 -0700337
Sunny Goyal64a75aa2017-07-03 13:50:52 -0700338 mAppWidgetHost = new LauncherAppWidgetHost(this);
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700339 mAppWidgetHost.startListening();
Romain Guycbb89e42009-06-08 15:52:54 -0700340
Sunny Goyal60820d72017-05-09 12:40:11 -0700341 mLauncherView = LayoutInflater.from(this).inflate(R.layout.launcher, null);
Michael Jurka7267fa52013-09-26 15:29:57 -0700342
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800343 setupViews();
Tony Wickham010d2552017-01-20 08:15:28 -0800344 mPopupDataProvider = new PopupDataProvider(this);
345
Sunny Goyal90548432018-04-04 17:17:00 -0700346 mAppTransitionManager = LauncherAppTransitionManager.newInstance(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800347
Sunny Goyald3864fa2017-11-14 15:06:36 -0800348 boolean internalStateHandled = InternalStateHandler.handleCreate(this, getIntent());
349 if (internalStateHandled) {
Sunny Goyald3864fa2017-11-14 15:06:36 -0800350 if (savedInstanceState != null) {
351 // InternalStateHandler has already set the appropriate state.
352 // We dont need to do anything.
353 savedInstanceState.remove(RUNTIME_STATE);
354 }
355 }
356 restoreState(savedInstanceState);
Sunny Goyalbbece862019-03-01 13:13:52 -0800357 mStateManager.reapplyState();
Winson Chungb63b44c2017-11-10 17:54:44 -0800358
Sunny Goyal2100c782016-08-22 16:00:03 -0700359 // We only load the page synchronously if the user rotates (or triggers a
360 // configuration change) while launcher is in the foreground
Sunny Goyalfe770c92016-09-27 14:38:58 -0700361 int currentScreen = PagedView.INVALID_RESTORE_PAGE;
362 if (savedInstanceState != null) {
363 currentScreen = savedInstanceState.getInt(RUNTIME_STATE_CURRENT_SCREEN, currentScreen);
364 }
Sunny Goyald3864fa2017-11-14 15:06:36 -0800365
Sunny Goyalfe770c92016-09-27 14:38:58 -0700366 if (!mModel.startLoader(currentScreen)) {
Sunny Goyald3864fa2017-11-14 15:06:36 -0800367 if (!internalStateHandled) {
368 // If we are not binding synchronously, show a fade in animation when
369 // the first page bind completes.
Sunny Goyal6001ea22018-05-10 16:31:00 -0700370 mDragLayer.getAlphaProperty(ALPHA_INDEX_LAUNCHER_LOAD).setValue(0);
Sunny Goyald3864fa2017-11-14 15:06:36 -0800371 }
Sunny Goyal2100c782016-08-22 16:00:03 -0700372 } else {
Sunny Goyalfe770c92016-09-27 14:38:58 -0700373 // Pages bound synchronously.
374 mWorkspace.setCurrentPage(currentScreen);
375
Sunny Goyal2100c782016-08-22 16:00:03 -0700376 setWorkspaceLoading(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800377 }
378
379 // For handling default keys
Sunny Goyalf4aceab2017-12-06 16:16:31 -0800380 setDefaultKeyMode(DEFAULT_KEYS_SEARCH_LOCAL);
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800381
Sunny Goyal0bbd5542016-11-11 10:41:26 -0800382 setContentView(mLauncherView);
Sunny Goyalf8d56fc2018-01-31 15:18:11 -0800383 getRootView().dispatchInsets();
Mario Bertschlera6936942017-05-31 14:48:19 -0700384
Jon Miranda7fda2852017-07-19 16:07:01 -0700385 // Listen for broadcasts
Sunny Goyal5d1873a2018-05-08 11:10:44 -0700386 registerReceiver(mScreenOffReceiver, new IntentFilter(Intent.ACTION_SCREEN_OFF));
Sunny Goyala616d2b2017-06-12 13:54:01 -0700387
Sunny Goyal8392c822017-06-20 10:03:56 -0700388 getSystemUiController().updateUiState(SystemUiController.UI_STATE_BASE_WINDOW,
389 Themes.getAttrBoolean(this, R.attr.isWorkspaceDarkText));
Sunny Goyal14b32402017-07-31 10:03:28 -0700390
391 if (mLauncherCallbacks != null) {
392 mLauncherCallbacks.onCreate(savedInstanceState);
393 }
Sunny Goyal623eddd2018-03-02 12:24:41 -0800394 mRotationHelper.initialize();
Sunny Goyalfca6bc92017-09-28 16:28:34 -0700395
396 TraceHelper.endSection("Launcher-onCreate");
vadimt00d42552018-12-11 17:59:36 -0800397 RaceConditionTracker.onEvent(ON_CREATE_EVT, EXIT);
Govinda Wassermanc06e1512019-04-09 09:56:53 -0400398 mStateManager.addStateListener(new LauncherStateManager.StateListener() {
399 @Override
Samuel Fufaca37b8a2019-08-19 17:04:36 -0700400 public void onStateTransitionStart(LauncherState toState) {
401 }
Govinda Wassermanc06e1512019-04-09 09:56:53 -0400402
403 @Override
404 public void onStateTransitionComplete(LauncherState finalState) {
405 float alpha = 1f - mCurrentAssistantVisibility;
406 if (finalState == NORMAL) {
407 mAppsView.getAlphaProperty(APPS_VIEW_ALPHA_CHANNEL_INDEX).setValue(alpha);
408 } else if (finalState == OVERVIEW || finalState == OVERVIEW_PEEK) {
409 mAppsView.getAlphaProperty(APPS_VIEW_ALPHA_CHANNEL_INDEX).setValue(alpha);
410 mScrimView.getAlphaProperty(SCRIM_VIEW_ALPHA_CHANNEL_INDEX).setValue(alpha);
411 } else {
412 mAppsView.getAlphaProperty(APPS_VIEW_ALPHA_CHANNEL_INDEX).setValue(1f);
413 mScrimView.getAlphaProperty(SCRIM_VIEW_ALPHA_CHANNEL_INDEX).setValue(1f);
414 }
415 }
416 });
Adam Cohen9211d422014-10-07 18:14:53 -0700417 }
418
Sunny Goyal7779d622015-06-11 16:18:39 -0700419 @Override
Winson Chung8eb49e02018-07-16 13:33:31 -0700420 public void onEnterAnimationComplete() {
421 super.onEnterAnimationComplete();
422 UiFactory.onEnterAnimationComplete(this);
arangelovad783052018-08-17 14:46:45 +0100423 mAllAppsController.highlightWorkTabIfNecessary();
Sunny Goyalbe8c3402019-05-22 15:17:52 -0700424 mRotationHelper.setCurrentTransitionRequest(REQUEST_NONE);
Winson Chung8eb49e02018-07-16 13:33:31 -0700425 }
426
427 @Override
Sunny Goyalf8d56fc2018-01-31 15:18:11 -0800428 public void onConfigurationChanged(Configuration newConfig) {
429 int diff = newConfig.diff(mOldConfig);
Jon Mirandaaeb4dd02018-07-11 14:16:23 -0700430
Sunny Goyalf8d56fc2018-01-31 15:18:11 -0800431 if ((diff & (CONFIG_ORIENTATION | CONFIG_SCREEN_SIZE)) != 0) {
Sunny Goyal371ea052019-03-06 15:38:32 -0800432 onIdpChanged(mDeviceProfile.inv);
Sunny Goyalf8d56fc2018-01-31 15:18:11 -0800433 }
434
435 mOldConfig.setTo(newConfig);
Tracy Zhoua706f002018-03-28 13:55:19 -0700436 UiFactory.onLauncherStateOrResumeChanged(this);
Sunny Goyalf8d56fc2018-01-31 15:18:11 -0800437 super.onConfigurationChanged(newConfig);
438 }
439
Sunny Goyal3e195d72019-06-19 14:24:38 -0700440 public void reload() {
441 onIdpChanged(mDeviceProfile.inv);
442 }
443
Sunny Goyal41d51a02019-05-14 09:44:34 -0700444 private boolean supportsFakeLandscapeUI() {
445 return FeatureFlags.FAKE_LANDSCAPE_UI.get() && !mRotationHelper.homeScreenCanRotate();
446 }
447
Sunny Goyal605bcf32018-03-02 15:16:12 -0800448 @Override
Sunny Goyal41d51a02019-05-14 09:44:34 -0700449 public void reapplyUi() {
450 if (supportsFakeLandscapeUI()) {
Sunny Goyal7a39b1b2019-05-02 13:39:16 -0700451 mRotationMode = mStableDeviceProfile == null
452 ? RotationMode.NORMAL : UiFactory.getRotationMode(mDeviceProfile);
Sunny Goyalae6e3182019-04-30 12:04:37 -0700453 }
Sunny Goyal59d086c2018-05-07 17:31:40 -0700454 getRootView().dispatchInsets();
455 getStateManager().reapplyState(true /* cancelCurrentAnimation */);
456 }
457
458 @Override
Sunny Goyal605bcf32018-03-02 15:16:12 -0800459 public void rebindModel() {
460 int currentPage = mWorkspace.getNextPage();
461 if (mModel.startLoader(currentPage)) {
462 mWorkspace.setCurrentPage(currentPage);
463 setWorkspaceLoading(true);
464 }
465 }
466
Hyunyoung Song31971a32019-01-27 12:31:12 -0800467 @Override
468 public void onIdpChanged(int changeFlags, InvariantDeviceProfile idp) {
Sunny Goyal371ea052019-03-06 15:38:32 -0800469 onIdpChanged(idp);
470 }
471
472 private void onIdpChanged(InvariantDeviceProfile idp) {
473 mUserEventDispatcher = null;
474
Sunny Goyalc8502c12019-06-10 12:14:47 -0700475 DeviceProfile oldWallpaperProfile = getWallpaperDeviceProfile();
Hyunyoung Song31971a32019-01-27 12:31:12 -0800476 initDeviceProfile(idp);
Sunny Goyal371ea052019-03-06 15:38:32 -0800477 dispatchDeviceProfileChanged();
478 reapplyUi();
479 mDragLayer.recreateControllers();
480
Sunny Goyal76ba0a32019-06-10 11:56:11 -0700481 // Calling onSaveInstanceState ensures that static cache used by listWidgets is
482 // initialized properly.
483 onSaveInstanceState(new Bundle());
Sunny Goyalc8502c12019-06-10 12:14:47 -0700484 if (oldWallpaperProfile != getWallpaperDeviceProfile()) {
485 rebindModel();
486 }
Hyunyoung Song31971a32019-01-27 12:31:12 -0800487 }
488
Govinda Wassermanc06e1512019-04-09 09:56:53 -0400489 public void onAssistantVisibilityChanged(float visibility) {
490 mCurrentAssistantVisibility = visibility;
491 float alpha = 1f - visibility;
492 LauncherState state = mStateManager.getState();
493 if (state == NORMAL) {
494 mAppsView.getAlphaProperty(APPS_VIEW_ALPHA_CHANNEL_INDEX).setValue(alpha);
495 } else if (state == OVERVIEW || state == OVERVIEW_PEEK) {
496 mAppsView.getAlphaProperty(APPS_VIEW_ALPHA_CHANNEL_INDEX).setValue(alpha);
497 mScrimView.getAlphaProperty(SCRIM_VIEW_ALPHA_CHANNEL_INDEX).setValue(alpha);
498 }
499 }
500
Sunny Goyalf8d56fc2018-01-31 15:18:11 -0800501 private void initDeviceProfile(InvariantDeviceProfile idp) {
502 // Load configuration-specific DeviceProfile
Sunny Goyal59d086c2018-05-07 17:31:40 -0700503 mDeviceProfile = idp.getDeviceProfile(this);
Sunny Goyal8c48d8b2019-01-25 15:10:18 -0800504 if (isInMultiWindowMode()) {
Winson Chung13c1c2c2019-09-06 11:46:19 -0700505 // Note: Calls to getSize() can't rely on our cached DefaultDisplay since it can return
506 // the app window size
Sunny Goyal59d086c2018-05-07 17:31:40 -0700507 Display display = getWindowManager().getDefaultDisplay();
508 Point mwSize = new Point();
509 display.getSize(mwSize);
510 mDeviceProfile = mDeviceProfile.getMultiWindowProfile(this, mwSize);
511 }
Sunny Goyalae6e3182019-04-30 12:04:37 -0700512
Sunny Goyalda14cf82019-05-30 10:31:09 -0700513 if (supportsFakeLandscapeUI() && mDeviceProfile.isVerticalBarLayout()) {
Sunny Goyalae6e3182019-04-30 12:04:37 -0700514 mStableDeviceProfile = mDeviceProfile.inv.portraitProfile;
Sunny Goyal7a39b1b2019-05-02 13:39:16 -0700515 mRotationMode = UiFactory.getRotationMode(mDeviceProfile);
Sunny Goyalae6e3182019-04-30 12:04:37 -0700516 } else {
517 mStableDeviceProfile = null;
518 mRotationMode = RotationMode.NORMAL;
519 }
520
Sunny Goyalda14cf82019-05-30 10:31:09 -0700521 mRotationHelper.updateRotationAnimation();
Sunny Goyal59d086c2018-05-07 17:31:40 -0700522 onDeviceProfileInitiated();
Sunny Goyalae6e3182019-04-30 12:04:37 -0700523 mModelWriter = mModel.getWriter(getWallpaperDeviceProfile().isVerticalBarLayout(), true);
524 }
525
526 public void updateInsets(Rect insets) {
527 mDeviceProfile.updateInsets(insets);
528 if (mStableDeviceProfile != null) {
Sunny Goyal7a39b1b2019-05-02 13:39:16 -0700529 Rect r = mStableDeviceProfile.getInsets();
530 mRotationMode.mapInsets(this, insets, r);
531 mStableDeviceProfile.updateInsets(r);
Sunny Goyalae6e3182019-04-30 12:04:37 -0700532 }
533 }
534
535 @Override
536 public RotationMode getRotationMode() {
537 return mRotationMode;
538 }
539
540 /**
541 * Device profile to be used by UI elements which are shown directly on top of the wallpaper
542 * and whose presentation is tied to the wallpaper (and physical device) and not the activity
543 * configuration.
544 */
545 @Override
546 public DeviceProfile getWallpaperDeviceProfile() {
547 return mStableDeviceProfile == null ? mDeviceProfile : mStableDeviceProfile;
Sunny Goyalf8d56fc2018-01-31 15:18:11 -0800548 }
549
Sunny Goyal623eddd2018-03-02 12:24:41 -0800550 public RotationHelper getRotationHelper() {
551 return mRotationHelper;
552 }
553
Sunny Goyal3e3f44c2017-10-23 17:14:52 -0700554 public LauncherStateManager getStateManager() {
555 return mStateManager;
Sunny Goyalbe93f262017-10-20 17:05:27 -0700556 }
557
Mario Bertschler27288382017-05-24 15:35:09 -0700558 @Override
Sunny Goyalc7b8df82017-06-27 11:11:03 -0700559 public <T extends View> T findViewById(int id) {
Sunny Goyal0bbd5542016-11-11 10:41:26 -0800560 return mLauncherView.findViewById(id);
561 }
562
563 @Override
Sunny Goyal2e013ea2016-10-07 16:17:19 -0700564 public void onAppWidgetHostReset() {
565 if (mAppWidgetHost != null) {
566 mAppWidgetHost.startListening();
567 }
568 }
569
Adam Cohen9211d422014-10-07 18:14:53 -0700570 private LauncherCallbacks mLauncherCallbacks;
571
Sunny Goyal32554d12015-12-03 15:31:25 -0800572 /**
573 * Call this after onCreate to set or clear overlay.
574 */
575 public void setLauncherOverlay(LauncherOverlay overlay) {
576 if (overlay != null) {
577 overlay.setOverlayCallbacks(new LauncherOverlayCallbacksImpl());
578 }
579 mWorkspace.setLauncherOverlay(overlay);
580 }
581
Adam Cohen9211d422014-10-07 18:14:53 -0700582 public boolean setLauncherCallbacks(LauncherCallbacks callbacks) {
583 mLauncherCallbacks = callbacks;
584 return true;
Adam Cohenf9426d52012-06-04 17:26:21 -0700585 }
586
Anjali Koppal67e7cae2014-03-13 12:14:12 -0700587 @Override
Sunny Goyal2e013ea2016-10-07 16:17:19 -0700588 public void onLauncherProviderChanged() {
Adam Cohen9211d422014-10-07 18:14:53 -0700589 if (mLauncherCallbacks != null) {
590 mLauncherCallbacks.onLauncherProviderChange();
591 }
592 }
Anjali Koppal67e7cae2014-03-13 12:14:12 -0700593
Hyunyoung Song3f471442015-04-08 19:01:34 -0700594 public boolean isDraggingEnabled() {
Winson Chung36a62fe2012-05-06 18:04:42 -0700595 // We prevent dragging when we are loading the workspace as it is possible to pick up a view
596 // that is subsequently removed from the workspace in startBinding().
Sunny Goyal639e9062015-08-19 19:17:06 -0700597 return !isWorkspaceLoading();
Winson Chung36a62fe2012-05-06 18:04:42 -0700598 }
599
Tony Wickham010d2552017-01-20 08:15:28 -0800600 public PopupDataProvider getPopupDataProvider() {
601 return mPopupDataProvider;
602 }
603
Sunny Goyal0b0847b2018-03-14 12:30:11 -0700604 @Override
Tony Wickhamf34bee82018-12-03 18:11:39 -0800605 public DotInfo getDotInfoForItem(ItemInfo info) {
606 return mPopupDataProvider.getDotInfoForItem(info);
Sunny Goyal0b0847b2018-03-14 12:30:11 -0700607 }
608
609 @Override
610 public void invalidateParent(ItemInfo info) {
Jon Mirandae6f3fa42019-03-04 09:14:40 -0800611 if (info.container >= 0) {
Sunny Goyal0b0847b2018-03-14 12:30:11 -0700612 View folderIcon = getWorkspace().getHomescreenIconByItemId(info.container);
Jon Mirandae6f3fa42019-03-04 09:14:40 -0800613 if (folderIcon instanceof FolderIcon && folderIcon.getTag() instanceof FolderInfo) {
Sunny Goyal11a50742019-08-07 09:24:26 -0700614 if (new FolderGridOrganizer(getDeviceProfile().inv)
615 .setFolderInfo((FolderInfo) folderIcon.getTag())
616 .isItemInPreview(info.rank)) {
Jon Mirandae6f3fa42019-03-04 09:14:40 -0800617 folderIcon.invalidate();
618 }
Sunny Goyal0b0847b2018-03-14 12:30:11 -0700619 }
620 }
621 }
622
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000623 /**
Winson Chung557d6ed2011-07-08 15:34:52 -0700624 * Returns whether we should delay spring loaded mode -- for shortcuts and widgets that have
625 * a configuration step, this allows the proper animations to run after other transitions.
626 */
Sunny Goyalefb7e842018-10-04 15:11:00 -0700627 private int completeAdd(
Sunny Goyal2100c782016-08-22 16:00:03 -0700628 int requestCode, Intent intent, int appWidgetId, PendingRequestArgs info) {
Sunny Goyalefb7e842018-10-04 15:11:00 -0700629 int screenId = info.screenId;
Sunny Goyal2100c782016-08-22 16:00:03 -0700630 if (info.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
Adam Cohen83079e42014-09-19 17:43:08 -0700631 // When the screen id represents an actual screen (as opposed to a rank) we make sure
632 // that the drop page actually exists.
Sunny Goyal2100c782016-08-22 16:00:03 -0700633 screenId = ensurePendingDropLayoutExists(info.screenId);
Adam Cohen83079e42014-09-19 17:43:08 -0700634 }
Adam Cohendb364c32014-05-20 14:23:40 -0700635
Sunny Goyal2100c782016-08-22 16:00:03 -0700636 switch (requestCode) {
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800637 case REQUEST_CREATE_SHORTCUT:
Sunny Goyalfb5096d2016-09-08 14:32:06 -0700638 completeAddShortcut(intent, info.container, screenId, info.cellX, info.cellY, info);
Winson Chungb8472bb2011-08-05 13:49:21 -0700639 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800640 case REQUEST_CREATE_APPWIDGET:
Sunny Goyal2100c782016-08-22 16:00:03 -0700641 completeAddAppWidget(appWidgetId, info, null, null);
Winson Chungb8472bb2011-08-05 13:49:21 -0700642 break;
Sunny Goyalff572272014-07-23 13:58:07 -0700643 case REQUEST_RECONFIGURE_APPWIDGET:
Sunny Goyal2100c782016-08-22 16:00:03 -0700644 completeRestoreAppWidget(appWidgetId, LauncherAppWidgetInfo.RESTORE_COMPLETED);
Sunny Goyalff572272014-07-23 13:58:07 -0700645 break;
Sunny Goyald478c832016-04-01 12:04:16 -0700646 case REQUEST_BIND_PENDING_APPWIDGET: {
Sunny Goyal2100c782016-08-22 16:00:03 -0700647 int widgetId = appWidgetId;
648 LauncherAppWidgetInfo widgetInfo =
Sunny Goyald478c832016-04-01 12:04:16 -0700649 completeRestoreAppWidget(widgetId, LauncherAppWidgetInfo.FLAG_UI_NOT_READY);
Sunny Goyal2100c782016-08-22 16:00:03 -0700650 if (widgetInfo != null) {
Sunny Goyald478c832016-04-01 12:04:16 -0700651 // Since the view was just bound, also launch the configure activity if needed
652 LauncherAppWidgetProviderInfo provider = mAppWidgetManager
653 .getLauncherAppWidgetInfo(widgetId);
Sunny Goyal04a324a2017-01-20 21:08:59 -0800654 if (provider != null) {
655 new WidgetAddFlowHandler(provider)
Samuel Fufaca37b8a2019-08-19 17:04:36 -0700656 .startConfigActivity(this, widgetInfo,
657 REQUEST_RECONFIGURE_APPWIDGET);
Sunny Goyald478c832016-04-01 12:04:16 -0700658 }
659 }
660 break;
661 }
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800662 }
Sunny Goyal2100c782016-08-22 16:00:03 -0700663
Adam Cohendb364c32014-05-20 14:23:40 -0700664 return screenId;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800665 }
666
Adam Cohenc7cd2cb2014-11-17 17:45:34 -0800667 private void handleActivityResult(
Michael Jurka8b805b12012-04-18 14:23:14 -0700668 final int requestCode, final int resultCode, final Intent data) {
Sunny Goyal2100c782016-08-22 16:00:03 -0700669 if (isWorkspaceLoading()) {
670 // process the result once the workspace has loaded.
671 mPendingActivityResult = new ActivityResultInfo(requestCode, resultCode, data);
672 return;
673 }
674 mPendingActivityResult = null;
675
Winson Chunge341d302013-08-16 14:31:00 -0700676 // Reset the startActivity waiting flag
Sunny Goyal2100c782016-08-22 16:00:03 -0700677 final PendingRequestArgs requestArgs = mPendingRequestArgs;
678 setWaitingForResult(null);
679 if (requestArgs == null) {
680 return;
681 }
682
683 final int pendingAddWidgetId = requestArgs.getWidgetId();
Winson Chunge341d302013-08-16 14:31:00 -0700684
Adam Cohenad4e15c2013-10-17 16:21:35 -0700685 Runnable exitSpringLoaded = new Runnable() {
686 @Override
687 public void run() {
Sunny Goyal3e3f44c2017-10-23 17:14:52 -0700688 mStateManager.goToState(NORMAL, SPRING_LOADED_EXIT_DELAY);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700689 }
690 };
691
Michael Jurka8b805b12012-04-18 14:23:14 -0700692 if (requestCode == REQUEST_BIND_APPWIDGET) {
Winsona1f79d32015-08-05 14:00:45 -0700693 // This is called only if the user did not previously have permissions to bind widgets
Adam Cohenad4e15c2013-10-17 16:21:35 -0700694 final int appWidgetId = data != null ?
Michael Jurka8b805b12012-04-18 14:23:14 -0700695 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
696 if (resultCode == RESULT_CANCELED) {
Sunny Goyal2100c782016-08-22 16:00:03 -0700697 completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId, requestArgs);
Adam Cohen689ff162014-05-08 17:27:56 -0700698 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
Adam Cohenad4e15c2013-10-17 16:21:35 -0700699 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
Michael Jurka8b805b12012-04-18 14:23:14 -0700700 } else if (resultCode == RESULT_OK) {
Sunny Goyal2100c782016-08-22 16:00:03 -0700701 addAppWidgetImpl(
702 appWidgetId, requestArgs, null,
Sunny Goyal04a324a2017-01-20 21:08:59 -0800703 requestArgs.getWidgetHandler(),
Sunny Goyal2100c782016-08-22 16:00:03 -0700704 ON_ACTIVITY_RESULT_ANIMATION_DELAY);
Michael Jurka8b805b12012-04-18 14:23:14 -0700705 }
706 return;
707 }
Michael Jurka336fd4f2013-09-12 00:05:02 +0200708
Adam Cohened66b2b2012-01-23 17:28:51 -0800709 boolean isWidgetDrop = (requestCode == REQUEST_PICK_APPWIDGET ||
Sunny Goyal5c97f512015-05-19 16:03:28 -0700710 requestCode == REQUEST_CREATE_APPWIDGET);
Romain Guyaad5ef42009-06-10 02:48:37 -0700711
Adam Cohened66b2b2012-01-23 17:28:51 -0800712 // We have special handling for widgets
713 if (isWidgetDrop) {
Adam Cohen4637b5a2013-11-04 18:21:24 -0800714 final int appWidgetId;
715 int widgetId = data != null ? data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1)
716 : -1;
717 if (widgetId < 0) {
718 appWidgetId = pendingAddWidgetId;
719 } else {
720 appWidgetId = widgetId;
721 }
722
Adam Cohenad4e15c2013-10-17 16:21:35 -0700723 final int result;
Adam Cohenf0129b12013-11-04 17:57:36 -0800724 if (appWidgetId < 0 || resultCode == RESULT_CANCELED) {
Adam Cohendb364c32014-05-20 14:23:40 -0700725 Log.e(TAG, "Error: appWidgetId (EXTRA_APPWIDGET_ID) was not " +
726 "returned from the widget configuration activity.");
Adam Cohenad4e15c2013-10-17 16:21:35 -0700727 result = RESULT_CANCELED;
Sunny Goyal2100c782016-08-22 16:00:03 -0700728 completeTwoStageWidgetDrop(result, appWidgetId, requestArgs);
Adam Cohendb364c32014-05-20 14:23:40 -0700729 final Runnable onComplete = new Runnable() {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700730 @Override
731 public void run() {
Sunny Goyal3e3f44c2017-10-23 17:14:52 -0700732 getStateManager().goToState(NORMAL);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700733 }
734 };
Adam Cohendb364c32014-05-20 14:23:40 -0700735
Sunny Goyal2100c782016-08-22 16:00:03 -0700736 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete,
737 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
738 } else {
739 if (requestArgs.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
740 // When the screen id represents an actual screen (as opposed to a rank)
741 // we make sure that the drop page actually exists.
742 requestArgs.screenId =
743 ensurePendingDropLayoutExists(requestArgs.screenId);
Adam Cohendb364c32014-05-20 14:23:40 -0700744 }
Sunny Goyal2100c782016-08-22 16:00:03 -0700745 final CellLayout dropLayout =
746 mWorkspace.getScreenWithId(requestArgs.screenId);
747
748 dropLayout.setDropPending(true);
749 final Runnable onComplete = new Runnable() {
750 @Override
751 public void run() {
752 completeTwoStageWidgetDrop(resultCode, appWidgetId, requestArgs);
753 dropLayout.setDropPending(false);
754 }
755 };
756 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete,
757 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
Winson Chung5aaab772012-04-27 15:24:02 -0700758 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800759 return;
760 }
761
Sunny Goyald478c832016-04-01 12:04:16 -0700762 if (requestCode == REQUEST_RECONFIGURE_APPWIDGET
763 || requestCode == REQUEST_BIND_PENDING_APPWIDGET) {
Sunny Goyalff572272014-07-23 13:58:07 -0700764 if (resultCode == RESULT_OK) {
765 // Update the widget view.
Sunny Goyal2100c782016-08-22 16:00:03 -0700766 completeAdd(requestCode, data, pendingAddWidgetId, requestArgs);
Sunny Goyalff572272014-07-23 13:58:07 -0700767 }
768 // Leave the widget in the pending state if the user canceled the configure.
769 return;
770 }
771
Sunny Goyalaad90582015-07-09 14:22:50 -0700772 if (requestCode == REQUEST_CREATE_SHORTCUT) {
773 // Handle custom shortcuts created using ACTION_CREATE_SHORTCUT.
Sunny Goyal2100c782016-08-22 16:00:03 -0700774 if (resultCode == RESULT_OK && requestArgs.container != ItemInfo.NO_ID) {
775 completeAdd(requestCode, data, -1, requestArgs);
776 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
777 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
778
Sunny Goyalaad90582015-07-09 14:22:50 -0700779 } else if (resultCode == RESULT_CANCELED) {
Adam Cohendb364c32014-05-20 14:23:40 -0700780 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
781 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800782 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800783 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800784 mDragLayer.clearAnimatedView();
Adam Cohenc7cd2cb2014-11-17 17:45:34 -0800785 }
786
787 @Override
Sunny Goyal64a75aa2017-07-03 13:50:52 -0700788 public void onActivityResult(
Adam Cohenc7cd2cb2014-11-17 17:45:34 -0800789 final int requestCode, final int resultCode, final Intent data) {
Sunny Goyaldedda052019-05-14 15:23:48 -0700790 mPendingActivityRequestCode = -1;
Adam Cohenc7cd2cb2014-11-17 17:45:34 -0800791 handleActivityResult(requestCode, resultCode, data);
792 if (mLauncherCallbacks != null) {
793 mLauncherCallbacks.onActivityResult(requestCode, resultCode, data);
794 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800795 }
796
Sunny Goyal7ce471b2017-08-02 03:37:39 -0700797 @Override
Sunny Goyaldd2e6df2015-07-07 10:57:57 -0700798 public void onRequestPermissionsResult(int requestCode, String[] permissions,
Dave Hawkey3a43ed62015-06-26 10:27:47 -0600799 int[] grantResults) {
Sunny Goyal2100c782016-08-22 16:00:03 -0700800 PendingRequestArgs pendingArgs = mPendingRequestArgs;
801 if (requestCode == REQUEST_PERMISSION_CALL_PHONE && pendingArgs != null
802 && pendingArgs.getRequestCode() == REQUEST_PERMISSION_CALL_PHONE) {
803 setWaitingForResult(null);
804
Sunny Goyal28c6b962015-10-12 11:42:05 -0700805 View v = null;
Sunny Goyal2100c782016-08-22 16:00:03 -0700806 CellLayout layout = getCellLayout(pendingArgs.container, pendingArgs.screenId);
Sunny Goyal28c6b962015-10-12 11:42:05 -0700807 if (layout != null) {
Sunny Goyal2100c782016-08-22 16:00:03 -0700808 v = layout.getChildAt(pendingArgs.cellX, pendingArgs.cellY);
Sunny Goyal28c6b962015-10-12 11:42:05 -0700809 }
Sunny Goyal2100c782016-08-22 16:00:03 -0700810 Intent intent = pendingArgs.getPendingIntent();
811
Sunny Goyal28c6b962015-10-12 11:42:05 -0700812 if (grantResults.length > 0
813 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
Sunny Goyal369212a2019-03-26 15:03:57 -0700814 startActivitySafely(v, intent, null, null);
Sunny Goyal28c6b962015-10-12 11:42:05 -0700815 } else {
816 // TODO: Show a snack bar with link to settings
817 Toast.makeText(this, getString(R.string.msg_no_phone_permission,
Sunny Goyal112ce422016-08-22 16:45:29 -0700818 getString(R.string.derived_app_name)), Toast.LENGTH_SHORT).show();
Sunny Goyal28c6b962015-10-12 11:42:05 -0700819 }
820 }
Dave Hawkey3a43ed62015-06-26 10:27:47 -0600821 if (mLauncherCallbacks != null) {
822 mLauncherCallbacks.onRequestPermissionsResult(requestCode, permissions,
823 grantResults);
824 }
825 }
826
Adam Cohendb364c32014-05-20 14:23:40 -0700827 /**
828 * Check to see if a given screen id exists. If not, create it at the end, return the new id.
829 *
830 * @param screenId the screen id to check
831 * @return the new screen, or screenId if it exists
832 */
Sunny Goyalefb7e842018-10-04 15:11:00 -0700833 private int ensurePendingDropLayoutExists(int screenId) {
Sunny Goyal32554d12015-12-03 15:31:25 -0800834 CellLayout dropLayout = mWorkspace.getScreenWithId(screenId);
Adam Cohendb364c32014-05-20 14:23:40 -0700835 if (dropLayout == null) {
836 // it's possible that the add screen was removed because it was
837 // empty and a re-bind occurred
838 mWorkspace.addExtraEmptyScreen();
839 return mWorkspace.commitExtraEmptyScreen();
840 } else {
841 return screenId;
842 }
843 }
844
Samuel Fufaca37b8a2019-08-19 17:04:36 -0700845 @Thunk
846 void completeTwoStageWidgetDrop(
Sunny Goyal2100c782016-08-22 16:00:03 -0700847 final int resultCode, final int appWidgetId, final PendingRequestArgs requestArgs) {
848 CellLayout cellLayout = mWorkspace.getScreenWithId(requestArgs.screenId);
Adam Cohened66b2b2012-01-23 17:28:51 -0800849 Runnable onCompleteRunnable = null;
850 int animationType = 0;
851
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700852 AppWidgetHostView boundWidget = null;
Adam Cohened66b2b2012-01-23 17:28:51 -0800853 if (resultCode == RESULT_OK) {
854 animationType = Workspace.COMPLETE_TWO_STAGE_WIDGET_DROP_ANIMATION;
855 final AppWidgetHostView layout = mAppWidgetHost.createView(this, appWidgetId,
Sunny Goyal04a324a2017-01-20 21:08:59 -0800856 requestArgs.getWidgetHandler().getProviderInfo(this));
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700857 boundWidget = layout;
Adam Cohened66b2b2012-01-23 17:28:51 -0800858 onCompleteRunnable = new Runnable() {
859 @Override
860 public void run() {
Sunny Goyal2100c782016-08-22 16:00:03 -0700861 completeAddAppWidget(appWidgetId, requestArgs, layout, null);
Sunny Goyal3e3f44c2017-10-23 17:14:52 -0700862 mStateManager.goToState(NORMAL, SPRING_LOADED_EXIT_DELAY);
Adam Cohened66b2b2012-01-23 17:28:51 -0800863 }
864 };
865 } else if (resultCode == RESULT_CANCELED) {
Adam Cohen4637b5a2013-11-04 18:21:24 -0800866 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
Adam Cohened66b2b2012-01-23 17:28:51 -0800867 animationType = Workspace.CANCEL_TWO_STAGE_WIDGET_DROP_ANIMATION;
Adam Cohened66b2b2012-01-23 17:28:51 -0800868 }
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700869 if (mDragLayer.getAnimatedView() != null) {
Sunny Goyal2100c782016-08-22 16:00:03 -0700870 mWorkspace.animateWidgetDrop(requestArgs, cellLayout,
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700871 (DragView) mDragLayer.getAnimatedView(), onCompleteRunnable,
872 animationType, boundWidget, true);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700873 } else if (onCompleteRunnable != null) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700874 // The animated view may be null in the case of a rotation during widget configuration
875 onCompleteRunnable.run();
876 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800877 }
878
879 @Override
Michael Jurkacd496d72013-04-11 11:32:45 -0700880 protected void onStop() {
881 super.onStop();
Winson Chung0b70cd42019-06-17 22:34:33 -0700882
Adam Cohen9211d422014-10-07 18:14:53 -0700883 if (mLauncherCallbacks != null) {
884 mLauncherCallbacks.onStop();
885 }
Becky Qiubfc2da12019-08-01 11:09:38 -0700886 logStopAndResume(Action.Command.STOP);
Hyunyoung Songbd6fba92018-05-16 15:54:31 -0700887
888 mAppWidgetHost.setListenIfResumed(false);
889
Tony Wickham010d2552017-01-20 08:15:28 -0800890 NotificationListener.removeNotificationsChangedListener();
Sunny Goyalaf161fd2018-02-05 16:34:57 -0800891 getStateManager().moveToRestState();
Winson Chungedb0d6b2018-03-21 17:32:55 -0700892
Tracy Zhou62646712018-06-26 14:19:02 -0700893 UiFactory.onLauncherStateOrResumeChanged(this);
894
Winson Chungdea51352018-04-24 13:02:10 -0700895 // Workaround for b/78520668, explicitly trim memory once UI is hidden
Winson Chung473730f2018-04-26 11:54:22 -0700896 onTrimMemory(TRIM_MEMORY_UI_HIDDEN);
Michael Jurkacd496d72013-04-11 11:32:45 -0700897 }
898
899 @Override
900 protected void onStart() {
vadimtcb863752018-12-19 17:44:57 -0800901 RaceConditionTracker.onEvent(ON_START_EVT, ENTER);
Michael Jurkacd496d72013-04-11 11:32:45 -0700902 super.onStart();
Adam Cohen9211d422014-10-07 18:14:53 -0700903 if (mLauncherCallbacks != null) {
904 mLauncherCallbacks.onStart();
905 }
Sunny Goyal67419a12017-11-14 16:55:22 -0800906 mAppWidgetHost.setListenIfResumed(true);
vadimtcb863752018-12-19 17:44:57 -0800907 RaceConditionTracker.onEvent(ON_START_EVT, EXIT);
Michael Jurkacd496d72013-04-11 11:32:45 -0700908 }
909
Sunny Goyala002c6c2019-02-12 16:20:10 -0800910 private void handleDeferredResume() {
Sunny Goyale9c6f4c2019-05-30 11:35:25 -0700911 if (hasBeenResumed() && !mStateManager.getState().disableInteraction) {
Becky Qiubfc2da12019-08-01 11:09:38 -0700912 logStopAndResume(Action.Command.RESUME);
Hyunyoung Songbd6fba92018-05-16 15:54:31 -0700913 getUserEventDispatcher().startSession();
Sunny Goyala002c6c2019-02-12 16:20:10 -0800914
915 UiFactory.onLauncherStateOrResumeChanged(this);
Sunny Goyal369212a2019-03-26 15:03:57 -0700916 AppLaunchTracker.INSTANCE.get(this).onReturnedToHome();
Hyunyoung Songbd6fba92018-05-16 15:54:31 -0700917
Sunny Goyale9c6f4c2019-05-30 11:35:25 -0700918 // Process any items that were added while Launcher was away.
919 InstallShortcutReceiver.disableAndFlushInstallQueue(
920 InstallShortcutReceiver.FLAG_ACTIVITY_PAUSED, this);
921
922 // Refresh shortcuts if the permission changed.
923 mModel.refreshShortcutsIfRequired();
924
Winson Chung87583112019-06-10 14:20:58 -0700925 // Set the notification listener and fetch updated notifications when we resume
926 NotificationListener.setNotificationsChangedListener(mPopupDataProvider);
927
Sunny Goyale9c6f4c2019-05-30 11:35:25 -0700928 DiscoveryBounce.showForHomeIfNeeded(this);
929
930 if (mPendingActivityRequestCode != -1 && isInState(NORMAL)) {
931 UiFactory.resetPendingActivityResults(this, mPendingActivityRequestCode);
932 }
933 mDeferredResumePending = false;
934 } else {
935 mDeferredResumePending = true;
Sunny Goyaldedda052019-05-14 15:23:48 -0700936 }
937 }
938
Becky Qiubfc2da12019-08-01 11:09:38 -0700939 private void logStopAndResume(int command) {
940 int containerType = mStateManager.getState().containerType;
941 if (containerType == ContainerType.WORKSPACE && mWorkspace != null) {
942 getUserEventDispatcher().logActionCommand(command,
Samuel Fufaca37b8a2019-08-19 17:04:36 -0700943 containerType, -1, mWorkspace.isOverlayShown() ? -1 : 0);
Becky Qiubfc2da12019-08-01 11:09:38 -0700944 } else {
945 getUserEventDispatcher().logActionCommand(command, containerType, -1);
946 }
947
948 }
949
Winson Chungef528762019-09-06 12:05:52 -0700950 public void onStateSetStart(LauncherState state) {
Sunny Goyale9c6f4c2019-05-30 11:35:25 -0700951 if (mDeferredResumePending) {
952 handleDeferredResume();
953 }
954 if (mLauncherCallbacks != null) {
955 mLauncherCallbacks.onStateChanged();
956 }
Sunny Goyaldedda052019-05-14 15:23:48 -0700957 }
958
Winson Chungef528762019-09-06 12:05:52 -0700959 public void onStateSetEnd(LauncherState state) {
960 getAppWidgetHost().setResumed(state == LauncherState.NORMAL);
961 getWorkspace().setClipChildren(!state.disablePageClipping);
962 finishAutoCancelActionMode();
963 }
964
Michael Jurkacd496d72013-04-11 11:32:45 -0700965 @Override
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800966 protected void onResume() {
vadimtcb863752018-12-19 17:44:57 -0800967 RaceConditionTracker.onEvent(ON_RESUME_EVT, ENTER);
Sunny Goyalfca6bc92017-09-28 16:28:34 -0700968 TraceHelper.beginSection("ON_RESUME");
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800969 super.onResume();
Sunny Goyalfca6bc92017-09-28 16:28:34 -0700970 TraceHelper.partitionSection("ON_RESUME", "superCall");
971
Sunny Goyala002c6c2019-02-12 16:20:10 -0800972 mHandler.removeCallbacks(mHandleDeferredResume);
973 Utilities.postAsyncCallback(mHandler, mHandleDeferredResume);
Hyunyoung Songbd6fba92018-05-16 15:54:31 -0700974
Winson Chung940b0ac2019-07-09 11:33:50 -0700975 if (!mOnResumeCallbacks.isEmpty()) {
976 final ArrayList<OnResumeCallback> resumeCallbacks = new ArrayList<>(mOnResumeCallbacks);
977 mOnResumeCallbacks.clear();
978 for (int i = resumeCallbacks.size() - 1; i >= 0; i--) {
979 resumeCallbacks.get(i).onLauncherResume();
980 }
981 resumeCallbacks.clear();
Winson Chung0b70cd42019-06-17 22:34:33 -0700982 }
Sunny Goyal95f3d6b2016-08-10 16:09:29 -0700983
Adam Cohen9211d422014-10-07 18:14:53 -0700984 if (mLauncherCallbacks != null) {
985 mLauncherCallbacks.onResume();
986 }
Mario Bertschler0fc6f682017-02-17 12:16:13 -0800987
Sunny Goyalfca6bc92017-09-28 16:28:34 -0700988 TraceHelper.endSection("ON_RESUME");
vadimtcb863752018-12-19 17:44:57 -0800989 RaceConditionTracker.onEvent(ON_RESUME_EVT, EXIT);
Adam Cohen06dff352012-06-01 17:17:08 -0700990 }
991
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800992 @Override
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700993 protected void onPause() {
Winson Chung997a9232013-07-24 15:33:46 -0700994 // Ensure that items added to Launcher are queued until Launcher returns
Sunny Goyala474a9b2017-05-04 16:47:11 -0700995 InstallShortcutReceiver.enableInstallQueue(InstallShortcutReceiver.FLAG_ACTIVITY_PAUSED);
Winson Chung997a9232013-07-24 15:33:46 -0700996
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700997 super.onPause();
Joe Onorato24b6fd82009-11-12 13:47:09 -0800998 mDragController.cancelDrag();
Winson Chunga2413752012-04-03 14:22:34 -0700999 mDragController.resetLastGestureUpTime();
Hyunyoung Song497708c2019-05-01 16:16:53 -07001000 mDropTargetBar.animateToVisibility(false);
Adam Cohen9211d422014-10-07 18:14:53 -07001001 if (mLauncherCallbacks != null) {
1002 mLauncherCallbacks.onPause();
Adam Cohenbffe7452013-07-22 18:21:45 -07001003 }
Adam Cohenbffe7452013-07-22 18:21:45 -07001004 }
1005
Winson Chungd7823942018-02-16 03:23:47 +00001006 @Override
Tracy Zhoua706f002018-03-28 13:55:19 -07001007 protected void onUserLeaveHint() {
1008 super.onUserLeaveHint();
1009 UiFactory.onLauncherStateOrResumeChanged(this);
1010 }
1011
1012 @Override
Winson Chungd7823942018-02-16 03:23:47 +00001013 public void onWindowFocusChanged(boolean hasFocus) {
1014 super.onWindowFocusChanged(hasFocus);
1015 mStateManager.onWindowFocusChanged();
1016 }
1017
Adam Cohenc2d6e892014-10-16 09:49:24 -07001018 public interface LauncherOverlay {
1019
1020 /**
1021 * Touch interaction leading to overscroll has begun
1022 */
Rajeev Kumar43c0f582017-06-23 15:34:55 -07001023 void onScrollInteractionBegin();
Adam Cohenc2d6e892014-10-16 09:49:24 -07001024
1025 /**
1026 * Touch interaction related to overscroll has ended
1027 */
Rajeev Kumar43c0f582017-06-23 15:34:55 -07001028 void onScrollInteractionEnd();
Adam Cohenc2d6e892014-10-16 09:49:24 -07001029
1030 /**
1031 * Scroll progress, between 0 and 100, when the user scrolls beyond the leftmost
1032 * screen (or in the case of RTL, the rightmost screen).
1033 */
Rajeev Kumar43c0f582017-06-23 15:34:55 -07001034 void onScrollChange(float progress, boolean rtl);
Adam Cohenc2d6e892014-10-16 09:49:24 -07001035
1036 /**
Sunny Goyal32554d12015-12-03 15:31:25 -08001037 * Called when the launcher is ready to use the overlay
1038 * @param callbacks A set of callbacks provided by Launcher in relation to the overlay
Adam Cohenc2d6e892014-10-16 09:49:24 -07001039 */
Rajeev Kumar43c0f582017-06-23 15:34:55 -07001040 void setOverlayCallbacks(LauncherOverlayCallbacks callbacks);
Adam Cohenc2d6e892014-10-16 09:49:24 -07001041 }
1042
1043 public interface LauncherOverlayCallbacks {
Rajeev Kumar43c0f582017-06-23 15:34:55 -07001044 void onScrollChanged(float progress);
Adam Cohenc2d6e892014-10-16 09:49:24 -07001045 }
1046
1047 class LauncherOverlayCallbacksImpl implements LauncherOverlayCallbacks {
1048
Sunny Goyalc86df472016-02-25 09:19:38 -08001049 public void onScrollChanged(float progress) {
1050 if (mWorkspace != null) {
1051 mWorkspace.onOverlayScrollChanged(progress);
1052 }
1053 }
Adam Cohenc2d6e892014-10-16 09:49:24 -07001054 }
1055
Sunny Goyalf9403d92017-10-18 10:55:56 -07001056 public boolean isInState(LauncherState state) {
Sunny Goyalea609262017-10-25 15:47:38 -07001057 return mStateManager.getState() == state;
Sunny Goyalf9403d92017-10-18 10:55:56 -07001058 }
1059
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001060 /**
1061 * Restores the previous state, if it exists.
1062 *
1063 * @param savedState The previous state.
1064 */
1065 private void restoreState(Bundle savedState) {
1066 if (savedState == null) {
1067 return;
1068 }
1069
Sunny Goyal3e3f44c2017-10-23 17:14:52 -07001070 int stateOrdinal = savedState.getInt(RUNTIME_STATE, NORMAL.ordinal);
Sunny Goyalf9403d92017-10-18 10:55:56 -07001071 LauncherState[] stateValues = LauncherState.values();
1072 LauncherState state = stateValues[stateOrdinal];
Sunny Goyalbc683e92017-12-06 10:25:07 -08001073 if (!state.disableRestore) {
Sunny Goyal3e3f44c2017-10-23 17:14:52 -07001074 mStateManager.goToState(state, false /* animated */);
Joe Onorato3a8820b2009-11-10 15:06:42 -08001075 }
1076
Samuel Fufaca37b8a2019-08-19 17:04:36 -07001077 PendingRequestArgs requestArgs = savedState.getParcelable(
1078 RUNTIME_STATE_PENDING_REQUEST_ARGS);
Sunny Goyal2100c782016-08-22 16:00:03 -07001079 if (requestArgs != null) {
1080 setWaitingForResult(requestArgs);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001081 }
Sunny Goyaldedda052019-05-14 15:23:48 -07001082 mPendingActivityRequestCode = savedState.getInt(RUNTIME_STATE_PENDING_REQUEST_CODE);
Sunny Goyal2100c782016-08-22 16:00:03 -07001083
1084 mPendingActivityResult = savedState.getParcelable(RUNTIME_STATE_PENDING_ACTIVITY_RESULT);
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -07001085
1086 SparseArray<Parcelable> widgetsState =
1087 savedState.getSparseParcelableArray(RUNTIME_STATE_WIDGET_PANEL);
1088 if (widgetsState != null) {
1089 WidgetsFullSheet.show(this, false).restoreHierarchyState(widgetsState);
1090 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001091 }
1092
1093 /**
1094 * Finds all the views we need and configure them properly.
1095 */
1096 private void setupViews() {
Sunny Goyalcc96aa12018-01-11 09:56:07 -08001097 mDragLayer = findViewById(R.id.drag_layer);
Sunny Goyal3333b0c2016-05-09 20:43:21 -07001098 mFocusHandler = mDragLayer.getFocusIndicatorHelper();
Sunny Goyal966d9012017-06-06 16:43:59 -07001099 mWorkspace = mDragLayer.findViewById(R.id.workspace);
Sunny Goyald0a6ae72016-06-16 12:29:03 -07001100 mWorkspace.initParentViews(mDragLayer);
Sunny Goyal16764582017-11-06 16:00:34 -08001101 mOverviewPanel = findViewById(R.id.overview_panel);
Sunny Goyal7c7be8c2018-03-07 19:58:07 -08001102 mHotseat = findViewById(R.id.hotseat);
Craig Mautner360310b2012-10-26 15:13:08 -07001103
Sunny Goyal784f9c32016-03-23 16:56:54 -07001104 mLauncherView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
1105 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
1106 | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001107
Winson Chung4c98d922011-05-31 16:50:48 -07001108 // Setup the drag layer
Sunny Goyal5d1873a2018-05-08 11:10:44 -07001109 mDragLayer.setup(mDragController, mWorkspace);
Sunny Goyal0b1cb752019-06-05 15:18:39 -07001110 mCancelTouchController = UiFactory.enableLiveUIChanges(this);
Winson Chung4c98d922011-05-31 16:50:48 -07001111
Hyunyoung Song645764e2016-06-06 14:19:02 -07001112 mWorkspace.setup(mDragController);
Winsonc7d2e832016-07-28 12:24:55 -07001113 // Until the workspace is bound, ensure that we keep the wallpaper offset locked to the
1114 // default state, otherwise we will update to the wrong offsets in RTL
1115 mWorkspace.lockWallpaperToDefaultPage();
Sunny Goyalda4fe1a2016-05-26 16:05:17 -07001116 mWorkspace.bindAndInitFirstWorkspaceScreen(null /* recycled qsb */);
Hyunyoung Song645764e2016-06-06 14:19:02 -07001117 mDragController.addDragListener(mWorkspace);
Winson Chung4c98d922011-05-31 16:50:48 -07001118
Tony Wickham34d2c912015-09-11 09:27:58 -07001119 // Get the search/delete/uninstall bar
Rajeev Kumar43c0f582017-06-23 15:34:55 -07001120 mDropTargetBar = mDragLayer.findViewById(R.id.drop_target_bar);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07001121
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -07001122 // Setup Apps
1123 mAppsView = findViewById(R.id.apps_view);
Craig Mautner360310b2012-10-26 15:13:08 -07001124
Govinda Wassermanc06e1512019-04-09 09:56:53 -04001125 // Setup Scrim
1126 mScrimView = findViewById(R.id.scrim_view);
1127
Winson Chung3d503fb2011-07-13 17:25:49 -07001128 // Setup the drag controller (drop targets have to be added in reverse order in priority)
Hyunyoung Song645764e2016-06-06 14:19:02 -07001129 mDragController.setMoveTarget(mWorkspace);
Sunny Goyal47328fd2016-05-25 18:56:41 -07001130 mDropTargetBar.setup(mDragController);
Daniel Sandler924b9932013-06-12 00:38:25 -04001131
Sunny Goyal7185dd62018-03-14 17:51:49 -07001132 mAllAppsController.setupViews(mAppsView);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001133 }
1134
1135 /**
1136 * Creates a view representing a shortcut.
1137 *
1138 * @param info The data structure describing the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001139 */
Sunny Goyal95899162019-03-27 16:03:06 -07001140 View createShortcut(WorkspaceItemInfo info) {
Sunny Goyaldfaccf62015-05-11 16:30:44 -07001141 return createShortcut((ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001142 }
1143
1144 /**
1145 * Creates a view representing a shortcut inflated from the specified resource.
1146 *
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001147 * @param parent The group the shortcut belongs to.
Samuel Fufaca37b8a2019-08-19 17:04:36 -07001148 * @param info The data structure describing the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001149 * @return A View inflated from layoutResId.
1150 */
Sunny Goyal95899162019-03-27 16:03:06 -07001151 public View createShortcut(ViewGroup parent, WorkspaceItemInfo info) {
Sunny Goyal9b29ca52017-02-17 10:39:44 -08001152 BubbleTextView favorite = (BubbleTextView) LayoutInflater.from(parent.getContext())
1153 .inflate(R.layout.app_icon, parent, false);
Sunny Goyal95899162019-03-27 16:03:06 -07001154 favorite.applyFromWorkspaceItem(info);
Sunny Goyal8a2a63b2018-03-06 22:15:18 -08001155 favorite.setOnClickListener(ItemClickHandler.INSTANCE);
Sunny Goyaldcbcc862014-08-12 15:58:36 -07001156 favorite.setOnFocusChangeListener(mFocusHandler);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001157 return favorite;
1158 }
1159
1160 /**
Jon Mirandac476d6e2017-05-04 16:30:01 -07001161 * Add a shortcut to the workspace or to a Folder.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001162 *
1163 * @param data The intent describing the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001164 */
Sunny Goyalefb7e842018-10-04 15:11:00 -07001165 private void completeAddShortcut(Intent data, int container, int screenId, int cellX,
Sunny Goyalfb5096d2016-09-08 14:32:06 -07001166 int cellY, PendingRequestArgs args) {
Jon Mirandac476d6e2017-05-04 16:30:01 -07001167 if (args.getRequestCode() != REQUEST_CREATE_SHORTCUT
1168 || args.getPendingIntent().getComponent() == null) {
Sunny Goyalfb5096d2016-09-08 14:32:06 -07001169 return;
1170 }
Adam Cohen558baaf2011-08-15 15:22:57 -07001171
Jon Mirandac476d6e2017-05-04 16:30:01 -07001172 int[] cellXY = mTmpAddItemCellCoordinates;
1173 CellLayout layout = getCellLayout(container, screenId);
1174
Sunny Goyal95899162019-03-27 16:03:06 -07001175 WorkspaceItemInfo info = null;
Hyunyoung Songe24cb632017-09-11 11:18:03 -07001176 if (Utilities.ATLEAST_OREO) {
Sunny Goyal95899162019-03-27 16:03:06 -07001177 info = LauncherAppsCompatVO.createWorkspaceItemFromPinItemRequest(
Sunny Goyal22ca9ec2017-05-18 15:03:13 -07001178 this, LauncherAppsCompatVO.getPinItemRequest(data), 0);
Sunny Goyal782f0c92017-01-19 10:27:54 -08001179 }
1180
1181 if (info == null) {
Sunny Goyalb57645f2017-03-20 13:57:28 -07001182 // Legacy shortcuts are only supported for primary profile.
1183 info = Process.myUserHandle().equals(args.user)
1184 ? InstallShortcutReceiver.fromShortcutIntent(this, data) : null;
Sunny Goyal782f0c92017-01-19 10:27:54 -08001185
Sunny Goyalb57645f2017-03-20 13:57:28 -07001186 if (info == null) {
1187 Log.e(TAG, "Unable to parse a valid custom shortcut result");
1188 return;
1189 } else if (!new PackageManagerHelper(this).hasPermissionForActivity(
Sunny Goyal342e4662017-02-02 15:21:08 -08001190 info.intent, args.getPendingIntent().getComponent().getPackageName())) {
Sunny Goyal782f0c92017-01-19 10:27:54 -08001191 // The app is trying to add a shortcut without sufficient permissions
1192 Log.e(TAG, "Ignoring malicious intent " + info.intent.toUri(0));
1193 return;
1194 }
1195 }
1196
Jon Mirandac476d6e2017-05-04 16:30:01 -07001197 if (container < 0) {
1198 // Adding a shortcut to the Workspace.
1199 final View view = createShortcut(info);
1200 boolean foundCellSpan = false;
1201 // First we check if we already know the exact location where we want to add this item.
1202 if (cellX >= 0 && cellY >= 0) {
1203 cellXY[0] = cellX;
1204 cellXY[1] = cellY;
1205 foundCellSpan = true;
Adam Cohen558baaf2011-08-15 15:22:57 -07001206
Jon Mirandac476d6e2017-05-04 16:30:01 -07001207 // If appropriate, either create a folder or add to an existing folder
1208 if (mWorkspace.createUserFolderIfNecessary(view, container, layout, cellXY, 0,
Sunny Goyal1797af42017-10-06 13:29:57 -07001209 true, null)) {
Jon Mirandac476d6e2017-05-04 16:30:01 -07001210 return;
1211 }
1212 DragObject dragObject = new DragObject();
1213 dragObject.dragInfo = info;
1214 if (mWorkspace.addToExistingFolderIfNecessary(view, layout, cellXY, 0, dragObject,
1215 true)) {
1216 return;
1217 }
1218 } else {
1219 foundCellSpan = layout.findCellForSpan(cellXY, 1, 1);
1220 }
1221
1222 if (!foundCellSpan) {
1223 mWorkspace.onNoCellFound(layout);
Adam Cohen558baaf2011-08-15 15:22:57 -07001224 return;
1225 }
Jon Mirandac476d6e2017-05-04 16:30:01 -07001226
1227 getModelWriter().addItemToDatabase(info, container, screenId, cellXY[0], cellXY[1]);
1228 mWorkspace.addInScreen(view, info);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001229 } else {
Jon Mirandac476d6e2017-05-04 16:30:01 -07001230 // Adding a shortcut to a Folder.
Sunny Goyale29897f52017-07-20 10:09:42 -07001231 FolderIcon folderIcon = findFolderIcon(container);
Jon Mirandac476d6e2017-05-04 16:30:01 -07001232 if (folderIcon != null) {
1233 FolderInfo folderInfo = (FolderInfo) folderIcon.getTag();
1234 folderInfo.add(info, args.rank, false);
1235 } else {
Sunny Goyale29897f52017-07-20 10:09:42 -07001236 Log.e(TAG, "Could not find folder with id " + container + " to add shortcut.");
Jon Mirandac476d6e2017-05-04 16:30:01 -07001237 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001238 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001239 }
1240
Sunny Goyalefb7e842018-10-04 15:11:00 -07001241 public FolderIcon findFolderIcon(final int folderIconId) {
Sunny Goyal83fd25e2018-07-09 16:47:01 -07001242 return (FolderIcon) mWorkspace.getHomescreenIconByItemId(folderIconId);
Sunny Goyale29897f52017-07-20 10:09:42 -07001243 }
1244
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001245 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001246 * Add a widget to the workspace.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001247 *
Romain Guy5bbc91b2010-08-18 11:38:46 -07001248 * @param appWidgetId The app widget id
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001249 */
Samuel Fufaca37b8a2019-08-19 17:04:36 -07001250 @Thunk
1251 void completeAddAppWidget(int appWidgetId, ItemInfo itemInfo,
Adam Cohen59400422014-03-05 18:07:04 -08001252 AppWidgetHostView hostView, LauncherAppWidgetProviderInfo appWidgetInfo) {
1253
Adam Cohened66b2b2012-01-23 17:28:51 -08001254 if (appWidgetInfo == null) {
Sunny Goyal2e1efb42016-03-03 16:58:55 -08001255 appWidgetInfo = mAppWidgetManager.getLauncherAppWidgetInfo(appWidgetId);
Adam Cohened66b2b2012-01-23 17:28:51 -08001256 }
Romain Guycbb89e42009-06-08 15:52:54 -07001257
Adam Cohen59400422014-03-05 18:07:04 -08001258 LauncherAppWidgetInfo launcherInfo;
1259 launcherInfo = new LauncherAppWidgetInfo(appWidgetId, appWidgetInfo.provider);
Sunny Goyal2100c782016-08-22 16:00:03 -07001260 launcherInfo.spanX = itemInfo.spanX;
1261 launcherInfo.spanY = itemInfo.spanY;
1262 launcherInfo.minSpanX = itemInfo.minSpanX;
1263 launcherInfo.minSpanY = itemInfo.minSpanY;
Sunny Goyal952e63d2017-08-16 04:59:08 -07001264 launcherInfo.user = appWidgetInfo.getProfile();
Romain Guycbb89e42009-06-08 15:52:54 -07001265
Sunny Goyal43bf11d2017-02-02 13:52:53 -08001266 getModelWriter().addItemToDatabase(launcherInfo,
Sunny Goyal2100c782016-08-22 16:00:03 -07001267 itemInfo.container, itemInfo.screenId, itemInfo.cellX, itemInfo.cellY);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001268
Sunny Goyal2100c782016-08-22 16:00:03 -07001269 if (hostView == null) {
1270 // Perform actual inflation because we're live
1271 hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001272 }
Sunny Goyal2100c782016-08-22 16:00:03 -07001273 hostView.setVisibility(View.VISIBLE);
Sunny Goyald5462aa2016-11-22 16:52:39 +05301274 prepareAppWidget(hostView, launcherInfo);
1275 mWorkspace.addInScreen(hostView, launcherInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001276 }
Romain Guycbb89e42009-06-08 15:52:54 -07001277
Sunny Goyald5462aa2016-11-22 16:52:39 +05301278 private void prepareAppWidget(AppWidgetHostView hostView, LauncherAppWidgetInfo item) {
Sunny Goyal87af0fd2016-05-16 14:56:02 -07001279 hostView.setTag(item);
1280 item.onBindAppWidget(this, hostView);
Sunny Goyal87af0fd2016-05-16 14:56:02 -07001281 hostView.setFocusable(true);
1282 hostView.setOnFocusChangeListener(mFocusHandler);
Sunny Goyal25c2e3e2015-10-28 23:28:21 -07001283 }
1284
Sunny Goyal5d1873a2018-05-08 11:10:44 -07001285 private final BroadcastReceiver mScreenOffReceiver = new BroadcastReceiver() {
Adam Cohended9f8d2010-11-03 13:25:16 -07001286 @Override
1287 public void onReceive(Context context, Intent intent) {
Sunny Goyal5d1873a2018-05-08 11:10:44 -07001288 // Reset AllApps to its initial state only if we are not in the middle of
1289 // processing a multi-step drop
1290 if (mPendingRequestArgs == null) {
1291 mStateManager.goToState(NORMAL);
Adam Cohended9f8d2010-11-03 13:25:16 -07001292 }
1293 }
1294 };
1295
Sunny Goyalaae6fbb2019-01-31 16:05:58 -08001296 public void updateNotificationDots(Predicate<PackageUserKey> updatedDots) {
Tony Wickhamf34bee82018-12-03 18:11:39 -08001297 mWorkspace.updateNotificationDots(updatedDots);
1298 mAppsView.getAppsStore().updateNotificationDots(updatedDots);
Tony Wickham010d2552017-01-20 08:15:28 -08001299 }
1300
Adam Cohended9f8d2010-11-03 13:25:16 -07001301 @Override
1302 public void onAttachedToWindow() {
1303 super.onAttachedToWindow();
1304
Sunny Goyalc86df472016-02-25 09:19:38 -08001305 if (mLauncherCallbacks != null) {
1306 mLauncherCallbacks.onAttachedToWindow();
1307 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001308 }
1309
1310 @Override
1311 public void onDetachedFromWindow() {
1312 super.onDetachedFromWindow();
Sunny Goyalc86df472016-02-25 09:19:38 -08001313
1314 if (mLauncherCallbacks != null) {
1315 mLauncherCallbacks.onDetachedFromWindow();
1316 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001317 }
1318
Sunny Goyalc4fa8c32017-11-07 12:23:58 -08001319 public AllAppsTransitionController getAllAppsController() {
1320 return mAllAppsController;
1321 }
1322
Sunny Goyal9d69c8d2018-03-19 13:41:31 -07001323 @Override
Winson Chung1a341002018-01-17 10:00:23 -08001324 public LauncherRootView getRootView() {
1325 return (LauncherRootView) mLauncherView;
1326 }
1327
Sunny Goyal0b0847b2018-03-14 12:30:11 -07001328 @Override
Winson Chunga6945242014-01-08 14:04:34 -08001329 public DragLayer getDragLayer() {
1330 return mDragLayer;
1331 }
1332
Winson Chung5f4e0fd2015-05-22 11:12:27 -07001333 public AllAppsContainerView getAppsView() {
Winson Chungb745afb2015-03-02 11:51:23 -08001334 return mAppsView;
1335 }
1336
Winson Chunga6945242014-01-08 14:04:34 -08001337 public Workspace getWorkspace() {
1338 return mWorkspace;
1339 }
1340
1341 public Hotseat getHotseat() {
1342 return mHotseat;
1343 }
1344
Sunny Goyal7c7be8c2018-03-07 19:58:07 -08001345 public <T extends View> T getOverviewPanel() {
Winson Chung8ae41982017-11-10 11:42:13 -08001346 return (T) mOverviewPanel;
Winson Chunga6945242014-01-08 14:04:34 -08001347 }
1348
Sunny Goyal47328fd2016-05-25 18:56:41 -07001349 public DropTargetBar getDropTargetBar() {
1350 return mDropTargetBar;
Tony Wickham34d2c912015-09-11 09:27:58 -07001351 }
1352
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001353 public LauncherAppWidgetHost getAppWidgetHost() {
1354 return mAppWidgetHost;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001355 }
Romain Guycbb89e42009-06-08 15:52:54 -07001356
Winson Chunga9abd0e2010-10-27 17:18:37 -07001357 public LauncherModel getModel() {
1358 return mModel;
1359 }
1360
Sunny Goyal43bf11d2017-02-02 13:52:53 -08001361 public ModelWriter getModelWriter() {
1362 return mModelWriter;
1363 }
1364
Adam Cohen79d90c52016-04-22 13:29:20 -07001365 public SharedPreferences getSharedPrefs() {
Winson Chunga6945242014-01-08 14:04:34 -08001366 return mSharedPrefs;
1367 }
1368
Samuel Fufaca37b8a2019-08-19 17:04:36 -07001369 public int getOrientation() {
1370 return mOldConfig.orientation;
1371 }
Jon Miranda6bed3502017-09-19 14:43:17 -07001372
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001373 @Override
1374 protected void onNewIntent(Intent intent) {
Sunny Goyalfca6bc92017-09-28 16:28:34 -07001375 TraceHelper.beginSection("NEW_INTENT");
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001376 super.onNewIntent(intent);
1377
Sunny Goyalf4aceab2017-12-06 16:16:31 -08001378 boolean alreadyOnHome = hasWindowFocus() && ((intent.getFlags() &
Winson15f8b172015-08-19 11:02:39 -07001379 Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
1380 != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
Sunny Goyal85313732016-09-28 12:00:07 -07001381
1382 // Check this condition before handling isActionMain, as this will get reset.
Sunny Goyal3e3f44c2017-10-23 17:14:52 -07001383 boolean shouldMoveToDefaultScreen = alreadyOnHome && isInState(NORMAL)
Sunny Goyalf9403d92017-10-18 10:55:56 -07001384 && AbstractFloatingView.getTopOpenView(this) == null;
Winson15f8b172015-08-19 11:02:39 -07001385 boolean isActionMain = Intent.ACTION_MAIN.equals(intent.getAction());
Sunny Goyald3864fa2017-11-14 15:06:36 -08001386 boolean internalStateHandled = InternalStateHandler
Sunny Goyal8b264562018-02-03 23:00:13 -08001387 .handleNewIntent(this, intent, isStarted());
Sunny Goyald3864fa2017-11-14 15:06:36 -08001388
Winson15f8b172015-08-19 11:02:39 -07001389 if (isActionMain) {
Sunny Goyald3864fa2017-11-14 15:06:36 -08001390 if (!internalStateHandled) {
Sunny Goyald3864fa2017-11-14 15:06:36 -08001391 // In all these cases, only animate if we're already on home
Sunny Goyalcc96aa12018-01-11 09:56:07 -08001392 AbstractFloatingView.closeAllOpenViews(this, isStarted());
Jon Mirandafeba90f2016-10-06 10:53:29 -07001393
Sunny Goyala2467272018-03-16 14:53:05 -07001394 if (!isInState(NORMAL)) {
1395 // Only change state, if not already the same. This prevents cancelling any
1396 // animations running as part of resume
1397 mStateManager.goToState(NORMAL);
1398 }
Sunny Goyald3864fa2017-11-14 15:06:36 -08001399
1400 // Reset the apps view
Sunny Goyal5d1873a2018-05-08 11:10:44 -07001401 if (!alreadyOnHome) {
Sunny Goyal7185dd62018-03-14 17:51:49 -07001402 mAppsView.reset(isStarted() /* animate */);
Sunny Goyald3864fa2017-11-14 15:06:36 -08001403 }
1404
Sunny Goyalaad33592018-08-07 17:20:35 -07001405 if (shouldMoveToDefaultScreen && !mWorkspace.isHandlingTouch()) {
Sunny Goyald3864fa2017-11-14 15:06:36 -08001406 mWorkspace.post(mWorkspace::moveToDefaultScreen);
1407 }
1408 }
Adam Cohen6fecd412013-10-02 17:41:50 -07001409
Hyunyoung Song2a70b3d2019-06-11 12:47:07 -07001410 // Handle HOME_INTENT
1411 UserEventDispatcher ued = getUserEventDispatcher();
1412 Target target = newContainerTarget(mStateManager.getState().containerType);
1413 target.pageIndex = mWorkspace.getCurrentPage();
1414 ued.logActionCommand(Action.Command.HOME_INTENT, target,
1415 newContainerTarget(ContainerType.WORKSPACE));
1416
Adam Cohen6fecd412013-10-02 17:41:50 -07001417 final View v = getWindow().peekDecorView();
1418 if (v != null && v.getWindowToken() != null) {
Sunny Goyal326403e2017-10-02 12:45:10 -07001419 UiThreadHelper.hideKeyboardAsync(this, v.getWindowToken());
Adam Cohen6fecd412013-10-02 17:41:50 -07001420 }
1421
Adam Cohen9211d422014-10-07 18:14:53 -07001422 if (mLauncherCallbacks != null) {
Sunny Goyal85462132018-04-24 11:39:37 -07001423 mLauncherCallbacks.onHomeIntent(internalStateHandled);
Adam Cohen9211d422014-10-07 18:14:53 -07001424 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001425 }
Winson15f8b172015-08-19 11:02:39 -07001426
Sunny Goyalfca6bc92017-09-28 16:28:34 -07001427 TraceHelper.endSection("NEW_INTENT");
Adam Coppa120b8e2013-11-12 16:26:04 +00001428 }
1429
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001430 @Override
Adam Cohen1462de32012-07-24 22:34:36 -07001431 public void onRestoreInstanceState(Bundle state) {
1432 super.onRestoreInstanceState(state);
Sunny Goyalf4aceab2017-12-06 16:16:31 -08001433 mWorkspace.restoreInstanceStateForChild(mSynchronouslyBoundPage);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001434 }
1435
1436 @Override
1437 protected void onSaveInstanceState(Bundle outState) {
Adam Cohen21cd0022013-10-09 18:57:02 -07001438 if (mWorkspace.getChildCount() > 0) {
Sunny Goyal7ce471b2017-08-02 03:37:39 -07001439 outState.putInt(RUNTIME_STATE_CURRENT_SCREEN, mWorkspace.getNextPage());
Hyunyoung Song645764e2016-06-06 14:19:02 -07001440
Adam Cohen21cd0022013-10-09 18:57:02 -07001441 }
Sunny Goyalea609262017-10-25 15:47:38 -07001442 outState.putInt(RUNTIME_STATE, mStateManager.getState().ordinal);
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -07001443
1444
1445 AbstractFloatingView widgets = AbstractFloatingView
1446 .getOpenView(this, AbstractFloatingView.TYPE_WIDGETS_FULL_SHEET);
1447 if (widgets != null) {
1448 SparseArray<Parcelable> widgetsState = new SparseArray<>();
1449 widgets.saveHierarchyState(widgetsState);
1450 outState.putSparseParcelableArray(RUNTIME_STATE_WIDGET_PANEL, widgetsState);
1451 } else {
1452 outState.remove(RUNTIME_STATE_WIDGET_PANEL);
1453 }
1454
Pinyao Tinga74b63a2019-07-17 23:26:06 -07001455 // We close any open folders and shortcut containers that are not safe for rebind,
Sunny Goyal740ac7f2016-09-28 16:47:32 -07001456 // and we need to make sure this state is reflected.
Pinyao Tinga74b63a2019-07-17 23:26:06 -07001457 AbstractFloatingView.closeOpenViews(this, false, TYPE_ALL & ~TYPE_REBIND_SAFE);
1458 finishAutoCancelActionMode();
Tony Wickham49c8d292016-07-01 11:44:34 -07001459
Sunny Goyal2100c782016-08-22 16:00:03 -07001460 if (mPendingRequestArgs != null) {
1461 outState.putParcelable(RUNTIME_STATE_PENDING_REQUEST_ARGS, mPendingRequestArgs);
1462 }
Sunny Goyaldedda052019-05-14 15:23:48 -07001463 outState.putInt(RUNTIME_STATE_PENDING_REQUEST_CODE, mPendingActivityRequestCode);
1464
Sunny Goyal2100c782016-08-22 16:00:03 -07001465 if (mPendingActivityResult != null) {
1466 outState.putParcelable(RUNTIME_STATE_PENDING_ACTIVITY_RESULT, mPendingActivityResult);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001467 }
1468
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -07001469 super.onSaveInstanceState(outState);
1470
Adam Cohen9211d422014-10-07 18:14:53 -07001471 if (mLauncherCallbacks != null) {
1472 mLauncherCallbacks.onSaveInstanceState(outState);
1473 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001474 }
1475
1476 @Override
1477 public void onDestroy() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001478 super.onDestroy();
Romain Guycbb89e42009-06-08 15:52:54 -07001479
Sunny Goyal5d1873a2018-05-08 11:10:44 -07001480 unregisterReceiver(mScreenOffReceiver);
Sunny Goyalaaf7d1d2016-05-17 13:38:54 -07001481 mWorkspace.removeFolderListeners();
Winson Chunge7a03942011-08-05 15:05:12 -07001482
Sunny Goyal5743f862019-03-28 15:35:32 -07001483 if (mCancelTouchController != null) {
1484 mCancelTouchController.run();
1485 mCancelTouchController = null;
1486 }
Tony Wickhama0068302018-04-11 16:16:11 -07001487
Winson Chungcd2b0142011-06-08 16:02:26 -07001488 // Stop callbacks from LauncherModel
Adam Cohen1a85c582014-09-30 09:48:49 -07001489 // It's possible to receive onDestroy after a new Launcher activity has
1490 // been created. In this case, don't interfere with the new Launcher.
1491 if (mModel.isCurrentCallbacks(this)) {
1492 mModel.stopLoader();
Sunny Goyal87f784c2017-01-11 10:48:34 -08001493 LauncherAppState.getInstance(this).setLauncher(null);
Adam Cohen1a85c582014-09-30 09:48:49 -07001494 }
Sunny Goyal623eddd2018-03-02 12:24:41 -08001495 mRotationHelper.destroy();
Sunny Goyal745bad92016-05-02 10:54:12 -07001496
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001497 try {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001498 mAppWidgetHost.stopListening();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001499 } catch (NullPointerException ex) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001500 Log.w(TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001501 }
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001502
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001503 TextKeyListener.getInstance().release();
Tony2917a8b2017-07-31 23:29:42 -07001504 clearPendingBinds();
Hyunyoung Song31971a32019-01-27 12:31:12 -08001505 LauncherAppState.getIDP(this).removeOnChangeListener(this);
Adam Cohen9211d422014-10-07 18:14:53 -07001506 if (mLauncherCallbacks != null) {
1507 mLauncherCallbacks.onDestroy();
1508 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001509 }
1510
Sunny Goyalae502842016-06-17 08:43:56 -07001511 public LauncherAccessibilityDelegate getAccessibilityDelegate() {
1512 return mAccessibilityDelegate;
1513 }
1514
Adam Cohena9cf38f2011-05-02 15:36:58 -07001515 public DragController getDragController() {
1516 return mDragController;
1517 }
1518
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001519 @Override
Sunny Goyal0eca4e22016-07-20 11:43:06 -07001520 public void startActivityForResult(Intent intent, int requestCode, Bundle options) {
Sunny Goyaldedda052019-05-14 15:23:48 -07001521 if (requestCode != -1) {
1522 mPendingActivityRequestCode = requestCode;
1523 }
1524 if (requestCode == -1
1525 || !UiFactory.startActivityForResult(this, intent, requestCode, options)) {
1526 super.startActivityForResult(intent, requestCode, options);
1527 }
Adam Cohen173f7112015-03-27 15:14:00 -07001528 }
1529
1530 @Override
Sunny Goyaldedda052019-05-14 15:23:48 -07001531 public void startIntentSenderForResult(IntentSender intent, int requestCode,
Adam Cohen173f7112015-03-27 15:14:00 -07001532 Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags, Bundle options) {
Sunny Goyaldedda052019-05-14 15:23:48 -07001533 if (requestCode != -1) {
1534 mPendingActivityRequestCode = requestCode;
1535 }
1536 if (requestCode == -1 || !UiFactory.startIntentSenderForResult(this, intent, requestCode,
1537 fillInIntent, flagsMask, flagsValues, extraFlags, options)) {
1538 try {
1539 super.startIntentSenderForResult(intent, requestCode,
1540 fillInIntent, flagsMask, flagsValues, extraFlags, options);
1541 } catch (IntentSender.SendIntentException e) {
1542 throw new ActivityNotFoundException();
1543 }
Adam Cohen173f7112015-03-27 15:14:00 -07001544 }
1545 }
1546
Winson Chung70d72102011-08-12 11:24:35 -07001547 /**
1548 * Indicates that we want global search for this activity by setting the globalSearch
1549 * argument for {@link #startSearch} to true.
1550 */
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001551 @Override
Romain Guycbb89e42009-06-08 15:52:54 -07001552 public void startSearch(String initialQuery, boolean selectInitialQuery,
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001553 Bundle appSearchData, boolean globalSearch) {
1554 if (appSearchData == null) {
1555 appSearchData = new Bundle();
Bjorn Bringert32b12d22013-06-06 13:00:41 +01001556 appSearchData.putString("source", "launcher-search");
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001557 }
Sunny Goyalda4fe1a2016-05-26 16:05:17 -07001558
Sunny Goyal6f28e712016-09-13 14:19:29 -07001559 if (mLauncherCallbacks == null ||
1560 !mLauncherCallbacks.startSearch(initialQuery, selectInitialQuery, appSearchData)) {
1561 // Starting search from the callbacks failed. Start the default global search.
Sunny Goyalf4aceab2017-12-06 16:16:31 -08001562 super.startSearch(initialQuery, selectInitialQuery, appSearchData, true);
Ian Parkinson047036e2014-09-01 15:40:53 +01001563 }
Winson Chungcd99cd32015-04-29 11:03:24 -07001564
1565 // We need to show the workspace after starting the search
Sunny Goyal3e3f44c2017-10-23 17:14:52 -07001566 mStateManager.goToState(NORMAL);
Bjorn Bringertc459e522013-06-07 19:36:01 +01001567 }
1568
Joe Onorato9c1289c2009-08-17 11:03:03 -04001569 public boolean isWorkspaceLocked() {
Sunny Goyal2100c782016-08-22 16:00:03 -07001570 return mWorkspaceLoading || mPendingRequestArgs != null;
Joe Onorato9c1289c2009-08-17 11:03:03 -04001571 }
1572
Adam Cohen517a7f52014-03-01 12:12:59 -08001573 public boolean isWorkspaceLoading() {
1574 return mWorkspaceLoading;
1575 }
1576
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001577 private void setWorkspaceLoading(boolean value) {
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001578 mWorkspaceLoading = value;
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001579 }
1580
Sunny Goyal04a324a2017-01-20 21:08:59 -08001581 public void setWaitingForResult(PendingRequestArgs args) {
Sunny Goyal2100c782016-08-22 16:00:03 -07001582 mPendingRequestArgs = args;
Adam Cohen9211d422014-10-07 18:14:53 -07001583 }
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001584
Sunny Goyal2100c782016-08-22 16:00:03 -07001585 void addAppWidgetFromDropImpl(int appWidgetId, ItemInfo info, AppWidgetHostView boundWidget,
Sunny Goyal04a324a2017-01-20 21:08:59 -08001586 WidgetAddFlowHandler addFlowHandler) {
Tony Wickhama0628cc2015-10-14 15:23:04 -07001587 if (LOGD) {
1588 Log.d(TAG, "Adding widget from drop");
1589 }
Sunny Goyal04a324a2017-01-20 21:08:59 -08001590 addAppWidgetImpl(appWidgetId, info, boundWidget, addFlowHandler, 0);
Adam Cohenad4e15c2013-10-17 16:21:35 -07001591 }
1592
Sunny Goyal2100c782016-08-22 16:00:03 -07001593 void addAppWidgetImpl(int appWidgetId, ItemInfo info,
Sunny Goyal04a324a2017-01-20 21:08:59 -08001594 AppWidgetHostView boundWidget, WidgetAddFlowHandler addFlowHandler, int delay) {
Samuel Fufaca37b8a2019-08-19 17:04:36 -07001595 if (!addFlowHandler.startConfigActivity(this, appWidgetId, info,
1596 REQUEST_CREATE_APPWIDGET)) {
Sunny Goyal04a324a2017-01-20 21:08:59 -08001597 // If the configuration flow was not started, add the widget
Michael Jurkaaf442092010-06-10 17:01:57 -07001598
Adam Cohenad4e15c2013-10-17 16:21:35 -07001599 Runnable onComplete = new Runnable() {
1600 @Override
1601 public void run() {
1602 // Exit spring loaded mode if necessary after adding the widget
Sunny Goyal3e3f44c2017-10-23 17:14:52 -07001603 mStateManager.goToState(NORMAL, SPRING_LOADED_EXIT_DELAY);
Adam Cohenad4e15c2013-10-17 16:21:35 -07001604 }
1605 };
Samuel Fufaca37b8a2019-08-19 17:04:36 -07001606 completeAddAppWidget(appWidgetId, info, boundWidget,
1607 addFlowHandler.getProviderInfo(this));
Adam Cohen689ff162014-05-08 17:27:56 -07001608 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete, delay, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001609 }
1610 }
Romain Guycbb89e42009-06-08 15:52:54 -07001611
Sunny Goyalefb7e842018-10-04 15:11:00 -07001612 public void addPendingItem(PendingAddItemInfo info, int container, int screenId,
Sunny Goyal71b5c0b2015-01-08 16:59:04 -08001613 int[] cell, int spanX, int spanY) {
Sunny Goyal2100c782016-08-22 16:00:03 -07001614 info.container = container;
1615 info.screenId = screenId;
1616 if (cell != null) {
1617 info.cellX = cell[0];
1618 info.cellY = cell[1];
1619 }
1620 info.spanX = spanX;
1621 info.spanY = spanY;
1622
Sunny Goyal71b5c0b2015-01-08 16:59:04 -08001623 switch (info.itemType) {
1624 case LauncherSettings.Favorites.ITEM_TYPE_CUSTOM_APPWIDGET:
1625 case LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET:
Sunny Goyal2100c782016-08-22 16:00:03 -07001626 addAppWidgetFromDrop((PendingAddWidgetInfo) info);
Sunny Goyal71b5c0b2015-01-08 16:59:04 -08001627 break;
1628 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Sunny Goyal782f0c92017-01-19 10:27:54 -08001629 processShortcutFromDrop((PendingAddShortcutInfo) info);
Sunny Goyal71b5c0b2015-01-08 16:59:04 -08001630 break;
1631 default:
1632 throw new IllegalStateException("Unknown item type: " + info.itemType);
Samuel Fufaca37b8a2019-08-19 17:04:36 -07001633 }
Sunny Goyal71b5c0b2015-01-08 16:59:04 -08001634 }
1635
Adam Cohenfbba09b2011-07-18 21:43:05 -07001636 /**
1637 * Process a shortcut drop.
Adam Cohenfbba09b2011-07-18 21:43:05 -07001638 */
Sunny Goyal782f0c92017-01-19 10:27:54 -08001639 private void processShortcutFromDrop(PendingAddShortcutInfo info) {
Sunny Goyalfb5096d2016-09-08 14:32:06 -07001640 Intent intent = new Intent(Intent.ACTION_CREATE_SHORTCUT).setComponent(info.componentName);
1641 setWaitingForResult(PendingRequestArgs.forIntent(REQUEST_CREATE_SHORTCUT, intent, info));
Sunny Goyal782f0c92017-01-19 10:27:54 -08001642 if (!info.activityInfo.startConfigActivity(this, REQUEST_CREATE_SHORTCUT)) {
1643 handleActivityResult(REQUEST_CREATE_SHORTCUT, RESULT_CANCELED, null);
1644 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001645 }
1646
Adam Cohenfbba09b2011-07-18 21:43:05 -07001647 /**
1648 * Process a widget drop.
Adam Cohenfbba09b2011-07-18 21:43:05 -07001649 */
Sunny Goyal2100c782016-08-22 16:00:03 -07001650 private void addAppWidgetFromDrop(PendingAddWidgetInfo info) {
Adam Cohened66b2b2012-01-23 17:28:51 -08001651 AppWidgetHostView hostView = info.boundWidget;
Sunny Goyal952e63d2017-08-16 04:59:08 -07001652 final int appWidgetId;
Sunny Goyal8a0dc382017-01-25 11:30:06 -08001653 WidgetAddFlowHandler addFlowHandler = info.getHandler();
Adam Cohened66b2b2012-01-23 17:28:51 -08001654 if (hostView != null) {
Tony Wickhama0628cc2015-10-14 15:23:04 -07001655 // In the case where we've prebound the widget, we remove it from the DragLayer
1656 if (LOGD) {
1657 Log.d(TAG, "Removing widget view from drag layer and setting boundWidget to null");
1658 }
1659 getDragLayer().removeView(hostView);
1660
Adam Cohened66b2b2012-01-23 17:28:51 -08001661 appWidgetId = hostView.getAppWidgetId();
Sunny Goyal04a324a2017-01-20 21:08:59 -08001662 addAppWidgetFromDropImpl(appWidgetId, info, hostView, addFlowHandler);
Sunny Goyal5b9ebca2015-06-01 18:37:32 -07001663
1664 // Clear the boundWidget so that it doesn't get destroyed.
1665 info.boundWidget = null;
Adam Cohened66b2b2012-01-23 17:28:51 -08001666 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001667 // In this case, we either need to start an activity to get permission to bind
1668 // the widget, or we need to start an activity to configure the widget, or both.
Pinyao Tingc7a6c292019-08-26 14:36:02 -07001669 if (info.itemType == LauncherSettings.Favorites.ITEM_TYPE_CUSTOM_APPWIDGET) {
1670 appWidgetId = CustomWidgetManager.INSTANCE.get(this).getWidgetIdForCustomProvider(
1671 info.componentName);
Sunny Goyal952e63d2017-08-16 04:59:08 -07001672 } else {
1673 appWidgetId = getAppWidgetHost().allocateAppWidgetId();
1674 }
Adam Cohendd70d662012-10-04 16:53:44 -07001675 Bundle options = info.bindOptions;
1676
Sunny Goyalffe83f12014-08-14 17:39:34 -07001677 boolean success = mAppWidgetManager.bindAppWidgetIdIfAllowed(
1678 appWidgetId, info.info, options);
Adam Cohendd70d662012-10-04 16:53:44 -07001679 if (success) {
Sunny Goyal04a324a2017-01-20 21:08:59 -08001680 addAppWidgetFromDropImpl(appWidgetId, info, null, addFlowHandler);
Michael Jurka8b805b12012-04-18 14:23:14 -07001681 } else {
Sunny Goyal04a324a2017-01-20 21:08:59 -08001682 addFlowHandler.startBindFlow(this, appWidgetId, info, REQUEST_BIND_APPWIDGET);
Michael Jurka8b805b12012-04-18 14:23:14 -07001683 }
Adam Cohened66b2b2012-01-23 17:28:51 -08001684 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001685 }
1686
Sunny Goyalefb7e842018-10-04 15:11:00 -07001687 FolderIcon addFolder(CellLayout layout, int container, final int screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07001688 int cellY) {
Michael Jurkac9d95c52011-08-29 14:03:34 -07001689 final FolderInfo folderInfo = new FolderInfo();
Samuel Fufa84245e82019-08-14 13:44:12 -07001690 folderInfo.title = "";
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001691
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001692 // Update the model
Sunny Goyal43bf11d2017-02-02 13:52:53 -08001693 getModelWriter().addItemToDatabase(folderInfo, container, screenId, cellX, cellY);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001694
1695 // Create the view
Sunny Goyal1cd01b02016-11-09 10:43:58 -08001696 FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this, layout, folderInfo);
Sunny Goyald5462aa2016-11-22 16:52:39 +05301697 mWorkspace.addInScreen(newFolder, folderInfo);
Winson Chung5f8afe62013-08-12 16:19:28 -07001698 // Force measure the new folder icon
1699 CellLayout parent = mWorkspace.getParentCellLayoutForView(newFolder);
1700 parent.getShortcutsAndWidgets().measureChild(newFolder);
Adam Cohendf035382011-04-11 17:22:04 -07001701 return newFolder;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001702 }
Romain Guycbb89e42009-06-08 15:52:54 -07001703
Winsonc0b52fe2015-09-09 16:38:15 -07001704 /**
Winsonfa56b3f2015-09-14 12:01:13 -07001705 * Unbinds the view for the specified item, and removes the item and all its children.
1706 *
1707 * @param v the view being removed.
Winsonfa56b3f2015-09-14 12:01:13 -07001708 * @param itemInfo the {@link ItemInfo} for this view.
1709 * @param deleteFromDb whether or not to delete this item from the db.
Winsonc0b52fe2015-09-09 16:38:15 -07001710 */
Tony Wickhambfbf7f92016-05-19 11:19:39 -07001711 public boolean removeItem(View v, final ItemInfo itemInfo, boolean deleteFromDb) {
Sunny Goyal95899162019-03-27 16:03:06 -07001712 if (itemInfo instanceof WorkspaceItemInfo) {
Winsonfa56b3f2015-09-14 12:01:13 -07001713 // Remove the shortcut from the folder before removing it from launcher
Sunny Goyal44c06432016-04-02 10:56:02 -07001714 View folderIcon = mWorkspace.getHomescreenIconByItemId(itemInfo.container);
1715 if (folderIcon instanceof FolderIcon) {
Sunny Goyal95899162019-03-27 16:03:06 -07001716 ((FolderInfo) folderIcon.getTag()).remove((WorkspaceItemInfo) itemInfo, true);
Winsonfa56b3f2015-09-14 12:01:13 -07001717 } else {
1718 mWorkspace.removeWorkspaceItem(v);
1719 }
Winsonc0b52fe2015-09-09 16:38:15 -07001720 if (deleteFromDb) {
Sunny Goyal43bf11d2017-02-02 13:52:53 -08001721 getModelWriter().deleteItemFromDatabase(itemInfo);
Winsonc0b52fe2015-09-09 16:38:15 -07001722 }
1723 } else if (itemInfo instanceof FolderInfo) {
1724 final FolderInfo folderInfo = (FolderInfo) itemInfo;
Sunny Goyalaaf7d1d2016-05-17 13:38:54 -07001725 if (v instanceof FolderIcon) {
1726 ((FolderIcon) v).removeListeners();
1727 }
Winsonc0b52fe2015-09-09 16:38:15 -07001728 mWorkspace.removeWorkspaceItem(v);
1729 if (deleteFromDb) {
Sunny Goyal43bf11d2017-02-02 13:52:53 -08001730 getModelWriter().deleteFolderAndContentsFromDatabase(folderInfo);
Winsonc0b52fe2015-09-09 16:38:15 -07001731 }
1732 } else if (itemInfo instanceof LauncherAppWidgetInfo) {
1733 final LauncherAppWidgetInfo widgetInfo = (LauncherAppWidgetInfo) itemInfo;
Winson44818e02015-10-02 11:25:46 -07001734 mWorkspace.removeWorkspaceItem(v);
Winsonc0b52fe2015-09-09 16:38:15 -07001735 if (deleteFromDb) {
Tony Wickham6a71a5b2018-08-21 11:40:23 -07001736 getModelWriter().deleteWidgetInfo(widgetInfo, getAppWidgetHost());
Winsonc0b52fe2015-09-09 16:38:15 -07001737 }
1738 } else {
1739 return false;
1740 }
1741 return true;
1742 }
1743
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001744 @Override
1745 public boolean dispatchKeyEvent(KeyEvent event) {
Hyunyoung Song3c7d9cb2017-01-30 15:11:27 -08001746 return (event.getKeyCode() == KeyEvent.KEYCODE_HOME) || super.dispatchKeyEvent(event);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001747 }
1748
Joe Onorato88ec0992009-11-19 13:16:06 -08001749 @Override
1750 public void onBackPressed() {
Sunny Goyal7c8a65e2017-12-22 11:11:33 -08001751 if (finishAutoCancelActionMode()) {
1752 return;
1753 }
Adam Cohen9211d422014-10-07 18:14:53 -07001754 if (mLauncherCallbacks != null && mLauncherCallbacks.handleBackPressed()) {
1755 return;
1756 }
1757
Sunny Goyal45478022015-06-08 16:52:41 -07001758 if (mDragController.isDragging()) {
1759 mDragController.cancelDrag();
Adam Cohenc9735cf2015-01-23 16:11:55 -08001760 return;
1761 }
1762
Jon Mirandafeba90f2016-10-06 10:53:29 -07001763 // Note: There should be at most one log per method call. This is enforced implicitly
1764 // by using if-else statements.
1765 UserEventDispatcher ued = getUserEventDispatcher();
Sunny Goyal740ac7f2016-09-28 16:47:32 -07001766 AbstractFloatingView topView = AbstractFloatingView.getTopOpenView(this);
Tony Wickham52c1b662018-05-21 13:13:58 -07001767 if (topView != null && topView.onBackPressed()) {
1768 // Handled by the floating view.
Patrick Dubroy94f78a52011-02-28 17:39:16 -08001769 } else {
Sunny Goyale39690b2018-08-02 13:35:07 -07001770 mStateManager.getState().onBackPressed(this);
Michael Jurkaaf442092010-06-10 17:01:57 -07001771 }
Joe Onorato88ec0992009-11-19 13:16:06 -08001772 }
1773
Sunny Goyalfe770c92016-09-27 14:38:58 -07001774 @TargetApi(Build.VERSION_CODES.M)
Sunny Goyal0b0847b2018-03-14 12:30:11 -07001775 @Override
Jon Miranda73c27ec2018-05-16 18:06:23 -07001776 public ActivityOptions getActivityLaunchOptions(View v) {
1777 return mAppTransitionManager.getActivityLaunchOptions(this, v);
Sunny Goyala7ce1662016-05-31 15:01:35 -07001778 }
1779
Tony Wickham3a6746a2018-03-29 09:39:56 -07001780 public LauncherAppTransitionManager getAppTransitionManager() {
1781 return mAppTransitionManager;
1782 }
1783
Sunny Goyal0b0847b2018-03-14 12:30:11 -07001784 @TargetApi(Build.VERSION_CODES.M)
1785 @Override
1786 protected boolean onErrorStartingShortcut(Intent intent, ItemInfo info) {
1787 // Due to legacy reasons, direct call shortcuts require Launchers to have the
1788 // corresponding permission. Show the appropriate permission prompt if that
1789 // is the case.
1790 if (intent.getComponent() == null
1791 && Intent.ACTION_CALL.equals(intent.getAction())
1792 && checkSelfPermission(android.Manifest.permission.CALL_PHONE) !=
1793 PackageManager.PERMISSION_GRANTED) {
1794
1795 setWaitingForResult(PendingRequestArgs
1796 .forIntent(REQUEST_PERMISSION_CALL_PHONE, intent, info));
1797 requestPermissions(new String[]{android.Manifest.permission.CALL_PHONE},
1798 REQUEST_PERMISSION_CALL_PHONE);
1799 return true;
1800 } else {
1801 return false;
1802 }
Sunny Goyal0eca4e22016-07-20 11:43:06 -07001803 }
1804
Hyunyoung Song46d07f72018-05-22 15:41:25 -07001805 @Override
Hyunyoung Songfc007472018-10-25 14:09:50 -07001806 public int getCurrentState() {
Samuel Fufaca37b8a2019-08-19 17:04:36 -07001807 if (mStateManager.getState() == LauncherState.ALL_APPS) {
Hyunyoung Songfc007472018-10-25 14:09:50 -07001808 return StatsLogUtils.LAUNCHER_STATE_ALLAPPS;
Govinda Wassermanc06e1512019-04-09 09:56:53 -04001809 } else if (mStateManager.getState() == OVERVIEW) {
Hyunyoung Songfc007472018-10-25 14:09:50 -07001810 return StatsLogUtils.LAUNCHER_STATE_OVERVIEW;
1811 }
Hyunyoung Song0ae38882018-11-05 14:45:19 -08001812 return StatsLogUtils.LAUNCHER_STATE_HOME;
Hyunyoung Songfc007472018-10-25 14:09:50 -07001813 }
1814
1815 @Override
Hyunyoung Song46d07f72018-05-22 15:41:25 -07001816 public void modifyUserEvent(LauncherLogProto.LauncherEvent event) {
1817 if (event.srcTarget != null && event.srcTarget.length > 0 &&
1818 event.srcTarget[1].containerType == ContainerType.PREDICTION) {
1819 Target[] targets = new Target[3];
1820 targets[0] = event.srcTarget[0];
1821 targets[1] = event.srcTarget[1];
1822 targets[2] = newTarget(Target.Type.CONTAINER);
1823 event.srcTarget = targets;
1824 LauncherState state = mStateManager.getState();
1825 if (state == LauncherState.ALL_APPS) {
1826 event.srcTarget[2].containerType = ContainerType.ALLAPPS;
Govinda Wassermanc06e1512019-04-09 09:56:53 -04001827 } else if (state == OVERVIEW) {
Hyunyoung Song46d07f72018-05-22 15:41:25 -07001828 event.srcTarget[2].containerType = ContainerType.TASKSWITCHER;
1829 }
1830 }
1831 }
1832
Sunny Goyal369212a2019-03-26 15:03:57 -07001833 public boolean startActivitySafely(View v, Intent intent, ItemInfo item,
1834 @Nullable String sourceContainer) {
Winson Chung0b70cd42019-06-17 22:34:33 -07001835 if (!hasBeenResumed()) {
1836 // Workaround an issue where the WM launch animation is clobbered when finishing the
1837 // recents animation into launcher. Defer launching the activity until Launcher is
1838 // next resumed.
1839 addOnResumeCallback(() -> startActivitySafely(v, intent, item, sourceContainer));
1840 UiFactory.clearSwipeSharedState(true /* finishAnimation */);
1841 return true;
1842 }
1843
Sunny Goyal369212a2019-03-26 15:03:57 -07001844 boolean success = super.startActivitySafely(v, intent, item, sourceContainer);
Hyunyoung Song1241e612018-05-15 21:46:51 -07001845 if (success && v instanceof BubbleTextView) {
Sunny Goyal0b0847b2018-03-14 12:30:11 -07001846 // This is set to the view that launched the activity that navigated the user away
1847 // from launcher. Since there is no callback for when the activity has finished
1848 // launching, enable the press state and keep this reference to reset the press
1849 // state when we return to launcher.
1850 BubbleTextView btv = (BubbleTextView) v;
1851 btv.setStayPressed(true);
Winson Chung0b70cd42019-06-17 22:34:33 -07001852 addOnResumeCallback(btv);
Sunny Goyala7ce1662016-05-31 15:01:35 -07001853 }
Hyunyoung Song1241e612018-05-15 21:46:51 -07001854 return success;
Michael Jurka86a720e2012-05-09 11:23:23 -07001855 }
1856
Winson Chung3d503fb2011-07-13 17:25:49 -07001857 boolean isHotseatLayout(View layout) {
Sunny Goyalc13403c2016-11-18 23:44:48 -08001858 // TODO: Remove this method
Sunny Goyal876e4622018-11-02 13:50:40 -07001859 return mHotseat != null && (layout == mHotseat);
Winson Chung3d503fb2011-07-13 17:25:49 -07001860 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08001861
Winson Chung3d503fb2011-07-13 17:25:49 -07001862 /**
1863 * Returns the CellLayout of the specified container at the specified screen.
1864 */
Sunny Goyalefb7e842018-10-04 15:11:00 -07001865 public CellLayout getCellLayout(int container, int screenId) {
Sunny Goyal876e4622018-11-02 13:50:40 -07001866 return (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT)
1867 ? mHotseat : mWorkspace.getScreenWithId(screenId);
Romain Guya6abce82009-11-10 02:54:41 -08001868 }
1869
Michael Jurkae326f182011-11-21 14:05:46 -08001870 @Override
1871 public void onTrimMemory(int level) {
1872 super.onTrimMemory(level);
Adam Cohen3f9c9712014-10-31 11:48:25 -07001873 if (level >= ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN) {
1874 // The widget preview db can result in holding onto over
1875 // 3MB of memory for caching which isn't necessary.
1876 SQLiteDatabase.releaseMemory();
1877
Adam Cohenc8f4e1b2014-11-19 16:03:20 -08001878 // This clears all widget bitmaps from the widget tray
Hyunyoung Song3f471442015-04-08 19:01:34 -07001879 // TODO(hyunyoungs)
Michael Jurkae326f182011-11-21 14:05:46 -08001880 }
Robert Kozikowski67c30862015-03-30 23:46:46 +01001881 if (mLauncherCallbacks != null) {
1882 mLauncherCallbacks.onTrimMemory(level);
1883 }
Winson Chung62a70be2018-02-23 15:10:05 -08001884 UiFactory.onTrimMemory(this, level);
Michael Jurkae326f182011-11-21 14:05:46 -08001885 }
1886
Michael Jurkad7c28052012-04-27 15:43:36 -07001887 @Override
1888 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
alanv1d4fde62012-10-17 13:15:47 -07001889 final boolean result = super.dispatchPopulateAccessibilityEvent(event);
Michael Jurkad7c28052012-04-27 15:43:36 -07001890 final List<CharSequence> text = event.getText();
1891 text.clear();
alanv1d4fde62012-10-17 13:15:47 -07001892 // Populate event with a fake title based on the current state.
Sunny Goyal3e3f44c2017-10-23 17:14:52 -07001893 // TODO: When can workspace be null?
1894 text.add(mWorkspace == null
1895 ? getString(R.string.all_apps_home_button_label)
Sunny Goyalea609262017-10-25 15:47:38 -07001896 : mStateManager.getState().getDescription(this));
Michael Jurkad7c28052012-04-27 15:43:36 -07001897 return result;
1898 }
1899
Winson Chung0b70cd42019-06-17 22:34:33 -07001900 public void addOnResumeCallback(OnResumeCallback callback) {
1901 mOnResumeCallbacks.add(callback);
Michael Jurka1e2f4652013-07-08 18:03:46 -07001902 }
1903
Michael Jurka7607c2f2013-04-03 14:33:19 -07001904 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04001905 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001906 */
Sunny Goyal93f878c2016-03-30 17:31:24 -07001907 @Override
Joe Onorato9c1289c2009-08-17 11:03:03 -04001908 public int getCurrentWorkspaceScreen() {
Joe Onoratod0afc872010-06-11 00:03:15 -07001909 if (mWorkspace != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07001910 return mWorkspace.getCurrentPage();
Joe Onoratod0afc872010-06-11 00:03:15 -07001911 } else {
Winson Chung882a52e2015-07-08 14:32:26 -07001912 return 0;
Joe Onoratod0afc872010-06-11 00:03:15 -07001913 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04001914 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07001915
Joe Onorato9c1289c2009-08-17 11:03:03 -04001916 /**
Sunny Goyal527c7d32015-08-28 15:19:36 -07001917 * Clear any pending bind callbacks. This is called when is loader is planning to
1918 * perform a full rebind from scratch.
1919 */
1920 @Override
1921 public void clearPendingBinds() {
Sunny Goyal527c7d32015-08-28 15:19:36 -07001922 if (mPendingExecutor != null) {
1923 mPendingExecutor.markCompleted();
1924 mPendingExecutor = null;
Sunny Goyal6b6d0a32019-08-05 17:19:32 -07001925
1926 // We might have set this flag previously and forgot to clear it.
1927 mAppsView.getAppsStore()
1928 .disableDeferUpdatesSilently(AllAppsStore.DEFER_UPDATES_NEXT_DRAW);
Sunny Goyal527c7d32015-08-28 15:19:36 -07001929 }
1930 }
1931
1932 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04001933 * Refreshes the shortcuts shown on the workspace.
1934 *
1935 * Implementation of the method from LauncherModel.Callbacks.
1936 */
1937 public void startBinding() {
Sunny Goyalfca6bc92017-09-28 16:28:34 -07001938 TraceHelper.beginSection("startBinding");
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -07001939 // Floating panels (except the full widget sheet) are associated with individual icons. If
1940 // we are starting a fresh bind, close all such panels as all the icons are about
1941 // to go away.
Pinyao Tinga74b63a2019-07-17 23:26:06 -07001942 AbstractFloatingView.closeOpenViews(this, true, TYPE_ALL & ~TYPE_REBIND_SAFE);
Jon Miranda6dc7f1e2017-02-21 12:37:51 -08001943
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001944 setWorkspaceLoading(true);
Adam Cohen517a7f52014-03-01 12:12:59 -08001945
Winson Chungd64d1762013-08-20 14:37:16 -07001946 // Clear the workspace because it's going to be rebound
Sunny Goyal2db53422019-03-01 16:06:12 -08001947 mDragController.cancelDrag();
1948
Adam Cohendf035382011-04-11 17:22:04 -07001949 mWorkspace.clearDropTargets();
Winson Chung9e6a0a22013-08-27 11:58:12 -07001950 mWorkspace.removeAllWorkspaceScreens();
Sunny Goyalc11fac32018-02-27 19:20:15 -08001951 mAppWidgetHost.clearViews();
Winson Chungd64d1762013-08-20 14:37:16 -07001952
Winson Chung3d503fb2011-07-13 17:25:49 -07001953 if (mHotseat != null) {
Sunny Goyalae6e3182019-04-30 12:04:37 -07001954 mHotseat.resetLayout(getWallpaperDeviceProfile().isVerticalBarLayout());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001955 }
Sunny Goyalfca6bc92017-09-28 16:28:34 -07001956 TraceHelper.endSection("startBinding");
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001957 }
1958
Adam Cohendcd297f2013-06-18 13:13:40 -07001959 @Override
Sunny Goyalefb7e842018-10-04 15:11:00 -07001960 public void bindScreens(IntArray orderedScreenIds) {
Sunny Goyalda4fe1a2016-05-26 16:05:17 -07001961 // Make sure the first screen is always at the start.
Jon Miranda7143ba62019-03-15 09:00:05 -07001962 if (FeatureFlags.QSB_ON_FIRST_SCREEN &&
Sunny Goyala9e2f5a2016-06-10 12:22:04 -07001963 orderedScreenIds.indexOf(Workspace.FIRST_SCREEN_ID) != 0) {
Sunny Goyalefb7e842018-10-04 15:11:00 -07001964 orderedScreenIds.removeValue(Workspace.FIRST_SCREEN_ID);
Sunny Goyalda4fe1a2016-05-26 16:05:17 -07001965 orderedScreenIds.add(0, Workspace.FIRST_SCREEN_ID);
Jon Miranda7143ba62019-03-15 09:00:05 -07001966 } else if (!FeatureFlags.QSB_ON_FIRST_SCREEN && orderedScreenIds.isEmpty()) {
Sunny Goyala9e2f5a2016-06-10 12:22:04 -07001967 // If there are no screens, we need to have an empty screen
1968 mWorkspace.addExtraEmptyScreen();
Adam Cohen5084cba2013-09-03 12:01:16 -07001969 }
Sunny Goyalda4fe1a2016-05-26 16:05:17 -07001970 bindAddScreens(orderedScreenIds);
Winson Chung0e6a7132013-08-23 12:55:10 -07001971
Winsonc7d2e832016-07-28 12:24:55 -07001972 // After we have added all the screens, if the wallpaper was locked to the default state,
1973 // then notify to indicate that it can be released and a proper wallpaper offset can be
1974 // computed before the next layout
1975 mWorkspace.unlockWallpaperFromDefaultPageOnNextLayout();
Winson Chung64359a52013-07-08 17:17:08 -07001976 }
1977
Sunny Goyalefb7e842018-10-04 15:11:00 -07001978 private void bindAddScreens(IntArray orderedScreenIds) {
Adam Cohendcd297f2013-06-18 13:13:40 -07001979 int count = orderedScreenIds.size();
1980 for (int i = 0; i < count; i++) {
Sunny Goyalefb7e842018-10-04 15:11:00 -07001981 int screenId = orderedScreenIds.get(i);
Jon Miranda7143ba62019-03-15 09:00:05 -07001982 if (!FeatureFlags.QSB_ON_FIRST_SCREEN || screenId != Workspace.FIRST_SCREEN_ID) {
Sunny Goyalda4fe1a2016-05-26 16:05:17 -07001983 // No need to bind the first screen, as its always bound.
1984 mWorkspace.insertNewWorkspaceScreenBeforeEmptyScreen(screenId);
1985 }
Adam Cohendcd297f2013-06-18 13:13:40 -07001986 }
Adam Cohendcd297f2013-06-18 13:13:40 -07001987 }
1988
Sunny Goyalb23980c2017-08-17 07:45:25 -07001989 @Override
Tony Wickham6a71a5b2018-08-21 11:40:23 -07001990 public void preAddApps() {
1991 // If there's an undo snackbar, force it to complete to ensure empty screens are removed
1992 // before trying to add new items.
1993 mModelWriter.commitDelete();
1994 AbstractFloatingView snackbar = AbstractFloatingView.getOpenView(this, TYPE_SNACKBAR);
1995 if (snackbar != null) {
1996 snackbar.post(() -> snackbar.close(true));
1997 }
1998 }
1999
2000 @Override
Sunny Goyalefb7e842018-10-04 15:11:00 -07002001 public void bindAppsAdded(IntArray newScreens, ArrayList<ItemInfo> addNotAnimated,
Sunny Goyal29947f02017-12-18 13:49:44 -08002002 ArrayList<ItemInfo> addAnimated) {
Winson Chungd64d1762013-08-20 14:37:16 -07002003 // Add the new screens
Adam Cohen76a47a12014-02-05 11:47:43 -08002004 if (newScreens != null) {
2005 bindAddScreens(newScreens);
2006 }
Winson Chungd64d1762013-08-20 14:37:16 -07002007
2008 // We add the items without animation on non-visible pages, and with
2009 // animations on the new page (which we will try and snap to).
Adam Cohen76a47a12014-02-05 11:47:43 -08002010 if (addNotAnimated != null && !addNotAnimated.isEmpty()) {
Sunny Goyalb23980c2017-08-17 07:45:25 -07002011 bindItems(addNotAnimated, false);
Winson Chungd64d1762013-08-20 14:37:16 -07002012 }
Adam Cohen76a47a12014-02-05 11:47:43 -08002013 if (addAnimated != null && !addAnimated.isEmpty()) {
Sunny Goyalb23980c2017-08-17 07:45:25 -07002014 bindItems(addAnimated, true);
Winson Chungd64d1762013-08-20 14:37:16 -07002015 }
Winson Chungc58497e2013-09-03 17:48:37 -07002016
Winson Chung87412982013-10-03 18:34:14 -07002017 // Remove the extra empty screen
Adam Cohen689ff162014-05-08 17:27:56 -07002018 mWorkspace.removeExtraEmptyScreen(false, false);
Winson Chungd64d1762013-08-20 14:37:16 -07002019 }
2020
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002021 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04002022 * Bind the items start-end from the list.
2023 *
2024 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002025 */
Tony Wickham0bb211a2015-10-02 16:22:08 -07002026 @Override
Sunny Goyalb23980c2017-08-17 07:45:25 -07002027 public void bindItems(final List<ItemInfo> items, final boolean forceAnimateIcons) {
Sunny Goyal3be633b2016-12-08 09:59:25 -08002028 // Get the list of added items and intersect them with the set of items here
Rajeev Kumar43c0f582017-06-23 15:34:55 -07002029 final Collection<Animator> bounceAnims = new ArrayList<>();
Winson Chung997a9232013-07-24 15:33:46 -07002030 final boolean animateIcons = forceAnimateIcons && canRunNewAppsAnimation();
Winson Chungf0c6ae02012-03-21 16:10:31 -07002031 Workspace workspace = mWorkspace;
Sunny Goyalefb7e842018-10-04 15:11:00 -07002032 int newItemsScreenId = -1;
Sunny Goyalb23980c2017-08-17 07:45:25 -07002033 int end = items.size();
2034 for (int i = 0; i < end; i++) {
Sunny Goyal3be633b2016-12-08 09:59:25 -08002035 final ItemInfo item = items.get(i);
Winson Chung4d279d92011-07-21 11:46:32 -07002036
2037 // Short circuit if we are loading dock items for a configuration which has no dock
2038 if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT &&
2039 mHotseat == null) {
2040 continue;
2041 }
2042
Sunny Goyal639e9062015-08-19 19:17:06 -07002043 final View view;
Joe Onorato9c1289c2009-08-17 11:03:03 -04002044 switch (item.itemType) {
2045 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
2046 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Sunny Goyal3be633b2016-12-08 09:59:25 -08002047 case LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT: {
Sunny Goyal95899162019-03-27 16:03:06 -07002048 WorkspaceItemInfo info = (WorkspaceItemInfo) item;
Sunny Goyal639e9062015-08-19 19:17:06 -07002049 view = createShortcut(info);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002050 break;
Sunny Goyal3be633b2016-12-08 09:59:25 -08002051 }
2052 case LauncherSettings.Favorites.ITEM_TYPE_FOLDER: {
Sunny Goyal639e9062015-08-19 19:17:06 -07002053 view = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07002054 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Sunny Goyal1cd01b02016-11-09 10:43:58 -08002055 (FolderInfo) item);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002056 break;
Sunny Goyal3be633b2016-12-08 09:59:25 -08002057 }
Sunny Goyal952e63d2017-08-16 04:59:08 -07002058 case LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET:
2059 case LauncherSettings.Favorites.ITEM_TYPE_CUSTOM_APPWIDGET: {
Sunny Goyala9a1a212017-08-18 01:03:21 -07002060 view = inflateAppWidget((LauncherAppWidgetInfo) item);
Sunny Goyalb23980c2017-08-17 07:45:25 -07002061 if (view == null) {
2062 continue;
Sunny Goyal3be633b2016-12-08 09:59:25 -08002063 }
Sunny Goyal3be633b2016-12-08 09:59:25 -08002064 break;
2065 }
Winson Chungc763c4e2013-07-19 13:49:06 -07002066 default:
2067 throw new RuntimeException("Invalid Item Type");
Joe Onorato9c1289c2009-08-17 11:03:03 -04002068 }
Sunny Goyal639e9062015-08-19 19:17:06 -07002069
Samuel Fufaca37b8a2019-08-19 17:04:36 -07002070 /*
Sunny Goyalda4fe1a2016-05-26 16:05:17 -07002071 * Remove colliding items.
2072 */
2073 if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
2074 CellLayout cl = mWorkspace.getScreenWithId(item.screenId);
2075 if (cl != null && cl.isOccupied(item.cellX, item.cellY)) {
2076 View v = cl.getChildAt(item.cellX, item.cellY);
2077 Object tag = v.getTag();
2078 String desc = "Collision while binding workspace item: " + item
2079 + ". Collides with " + tag;
Sunny Goyal3d706ad2017-03-06 16:56:39 -08002080 if (FeatureFlags.IS_DOGFOOD_BUILD) {
Sunny Goyalda4fe1a2016-05-26 16:05:17 -07002081 throw (new RuntimeException(desc));
2082 } else {
2083 Log.d(TAG, desc);
Sunny Goyal43bf11d2017-02-02 13:52:53 -08002084 getModelWriter().deleteItemFromDatabase(item);
Sunny Goyalda4fe1a2016-05-26 16:05:17 -07002085 continue;
2086 }
2087 }
2088 }
Sunny Goyald5462aa2016-11-22 16:52:39 +05302089 workspace.addInScreenFromBind(view, item);
Sunny Goyal639e9062015-08-19 19:17:06 -07002090 if (animateIcons) {
2091 // Animate all the applications up now
2092 view.setAlpha(0f);
2093 view.setScaleX(0f);
2094 view.setScaleY(0f);
2095 bounceAnims.add(createNewAppBounceAnimation(view, i));
Sunny Goyal3be633b2016-12-08 09:59:25 -08002096 newItemsScreenId = item.screenId;
Sunny Goyal639e9062015-08-19 19:17:06 -07002097 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002098 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07002099
Sunny Goyalf0b6db72018-08-13 16:10:14 -07002100 // Animate to the correct page
2101 if (animateIcons && newItemsScreenId > -1) {
2102 AnimatorSet anim = new AnimatorSet();
2103 anim.playTogether(bounceAnims);
Jon Miranda64eb8ea2018-03-29 11:43:58 -07002104
Sunny Goyalefb7e842018-10-04 15:11:00 -07002105 int currentScreenId = mWorkspace.getScreenIdForPageIndex(mWorkspace.getNextPage());
Sunny Goyalf0b6db72018-08-13 16:10:14 -07002106 final int newScreenIndex = mWorkspace.getPageIndexForScreenId(newItemsScreenId);
2107 final Runnable startBounceAnimRunnable = anim::start;
2108
2109 if (newItemsScreenId != currentScreenId) {
2110 // We post the animation slightly delayed to prevent slowdowns
2111 // when we are loading right after we return to launcher.
2112 mWorkspace.postDelayed(new Runnable() {
2113 public void run() {
2114 if (mWorkspace != null) {
2115 AbstractFloatingView.closeAllOpenViews(Launcher.this, false);
2116
2117 mWorkspace.snapToPage(newScreenIndex);
2118 mWorkspace.postDelayed(startBounceAnimRunnable,
2119 NEW_APPS_ANIMATION_DELAY);
Winson Chung94d67682013-09-25 16:29:40 -07002120 }
Sunny Goyalf0b6db72018-08-13 16:10:14 -07002121 }
2122 }, NEW_APPS_PAGE_MOVE_DELAY);
2123 } else {
2124 mWorkspace.postDelayed(startBounceAnimRunnable, NEW_APPS_ANIMATION_DELAY);
Winson Chung997a9232013-07-24 15:33:46 -07002125 }
Winson Chung64359a52013-07-08 17:17:08 -07002126 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04002127 workspace.requestLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002128 }
2129
Joe Onorato9c1289c2009-08-17 11:03:03 -04002130 /**
2131 * Add the views for a widget to the workspace.
Joe Onorato9c1289c2009-08-17 11:03:03 -04002132 */
Sunny Goyala9a1a212017-08-18 01:03:21 -07002133 public void bindAppWidget(LauncherAppWidgetInfo item) {
2134 View view = inflateAppWidget(item);
2135 if (view != null) {
2136 mWorkspace.addInScreen(view, item);
2137 mWorkspace.requestLayout();
2138 }
2139 }
2140
2141 private View inflateAppWidget(LauncherAppWidgetInfo item) {
Samuel Fufaca37b8a2019-08-19 17:04:36 -07002142 if (item.hasOptionFlag(LauncherAppWidgetInfo.OPTION_SEARCH_WIDGET)) {
2143 item.providerName = QsbContainerView.getSearchComponentName(this);
2144 if (item.providerName == null) {
2145 getModelWriter().deleteItemFromDatabase(item);
2146 return null;
2147 }
2148 }
2149
Sunny Goyal2e1efb42016-03-03 16:58:55 -08002150 if (mIsSafeModeEnabled) {
Sunny Goyald5462aa2016-11-22 16:52:39 +05302151 PendingAppWidgetHostView view =
2152 new PendingAppWidgetHostView(this, item, mIconCache, true);
2153 prepareAppWidget(view, item);
Sunny Goyalb23980c2017-08-17 07:45:25 -07002154 return view;
Sunny Goyal2e1efb42016-03-03 16:58:55 -08002155 }
2156
Sunny Goyalfca6bc92017-09-28 16:28:34 -07002157 TraceHelper.beginSection("BIND_WIDGET");
Joe Onorato9c1289c2009-08-17 11:03:03 -04002158
Sunny Goyal2e1efb42016-03-03 16:58:55 -08002159 final LauncherAppWidgetProviderInfo appWidgetInfo;
Adam Cohen59400422014-03-05 18:07:04 -08002160
Sunny Goyal2e1efb42016-03-03 16:58:55 -08002161 if (item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_PROVIDER_NOT_READY)) {
2162 // If the provider is not ready, bind as a pending widget.
2163 appWidgetInfo = null;
2164 } else if (item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_ID_NOT_VALID)) {
2165 // The widget id is not valid. Try to find the widget based on the provider info.
2166 appWidgetInfo = mAppWidgetManager.findProvider(item.providerName, item.user);
2167 } else {
2168 appWidgetInfo = mAppWidgetManager.getLauncherAppWidgetInfo(item.appWidgetId);
2169 }
Sunny Goyal84b4adc2015-08-12 15:12:16 -07002170
Sunny Goyal2e1efb42016-03-03 16:58:55 -08002171 // If the provider is ready, but the width is not yet restored, try to restore it.
2172 if (!item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_PROVIDER_NOT_READY) &&
2173 (item.restoreStatus != LauncherAppWidgetInfo.RESTORE_COMPLETED)) {
Sunny Goyalff572272014-07-23 13:58:07 -07002174 if (appWidgetInfo == null) {
Sunny Goyalfca6bc92017-09-28 16:28:34 -07002175 Log.d(TAG, "Removing restored widget: id=" + item.appWidgetId
2176 + " belongs to component " + item.providerName
2177 + ", as the provider is null");
Sunny Goyal43bf11d2017-02-02 13:52:53 -08002178 getModelWriter().deleteItemFromDatabase(item);
Sunny Goyalb23980c2017-08-17 07:45:25 -07002179 return null;
Sunny Goyalff572272014-07-23 13:58:07 -07002180 }
Sunny Goyalff572272014-07-23 13:58:07 -07002181
Sunny Goyal84b4adc2015-08-12 15:12:16 -07002182 // If we do not have a valid id, try to bind an id.
Sunny Goyal2e1efb42016-03-03 16:58:55 -08002183 if (item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_ID_NOT_VALID)) {
Sunny Goyald478c832016-04-01 12:04:16 -07002184 if (!item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_ID_ALLOCATED)) {
2185 // Id has not been allocated yet. Allocate a new id.
2186 item.appWidgetId = mAppWidgetHost.allocateAppWidgetId();
2187 item.restoreStatus |= LauncherAppWidgetInfo.FLAG_ID_ALLOCATED;
Sunny Goyalff572272014-07-23 13:58:07 -07002188
Sunny Goyald478c832016-04-01 12:04:16 -07002189 // Also try to bind the widget. If the bind fails, the user will be shown
2190 // a click to setup UI, which will ask for the bind permission.
Sunny Goyala52ecb02016-12-16 15:04:51 -08002191 PendingAddWidgetInfo pendingInfo = new PendingAddWidgetInfo(appWidgetInfo);
Sunny Goyald478c832016-04-01 12:04:16 -07002192 pendingInfo.spanX = item.spanX;
2193 pendingInfo.spanY = item.spanY;
2194 pendingInfo.minSpanX = item.minSpanX;
2195 pendingInfo.minSpanY = item.minSpanY;
Samuel Fufaca37b8a2019-08-19 17:04:36 -07002196 Bundle options = WidgetHostViewLoader.getDefaultOptionsForWidget(this,
2197 pendingInfo);
Sunny Goyal86df1382016-08-10 15:03:22 -07002198
2199 boolean isDirectConfig =
2200 item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_DIRECT_CONFIG);
2201 if (isDirectConfig && item.bindOptions != null) {
2202 Bundle newOptions = item.bindOptions.getExtras();
2203 if (options != null) {
2204 newOptions.putAll(options);
2205 }
2206 options = newOptions;
2207 }
Sunny Goyald478c832016-04-01 12:04:16 -07002208 boolean success = mAppWidgetManager.bindAppWidgetIdIfAllowed(
2209 item.appWidgetId, appWidgetInfo, options);
Sunny Goyal84b4adc2015-08-12 15:12:16 -07002210
Sunny Goyal86df1382016-08-10 15:03:22 -07002211 // We tried to bind once. If we were not able to bind, we would need to
2212 // go through the permission dialog, which means we cannot skip the config
2213 // activity.
2214 item.bindOptions = null;
2215 item.restoreStatus &= ~LauncherAppWidgetInfo.FLAG_DIRECT_CONFIG;
2216
Sunny Goyald478c832016-04-01 12:04:16 -07002217 // Bind succeeded
2218 if (success) {
2219 // If the widget has a configure activity, it is still needs to set it up,
2220 // otherwise the widget is ready to go.
Sunny Goyal86df1382016-08-10 15:03:22 -07002221 item.restoreStatus = (appWidgetInfo.configure == null) || isDirectConfig
Sunny Goyald478c832016-04-01 12:04:16 -07002222 ? LauncherAppWidgetInfo.RESTORE_COMPLETED
2223 : LauncherAppWidgetInfo.FLAG_UI_NOT_READY;
Sunny Goyal84b4adc2015-08-12 15:12:16 -07002224 }
Sunny Goyald478c832016-04-01 12:04:16 -07002225
Sunny Goyal43bf11d2017-02-02 13:52:53 -08002226 getModelWriter().updateItemInDatabase(item);
Sunny Goyalff572272014-07-23 13:58:07 -07002227 }
Sunny Goyal2e1efb42016-03-03 16:58:55 -08002228 } else if (item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_UI_NOT_READY)
Sunny Goyal84b4adc2015-08-12 15:12:16 -07002229 && (appWidgetInfo.configure == null)) {
Sunny Goyal2e1efb42016-03-03 16:58:55 -08002230 // The widget was marked as UI not ready, but there is no configure activity to
2231 // update the UI.
Sunny Goyal84b4adc2015-08-12 15:12:16 -07002232 item.restoreStatus = LauncherAppWidgetInfo.RESTORE_COMPLETED;
Sunny Goyal43bf11d2017-02-02 13:52:53 -08002233 getModelWriter().updateItemInDatabase(item);
Sunny Goyalff572272014-07-23 13:58:07 -07002234 }
Sunny Goyalff572272014-07-23 13:58:07 -07002235 }
2236
Sunny Goyald5462aa2016-11-22 16:52:39 +05302237 final AppWidgetHostView view;
Sunny Goyal2e1efb42016-03-03 16:58:55 -08002238 if (item.restoreStatus == LauncherAppWidgetInfo.RESTORE_COMPLETED) {
Sunny Goyal56c73602015-09-25 12:55:01 -07002239 // Verify that we own the widget
Sunny Goyal2e1efb42016-03-03 16:58:55 -08002240 if (appWidgetInfo == null) {
Sunny Goyal713edfc2016-05-06 09:58:34 -07002241 FileLog.e(TAG, "Removing invalid widget: id=" + item.appWidgetId);
Tony Wickham6a71a5b2018-08-21 11:40:23 -07002242 getModelWriter().deleteWidgetInfo(item, getAppWidgetHost());
Sunny Goyalb23980c2017-08-17 07:45:25 -07002243 return null;
Sunny Goyal56c73602015-09-25 12:55:01 -07002244 }
2245
Sunny Goyal233ee962015-08-03 13:05:01 -07002246 item.minSpanX = appWidgetInfo.minSpanX;
2247 item.minSpanY = appWidgetInfo.minSpanY;
Sunny Goyald5462aa2016-11-22 16:52:39 +05302248 view = mAppWidgetHost.createView(this, item.appWidgetId, appWidgetInfo);
Sunny Goyal651077b2014-06-30 14:15:31 -07002249 } else {
Sunny Goyald5462aa2016-11-22 16:52:39 +05302250 view = new PendingAppWidgetHostView(this, item, mIconCache, false);
Sunny Goyal651077b2014-06-30 14:15:31 -07002251 }
Sunny Goyald5462aa2016-11-22 16:52:39 +05302252 prepareAppWidget(view, item);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002253
Sunny Goyalfca6bc92017-09-28 16:28:34 -07002254 TraceHelper.endSection("BIND_WIDGET", "id=" + item.appWidgetId);
Sunny Goyalb23980c2017-08-17 07:45:25 -07002255 return view;
Joe Onorato9c1289c2009-08-17 11:03:03 -04002256 }
2257
Sunny Goyalff572272014-07-23 13:58:07 -07002258 /**
2259 * Restores a pending widget.
2260 *
2261 * @param appWidgetId The app widget id
Sunny Goyalff572272014-07-23 13:58:07 -07002262 */
Sunny Goyald478c832016-04-01 12:04:16 -07002263 private LauncherAppWidgetInfo completeRestoreAppWidget(int appWidgetId, int finalRestoreFlag) {
Sunny Goyalff572272014-07-23 13:58:07 -07002264 LauncherAppWidgetHostView view = mWorkspace.getWidgetForAppWidgetId(appWidgetId);
2265 if ((view == null) || !(view instanceof PendingAppWidgetHostView)) {
2266 Log.e(TAG, "Widget update called, when the widget no longer exists.");
Sunny Goyald478c832016-04-01 12:04:16 -07002267 return null;
Sunny Goyalff572272014-07-23 13:58:07 -07002268 }
2269
Sunny Goyal0fc1be12014-08-11 17:05:23 -07002270 LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) view.getTag();
Sunny Goyald478c832016-04-01 12:04:16 -07002271 info.restoreStatus = finalRestoreFlag;
Jon Miranda2b823f42017-05-02 18:36:18 -07002272 if (info.restoreStatus == LauncherAppWidgetInfo.RESTORE_COMPLETED) {
2273 info.pendingItemInfo = null;
2274 }
Sunny Goyalff572272014-07-23 13:58:07 -07002275
Sunny Goyalba47faa2017-10-04 16:50:57 -07002276 if (((PendingAppWidgetHostView) view).isReinflateIfNeeded()) {
Sunny Goyal29947f02017-12-18 13:49:44 -08002277 view.reInflate();
Sunny Goyalba47faa2017-10-04 16:50:57 -07002278 }
2279
Sunny Goyal43bf11d2017-02-02 13:52:53 -08002280 getModelWriter().updateItemInDatabase(info);
Sunny Goyald478c832016-04-01 12:04:16 -07002281 return info;
Sunny Goyalff572272014-07-23 13:58:07 -07002282 }
2283
Adam Cohen1462de32012-07-24 22:34:36 -07002284 public void onPageBoundSynchronously(int page) {
Sunny Goyalf4aceab2017-12-06 16:16:31 -08002285 mSynchronouslyBoundPage = page;
Adam Cohen1462de32012-07-24 22:34:36 -07002286 }
2287
Sunny Goyal527c7d32015-08-28 15:19:36 -07002288 @Override
2289 public void executeOnNextDraw(ViewOnDrawExecutor executor) {
Sunny Goyal6b6d0a32019-08-05 17:19:32 -07002290 clearPendingBinds();
Sunny Goyal527c7d32015-08-28 15:19:36 -07002291 mPendingExecutor = executor;
Sunny Goyal60180b02018-02-07 12:56:30 -08002292 if (!isInState(ALL_APPS)) {
vadimtd4c90e12019-06-04 13:59:43 -07002293 mAppsView.getAppsStore().enableDeferUpdates(AllAppsStore.DEFER_UPDATES_NEXT_DRAW);
2294 mPendingExecutor.execute(() -> mAppsView.getAppsStore().disableDeferUpdates(
2295 AllAppsStore.DEFER_UPDATES_NEXT_DRAW));
Sunny Goyal60180b02018-02-07 12:56:30 -08002296 }
2297
Sunny Goyal527c7d32015-08-28 15:19:36 -07002298 executor.attachTo(this);
2299 }
2300
2301 public void clearPendingExecutor(ViewOnDrawExecutor executor) {
2302 if (mPendingExecutor == executor) {
2303 mPendingExecutor = null;
2304 }
2305 }
2306
Sunny Goyalb5b9ad62016-04-02 11:23:39 -07002307 @Override
2308 public void finishFirstPageBind(final ViewOnDrawExecutor executor) {
Sunny Goyal6001ea22018-05-10 16:31:00 -07002309 AlphaProperty property = mDragLayer.getAlphaProperty(ALPHA_INDEX_LAUNCHER_LOAD);
2310 if (property.getValue() < 1) {
2311 ObjectAnimator anim = ObjectAnimator.ofFloat(property, MultiValueAlpha.VALUE, 1);
2312 if (executor != null) {
2313 anim.addListener(new AnimatorListenerAdapter() {
2314 @Override
2315 public void onAnimationEnd(Animator animation) {
2316 executor.onLoadAnimationCompleted();
2317 }
2318 });
2319 }
2320 anim.start();
Sunny Goyal29947f02017-12-18 13:49:44 -08002321 } else if (executor != null) {
2322 executor.onLoadAnimationCompleted();
Sunny Goyalb5b9ad62016-04-02 11:23:39 -07002323 }
2324 }
2325
Joe Onorato9c1289c2009-08-17 11:03:03 -04002326 /**
2327 * Callback saying that there aren't any more items to bind.
2328 *
2329 * Implementation of the method from LauncherModel.Callbacks.
2330 */
Tonyf80e8932018-12-21 11:58:04 -08002331 public void finishBindingItems(int pageBoundFirst) {
Sunny Goyalfca6bc92017-09-28 16:28:34 -07002332 TraceHelper.beginSection("finishBindingItems");
Adam Cohen1462de32012-07-24 22:34:36 -07002333 mWorkspace.restoreInstanceStateForRemainingPages();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002334
Anjali Koppalff7ceff2014-05-01 18:26:37 -07002335 setWorkspaceLoading(false);
Adam Cohendb364c32014-05-20 14:23:40 -07002336
Sunny Goyal2100c782016-08-22 16:00:03 -07002337 if (mPendingActivityResult != null) {
2338 handleActivityResult(mPendingActivityResult.requestCode,
2339 mPendingActivityResult.resultCode, mPendingActivityResult.data);
2340 mPendingActivityResult = null;
Adam Cohendb364c32014-05-20 14:23:40 -07002341 }
2342
Sunny Goyala474a9b2017-05-04 16:47:11 -07002343 InstallShortcutReceiver.disableAndFlushInstallQueue(
2344 InstallShortcutReceiver.FLAG_LOADER_RUNNING, this);
Adam Cohen9211d422014-10-07 18:14:53 -07002345
Tonyf80e8932018-12-21 11:58:04 -08002346 // When undoing the removal of the last item on a page, return to that page.
Tony Wickham03f27012019-04-25 14:22:54 -07002347 // Since we are just resetting the current page without user interaction,
2348 // override the previous page so we don't log the page switch.
2349 mWorkspace.setCurrentPage(pageBoundFirst, pageBoundFirst /* overridePrevPage */);
Tony Wickham6a71a5b2018-08-21 11:40:23 -07002350
Sunny Goyalac6f69f2019-08-16 11:59:55 -07002351 // Cache one page worth of icons
2352 getViewCache().setCacheSize(R.layout.folder_application,
2353 mDeviceProfile.inv.numFolderColumns * mDeviceProfile.inv.numFolderRows);
2354 getViewCache().setCacheSize(R.layout.folder_page, 2);
2355
Sunny Goyalfca6bc92017-09-28 16:28:34 -07002356 TraceHelper.endSection("finishBindingItems");
Winson Chungf0c6ae02012-03-21 16:10:31 -07002357 }
2358
Winson Chunga2413752012-04-03 14:22:34 -07002359 private boolean canRunNewAppsAnimation() {
2360 long diff = System.currentTimeMillis() - mDragController.getLastGestureUpTime();
Andrew Sapperstein932eb832016-06-30 18:10:09 -07002361 return diff > (NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS * 1000);
Winson Chunga2413752012-04-03 14:22:34 -07002362 }
2363
Winson Chungc9168342013-06-26 14:54:55 -07002364 private ValueAnimator createNewAppBounceAnimation(View v, int i) {
Sunny Goyalf0b6db72018-08-13 16:10:14 -07002365 ValueAnimator bounceAnim = new PropertyListBuilder().alpha(1).scale(1).build(v)
2366 .setDuration(InstallShortcutReceiver.NEW_SHORTCUT_BOUNCE_DURATION);
Winson Chungc9168342013-06-26 14:54:55 -07002367 bounceAnim.setStartDelay(i * InstallShortcutReceiver.NEW_SHORTCUT_STAGGER_DELAY);
Sunny Goyal5a1f53b2015-05-27 10:24:24 -07002368 bounceAnim.setInterpolator(new OvershootInterpolator(BOUNCE_ANIMATION_TENSION));
Winson Chungc9168342013-06-26 14:54:55 -07002369 return bounceAnim;
2370 }
2371
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002372 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04002373 * Add the icons for all apps.
2374 *
2375 * Implementation of the method from LauncherModel.Callbacks.
2376 */
Sunny Goyal87dcde62019-07-17 20:35:56 -07002377 public void bindAllApplications(AppInfo[] apps) {
Sunny Goyal60180b02018-02-07 12:56:30 -08002378 mAppsView.getAppsStore().setApps(apps);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002379 }
2380
2381 /**
Zak Cohen658c67a2018-10-19 14:21:05 -07002382 * Copies LauncherModel's map of activities to shortcut counts to Launcher's. This is necessary
Tony Wickhambfbf7f92016-05-19 11:19:39 -07002383 * because LauncherModel's map is updated in the background, while Launcher runs on the UI.
2384 */
2385 @Override
Zak Cohen658c67a2018-10-19 14:21:05 -07002386 public void bindDeepShortcutMap(HashMap<ComponentKey, Integer> deepShortcutMapCopy) {
Tony Wickham010d2552017-01-20 08:15:28 -08002387 mPopupDataProvider.setDeepShortcutMap(deepShortcutMapCopy);
Tony Wickham1bce7fd2016-04-28 17:39:03 -07002388 }
2389
Sunny Goyal4390ace2014-10-13 11:33:11 -07002390 @Override
Sunny Goyal29947f02017-12-18 13:49:44 -08002391 public void bindPromiseAppProgressUpdated(PromiseAppInfo app) {
Sunny Goyal60180b02018-02-07 12:56:30 -08002392 mAppsView.getAppsStore().updatePromiseAppProgress(app);
Mario Bertschler08ffaae2017-03-20 11:30:27 -07002393 }
2394
2395 @Override
Sunny Goyal29947f02017-12-18 13:49:44 -08002396 public void bindWidgetsRestored(ArrayList<LauncherAppWidgetInfo> widgets) {
Sunny Goyal4390ace2014-10-13 11:33:11 -07002397 mWorkspace.widgetsRestored(widgets);
2398 }
2399
Joe Onorato9c1289c2009-08-17 11:03:03 -04002400 /**
Sunny Goyalb50cc8c2014-10-06 16:23:56 -07002401 * Some shortcuts were updated in the background.
Sunny Goyalb50cc8c2014-10-06 16:23:56 -07002402 * Implementation of the method from LauncherModel.Callbacks.
Sunny Goyald3b87ef2016-07-28 12:11:54 -07002403 *
2404 * @param updated list of shortcuts which have changed.
Sunny Goyalb50cc8c2014-10-06 16:23:56 -07002405 */
Sunny Goyal4390ace2014-10-13 11:33:11 -07002406 @Override
Sunny Goyal95899162019-03-27 16:03:06 -07002407 public void bindWorkspaceItemsChanged(ArrayList<WorkspaceItemInfo> updated) {
Sunny Goyal4390ace2014-10-13 11:33:11 -07002408 if (!updated.isEmpty()) {
2409 mWorkspace.updateShortcuts(updated);
2410 }
Sunny Goyalb50cc8c2014-10-06 16:23:56 -07002411 }
2412
2413 /**
Chris Wrenaeff7ea2014-02-14 16:59:24 -05002414 * Update the state of a package, typically related to install state.
2415 *
2416 * Implementation of the method from LauncherModel.Callbacks.
2417 */
Sunny Goyale755d462014-07-22 13:48:29 -07002418 @Override
Sunny Goyal29947f02017-12-18 13:49:44 -08002419 public void bindRestoreItemsChange(HashSet<ItemInfo> updates) {
Sunny Goyal756adbc2015-04-16 15:20:51 -07002420 mWorkspace.updateRestoreItems(updates);
Sunny Goyala22666f2014-09-18 13:25:15 -07002421 }
2422
2423 /**
Sunny Goyal3bbbabc2016-03-15 09:16:30 -07002424 * A package was uninstalled/updated. We take both the super set of packageNames
Winson Chung83892cc2013-05-01 16:53:33 -07002425 * in addition to specific applications to remove, the reason being that
2426 * this can be called when a package is updated as well. In that scenario,
Sunny Goyal3bbbabc2016-03-15 09:16:30 -07002427 * we only remove specific components from the workspace and hotseat, where as
Winson Chung83892cc2013-05-01 16:53:33 -07002428 * package-removal should clear all items by package name.
Joe Onorato9c1289c2009-08-17 11:03:03 -04002429 */
Sunny Goyal1a745e82014-10-02 15:58:31 -07002430 @Override
Sunny Goyal6e13dd32017-08-17 03:01:19 -07002431 public void bindWorkspaceComponentsRemoved(final ItemInfoMatcher matcher) {
Sunny Goyal6e13dd32017-08-17 03:01:19 -07002432 mWorkspace.removeItemsByMatcher(matcher);
2433 mDragController.onAppsRemoved(matcher);
Sunny Goyal3bbbabc2016-03-15 09:16:30 -07002434 }
Sunny Goyal4390ace2014-10-13 11:33:11 -07002435
Sunny Goyal3bbbabc2016-03-15 09:16:30 -07002436 @Override
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -07002437 public void bindAllWidgets(final ArrayList<WidgetListRowEntry> allWidgets) {
2438 mPopupDataProvider.setAllWidgets(allWidgets);
Tony Wickham26b17462017-03-20 17:12:24 -07002439 }
2440
Tony Wickham86222d22017-03-29 15:30:43 -07002441 /**
2442 * @param packageUser if null, refreshes all widgets and shortcuts, otherwise only
2443 * refreshes the widgets and shortcuts associated with the given package/user
2444 */
2445 public void refreshAndBindWidgetsForPackageUser(@Nullable PackageUserKey packageUser) {
Sunny Goyalc6e97692017-06-02 13:46:55 -07002446 mModel.refreshAndBindWidgetsAndShortcuts(packageUser);
Sunny Goyal2e1efb42016-03-03 16:58:55 -08002447 }
2448
Winson Chung80baf5a2010-08-09 16:03:15 -07002449 /**
Hyunyoung Song3c7d9cb2017-01-30 15:11:27 -08002450 * $ adb shell dumpsys activity com.android.launcher3.Launcher [--all]
Joe Onoratobe386092009-11-17 17:32:16 -08002451 */
Adam Cohen16d7ffc2011-10-05 17:49:14 -07002452 @Override
2453 public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
2454 super.dump(prefix, fd, writer, args);
Sunny Goyala1365452015-10-01 15:46:24 -07002455
Hyunyoung Song3c7d9cb2017-01-30 15:11:27 -08002456 if (args.length > 0 && TextUtils.equals(args[0], "--all")) {
2457 writer.println(prefix + "Workspace Items");
Sunny Goyal7ce471b2017-08-02 03:37:39 -07002458 for (int i = 0; i < mWorkspace.getPageCount(); i++) {
Hyunyoung Song3c7d9cb2017-01-30 15:11:27 -08002459 writer.println(prefix + " Homescreen " + i);
2460
2461 ViewGroup layout = ((CellLayout) mWorkspace.getPageAt(i)).getShortcutsAndWidgets();
2462 for (int j = 0; j < layout.getChildCount(); j++) {
2463 Object tag = layout.getChildAt(j).getTag();
2464 if (tag != null) {
2465 writer.println(prefix + " " + tag.toString());
2466 }
2467 }
2468 }
2469
2470 writer.println(prefix + " Hotseat");
Sunny Goyal876e4622018-11-02 13:50:40 -07002471 ViewGroup layout = mHotseat.getShortcutsAndWidgets();
Sunny Goyala1365452015-10-01 15:46:24 -07002472 for (int j = 0; j < layout.getChildCount(); j++) {
2473 Object tag = layout.getChildAt(j).getTag();
2474 if (tag != null) {
2475 writer.println(prefix + " " + tag.toString());
2476 }
Adam Cohen4caf2982013-08-20 18:54:31 -07002477 }
Sunny Goyala1365452015-10-01 15:46:24 -07002478 }
2479
Hyunyoung Song3c7d9cb2017-01-30 15:11:27 -08002480 writer.println(prefix + "Misc:");
Winson Chungef528762019-09-06 12:05:52 -07002481 dumpMisc(prefix + "\t", writer);
2482 writer.println(prefix + "\tmWorkspaceLoading=" + mWorkspaceLoading);
2483 writer.println(prefix + "\tmPendingRequestArgs=" + mPendingRequestArgs
2484 + " mPendingActivityResult=" + mPendingActivityResult);
2485 writer.println(prefix + "\tmRotationHelper: " + mRotationHelper);
2486 writer.println(prefix + "\tmAppWidgetHost.isListening: " + mAppWidgetHost.isListening());
2487
Sunny Goyalcb2c5052018-10-15 12:30:29 -07002488 // Extra logging for b/116853349
Hyunyoung Songa310a802019-04-25 13:57:16 -07002489 mDragLayer.dump(prefix, writer);
2490 mStateManager.dump(prefix, writer);
Sunny Goyal2bba1902018-02-27 12:20:50 -08002491
2492 try {
2493 FileLog.flushAll(writer);
2494 } catch (Exception e) {
2495 // Ignore
2496 }
Hyunyoung Song3c7d9cb2017-01-30 15:11:27 -08002497
2498 mModel.dumpState(prefix, fd, writer, args);
Sunny Goyala1365452015-10-01 15:46:24 -07002499
Adam Cohen9211d422014-10-07 18:14:53 -07002500 if (mLauncherCallbacks != null) {
2501 mLauncherCallbacks.dump(prefix, fd, writer, args);
2502 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07002503 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07002504
Sunny Goyal66b24572016-09-21 15:57:55 -07002505 @Override
Sunny Goyal66b24572016-09-21 15:57:55 -07002506 public void onProvideKeyboardShortcuts(
2507 List<KeyboardShortcutGroup> data, Menu menu, int deviceId) {
2508
2509 ArrayList<KeyboardShortcutInfo> shortcutInfos = new ArrayList<>();
Sunny Goyal3e3f44c2017-10-23 17:14:52 -07002510 if (isInState(NORMAL)) {
Sunny Goyal66b24572016-09-21 15:57:55 -07002511 shortcutInfos.add(new KeyboardShortcutInfo(getString(R.string.all_apps_button_label),
2512 KeyEvent.KEYCODE_A, KeyEvent.META_CTRL_ON));
Vadim Tryshev74c261c2018-06-12 13:44:43 -07002513 shortcutInfos.add(new KeyboardShortcutInfo(getString(R.string.widget_button_text),
2514 KeyEvent.KEYCODE_W, KeyEvent.META_CTRL_ON));
Sunny Goyal66b24572016-09-21 15:57:55 -07002515 }
Vadim Tryshev3455f8d2018-05-11 20:02:20 -07002516 final View currentFocus = getCurrentFocus();
2517 if (currentFocus != null) {
2518 if (new CustomActionsPopup(this, currentFocus).canShow()) {
2519 shortcutInfos.add(new KeyboardShortcutInfo(getString(R.string.custom_actions),
2520 KeyEvent.KEYCODE_O, KeyEvent.META_CTRL_ON));
2521 }
2522 if (currentFocus.getTag() instanceof ItemInfo
Pinyao Ting49a3e692019-07-26 12:28:38 -07002523 && ShortcutUtil.supportsShortcuts((ItemInfo) currentFocus.getTag())) {
Vadim Tryshev3455f8d2018-05-11 20:02:20 -07002524 shortcutInfos.add(new KeyboardShortcutInfo(
2525 getString(R.string.shortcuts_menu_with_notifications_description),
2526 KeyEvent.KEYCODE_S, KeyEvent.META_CTRL_ON));
2527 }
Sunny Goyal66b24572016-09-21 15:57:55 -07002528 }
2529 if (!shortcutInfos.isEmpty()) {
2530 data.add(new KeyboardShortcutGroup(getString(R.string.home_screen), shortcutInfos));
2531 }
2532
2533 super.onProvideKeyboardShortcuts(data, menu, deviceId);
2534 }
2535
2536 @Override
2537 public boolean onKeyShortcut(int keyCode, KeyEvent event) {
2538 if (event.hasModifiers(KeyEvent.META_CTRL_ON)) {
2539 switch (keyCode) {
2540 case KeyEvent.KEYCODE_A:
Sunny Goyal3e3f44c2017-10-23 17:14:52 -07002541 if (isInState(NORMAL)) {
2542 getStateManager().goToState(ALL_APPS);
Sunny Goyal66b24572016-09-21 15:57:55 -07002543 return true;
2544 }
2545 break;
2546 case KeyEvent.KEYCODE_S: {
2547 View focusedView = getCurrentFocus();
2548 if (focusedView instanceof BubbleTextView
2549 && focusedView.getTag() instanceof ItemInfo
2550 && mAccessibilityDelegate.performAction(focusedView,
Samuel Fufaca37b8a2019-08-19 17:04:36 -07002551 (ItemInfo) focusedView.getTag(),
2552 LauncherAccessibilityDelegate.DEEP_SHORTCUTS)) {
Sunny Goyal00ac9202017-11-09 15:24:06 -08002553 PopupContainerWithArrow.getOpen(this).requestFocus();
Sunny Goyal66b24572016-09-21 15:57:55 -07002554 return true;
2555 }
2556 break;
2557 }
2558 case KeyEvent.KEYCODE_O:
2559 if (new CustomActionsPopup(this, getCurrentFocus()).show()) {
2560 return true;
2561 }
2562 break;
Vadim Tryshev74c261c2018-06-12 13:44:43 -07002563 case KeyEvent.KEYCODE_W:
2564 if (isInState(NORMAL)) {
2565 OptionsPopupView.openWidgets(this);
2566 return true;
2567 }
2568 break;
Sunny Goyal66b24572016-09-21 15:57:55 -07002569 }
2570 }
2571 return super.onKeyShortcut(keyCode, event);
2572 }
2573
Vadim Tryshev646a0dd2018-02-05 16:27:50 -08002574 @Override
2575 public boolean onKeyUp(int keyCode, KeyEvent event) {
2576 if (keyCode == KeyEvent.KEYCODE_MENU) {
2577 // KEYCODE_MENU is sent by some tests, for example
2578 // LauncherJankTests#testWidgetsContainerFling. Don't just remove its handling.
2579 if (!mDragController.isDragging() && !mWorkspace.isSwitchingState() &&
2580 isInState(NORMAL)) {
2581 // Close any open floating views.
2582 AbstractFloatingView.closeAllOpenViews(this);
2583
2584 // Setting the touch point to (-1, -1) will show the options popup in the center of
2585 // the screen.
Sunny Goyal2fd7a8b2018-03-30 17:10:13 -07002586 OptionsPopupView.showDefaultOptions(this, -1, -1);
Vadim Tryshev646a0dd2018-02-05 16:27:50 -08002587 }
2588 return true;
2589 }
2590 return super.onKeyUp(keyCode, event);
2591 }
2592
Andrew Sappersteinabef55a2016-06-19 12:49:00 -07002593 public static Launcher getLauncher(Context context) {
Sunny Goyal87b5eb62018-07-03 15:53:39 -07002594 return (Launcher) fromContext(context);
Andrew Sappersteinabef55a2016-06-19 12:49:00 -07002595 }
2596
Vinit Nayakf9b585b2019-07-10 14:25:32 -07002597 @Override
2598 public void returnToHomescreen() {
2599 super.returnToHomescreen();
2600 getStateManager().goToState(LauncherState.NORMAL);
2601 }
2602
Sunny Goyal3dce5f32017-10-05 11:40:05 -07002603 /**
Sunny Goyalab770a12018-11-14 15:17:26 -08002604 * Just a wrapper around the type cast to allow easier tracking of calls.
2605 */
2606 public static <T extends Launcher> T cast(ActivityContext activityContext) {
2607 return (T) activityContext;
2608 }
2609
2610 /**
Sunny Goyal3dce5f32017-10-05 11:40:05 -07002611 * Callback for listening for onResume
2612 */
2613 public interface OnResumeCallback {
2614
2615 void onLauncherResume();
2616 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002617}