blob: c5f593a9efd5c45a58834dcd886002f629f1fab1 [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
Jon Mirandaaeb4dd02018-07-11 14:16:23 -070019import static android.content.pm.ActivityInfo.CONFIG_LOCALE;
Sunny Goyalf8d56fc2018-01-31 15:18:11 -080020import static android.content.pm.ActivityInfo.CONFIG_ORIENTATION;
21import static android.content.pm.ActivityInfo.CONFIG_SCREEN_SIZE;
Tony Wickham6a71a5b2018-08-21 11:40:23 -070022import static com.android.launcher3.AbstractFloatingView.TYPE_SNACKBAR;
Sunny Goyal4c7f2152017-10-17 17:17:16 -070023import static com.android.launcher3.LauncherAnimUtils.SPRING_LOADED_EXIT_DELAY;
Sunny Goyal3e3f44c2017-10-23 17:14:52 -070024import static com.android.launcher3.LauncherState.ALL_APPS;
25import static com.android.launcher3.LauncherState.NORMAL;
Sunny Goyal6001ea22018-05-10 16:31:00 -070026import static com.android.launcher3.dragndrop.DragLayer.ALPHA_INDEX_LAUNCHER_LOAD;
Sunny Goyalaeb16432017-10-16 11:46:41 -070027import static com.android.launcher3.logging.LoggerUtils.newContainerTarget;
Hyunyoung Song46d07f72018-05-22 15:41:25 -070028import static com.android.launcher3.logging.LoggerUtils.newTarget;
Sunny Goyal326403e2017-10-02 12:45:10 -070029
Gilles Debunnedd6c9922010-10-25 11:23:41 -070030import android.animation.Animator;
Sunny Goyal6001ea22018-05-10 16:31:00 -070031import android.animation.AnimatorListenerAdapter;
Gilles Debunnedd6c9922010-10-25 11:23:41 -070032import android.animation.AnimatorSet;
Sunny Goyal6001ea22018-05-10 16:31:00 -070033import android.animation.ObjectAnimator;
Gilles Debunnedd6c9922010-10-25 11:23:41 -070034import android.animation.ValueAnimator;
Adam Cohen0b395352014-06-09 22:54:36 +000035import android.annotation.TargetApi;
Tony Wickham005df0b2018-02-13 11:28:12 -080036import android.app.ActivityOptions;
Adam Cohen0cf2a7c2011-11-08 15:07:01 -080037import android.appwidget.AppWidgetHostView;
Michael Jurkaaf442092010-06-10 17:01:57 -070038import android.appwidget.AppWidgetManager;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080039import android.content.ActivityNotFoundException;
Joe Onorato2ca0ae72009-11-10 13:14:13 -080040import android.content.BroadcastReceiver;
Michael Jurkae326f182011-11-21 14:05:46 -080041import android.content.ComponentCallbacks2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080042import android.content.Context;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080043import android.content.Intent;
Winson Chungf0ea4d32011-06-06 14:27:16 -070044import android.content.IntentFilter;
Adam Cohen173f7112015-03-27 15:14:00 -070045import android.content.IntentSender;
Winson Chung82f55532011-08-09 14:14:23 -070046import android.content.SharedPreferences;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080047import android.content.pm.PackageManager;
Sunny Goyalf8d56fc2018-01-31 15:18:11 -080048import android.content.res.Configuration;
Adam Cohen3f9c9712014-10-31 11:48:25 -070049import android.database.sqlite.SQLiteDatabase;
Sunny Goyal59d086c2018-05-07 17:31:40 -070050import android.graphics.Point;
Adam Cohen0f668f32014-09-08 19:54:17 +020051import android.os.Build;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080052import android.os.Bundle;
Hyunyoung Songbd6fba92018-05-16 15:54:31 -070053import android.os.Handler;
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -070054import android.os.Parcelable;
Sunny Goyal7c74e4a2016-12-15 15:53:17 -080055import android.os.Process;
Winson Chunga2413752012-04-03 14:22:34 -070056import android.os.StrictMode;
Sunny Goyala1d1bf32015-06-26 13:24:53 -070057import android.os.UserHandle;
Michael Jurkaa33411c2012-06-14 16:18:21 -070058import android.text.TextUtils;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080059import android.text.method.TextKeyListener;
Joe Onorato7c312c12009-08-13 21:36:53 -070060import android.util.Log;
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -070061import android.util.SparseArray;
Sunny Goyal59d086c2018-05-07 17:31:40 -070062import android.view.Display;
Adam Cohen96d30a12013-07-16 18:13:21 -070063import android.view.KeyEvent;
Sunny Goyal66b24572016-09-21 15:57:55 -070064import android.view.KeyboardShortcutGroup;
65import android.view.KeyboardShortcutInfo;
Sunny Goyal9b29ca52017-02-17 10:39:44 -080066import android.view.LayoutInflater;
Adam Cohen96d30a12013-07-16 18:13:21 -070067import android.view.Menu;
Adam Cohen96d30a12013-07-16 18:13:21 -070068import android.view.View;
Adam Cohen96d30a12013-07-16 18:13:21 -070069import android.view.ViewGroup;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -080070import android.view.accessibility.AccessibilityEvent;
Sunny Goyal5a1f53b2015-05-27 10:24:24 -070071import android.view.animation.OvershootInterpolator;
Adam Cohen96d30a12013-07-16 18:13:21 -070072import android.widget.Toast;
Sunny Goyala1d1bf32015-06-26 13:24:53 -070073
Sunny Goyal651077b2014-06-30 14:15:31 -070074import com.android.launcher3.DropTarget.DragObject;
Sunny Goyalae502842016-06-17 08:43:56 -070075import com.android.launcher3.accessibility.LauncherAccessibilityDelegate;
Winson Chung5f4e0fd2015-05-22 11:12:27 -070076import com.android.launcher3.allapps.AllAppsContainerView;
Hyunyoung Song645764e2016-06-06 14:19:02 -070077import com.android.launcher3.allapps.AllAppsTransitionController;
Sunny Goyal7ede6112017-12-05 15:11:21 -080078import com.android.launcher3.allapps.DiscoveryBounce;
Sunny Goyalf0b6db72018-08-13 16:10:14 -070079import com.android.launcher3.anim.PropertyListBuilder;
Sunny Goyal0b0847b2018-03-14 12:30:11 -070080import com.android.launcher3.badge.BadgeInfo;
Sunny Goyalffe83f12014-08-14 17:39:34 -070081import com.android.launcher3.compat.AppWidgetManagerCompat;
Sunny Goyal22ca9ec2017-05-18 15:03:13 -070082import com.android.launcher3.compat.LauncherAppsCompatVO;
Tony Wickhame0c33232016-02-08 11:37:04 -080083import com.android.launcher3.config.FeatureFlags;
Vadim Tryshevfedca432015-08-19 17:55:02 -070084import com.android.launcher3.dragndrop.DragController;
85import com.android.launcher3.dragndrop.DragLayer;
86import com.android.launcher3.dragndrop.DragView;
Jon Mirandaaeb4dd02018-07-11 14:16:23 -070087import com.android.launcher3.folder.Folder;
Sunny Goyal26119432016-02-18 22:09:23 +000088import com.android.launcher3.folder.FolderIcon;
Sunny Goyal0b0847b2018-03-14 12:30:11 -070089import com.android.launcher3.folder.FolderIconPreviewVerifier;
Sunny Goyalf840f102018-09-21 14:41:05 -070090import com.android.launcher3.icons.IconCache;
Sunny Goyal66b24572016-09-21 15:57:55 -070091import com.android.launcher3.keyboard.CustomActionsPopup;
Sunny Goyal3333b0c2016-05-09 20:43:21 -070092import com.android.launcher3.keyboard.ViewGroupFocusHelper;
Sunny Goyala7ce1662016-05-31 15:01:35 -070093import com.android.launcher3.logging.FileLog;
Hyunyoung Songaa953652016-04-19 18:30:24 -070094import com.android.launcher3.logging.UserEventDispatcher;
Hyunyoung Song46d07f72018-05-22 15:41:25 -070095import com.android.launcher3.logging.UserEventDispatcher.UserEventDelegate;
Sunny Goyala535ae42017-02-27 10:07:13 -080096import com.android.launcher3.model.ModelWriter;
Sunny Goyala535ae42017-02-27 10:07:13 -080097import com.android.launcher3.notification.NotificationListener;
Tony Wickham540913e2017-01-23 11:47:51 -080098import com.android.launcher3.popup.PopupContainerWithArrow;
Sunny Goyala535ae42017-02-27 10:07:13 -080099import com.android.launcher3.popup.PopupDataProvider;
Tony Wickham1bce7fd2016-04-28 17:39:03 -0700100import com.android.launcher3.shortcuts.DeepShortcutManager;
Sunny Goyalf8088ee2017-11-10 14:52:00 -0800101import com.android.launcher3.states.InternalStateHandler;
Sunny Goyal623eddd2018-03-02 12:24:41 -0800102import com.android.launcher3.states.RotationHelper;
Sunny Goyal8a2a63b2018-03-06 22:15:18 -0800103import com.android.launcher3.touch.ItemClickHandler;
Sunny Goyala5ace712017-11-15 17:12:51 -0800104import com.android.launcher3.uioverrides.UiFactory;
Hyunyoung Song46d07f72018-05-22 15:41:25 -0700105import com.android.launcher3.userevent.nano.LauncherLogProto;
Sunny Goyal6c46a6d2016-11-23 02:24:32 +0530106import com.android.launcher3.userevent.nano.LauncherLogProto.Action;
107import com.android.launcher3.userevent.nano.LauncherLogProto.ContainerType;
Sunny Goyalaeb16432017-10-16 11:46:41 -0700108import com.android.launcher3.userevent.nano.LauncherLogProto.Target;
Sunny Goyal2100c782016-08-22 16:00:03 -0700109import com.android.launcher3.util.ActivityResultInfo;
Winson Chung6b1c73f2015-06-18 11:38:42 -0700110import com.android.launcher3.util.ComponentKey;
Sunny Goyalefb7e842018-10-04 15:11:00 -0700111import com.android.launcher3.util.IntArray;
Sunny Goyald3b87ef2016-07-28 12:11:54 -0700112import com.android.launcher3.util.ItemInfoMatcher;
Tony Wickhambfbf7f92016-05-19 11:19:39 -0700113import com.android.launcher3.util.MultiHashMap;
Sunny Goyal6001ea22018-05-10 16:31:00 -0700114import com.android.launcher3.util.MultiValueAlpha;
115import com.android.launcher3.util.MultiValueAlpha.AlphaProperty;
Sunny Goyal04cc3a72016-05-17 10:32:43 -0700116import com.android.launcher3.util.PackageManagerHelper;
Tony Wickham010d2552017-01-20 08:15:28 -0800117import com.android.launcher3.util.PackageUserKey;
Sunny Goyal2100c782016-08-22 16:00:03 -0700118import com.android.launcher3.util.PendingRequestArgs;
Sunny Goyal8392c822017-06-20 10:03:56 -0700119import com.android.launcher3.util.SystemUiController;
Mario Bertschlera6936942017-05-31 14:48:19 -0700120import com.android.launcher3.util.Themes;
Adam Cohen091440a2015-03-18 14:16:05 -0700121import com.android.launcher3.util.Thunk;
Sunny Goyalfca6bc92017-09-28 16:28:34 -0700122import com.android.launcher3.util.TraceHelper;
Sunny Goyal326403e2017-10-02 12:45:10 -0700123import com.android.launcher3.util.UiThreadHelper;
Sunny Goyal527c7d32015-08-28 15:19:36 -0700124import com.android.launcher3.util.ViewOnDrawExecutor;
Sunny Goyal7c7be8c2018-03-07 19:58:07 -0800125import com.android.launcher3.views.OptionsPopupView;
Sunny Goyal29947f02017-12-18 13:49:44 -0800126import com.android.launcher3.widget.LauncherAppWidgetHostView;
Sunny Goyal782f0c92017-01-19 10:27:54 -0800127import com.android.launcher3.widget.PendingAddShortcutInfo;
Hyunyoung Song3f471442015-04-08 19:01:34 -0700128import com.android.launcher3.widget.PendingAddWidgetInfo;
Sunny Goyal29947f02017-12-18 13:49:44 -0800129import com.android.launcher3.widget.PendingAppWidgetHostView;
Sunny Goyal04a324a2017-01-20 21:08:59 -0800130import com.android.launcher3.widget.WidgetAddFlowHandler;
Hyunyoung Songb99ff3e2015-04-23 15:17:50 -0700131import com.android.launcher3.widget.WidgetHostViewLoader;
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -0700132import com.android.launcher3.widget.WidgetListRowEntry;
133import com.android.launcher3.widget.WidgetsFullSheet;
Sunny Goyal952e63d2017-08-16 04:59:08 -0700134import com.android.launcher3.widget.custom.CustomWidgetParser;
Adam Cohen6c5891a2014-07-09 23:53:15 -0700135
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700136import java.io.FileDescriptor;
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700137import java.io.PrintWriter;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700138import java.util.ArrayList;
Winson Chungf0c6ae02012-03-21 16:10:31 -0700139import java.util.Collection;
Sunny Goyal4390ace2014-10-13 11:33:11 -0700140import java.util.HashSet;
Michael Jurkad7c28052012-04-27 15:43:36 -0700141import java.util.List;
Tony Wickham010d2552017-01-20 08:15:28 -0800142import java.util.Set;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700143
Sunny Goyald2303072018-08-14 15:21:45 -0700144import androidx.annotation.Nullable;
145
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800146/**
147 * Default launcher application.
148 */
Hyunyoung Song46d07f72018-05-22 15:41:25 -0700149public class Launcher extends BaseDraggingActivity implements LauncherExterns,
150 LauncherModel.Callbacks, LauncherProviderChangeListener, UserEventDelegate{
Vadim Tryshevfedca432015-08-19 17:55:02 -0700151 public static final String TAG = "Launcher";
Sunny Goyal2bba4c32015-05-18 15:42:48 -0700152 static final boolean LOGD = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800153
Winson Chunga2413752012-04-03 14:22:34 -0700154 static final boolean DEBUG_STRICT_MODE = false;
Romain Guy6fefcf12009-06-11 13:07:43 -0700155
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800156 private static final int REQUEST_CREATE_SHORTCUT = 1;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700157 private static final int REQUEST_CREATE_APPWIDGET = 5;
Jon Mirandac476d6e2017-05-04 16:30:01 -0700158
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700159 private static final int REQUEST_PICK_APPWIDGET = 9;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800160
Michael Jurka8b805b12012-04-18 14:23:14 -0700161 private static final int REQUEST_BIND_APPWIDGET = 11;
Sunny Goyal8a2a63b2018-03-06 22:15:18 -0800162 public static final int REQUEST_BIND_PENDING_APPWIDGET = 12;
163 public static final int REQUEST_RECONFIGURE_APPWIDGET = 13;
Michael Jurka8b805b12012-04-18 14:23:14 -0700164
Jon Mirandac476d6e2017-05-04 16:30:01 -0700165 private static final int REQUEST_PERMISSION_CALL_PHONE = 14;
Sunny Goyal28c6b962015-10-12 11:42:05 -0700166
Sunny Goyal5a1f53b2015-05-27 10:24:24 -0700167 private static final float BOUNCE_ANIMATION_TENSION = 1.3f;
168
Mathew Inwood876a8462013-06-14 14:12:41 +0100169 /**
170 * IntentStarter uses request codes starting with this. This must be greater than all activity
171 * request codes used internally.
172 */
173 protected static final int REQUEST_LAST = 100;
174
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800175 // Type: int
176 private static final String RUNTIME_STATE_CURRENT_SCREEN = "launcher.current_screen";
Michael Jurka883f55b2010-10-21 15:47:14 -0700177 // Type: int
178 private static final String RUNTIME_STATE = "launcher.state";
Sunny Goyal2100c782016-08-22 16:00:03 -0700179 // Type: PendingRequestArgs
180 private static final String RUNTIME_STATE_PENDING_REQUEST_ARGS = "launcher.request_args";
181 // Type: ActivityResultInfo
182 private static final String RUNTIME_STATE_PENDING_ACTIVITY_RESULT = "launcher.activity_result";
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -0700183 // Type: SparseArray<Parcelable>
184 private static final String RUNTIME_STATE_WIDGET_PANEL = "launcher.widget_panel";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800185
Sunny Goyal3e3f44c2017-10-23 17:14:52 -0700186 private LauncherStateManager mStateManager;
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700187
Adam Cohenad4e15c2013-10-17 16:21:35 -0700188 private static final int ON_ACTIVITY_RESULT_ANIMATION_DELAY = 500;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800189
Winson Chunga2413752012-04-03 14:22:34 -0700190 // How long to wait before the new-shortcut animation automatically pans the workspace
Rajeev Kumar43c0f582017-06-23 15:34:55 -0700191 private static final int NEW_APPS_PAGE_MOVE_DELAY = 500;
192 private static final int NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS = 5;
193 @Thunk static final int NEW_APPS_ANIMATION_DELAY = 500;
Winson Chunga2413752012-04-03 14:22:34 -0700194
Jon Miranda54441f52018-01-24 15:38:25 -0800195 private LauncherAppTransitionManager mAppTransitionManager;
Sunny Goyalf8d56fc2018-01-31 15:18:11 -0800196 private Configuration mOldConfig;
Jon Miranda54441f52018-01-24 15:38:25 -0800197
Adam Cohen091440a2015-03-18 14:16:05 -0700198 @Thunk Workspace mWorkspace;
Craig Mautner360310b2012-10-26 15:13:08 -0700199 private View mLauncherView;
Adam Cohen091440a2015-03-18 14:16:05 -0700200 @Thunk DragLayer mDragLayer;
Michael Jurkab737ee62011-11-15 15:57:22 -0800201 private DragController mDragController;
Sunny Goyal322d5562015-06-25 19:35:49 -0700202
Sunny Goyalffe83f12014-08-14 17:39:34 -0700203 private AppWidgetManagerCompat mAppWidgetManager;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700204 private LauncherAppWidgetHost mAppWidgetHost;
Romain Guycbb89e42009-06-08 15:52:54 -0700205
Rajeev Kumar43c0f582017-06-23 15:34:55 -0700206 private final int[] mTmpAddItemCellCoordinates = new int[2];
Michael Jurka0280c3b2010-09-17 15:00:07 -0700207
Sunny Goyal316490e2015-06-02 09:38:28 -0700208 @Thunk Hotseat mHotseat;
Sunny Goyal81b4c7b2018-03-26 12:10:31 -0700209 @Nullable private View mHotseatSearchBox;
Adam Cohenf358a4b2013-07-23 16:47:31 -0700210
Sunny Goyal47328fd2016-05-25 18:56:41 -0700211 private DropTargetBar mDropTargetBar;
Hyunyoung Song3f471442015-04-08 19:01:34 -0700212
213 // Main container view for the all apps screen.
Winson Chung5f4e0fd2015-05-22 11:12:27 -0700214 @Thunk AllAppsContainerView mAppsView;
Hyunyoung Song645764e2016-06-06 14:19:02 -0700215 AllAppsTransitionController mAllAppsController;
Hyunyoung Song3f471442015-04-08 19:01:34 -0700216
Winson Chung8ae41982017-11-10 11:42:13 -0800217 // UI and state for the overview panel
Sunny Goyal7c7be8c2018-03-07 19:58:07 -0800218 private View mOverviewPanel;
Winson Chung8ae41982017-11-10 11:42:13 -0800219
Adam Cohen091440a2015-03-18 14:16:05 -0700220 @Thunk boolean mWorkspaceLoading = true;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400221
Sunny Goyal3dce5f32017-10-05 11:40:05 -0700222 private OnResumeCallback mOnResumeCallback;
223
Sunny Goyal527c7d32015-08-28 15:19:36 -0700224 private ViewOnDrawExecutor mPendingExecutor;
Michael Jurka7607c2f2013-04-03 14:33:19 -0700225
Joe Onorato9c1289c2009-08-17 11:03:03 -0400226 private LauncherModel mModel;
Sunny Goyal43bf11d2017-02-02 13:52:53 -0800227 private ModelWriter mModelWriter;
Joe Onorato0589f0f2010-02-08 13:44:00 -0800228 private IconCache mIconCache;
Sunny Goyalae502842016-06-17 08:43:56 -0700229 private LauncherAccessibilityDelegate mAccessibilityDelegate;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400230
Tony Wickham010d2552017-01-20 08:15:28 -0800231 private PopupDataProvider mPopupDataProvider;
Tony Wickhambfbf7f92016-05-19 11:19:39 -0700232
Sunny Goyalf4aceab2017-12-06 16:16:31 -0800233 private int mSynchronouslyBoundPage = PagedView.INVALID_PAGE;
Adam Cohen1462de32012-07-24 22:34:36 -0700234
Winson Chung46353de2012-02-16 14:05:10 -0800235 // We only want to get the SharedPreferences once since it does an FS stat each time we get
236 // it from the context.
237 private SharedPreferences mSharedPrefs;
238
Sunny Goyal2100c782016-08-22 16:00:03 -0700239 // Activity result which needs to be processed after workspace has loaded.
240 private ActivityResultInfo mPendingActivityResult;
241 /**
242 * Holds extra information required to handle a result from an external call, like
243 * {@link #startActivityForResult(Intent, int)} or {@link #requestPermissions(String[], int)}
244 */
245 private PendingRequestArgs mPendingRequestArgs;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800246
Sunny Goyal3333b0c2016-05-09 20:43:21 -0700247 public ViewGroupFocusHelper mFocusHandler;
Hyunyoung Song7fb3ccc2017-10-17 15:39:46 -0700248
Sunny Goyal623eddd2018-03-02 12:24:41 -0800249 private RotationHelper mRotationHelper;
Sunny Goyal7779d622015-06-11 16:18:39 -0700250
Hyunyoung Songbd6fba92018-05-16 15:54:31 -0700251
252 private final Handler mHandler = new Handler();
253 private final Runnable mLogOnDelayedResume = this::logOnDelayedResume;
254
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800255 @Override
256 protected void onCreate(Bundle savedInstanceState) {
Winson Chunga2413752012-04-03 14:22:34 -0700257 if (DEBUG_STRICT_MODE) {
258 StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
259 .detectDiskReads()
260 .detectDiskWrites()
261 .detectNetwork() // or .detectAll() for all detectable problems
262 .penaltyLog()
263 .build());
264 StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
265 .detectLeakedSqlLiteObjects()
266 .detectLeakedClosableObjects()
267 .penaltyLog()
268 .penaltyDeath()
269 .build());
270 }
Sunny Goyalfca6bc92017-09-28 16:28:34 -0700271 TraceHelper.beginSection("Launcher-onCreate");
Winson Chunga2413752012-04-03 14:22:34 -0700272
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800273 super.onCreate(savedInstanceState);
Sunny Goyalfca6bc92017-09-28 16:28:34 -0700274 TraceHelper.partitionSection("Launcher-onCreate", "super call");
Daniel Sandlere060b0b2013-06-27 21:47:55 -0400275
Sunny Goyal87f784c2017-01-11 10:48:34 -0800276 LauncherAppState app = LauncherAppState.getInstance(this);
Sunny Goyalf8d56fc2018-01-31 15:18:11 -0800277 mOldConfig = new Configuration(getResources().getConfiguration());
Sunny Goyal0e7724c2018-02-22 13:22:21 -0800278 mModel = app.setLauncher(this);
Sunny Goyalf8d56fc2018-01-31 15:18:11 -0800279 initDeviceProfile(app.getInvariantDeviceProfile());
Winson Chung6e1c0d32013-10-25 15:24:24 -0700280
Sunny Goyalf7258242015-10-19 16:59:07 -0700281 mSharedPrefs = Utilities.getPrefs(this);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800282 mIconCache = app.getIconCache();
Sunny Goyalae502842016-06-17 08:43:56 -0700283 mAccessibilityDelegate = new LauncherAccessibilityDelegate(this);
Adam Cohen2e6da152015-05-06 11:42:25 -0700284
Joe Onorato41a12d22009-10-31 18:30:00 -0400285 mDragController = new DragController(this);
Hyunyoung Song645764e2016-06-06 14:19:02 -0700286 mAllAppsController = new AllAppsTransitionController(this);
Sunny Goyalc4fa8c32017-11-07 12:23:58 -0800287 mStateManager = new LauncherStateManager(this);
Tracy Zhou8b23c6f2018-04-30 17:13:27 -0700288 UiFactory.onCreate(this);
Romain Guycbb89e42009-06-08 15:52:54 -0700289
Sunny Goyalffe83f12014-08-14 17:39:34 -0700290 mAppWidgetManager = AppWidgetManagerCompat.getInstance(this);
Adam Cohen53805212013-10-01 10:39:23 -0700291
Sunny Goyal64a75aa2017-07-03 13:50:52 -0700292 mAppWidgetHost = new LauncherAppWidgetHost(this);
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700293 mAppWidgetHost.startListening();
Romain Guycbb89e42009-06-08 15:52:54 -0700294
Sunny Goyal60820d72017-05-09 12:40:11 -0700295 mLauncherView = LayoutInflater.from(this).inflate(R.layout.launcher, null);
Michael Jurka7267fa52013-09-26 15:29:57 -0700296
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800297 setupViews();
Tony Wickham010d2552017-01-20 08:15:28 -0800298 mPopupDataProvider = new PopupDataProvider(this);
299
Sunny Goyal623eddd2018-03-02 12:24:41 -0800300 mRotationHelper = new RotationHelper(this);
Sunny Goyal90548432018-04-04 17:17:00 -0700301 mAppTransitionManager = LauncherAppTransitionManager.newInstance(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800302
Sunny Goyald3864fa2017-11-14 15:06:36 -0800303 boolean internalStateHandled = InternalStateHandler.handleCreate(this, getIntent());
304 if (internalStateHandled) {
Sunny Goyald3864fa2017-11-14 15:06:36 -0800305 if (savedInstanceState != null) {
306 // InternalStateHandler has already set the appropriate state.
307 // We dont need to do anything.
308 savedInstanceState.remove(RUNTIME_STATE);
309 }
310 }
311 restoreState(savedInstanceState);
Winson Chungb63b44c2017-11-10 17:54:44 -0800312
Sunny Goyal2100c782016-08-22 16:00:03 -0700313 // We only load the page synchronously if the user rotates (or triggers a
314 // configuration change) while launcher is in the foreground
Sunny Goyalfe770c92016-09-27 14:38:58 -0700315 int currentScreen = PagedView.INVALID_RESTORE_PAGE;
316 if (savedInstanceState != null) {
317 currentScreen = savedInstanceState.getInt(RUNTIME_STATE_CURRENT_SCREEN, currentScreen);
318 }
Sunny Goyald3864fa2017-11-14 15:06:36 -0800319
Sunny Goyalfe770c92016-09-27 14:38:58 -0700320 if (!mModel.startLoader(currentScreen)) {
Sunny Goyald3864fa2017-11-14 15:06:36 -0800321 if (!internalStateHandled) {
322 // If we are not binding synchronously, show a fade in animation when
323 // the first page bind completes.
Sunny Goyal6001ea22018-05-10 16:31:00 -0700324 mDragLayer.getAlphaProperty(ALPHA_INDEX_LAUNCHER_LOAD).setValue(0);
Sunny Goyald3864fa2017-11-14 15:06:36 -0800325 }
Sunny Goyal2100c782016-08-22 16:00:03 -0700326 } else {
Sunny Goyalfe770c92016-09-27 14:38:58 -0700327 // Pages bound synchronously.
328 mWorkspace.setCurrentPage(currentScreen);
329
Sunny Goyal2100c782016-08-22 16:00:03 -0700330 setWorkspaceLoading(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800331 }
332
333 // For handling default keys
Sunny Goyalf4aceab2017-12-06 16:16:31 -0800334 setDefaultKeyMode(DEFAULT_KEYS_SEARCH_LOCAL);
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800335
Sunny Goyal0bbd5542016-11-11 10:41:26 -0800336 setContentView(mLauncherView);
Sunny Goyalf8d56fc2018-01-31 15:18:11 -0800337 getRootView().dispatchInsets();
Mario Bertschlera6936942017-05-31 14:48:19 -0700338
Jon Miranda7fda2852017-07-19 16:07:01 -0700339 // Listen for broadcasts
Sunny Goyal5d1873a2018-05-08 11:10:44 -0700340 registerReceiver(mScreenOffReceiver, new IntentFilter(Intent.ACTION_SCREEN_OFF));
Sunny Goyala616d2b2017-06-12 13:54:01 -0700341
Sunny Goyal8392c822017-06-20 10:03:56 -0700342 getSystemUiController().updateUiState(SystemUiController.UI_STATE_BASE_WINDOW,
343 Themes.getAttrBoolean(this, R.attr.isWorkspaceDarkText));
Sunny Goyal14b32402017-07-31 10:03:28 -0700344
345 if (mLauncherCallbacks != null) {
346 mLauncherCallbacks.onCreate(savedInstanceState);
347 }
Sunny Goyal623eddd2018-03-02 12:24:41 -0800348 mRotationHelper.initialize();
Sunny Goyalfca6bc92017-09-28 16:28:34 -0700349
350 TraceHelper.endSection("Launcher-onCreate");
Adam Cohen9211d422014-10-07 18:14:53 -0700351 }
352
Sunny Goyal7779d622015-06-11 16:18:39 -0700353 @Override
Winson Chung8eb49e02018-07-16 13:33:31 -0700354 public void onEnterAnimationComplete() {
355 super.onEnterAnimationComplete();
356 UiFactory.onEnterAnimationComplete(this);
arangelovad783052018-08-17 14:46:45 +0100357 mAllAppsController.highlightWorkTabIfNecessary();
Winson Chung8eb49e02018-07-16 13:33:31 -0700358 }
359
360 @Override
Sunny Goyalf8d56fc2018-01-31 15:18:11 -0800361 public void onConfigurationChanged(Configuration newConfig) {
362 int diff = newConfig.diff(mOldConfig);
Jon Mirandaaeb4dd02018-07-11 14:16:23 -0700363
364 if ((diff & CONFIG_LOCALE) != 0) {
365 Folder.setLocaleDependentFields(getResources(), true /* force */);
366 }
367
Sunny Goyalf8d56fc2018-01-31 15:18:11 -0800368 if ((diff & (CONFIG_ORIENTATION | CONFIG_SCREEN_SIZE)) != 0) {
369 mUserEventDispatcher = null;
370 initDeviceProfile(mDeviceProfile.inv);
Sunny Goyalfde55052018-02-01 14:46:13 -0800371 dispatchDeviceProfileChanged();
Sunny Goyal59d086c2018-05-07 17:31:40 -0700372 reapplyUi();
Sunny Goyal5d1873a2018-05-08 11:10:44 -0700373 mDragLayer.recreateControllers();
Sunny Goyal7185dd62018-03-14 17:51:49 -0700374
Sunny Goyalf8d56fc2018-01-31 15:18:11 -0800375 // TODO: We can probably avoid rebind when only screen size changed.
Sunny Goyal605bcf32018-03-02 15:16:12 -0800376 rebindModel();
Sunny Goyalf8d56fc2018-01-31 15:18:11 -0800377 }
378
379 mOldConfig.setTo(newConfig);
Tracy Zhoua706f002018-03-28 13:55:19 -0700380 UiFactory.onLauncherStateOrResumeChanged(this);
Sunny Goyalf8d56fc2018-01-31 15:18:11 -0800381 super.onConfigurationChanged(newConfig);
382 }
383
Sunny Goyal605bcf32018-03-02 15:16:12 -0800384 @Override
Sunny Goyal59d086c2018-05-07 17:31:40 -0700385 protected void reapplyUi() {
386 getRootView().dispatchInsets();
387 getStateManager().reapplyState(true /* cancelCurrentAnimation */);
388 }
389
390 @Override
Sunny Goyal605bcf32018-03-02 15:16:12 -0800391 public void rebindModel() {
392 int currentPage = mWorkspace.getNextPage();
393 if (mModel.startLoader(currentPage)) {
394 mWorkspace.setCurrentPage(currentPage);
395 setWorkspaceLoading(true);
396 }
397 }
398
Sunny Goyalf8d56fc2018-01-31 15:18:11 -0800399 private void initDeviceProfile(InvariantDeviceProfile idp) {
400 // Load configuration-specific DeviceProfile
Sunny Goyal59d086c2018-05-07 17:31:40 -0700401 mDeviceProfile = idp.getDeviceProfile(this);
402 if (isInMultiWindowModeCompat()) {
403 Display display = getWindowManager().getDefaultDisplay();
404 Point mwSize = new Point();
405 display.getSize(mwSize);
406 mDeviceProfile = mDeviceProfile.getMultiWindowProfile(this, mwSize);
407 }
408 onDeviceProfileInitiated();
Sunny Goyal605bcf32018-03-02 15:16:12 -0800409 mModelWriter = mModel.getWriter(mDeviceProfile.isVerticalBarLayout(), true);
Sunny Goyalf8d56fc2018-01-31 15:18:11 -0800410 }
411
Sunny Goyal623eddd2018-03-02 12:24:41 -0800412 public RotationHelper getRotationHelper() {
413 return mRotationHelper;
414 }
415
Sunny Goyal3e3f44c2017-10-23 17:14:52 -0700416 public LauncherStateManager getStateManager() {
417 return mStateManager;
Sunny Goyalbe93f262017-10-20 17:05:27 -0700418 }
419
Mario Bertschler27288382017-05-24 15:35:09 -0700420 @Override
Sunny Goyalc7b8df82017-06-27 11:11:03 -0700421 public <T extends View> T findViewById(int id) {
Sunny Goyal0bbd5542016-11-11 10:41:26 -0800422 return mLauncherView.findViewById(id);
423 }
424
425 @Override
Sunny Goyal2e013ea2016-10-07 16:17:19 -0700426 public void onAppWidgetHostReset() {
427 if (mAppWidgetHost != null) {
428 mAppWidgetHost.startListening();
429 }
430 }
431
Adam Cohen9211d422014-10-07 18:14:53 -0700432 private LauncherCallbacks mLauncherCallbacks;
433
Sunny Goyal32554d12015-12-03 15:31:25 -0800434 /**
435 * Call this after onCreate to set or clear overlay.
436 */
437 public void setLauncherOverlay(LauncherOverlay overlay) {
438 if (overlay != null) {
439 overlay.setOverlayCallbacks(new LauncherOverlayCallbacksImpl());
440 }
441 mWorkspace.setLauncherOverlay(overlay);
442 }
443
Adam Cohen9211d422014-10-07 18:14:53 -0700444 public boolean setLauncherCallbacks(LauncherCallbacks callbacks) {
445 mLauncherCallbacks = callbacks;
446 return true;
Adam Cohenf9426d52012-06-04 17:26:21 -0700447 }
448
Anjali Koppal67e7cae2014-03-13 12:14:12 -0700449 @Override
Sunny Goyal2e013ea2016-10-07 16:17:19 -0700450 public void onLauncherProviderChanged() {
Adam Cohen9211d422014-10-07 18:14:53 -0700451 if (mLauncherCallbacks != null) {
452 mLauncherCallbacks.onLauncherProviderChange();
453 }
454 }
Anjali Koppal67e7cae2014-03-13 12:14:12 -0700455
Hyunyoung Song3f471442015-04-08 19:01:34 -0700456 public boolean isDraggingEnabled() {
Winson Chung36a62fe2012-05-06 18:04:42 -0700457 // We prevent dragging when we are loading the workspace as it is possible to pick up a view
458 // that is subsequently removed from the workspace in startBinding().
Sunny Goyal639e9062015-08-19 19:17:06 -0700459 return !isWorkspaceLoading();
Winson Chung36a62fe2012-05-06 18:04:42 -0700460 }
461
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000462 public int getViewIdForItem(ItemInfo info) {
Sunny Goyale2fd14b2015-08-27 17:45:46 -0700463 // aapt-generated IDs have the high byte nonzero; clamp to the range under that.
464 // This cast is safe as long as the id < 0x00FFFFFF
465 // Since we jail all the dynamically generated views, there should be no clashes
466 // with any other views.
467 return (int) info.id;
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000468 }
469
Tony Wickham010d2552017-01-20 08:15:28 -0800470 public PopupDataProvider getPopupDataProvider() {
471 return mPopupDataProvider;
472 }
473
Sunny Goyal0b0847b2018-03-14 12:30:11 -0700474 @Override
475 public BadgeInfo getBadgeInfoForItem(ItemInfo info) {
476 return mPopupDataProvider.getBadgeInfoForItem(info);
477 }
478
479 @Override
480 public void invalidateParent(ItemInfo info) {
481 FolderIconPreviewVerifier verifier = new FolderIconPreviewVerifier(getDeviceProfile().inv);
482 if (verifier.isItemInPreview(info.rank) && (info.container >= 0)) {
483 View folderIcon = getWorkspace().getHomescreenIconByItemId(info.container);
484 if (folderIcon != null) {
485 folderIcon.invalidate();
486 }
487 }
488 }
489
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000490 /**
Winson Chung557d6ed2011-07-08 15:34:52 -0700491 * Returns whether we should delay spring loaded mode -- for shortcuts and widgets that have
492 * a configuration step, this allows the proper animations to run after other transitions.
493 */
Sunny Goyalefb7e842018-10-04 15:11:00 -0700494 private int completeAdd(
Sunny Goyal2100c782016-08-22 16:00:03 -0700495 int requestCode, Intent intent, int appWidgetId, PendingRequestArgs info) {
Sunny Goyalefb7e842018-10-04 15:11:00 -0700496 int screenId = info.screenId;
Sunny Goyal2100c782016-08-22 16:00:03 -0700497 if (info.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
Adam Cohen83079e42014-09-19 17:43:08 -0700498 // When the screen id represents an actual screen (as opposed to a rank) we make sure
499 // that the drop page actually exists.
Sunny Goyal2100c782016-08-22 16:00:03 -0700500 screenId = ensurePendingDropLayoutExists(info.screenId);
Adam Cohen83079e42014-09-19 17:43:08 -0700501 }
Adam Cohendb364c32014-05-20 14:23:40 -0700502
Sunny Goyal2100c782016-08-22 16:00:03 -0700503 switch (requestCode) {
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800504 case REQUEST_CREATE_SHORTCUT:
Sunny Goyalfb5096d2016-09-08 14:32:06 -0700505 completeAddShortcut(intent, info.container, screenId, info.cellX, info.cellY, info);
Winson Chungb8472bb2011-08-05 13:49:21 -0700506 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800507 case REQUEST_CREATE_APPWIDGET:
Sunny Goyal2100c782016-08-22 16:00:03 -0700508 completeAddAppWidget(appWidgetId, info, null, null);
Winson Chungb8472bb2011-08-05 13:49:21 -0700509 break;
Sunny Goyalff572272014-07-23 13:58:07 -0700510 case REQUEST_RECONFIGURE_APPWIDGET:
Sunny Goyal2100c782016-08-22 16:00:03 -0700511 completeRestoreAppWidget(appWidgetId, LauncherAppWidgetInfo.RESTORE_COMPLETED);
Sunny Goyalff572272014-07-23 13:58:07 -0700512 break;
Sunny Goyald478c832016-04-01 12:04:16 -0700513 case REQUEST_BIND_PENDING_APPWIDGET: {
Sunny Goyal2100c782016-08-22 16:00:03 -0700514 int widgetId = appWidgetId;
515 LauncherAppWidgetInfo widgetInfo =
Sunny Goyald478c832016-04-01 12:04:16 -0700516 completeRestoreAppWidget(widgetId, LauncherAppWidgetInfo.FLAG_UI_NOT_READY);
Sunny Goyal2100c782016-08-22 16:00:03 -0700517 if (widgetInfo != null) {
Sunny Goyald478c832016-04-01 12:04:16 -0700518 // Since the view was just bound, also launch the configure activity if needed
519 LauncherAppWidgetProviderInfo provider = mAppWidgetManager
520 .getLauncherAppWidgetInfo(widgetId);
Sunny Goyal04a324a2017-01-20 21:08:59 -0800521 if (provider != null) {
522 new WidgetAddFlowHandler(provider)
523 .startConfigActivity(this, widgetInfo, REQUEST_RECONFIGURE_APPWIDGET);
Sunny Goyald478c832016-04-01 12:04:16 -0700524 }
525 }
526 break;
527 }
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800528 }
Sunny Goyal2100c782016-08-22 16:00:03 -0700529
Adam Cohendb364c32014-05-20 14:23:40 -0700530 return screenId;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800531 }
532
Adam Cohenc7cd2cb2014-11-17 17:45:34 -0800533 private void handleActivityResult(
Michael Jurka8b805b12012-04-18 14:23:14 -0700534 final int requestCode, final int resultCode, final Intent data) {
Sunny Goyal2100c782016-08-22 16:00:03 -0700535 if (isWorkspaceLoading()) {
536 // process the result once the workspace has loaded.
537 mPendingActivityResult = new ActivityResultInfo(requestCode, resultCode, data);
538 return;
539 }
540 mPendingActivityResult = null;
541
Winson Chunge341d302013-08-16 14:31:00 -0700542 // Reset the startActivity waiting flag
Sunny Goyal2100c782016-08-22 16:00:03 -0700543 final PendingRequestArgs requestArgs = mPendingRequestArgs;
544 setWaitingForResult(null);
545 if (requestArgs == null) {
546 return;
547 }
548
549 final int pendingAddWidgetId = requestArgs.getWidgetId();
Winson Chunge341d302013-08-16 14:31:00 -0700550
Adam Cohenad4e15c2013-10-17 16:21:35 -0700551 Runnable exitSpringLoaded = new Runnable() {
552 @Override
553 public void run() {
Sunny Goyal3e3f44c2017-10-23 17:14:52 -0700554 mStateManager.goToState(NORMAL, SPRING_LOADED_EXIT_DELAY);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700555 }
556 };
557
Michael Jurka8b805b12012-04-18 14:23:14 -0700558 if (requestCode == REQUEST_BIND_APPWIDGET) {
Winsona1f79d32015-08-05 14:00:45 -0700559 // This is called only if the user did not previously have permissions to bind widgets
Adam Cohenad4e15c2013-10-17 16:21:35 -0700560 final int appWidgetId = data != null ?
Michael Jurka8b805b12012-04-18 14:23:14 -0700561 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
562 if (resultCode == RESULT_CANCELED) {
Sunny Goyal2100c782016-08-22 16:00:03 -0700563 completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId, requestArgs);
Adam Cohen689ff162014-05-08 17:27:56 -0700564 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
Adam Cohenad4e15c2013-10-17 16:21:35 -0700565 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
Michael Jurka8b805b12012-04-18 14:23:14 -0700566 } else if (resultCode == RESULT_OK) {
Sunny Goyal2100c782016-08-22 16:00:03 -0700567 addAppWidgetImpl(
568 appWidgetId, requestArgs, null,
Sunny Goyal04a324a2017-01-20 21:08:59 -0800569 requestArgs.getWidgetHandler(),
Sunny Goyal2100c782016-08-22 16:00:03 -0700570 ON_ACTIVITY_RESULT_ANIMATION_DELAY);
Michael Jurka8b805b12012-04-18 14:23:14 -0700571 }
572 return;
573 }
Michael Jurka336fd4f2013-09-12 00:05:02 +0200574
Adam Cohened66b2b2012-01-23 17:28:51 -0800575 boolean isWidgetDrop = (requestCode == REQUEST_PICK_APPWIDGET ||
Sunny Goyal5c97f512015-05-19 16:03:28 -0700576 requestCode == REQUEST_CREATE_APPWIDGET);
Romain Guyaad5ef42009-06-10 02:48:37 -0700577
Adam Cohened66b2b2012-01-23 17:28:51 -0800578 // We have special handling for widgets
579 if (isWidgetDrop) {
Adam Cohen4637b5a2013-11-04 18:21:24 -0800580 final int appWidgetId;
581 int widgetId = data != null ? data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1)
582 : -1;
583 if (widgetId < 0) {
584 appWidgetId = pendingAddWidgetId;
585 } else {
586 appWidgetId = widgetId;
587 }
588
Adam Cohenad4e15c2013-10-17 16:21:35 -0700589 final int result;
Adam Cohenf0129b12013-11-04 17:57:36 -0800590 if (appWidgetId < 0 || resultCode == RESULT_CANCELED) {
Adam Cohendb364c32014-05-20 14:23:40 -0700591 Log.e(TAG, "Error: appWidgetId (EXTRA_APPWIDGET_ID) was not " +
592 "returned from the widget configuration activity.");
Adam Cohenad4e15c2013-10-17 16:21:35 -0700593 result = RESULT_CANCELED;
Sunny Goyal2100c782016-08-22 16:00:03 -0700594 completeTwoStageWidgetDrop(result, appWidgetId, requestArgs);
Adam Cohendb364c32014-05-20 14:23:40 -0700595 final Runnable onComplete = new Runnable() {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700596 @Override
597 public void run() {
Sunny Goyal3e3f44c2017-10-23 17:14:52 -0700598 getStateManager().goToState(NORMAL);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700599 }
600 };
Adam Cohendb364c32014-05-20 14:23:40 -0700601
Sunny Goyal2100c782016-08-22 16:00:03 -0700602 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete,
603 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
604 } else {
605 if (requestArgs.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
606 // When the screen id represents an actual screen (as opposed to a rank)
607 // we make sure that the drop page actually exists.
608 requestArgs.screenId =
609 ensurePendingDropLayoutExists(requestArgs.screenId);
Adam Cohendb364c32014-05-20 14:23:40 -0700610 }
Sunny Goyal2100c782016-08-22 16:00:03 -0700611 final CellLayout dropLayout =
612 mWorkspace.getScreenWithId(requestArgs.screenId);
613
614 dropLayout.setDropPending(true);
615 final Runnable onComplete = new Runnable() {
616 @Override
617 public void run() {
618 completeTwoStageWidgetDrop(resultCode, appWidgetId, requestArgs);
619 dropLayout.setDropPending(false);
620 }
621 };
622 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete,
623 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
Winson Chung5aaab772012-04-27 15:24:02 -0700624 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800625 return;
626 }
627
Sunny Goyald478c832016-04-01 12:04:16 -0700628 if (requestCode == REQUEST_RECONFIGURE_APPWIDGET
629 || requestCode == REQUEST_BIND_PENDING_APPWIDGET) {
Sunny Goyalff572272014-07-23 13:58:07 -0700630 if (resultCode == RESULT_OK) {
631 // Update the widget view.
Sunny Goyal2100c782016-08-22 16:00:03 -0700632 completeAdd(requestCode, data, pendingAddWidgetId, requestArgs);
Sunny Goyalff572272014-07-23 13:58:07 -0700633 }
634 // Leave the widget in the pending state if the user canceled the configure.
635 return;
636 }
637
Sunny Goyalaad90582015-07-09 14:22:50 -0700638 if (requestCode == REQUEST_CREATE_SHORTCUT) {
639 // Handle custom shortcuts created using ACTION_CREATE_SHORTCUT.
Sunny Goyal2100c782016-08-22 16:00:03 -0700640 if (resultCode == RESULT_OK && requestArgs.container != ItemInfo.NO_ID) {
641 completeAdd(requestCode, data, -1, requestArgs);
642 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
643 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
644
Sunny Goyalaad90582015-07-09 14:22:50 -0700645 } else if (resultCode == RESULT_CANCELED) {
Adam Cohendb364c32014-05-20 14:23:40 -0700646 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
647 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800648 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800649 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800650 mDragLayer.clearAnimatedView();
Adam Cohenc7cd2cb2014-11-17 17:45:34 -0800651 }
652
653 @Override
Sunny Goyal64a75aa2017-07-03 13:50:52 -0700654 public void onActivityResult(
Adam Cohenc7cd2cb2014-11-17 17:45:34 -0800655 final int requestCode, final int resultCode, final Intent data) {
656 handleActivityResult(requestCode, resultCode, data);
657 if (mLauncherCallbacks != null) {
658 mLauncherCallbacks.onActivityResult(requestCode, resultCode, data);
659 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800660 }
661
Sunny Goyal7ce471b2017-08-02 03:37:39 -0700662 @Override
Sunny Goyaldd2e6df2015-07-07 10:57:57 -0700663 public void onRequestPermissionsResult(int requestCode, String[] permissions,
Dave Hawkey3a43ed62015-06-26 10:27:47 -0600664 int[] grantResults) {
Sunny Goyal2100c782016-08-22 16:00:03 -0700665 PendingRequestArgs pendingArgs = mPendingRequestArgs;
666 if (requestCode == REQUEST_PERMISSION_CALL_PHONE && pendingArgs != null
667 && pendingArgs.getRequestCode() == REQUEST_PERMISSION_CALL_PHONE) {
668 setWaitingForResult(null);
669
Sunny Goyal28c6b962015-10-12 11:42:05 -0700670 View v = null;
Sunny Goyal2100c782016-08-22 16:00:03 -0700671 CellLayout layout = getCellLayout(pendingArgs.container, pendingArgs.screenId);
Sunny Goyal28c6b962015-10-12 11:42:05 -0700672 if (layout != null) {
Sunny Goyal2100c782016-08-22 16:00:03 -0700673 v = layout.getChildAt(pendingArgs.cellX, pendingArgs.cellY);
Sunny Goyal28c6b962015-10-12 11:42:05 -0700674 }
Sunny Goyal2100c782016-08-22 16:00:03 -0700675 Intent intent = pendingArgs.getPendingIntent();
676
Sunny Goyal28c6b962015-10-12 11:42:05 -0700677 if (grantResults.length > 0
678 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
Sunny Goyal85fc55a2016-05-31 10:44:03 -0700679 startActivitySafely(v, intent, null);
Sunny Goyal28c6b962015-10-12 11:42:05 -0700680 } else {
681 // TODO: Show a snack bar with link to settings
682 Toast.makeText(this, getString(R.string.msg_no_phone_permission,
Sunny Goyal112ce422016-08-22 16:45:29 -0700683 getString(R.string.derived_app_name)), Toast.LENGTH_SHORT).show();
Sunny Goyal28c6b962015-10-12 11:42:05 -0700684 }
685 }
Dave Hawkey3a43ed62015-06-26 10:27:47 -0600686 if (mLauncherCallbacks != null) {
687 mLauncherCallbacks.onRequestPermissionsResult(requestCode, permissions,
688 grantResults);
689 }
690 }
691
Adam Cohendb364c32014-05-20 14:23:40 -0700692 /**
693 * Check to see if a given screen id exists. If not, create it at the end, return the new id.
694 *
695 * @param screenId the screen id to check
696 * @return the new screen, or screenId if it exists
697 */
Sunny Goyalefb7e842018-10-04 15:11:00 -0700698 private int ensurePendingDropLayoutExists(int screenId) {
Sunny Goyal32554d12015-12-03 15:31:25 -0800699 CellLayout dropLayout = mWorkspace.getScreenWithId(screenId);
Adam Cohendb364c32014-05-20 14:23:40 -0700700 if (dropLayout == null) {
701 // it's possible that the add screen was removed because it was
702 // empty and a re-bind occurred
703 mWorkspace.addExtraEmptyScreen();
704 return mWorkspace.commitExtraEmptyScreen();
705 } else {
706 return screenId;
707 }
708 }
709
Sunny Goyal2100c782016-08-22 16:00:03 -0700710 @Thunk void completeTwoStageWidgetDrop(
711 final int resultCode, final int appWidgetId, final PendingRequestArgs requestArgs) {
712 CellLayout cellLayout = mWorkspace.getScreenWithId(requestArgs.screenId);
Adam Cohened66b2b2012-01-23 17:28:51 -0800713 Runnable onCompleteRunnable = null;
714 int animationType = 0;
715
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700716 AppWidgetHostView boundWidget = null;
Adam Cohened66b2b2012-01-23 17:28:51 -0800717 if (resultCode == RESULT_OK) {
718 animationType = Workspace.COMPLETE_TWO_STAGE_WIDGET_DROP_ANIMATION;
719 final AppWidgetHostView layout = mAppWidgetHost.createView(this, appWidgetId,
Sunny Goyal04a324a2017-01-20 21:08:59 -0800720 requestArgs.getWidgetHandler().getProviderInfo(this));
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700721 boundWidget = layout;
Adam Cohened66b2b2012-01-23 17:28:51 -0800722 onCompleteRunnable = new Runnable() {
723 @Override
724 public void run() {
Sunny Goyal2100c782016-08-22 16:00:03 -0700725 completeAddAppWidget(appWidgetId, requestArgs, layout, null);
Sunny Goyal3e3f44c2017-10-23 17:14:52 -0700726 mStateManager.goToState(NORMAL, SPRING_LOADED_EXIT_DELAY);
Adam Cohened66b2b2012-01-23 17:28:51 -0800727 }
728 };
729 } else if (resultCode == RESULT_CANCELED) {
Adam Cohen4637b5a2013-11-04 18:21:24 -0800730 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
Adam Cohened66b2b2012-01-23 17:28:51 -0800731 animationType = Workspace.CANCEL_TWO_STAGE_WIDGET_DROP_ANIMATION;
Adam Cohened66b2b2012-01-23 17:28:51 -0800732 }
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700733 if (mDragLayer.getAnimatedView() != null) {
Sunny Goyal2100c782016-08-22 16:00:03 -0700734 mWorkspace.animateWidgetDrop(requestArgs, cellLayout,
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700735 (DragView) mDragLayer.getAnimatedView(), onCompleteRunnable,
736 animationType, boundWidget, true);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700737 } else if (onCompleteRunnable != null) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700738 // The animated view may be null in the case of a rotation during widget configuration
739 onCompleteRunnable.run();
740 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800741 }
742
743 @Override
Michael Jurkacd496d72013-04-11 11:32:45 -0700744 protected void onStop() {
745 super.onStop();
Adam Cohen9211d422014-10-07 18:14:53 -0700746 if (mLauncherCallbacks != null) {
747 mLauncherCallbacks.onStop();
748 }
Hyunyoung Song1241e612018-05-15 21:46:51 -0700749 getUserEventDispatcher().logActionCommand(Action.Command.STOP,
750 mStateManager.getState().containerType, -1);
Hyunyoung Songbd6fba92018-05-16 15:54:31 -0700751
752 mAppWidgetHost.setListenIfResumed(false);
753
Tony Wickham010d2552017-01-20 08:15:28 -0800754 NotificationListener.removeNotificationsChangedListener();
Sunny Goyalaf161fd2018-02-05 16:34:57 -0800755 getStateManager().moveToRestState();
Winson Chungedb0d6b2018-03-21 17:32:55 -0700756
Tracy Zhou62646712018-06-26 14:19:02 -0700757 UiFactory.onLauncherStateOrResumeChanged(this);
758
Winson Chungdea51352018-04-24 13:02:10 -0700759 // Workaround for b/78520668, explicitly trim memory once UI is hidden
Winson Chung473730f2018-04-26 11:54:22 -0700760 onTrimMemory(TRIM_MEMORY_UI_HIDDEN);
Michael Jurkacd496d72013-04-11 11:32:45 -0700761 }
762
763 @Override
764 protected void onStart() {
765 super.onStart();
Adam Cohen9211d422014-10-07 18:14:53 -0700766 if (mLauncherCallbacks != null) {
767 mLauncherCallbacks.onStart();
768 }
Sunny Goyal67419a12017-11-14 16:55:22 -0800769 mAppWidgetHost.setListenIfResumed(true);
Sunny Goyalcac002d2018-01-04 09:51:45 -0800770 NotificationListener.setNotificationsChangedListener(mPopupDataProvider);
Winson Chung62a70be2018-02-23 15:10:05 -0800771 UiFactory.onStart(this);
Michael Jurkacd496d72013-04-11 11:32:45 -0700772 }
773
Hyunyoung Songbd6fba92018-05-16 15:54:31 -0700774 private void logOnDelayedResume() {
775 if (hasBeenResumed()) {
776 getUserEventDispatcher().logActionCommand(Action.Command.RESUME,
777 mStateManager.getState().containerType, -1);
778 getUserEventDispatcher().startSession();
779 }
780 }
781
Michael Jurkacd496d72013-04-11 11:32:45 -0700782 @Override
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800783 protected void onResume() {
Sunny Goyalfca6bc92017-09-28 16:28:34 -0700784 TraceHelper.beginSection("ON_RESUME");
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800785 super.onResume();
Sunny Goyalfca6bc92017-09-28 16:28:34 -0700786 TraceHelper.partitionSection("ON_RESUME", "superCall");
787
Hyunyoung Songbd6fba92018-05-16 15:54:31 -0700788 mHandler.removeCallbacks(mLogOnDelayedResume);
789 Utilities.postAsyncCallback(mHandler, mLogOnDelayedResume);
790
Sunny Goyal3dce5f32017-10-05 11:40:05 -0700791 setOnResumeCallback(null);
Sunny Goyala474a9b2017-05-04 16:47:11 -0700792 // Process any items that were added while Launcher was away.
793 InstallShortcutReceiver.disableAndFlushInstallQueue(
794 InstallShortcutReceiver.FLAG_ACTIVITY_PAUSED, this);
Sunny Goyal95f3d6b2016-08-10 16:09:29 -0700795
Sunny Goyala474a9b2017-05-04 16:47:11 -0700796 // Refresh shortcuts if the permission changed.
797 mModel.refreshShortcutsIfRequired();
Adam Cohen9211d422014-10-07 18:14:53 -0700798
Tracy Zhoue5575f92018-04-19 11:12:53 -0700799 DiscoveryBounce.showForHomeIfNeeded(this);
Adam Cohen9211d422014-10-07 18:14:53 -0700800 if (mLauncherCallbacks != null) {
801 mLauncherCallbacks.onResume();
802 }
Tracy Zhoua706f002018-03-28 13:55:19 -0700803 UiFactory.onLauncherStateOrResumeChanged(this);
Mario Bertschler0fc6f682017-02-17 12:16:13 -0800804
Sunny Goyalfca6bc92017-09-28 16:28:34 -0700805 TraceHelper.endSection("ON_RESUME");
Adam Cohen06dff352012-06-01 17:17:08 -0700806 }
807
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800808 @Override
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700809 protected void onPause() {
Winson Chung997a9232013-07-24 15:33:46 -0700810 // Ensure that items added to Launcher are queued until Launcher returns
Sunny Goyala474a9b2017-05-04 16:47:11 -0700811 InstallShortcutReceiver.enableInstallQueue(InstallShortcutReceiver.FLAG_ACTIVITY_PAUSED);
Winson Chung997a9232013-07-24 15:33:46 -0700812
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700813 super.onPause();
Joe Onorato24b6fd82009-11-12 13:47:09 -0800814 mDragController.cancelDrag();
Winson Chunga2413752012-04-03 14:22:34 -0700815 mDragController.resetLastGestureUpTime();
Adam Cohen6fecd412013-10-02 17:41:50 -0700816
Adam Cohen9211d422014-10-07 18:14:53 -0700817 if (mLauncherCallbacks != null) {
818 mLauncherCallbacks.onPause();
Adam Cohenbffe7452013-07-22 18:21:45 -0700819 }
Adam Cohenbffe7452013-07-22 18:21:45 -0700820 }
821
Winson Chungd7823942018-02-16 03:23:47 +0000822 @Override
Tracy Zhoua706f002018-03-28 13:55:19 -0700823 protected void onUserLeaveHint() {
824 super.onUserLeaveHint();
825 UiFactory.onLauncherStateOrResumeChanged(this);
826 }
827
828 @Override
Winson Chungd7823942018-02-16 03:23:47 +0000829 public void onWindowFocusChanged(boolean hasFocus) {
830 super.onWindowFocusChanged(hasFocus);
831 mStateManager.onWindowFocusChanged();
832 }
833
Adam Cohenc2d6e892014-10-16 09:49:24 -0700834 public interface LauncherOverlay {
835
836 /**
837 * Touch interaction leading to overscroll has begun
838 */
Rajeev Kumar43c0f582017-06-23 15:34:55 -0700839 void onScrollInteractionBegin();
Adam Cohenc2d6e892014-10-16 09:49:24 -0700840
841 /**
842 * Touch interaction related to overscroll has ended
843 */
Rajeev Kumar43c0f582017-06-23 15:34:55 -0700844 void onScrollInteractionEnd();
Adam Cohenc2d6e892014-10-16 09:49:24 -0700845
846 /**
847 * Scroll progress, between 0 and 100, when the user scrolls beyond the leftmost
848 * screen (or in the case of RTL, the rightmost screen).
849 */
Rajeev Kumar43c0f582017-06-23 15:34:55 -0700850 void onScrollChange(float progress, boolean rtl);
Adam Cohenc2d6e892014-10-16 09:49:24 -0700851
852 /**
Sunny Goyal32554d12015-12-03 15:31:25 -0800853 * Called when the launcher is ready to use the overlay
854 * @param callbacks A set of callbacks provided by Launcher in relation to the overlay
Adam Cohenc2d6e892014-10-16 09:49:24 -0700855 */
Rajeev Kumar43c0f582017-06-23 15:34:55 -0700856 void setOverlayCallbacks(LauncherOverlayCallbacks callbacks);
Adam Cohenc2d6e892014-10-16 09:49:24 -0700857 }
858
859 public interface LauncherOverlayCallbacks {
Rajeev Kumar43c0f582017-06-23 15:34:55 -0700860 void onScrollChanged(float progress);
Adam Cohenc2d6e892014-10-16 09:49:24 -0700861 }
862
863 class LauncherOverlayCallbacksImpl implements LauncherOverlayCallbacks {
864
Sunny Goyalc86df472016-02-25 09:19:38 -0800865 public void onScrollChanged(float progress) {
866 if (mWorkspace != null) {
867 mWorkspace.onOverlayScrollChanged(progress);
868 }
869 }
Adam Cohenc2d6e892014-10-16 09:49:24 -0700870 }
871
Sunny Goyalf9403d92017-10-18 10:55:56 -0700872 public boolean isInState(LauncherState state) {
Sunny Goyalea609262017-10-25 15:47:38 -0700873 return mStateManager.getState() == state;
Sunny Goyalf9403d92017-10-18 10:55:56 -0700874 }
875
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800876 /**
877 * Restores the previous state, if it exists.
878 *
879 * @param savedState The previous state.
880 */
881 private void restoreState(Bundle savedState) {
882 if (savedState == null) {
883 return;
884 }
885
Sunny Goyal3e3f44c2017-10-23 17:14:52 -0700886 int stateOrdinal = savedState.getInt(RUNTIME_STATE, NORMAL.ordinal);
Sunny Goyalf9403d92017-10-18 10:55:56 -0700887 LauncherState[] stateValues = LauncherState.values();
888 LauncherState state = stateValues[stateOrdinal];
Sunny Goyalbc683e92017-12-06 10:25:07 -0800889 if (!state.disableRestore) {
Sunny Goyal3e3f44c2017-10-23 17:14:52 -0700890 mStateManager.goToState(state, false /* animated */);
Joe Onorato3a8820b2009-11-10 15:06:42 -0800891 }
892
Sunny Goyal2100c782016-08-22 16:00:03 -0700893 PendingRequestArgs requestArgs = savedState.getParcelable(RUNTIME_STATE_PENDING_REQUEST_ARGS);
894 if (requestArgs != null) {
895 setWaitingForResult(requestArgs);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800896 }
Sunny Goyal2100c782016-08-22 16:00:03 -0700897
898 mPendingActivityResult = savedState.getParcelable(RUNTIME_STATE_PENDING_ACTIVITY_RESULT);
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -0700899
900 SparseArray<Parcelable> widgetsState =
901 savedState.getSparseParcelableArray(RUNTIME_STATE_WIDGET_PANEL);
902 if (widgetsState != null) {
903 WidgetsFullSheet.show(this, false).restoreHierarchyState(widgetsState);
904 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800905 }
906
907 /**
908 * Finds all the views we need and configure them properly.
909 */
910 private void setupViews() {
Sunny Goyalcc96aa12018-01-11 09:56:07 -0800911 mDragLayer = findViewById(R.id.drag_layer);
Sunny Goyal3333b0c2016-05-09 20:43:21 -0700912 mFocusHandler = mDragLayer.getFocusIndicatorHelper();
Sunny Goyal966d9012017-06-06 16:43:59 -0700913 mWorkspace = mDragLayer.findViewById(R.id.workspace);
Sunny Goyald0a6ae72016-06-16 12:29:03 -0700914 mWorkspace.initParentViews(mDragLayer);
Sunny Goyal16764582017-11-06 16:00:34 -0800915 mOverviewPanel = findViewById(R.id.overview_panel);
Sunny Goyal7c7be8c2018-03-07 19:58:07 -0800916 mHotseat = findViewById(R.id.hotseat);
Sunny Goyal81b4c7b2018-03-26 12:10:31 -0700917 mHotseatSearchBox = findViewById(R.id.search_container_hotseat);
Craig Mautner360310b2012-10-26 15:13:08 -0700918
Sunny Goyal784f9c32016-03-23 16:56:54 -0700919 mLauncherView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
920 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
921 | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800922
Winson Chung4c98d922011-05-31 16:50:48 -0700923 // Setup the drag layer
Sunny Goyal5d1873a2018-05-08 11:10:44 -0700924 mDragLayer.setup(mDragController, mWorkspace);
925 UiFactory.setOnTouchControllersChangedListener(this, mDragLayer::recreateControllers);
Winson Chung4c98d922011-05-31 16:50:48 -0700926
Hyunyoung Song645764e2016-06-06 14:19:02 -0700927 mWorkspace.setup(mDragController);
Winsonc7d2e832016-07-28 12:24:55 -0700928 // Until the workspace is bound, ensure that we keep the wallpaper offset locked to the
929 // default state, otherwise we will update to the wrong offsets in RTL
930 mWorkspace.lockWallpaperToDefaultPage();
Sunny Goyalda4fe1a2016-05-26 16:05:17 -0700931 mWorkspace.bindAndInitFirstWorkspaceScreen(null /* recycled qsb */);
Hyunyoung Song645764e2016-06-06 14:19:02 -0700932 mDragController.addDragListener(mWorkspace);
Winson Chung4c98d922011-05-31 16:50:48 -0700933
Tony Wickham34d2c912015-09-11 09:27:58 -0700934 // Get the search/delete/uninstall bar
Rajeev Kumar43c0f582017-06-23 15:34:55 -0700935 mDropTargetBar = mDragLayer.findViewById(R.id.drop_target_bar);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -0700936
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -0700937 // Setup Apps
938 mAppsView = findViewById(R.id.apps_view);
Craig Mautner360310b2012-10-26 15:13:08 -0700939
Winson Chung3d503fb2011-07-13 17:25:49 -0700940 // Setup the drag controller (drop targets have to be added in reverse order in priority)
Hyunyoung Song645764e2016-06-06 14:19:02 -0700941 mDragController.setMoveTarget(mWorkspace);
Sunny Goyal47328fd2016-05-25 18:56:41 -0700942 mDropTargetBar.setup(mDragController);
Daniel Sandler924b9932013-06-12 00:38:25 -0400943
Sunny Goyal7185dd62018-03-14 17:51:49 -0700944 mAllAppsController.setupViews(mAppsView);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800945 }
946
947 /**
948 * Creates a view representing a shortcut.
949 *
950 * @param info The data structure describing the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800951 */
Joe Onorato0589f0f2010-02-08 13:44:00 -0800952 View createShortcut(ShortcutInfo info) {
Sunny Goyaldfaccf62015-05-11 16:30:44 -0700953 return createShortcut((ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800954 }
955
956 /**
957 * Creates a view representing a shortcut inflated from the specified resource.
958 *
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800959 * @param parent The group the shortcut belongs to.
960 * @param info The data structure describing the shortcut.
961 *
962 * @return A View inflated from layoutResId.
963 */
Sunny Goyaldfaccf62015-05-11 16:30:44 -0700964 public View createShortcut(ViewGroup parent, ShortcutInfo info) {
Sunny Goyal9b29ca52017-02-17 10:39:44 -0800965 BubbleTextView favorite = (BubbleTextView) LayoutInflater.from(parent.getContext())
966 .inflate(R.layout.app_icon, parent, false);
Sunny Goyal1cd01b02016-11-09 10:43:58 -0800967 favorite.applyFromShortcutInfo(info);
Sunny Goyal8a2a63b2018-03-06 22:15:18 -0800968 favorite.setOnClickListener(ItemClickHandler.INSTANCE);
Sunny Goyaldcbcc862014-08-12 15:58:36 -0700969 favorite.setOnFocusChangeListener(mFocusHandler);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800970 return favorite;
971 }
972
973 /**
Jon Mirandac476d6e2017-05-04 16:30:01 -0700974 * Add a shortcut to the workspace or to a Folder.
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800975 *
976 * @param data The intent describing the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800977 */
Sunny Goyalefb7e842018-10-04 15:11:00 -0700978 private void completeAddShortcut(Intent data, int container, int screenId, int cellX,
Sunny Goyalfb5096d2016-09-08 14:32:06 -0700979 int cellY, PendingRequestArgs args) {
Jon Mirandac476d6e2017-05-04 16:30:01 -0700980 if (args.getRequestCode() != REQUEST_CREATE_SHORTCUT
981 || args.getPendingIntent().getComponent() == null) {
Sunny Goyalfb5096d2016-09-08 14:32:06 -0700982 return;
983 }
Adam Cohen558baaf2011-08-15 15:22:57 -0700984
Jon Mirandac476d6e2017-05-04 16:30:01 -0700985 int[] cellXY = mTmpAddItemCellCoordinates;
986 CellLayout layout = getCellLayout(container, screenId);
987
Sunny Goyal782f0c92017-01-19 10:27:54 -0800988 ShortcutInfo info = null;
Hyunyoung Songe24cb632017-09-11 11:18:03 -0700989 if (Utilities.ATLEAST_OREO) {
Sunny Goyal22ca9ec2017-05-18 15:03:13 -0700990 info = LauncherAppsCompatVO.createShortcutInfoFromPinItemRequest(
991 this, LauncherAppsCompatVO.getPinItemRequest(data), 0);
Sunny Goyal782f0c92017-01-19 10:27:54 -0800992 }
993
994 if (info == null) {
Sunny Goyalb57645f2017-03-20 13:57:28 -0700995 // Legacy shortcuts are only supported for primary profile.
996 info = Process.myUserHandle().equals(args.user)
997 ? InstallShortcutReceiver.fromShortcutIntent(this, data) : null;
Sunny Goyal782f0c92017-01-19 10:27:54 -0800998
Sunny Goyalb57645f2017-03-20 13:57:28 -0700999 if (info == null) {
1000 Log.e(TAG, "Unable to parse a valid custom shortcut result");
1001 return;
1002 } else if (!new PackageManagerHelper(this).hasPermissionForActivity(
Sunny Goyal342e4662017-02-02 15:21:08 -08001003 info.intent, args.getPendingIntent().getComponent().getPackageName())) {
Sunny Goyal782f0c92017-01-19 10:27:54 -08001004 // The app is trying to add a shortcut without sufficient permissions
1005 Log.e(TAG, "Ignoring malicious intent " + info.intent.toUri(0));
1006 return;
1007 }
1008 }
1009
Jon Mirandac476d6e2017-05-04 16:30:01 -07001010 if (container < 0) {
1011 // Adding a shortcut to the Workspace.
1012 final View view = createShortcut(info);
1013 boolean foundCellSpan = false;
1014 // First we check if we already know the exact location where we want to add this item.
1015 if (cellX >= 0 && cellY >= 0) {
1016 cellXY[0] = cellX;
1017 cellXY[1] = cellY;
1018 foundCellSpan = true;
Adam Cohen558baaf2011-08-15 15:22:57 -07001019
Jon Mirandac476d6e2017-05-04 16:30:01 -07001020 // If appropriate, either create a folder or add to an existing folder
1021 if (mWorkspace.createUserFolderIfNecessary(view, container, layout, cellXY, 0,
Sunny Goyal1797af42017-10-06 13:29:57 -07001022 true, null)) {
Jon Mirandac476d6e2017-05-04 16:30:01 -07001023 return;
1024 }
1025 DragObject dragObject = new DragObject();
1026 dragObject.dragInfo = info;
1027 if (mWorkspace.addToExistingFolderIfNecessary(view, layout, cellXY, 0, dragObject,
1028 true)) {
1029 return;
1030 }
1031 } else {
1032 foundCellSpan = layout.findCellForSpan(cellXY, 1, 1);
1033 }
1034
1035 if (!foundCellSpan) {
1036 mWorkspace.onNoCellFound(layout);
Adam Cohen558baaf2011-08-15 15:22:57 -07001037 return;
1038 }
Jon Mirandac476d6e2017-05-04 16:30:01 -07001039
1040 getModelWriter().addItemToDatabase(info, container, screenId, cellXY[0], cellXY[1]);
1041 mWorkspace.addInScreen(view, info);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001042 } else {
Jon Mirandac476d6e2017-05-04 16:30:01 -07001043 // Adding a shortcut to a Folder.
Sunny Goyale29897f2017-07-20 10:09:42 -07001044 FolderIcon folderIcon = findFolderIcon(container);
Jon Mirandac476d6e2017-05-04 16:30:01 -07001045 if (folderIcon != null) {
1046 FolderInfo folderInfo = (FolderInfo) folderIcon.getTag();
1047 folderInfo.add(info, args.rank, false);
1048 } else {
Sunny Goyale29897f2017-07-20 10:09:42 -07001049 Log.e(TAG, "Could not find folder with id " + container + " to add shortcut.");
Jon Mirandac476d6e2017-05-04 16:30:01 -07001050 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001051 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001052 }
1053
Sunny Goyalefb7e842018-10-04 15:11:00 -07001054 public FolderIcon findFolderIcon(final int folderIconId) {
Sunny Goyal83fd25e2018-07-09 16:47:01 -07001055 return (FolderIcon) mWorkspace.getHomescreenIconByItemId(folderIconId);
Sunny Goyale29897f2017-07-20 10:09:42 -07001056 }
1057
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001058 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001059 * Add a widget to the workspace.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001060 *
Romain Guy5bbc91b2010-08-18 11:38:46 -07001061 * @param appWidgetId The app widget id
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001062 */
Sunny Goyal2100c782016-08-22 16:00:03 -07001063 @Thunk void completeAddAppWidget(int appWidgetId, ItemInfo itemInfo,
Adam Cohen59400422014-03-05 18:07:04 -08001064 AppWidgetHostView hostView, LauncherAppWidgetProviderInfo appWidgetInfo) {
1065
Adam Cohened66b2b2012-01-23 17:28:51 -08001066 if (appWidgetInfo == null) {
Sunny Goyal2e1efb42016-03-03 16:58:55 -08001067 appWidgetInfo = mAppWidgetManager.getLauncherAppWidgetInfo(appWidgetId);
Adam Cohened66b2b2012-01-23 17:28:51 -08001068 }
Romain Guycbb89e42009-06-08 15:52:54 -07001069
Adam Cohen59400422014-03-05 18:07:04 -08001070 LauncherAppWidgetInfo launcherInfo;
1071 launcherInfo = new LauncherAppWidgetInfo(appWidgetId, appWidgetInfo.provider);
Sunny Goyal2100c782016-08-22 16:00:03 -07001072 launcherInfo.spanX = itemInfo.spanX;
1073 launcherInfo.spanY = itemInfo.spanY;
1074 launcherInfo.minSpanX = itemInfo.minSpanX;
1075 launcherInfo.minSpanY = itemInfo.minSpanY;
Sunny Goyal952e63d2017-08-16 04:59:08 -07001076 launcherInfo.user = appWidgetInfo.getProfile();
Romain Guycbb89e42009-06-08 15:52:54 -07001077
Sunny Goyal43bf11d2017-02-02 13:52:53 -08001078 getModelWriter().addItemToDatabase(launcherInfo,
Sunny Goyal2100c782016-08-22 16:00:03 -07001079 itemInfo.container, itemInfo.screenId, itemInfo.cellX, itemInfo.cellY);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001080
Sunny Goyal2100c782016-08-22 16:00:03 -07001081 if (hostView == null) {
1082 // Perform actual inflation because we're live
1083 hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001084 }
Sunny Goyal2100c782016-08-22 16:00:03 -07001085 hostView.setVisibility(View.VISIBLE);
Sunny Goyald5462aa2016-11-22 16:52:39 +05301086 prepareAppWidget(hostView, launcherInfo);
1087 mWorkspace.addInScreen(hostView, launcherInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001088 }
Romain Guycbb89e42009-06-08 15:52:54 -07001089
Sunny Goyald5462aa2016-11-22 16:52:39 +05301090 private void prepareAppWidget(AppWidgetHostView hostView, LauncherAppWidgetInfo item) {
Sunny Goyal87af0fd2016-05-16 14:56:02 -07001091 hostView.setTag(item);
1092 item.onBindAppWidget(this, hostView);
Sunny Goyal87af0fd2016-05-16 14:56:02 -07001093 hostView.setFocusable(true);
1094 hostView.setOnFocusChangeListener(mFocusHandler);
Sunny Goyal25c2e3e2015-10-28 23:28:21 -07001095 }
1096
Sunny Goyal5d1873a2018-05-08 11:10:44 -07001097 private final BroadcastReceiver mScreenOffReceiver = new BroadcastReceiver() {
Adam Cohended9f8d2010-11-03 13:25:16 -07001098 @Override
1099 public void onReceive(Context context, Intent intent) {
Sunny Goyal5d1873a2018-05-08 11:10:44 -07001100 // Reset AllApps to its initial state only if we are not in the middle of
1101 // processing a multi-step drop
1102 if (mPendingRequestArgs == null) {
1103 mStateManager.goToState(NORMAL);
Adam Cohended9f8d2010-11-03 13:25:16 -07001104 }
1105 }
1106 };
1107
Tony Wickham010d2552017-01-20 08:15:28 -08001108 public void updateIconBadges(final Set<PackageUserKey> updatedBadges) {
Sunny Goyal29947f02017-12-18 13:49:44 -08001109 mWorkspace.updateIconBadges(updatedBadges);
Sunny Goyal60180b02018-02-07 12:56:30 -08001110 mAppsView.getAppsStore().updateIconBadges(updatedBadges);
Tony Wickham2fe09f22017-04-25 12:46:04 -07001111
Sunny Goyal29947f02017-12-18 13:49:44 -08001112 PopupContainerWithArrow popup = PopupContainerWithArrow.getOpen(Launcher.this);
1113 if (popup != null) {
1114 popup.updateNotificationHeader(updatedBadges);
Tony Wickham010d2552017-01-20 08:15:28 -08001115 }
1116 }
1117
Adam Cohended9f8d2010-11-03 13:25:16 -07001118 @Override
1119 public void onAttachedToWindow() {
1120 super.onAttachedToWindow();
1121
Sunny Goyalc86df472016-02-25 09:19:38 -08001122 if (mLauncherCallbacks != null) {
1123 mLauncherCallbacks.onAttachedToWindow();
1124 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001125 }
1126
1127 @Override
1128 public void onDetachedFromWindow() {
1129 super.onDetachedFromWindow();
Sunny Goyalc86df472016-02-25 09:19:38 -08001130
1131 if (mLauncherCallbacks != null) {
1132 mLauncherCallbacks.onDetachedFromWindow();
1133 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001134 }
1135
Sunny Goyalc4fa8c32017-11-07 12:23:58 -08001136 public AllAppsTransitionController getAllAppsController() {
1137 return mAllAppsController;
1138 }
1139
Sunny Goyal9d69c8d2018-03-19 13:41:31 -07001140 @Override
Winson Chung1a341002018-01-17 10:00:23 -08001141 public LauncherRootView getRootView() {
1142 return (LauncherRootView) mLauncherView;
1143 }
1144
Sunny Goyal0b0847b2018-03-14 12:30:11 -07001145 @Override
Winson Chunga6945242014-01-08 14:04:34 -08001146 public DragLayer getDragLayer() {
1147 return mDragLayer;
1148 }
1149
Winson Chung5f4e0fd2015-05-22 11:12:27 -07001150 public AllAppsContainerView getAppsView() {
Winson Chungb745afb2015-03-02 11:51:23 -08001151 return mAppsView;
1152 }
1153
Winson Chunga6945242014-01-08 14:04:34 -08001154 public Workspace getWorkspace() {
1155 return mWorkspace;
1156 }
1157
1158 public Hotseat getHotseat() {
1159 return mHotseat;
1160 }
1161
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001162 public View getHotseatSearchBox() {
1163 return mHotseatSearchBox;
1164 }
1165
Sunny Goyal7c7be8c2018-03-07 19:58:07 -08001166 public <T extends View> T getOverviewPanel() {
Winson Chung8ae41982017-11-10 11:42:13 -08001167 return (T) mOverviewPanel;
Winson Chunga6945242014-01-08 14:04:34 -08001168 }
1169
Sunny Goyal47328fd2016-05-25 18:56:41 -07001170 public DropTargetBar getDropTargetBar() {
1171 return mDropTargetBar;
Tony Wickham34d2c912015-09-11 09:27:58 -07001172 }
1173
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001174 public LauncherAppWidgetHost getAppWidgetHost() {
1175 return mAppWidgetHost;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001176 }
Romain Guycbb89e42009-06-08 15:52:54 -07001177
Winson Chunga9abd0e2010-10-27 17:18:37 -07001178 public LauncherModel getModel() {
1179 return mModel;
1180 }
1181
Sunny Goyal43bf11d2017-02-02 13:52:53 -08001182 public ModelWriter getModelWriter() {
1183 return mModelWriter;
1184 }
1185
Adam Cohen79d90c52016-04-22 13:29:20 -07001186 public SharedPreferences getSharedPrefs() {
Winson Chunga6945242014-01-08 14:04:34 -08001187 return mSharedPrefs;
1188 }
1189
Sunny Goyalf8d56fc2018-01-31 15:18:11 -08001190 public int getOrientation() { return mOldConfig.orientation; }
Jon Miranda6bed3502017-09-19 14:43:17 -07001191
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001192 @Override
1193 protected void onNewIntent(Intent intent) {
Sunny Goyalfca6bc92017-09-28 16:28:34 -07001194 TraceHelper.beginSection("NEW_INTENT");
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001195 super.onNewIntent(intent);
1196
Sunny Goyalf4aceab2017-12-06 16:16:31 -08001197 boolean alreadyOnHome = hasWindowFocus() && ((intent.getFlags() &
Winson15f8b172015-08-19 11:02:39 -07001198 Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
1199 != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
Sunny Goyal85313732016-09-28 12:00:07 -07001200
1201 // Check this condition before handling isActionMain, as this will get reset.
Sunny Goyal3e3f44c2017-10-23 17:14:52 -07001202 boolean shouldMoveToDefaultScreen = alreadyOnHome && isInState(NORMAL)
Sunny Goyalf9403d92017-10-18 10:55:56 -07001203 && AbstractFloatingView.getTopOpenView(this) == null;
Winson15f8b172015-08-19 11:02:39 -07001204 boolean isActionMain = Intent.ACTION_MAIN.equals(intent.getAction());
Sunny Goyald3864fa2017-11-14 15:06:36 -08001205 boolean internalStateHandled = InternalStateHandler
Sunny Goyal8b264562018-02-03 23:00:13 -08001206 .handleNewIntent(this, intent, isStarted());
Sunny Goyald3864fa2017-11-14 15:06:36 -08001207
Winson15f8b172015-08-19 11:02:39 -07001208 if (isActionMain) {
Sunny Goyald3864fa2017-11-14 15:06:36 -08001209 if (!internalStateHandled) {
1210 // Note: There should be at most one log per method call. This is enforced
1211 // implicitly by using if-else statements.
1212 UserEventDispatcher ued = getUserEventDispatcher();
1213 AbstractFloatingView topOpenView = AbstractFloatingView.getTopOpenView(this);
1214 if (topOpenView != null) {
1215 topOpenView.logActionCommand(Action.Command.HOME_INTENT);
1216 } else if (alreadyOnHome) {
1217 Target target = newContainerTarget(mStateManager.getState().containerType);
1218 target.pageIndex = mWorkspace.getCurrentPage();
Hyunyoung Songb3fbc0b2018-02-14 13:40:25 -08001219 ued.logActionCommand(Action.Command.HOME_INTENT, target,
1220 newContainerTarget(ContainerType.WORKSPACE));
Sunny Goyald3864fa2017-11-14 15:06:36 -08001221 }
Jon Mirandafeba90f2016-10-06 10:53:29 -07001222
Sunny Goyald3864fa2017-11-14 15:06:36 -08001223 // In all these cases, only animate if we're already on home
Sunny Goyalcc96aa12018-01-11 09:56:07 -08001224 AbstractFloatingView.closeAllOpenViews(this, isStarted());
Jon Mirandafeba90f2016-10-06 10:53:29 -07001225
Sunny Goyala2467272018-03-16 14:53:05 -07001226 if (!isInState(NORMAL)) {
1227 // Only change state, if not already the same. This prevents cancelling any
1228 // animations running as part of resume
1229 mStateManager.goToState(NORMAL);
1230 }
Sunny Goyald3864fa2017-11-14 15:06:36 -08001231
1232 // Reset the apps view
Sunny Goyal5d1873a2018-05-08 11:10:44 -07001233 if (!alreadyOnHome) {
Sunny Goyal7185dd62018-03-14 17:51:49 -07001234 mAppsView.reset(isStarted() /* animate */);
Sunny Goyald3864fa2017-11-14 15:06:36 -08001235 }
1236
Sunny Goyalaad33592018-08-07 17:20:35 -07001237 if (shouldMoveToDefaultScreen && !mWorkspace.isHandlingTouch()) {
Sunny Goyald3864fa2017-11-14 15:06:36 -08001238 mWorkspace.post(mWorkspace::moveToDefaultScreen);
1239 }
1240 }
Adam Cohen6fecd412013-10-02 17:41:50 -07001241
1242 final View v = getWindow().peekDecorView();
1243 if (v != null && v.getWindowToken() != null) {
Sunny Goyal326403e2017-10-02 12:45:10 -07001244 UiThreadHelper.hideKeyboardAsync(this, v.getWindowToken());
Adam Cohen6fecd412013-10-02 17:41:50 -07001245 }
1246
Adam Cohen9211d422014-10-07 18:14:53 -07001247 if (mLauncherCallbacks != null) {
Sunny Goyal85462132018-04-24 11:39:37 -07001248 mLauncherCallbacks.onHomeIntent(internalStateHandled);
Adam Cohen9211d422014-10-07 18:14:53 -07001249 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001250 }
Winson15f8b172015-08-19 11:02:39 -07001251
Sunny Goyalfca6bc92017-09-28 16:28:34 -07001252 TraceHelper.endSection("NEW_INTENT");
Adam Coppa120b8e2013-11-12 16:26:04 +00001253 }
1254
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001255 @Override
Adam Cohen1462de32012-07-24 22:34:36 -07001256 public void onRestoreInstanceState(Bundle state) {
1257 super.onRestoreInstanceState(state);
Sunny Goyalf4aceab2017-12-06 16:16:31 -08001258 mWorkspace.restoreInstanceStateForChild(mSynchronouslyBoundPage);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001259 }
1260
1261 @Override
1262 protected void onSaveInstanceState(Bundle outState) {
Adam Cohen21cd0022013-10-09 18:57:02 -07001263 if (mWorkspace.getChildCount() > 0) {
Sunny Goyal7ce471b2017-08-02 03:37:39 -07001264 outState.putInt(RUNTIME_STATE_CURRENT_SCREEN, mWorkspace.getNextPage());
Hyunyoung Song645764e2016-06-06 14:19:02 -07001265
Adam Cohen21cd0022013-10-09 18:57:02 -07001266 }
Sunny Goyalea609262017-10-25 15:47:38 -07001267 outState.putInt(RUNTIME_STATE, mStateManager.getState().ordinal);
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -07001268
1269
1270 AbstractFloatingView widgets = AbstractFloatingView
1271 .getOpenView(this, AbstractFloatingView.TYPE_WIDGETS_FULL_SHEET);
1272 if (widgets != null) {
1273 SparseArray<Parcelable> widgetsState = new SparseArray<>();
1274 widgets.saveHierarchyState(widgetsState);
1275 outState.putSparseParcelableArray(RUNTIME_STATE_WIDGET_PANEL, widgetsState);
1276 } else {
1277 outState.remove(RUNTIME_STATE_WIDGET_PANEL);
1278 }
1279
Sunny Goyal740ac7f2016-09-28 16:47:32 -07001280 // We close any open folders and shortcut containers since they will not be re-opened,
1281 // and we need to make sure this state is reflected.
1282 AbstractFloatingView.closeAllOpenViews(this, false);
Tony Wickham49c8d292016-07-01 11:44:34 -07001283
Sunny Goyal2100c782016-08-22 16:00:03 -07001284 if (mPendingRequestArgs != null) {
1285 outState.putParcelable(RUNTIME_STATE_PENDING_REQUEST_ARGS, mPendingRequestArgs);
1286 }
1287 if (mPendingActivityResult != null) {
1288 outState.putParcelable(RUNTIME_STATE_PENDING_ACTIVITY_RESULT, mPendingActivityResult);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001289 }
1290
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -07001291 super.onSaveInstanceState(outState);
1292
Adam Cohen9211d422014-10-07 18:14:53 -07001293 if (mLauncherCallbacks != null) {
1294 mLauncherCallbacks.onSaveInstanceState(outState);
1295 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001296 }
1297
1298 @Override
1299 public void onDestroy() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001300 super.onDestroy();
Romain Guycbb89e42009-06-08 15:52:54 -07001301
Sunny Goyal5d1873a2018-05-08 11:10:44 -07001302 unregisterReceiver(mScreenOffReceiver);
Sunny Goyalaaf7d1d2016-05-17 13:38:54 -07001303 mWorkspace.removeFolderListeners();
Winson Chunge7a03942011-08-05 15:05:12 -07001304
Tony Wickhama0068302018-04-11 16:16:11 -07001305 UiFactory.setOnTouchControllersChangedListener(this, null);
1306
Winson Chungcd2b0142011-06-08 16:02:26 -07001307 // Stop callbacks from LauncherModel
Adam Cohen1a85c582014-09-30 09:48:49 -07001308 // It's possible to receive onDestroy after a new Launcher activity has
1309 // been created. In this case, don't interfere with the new Launcher.
1310 if (mModel.isCurrentCallbacks(this)) {
1311 mModel.stopLoader();
Sunny Goyal87f784c2017-01-11 10:48:34 -08001312 LauncherAppState.getInstance(this).setLauncher(null);
Adam Cohen1a85c582014-09-30 09:48:49 -07001313 }
Sunny Goyal623eddd2018-03-02 12:24:41 -08001314 mRotationHelper.destroy();
Sunny Goyal745bad92016-05-02 10:54:12 -07001315
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001316 try {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001317 mAppWidgetHost.stopListening();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001318 } catch (NullPointerException ex) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001319 Log.w(TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001320 }
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001321
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001322 TextKeyListener.getInstance().release();
Tony2917a8b2017-07-31 23:29:42 -07001323 clearPendingBinds();
1324
Adam Cohen9211d422014-10-07 18:14:53 -07001325 if (mLauncherCallbacks != null) {
1326 mLauncherCallbacks.onDestroy();
1327 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001328 }
1329
Sunny Goyalae502842016-06-17 08:43:56 -07001330 public LauncherAccessibilityDelegate getAccessibilityDelegate() {
1331 return mAccessibilityDelegate;
1332 }
1333
Adam Cohena9cf38f2011-05-02 15:36:58 -07001334 public DragController getDragController() {
1335 return mDragController;
1336 }
1337
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001338 @Override
Sunny Goyal0eca4e22016-07-20 11:43:06 -07001339 public void startActivityForResult(Intent intent, int requestCode, Bundle options) {
Sunny Goyal0eca4e22016-07-20 11:43:06 -07001340 super.startActivityForResult(intent, requestCode, options);
Adam Cohen173f7112015-03-27 15:14:00 -07001341 }
1342
1343 @Override
1344 public void startIntentSenderForResult (IntentSender intent, int requestCode,
1345 Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags, Bundle options) {
Adam Cohen173f7112015-03-27 15:14:00 -07001346 try {
1347 super.startIntentSenderForResult(intent, requestCode,
1348 fillInIntent, flagsMask, flagsValues, extraFlags, options);
1349 } catch (IntentSender.SendIntentException e) {
1350 throw new ActivityNotFoundException();
1351 }
1352 }
1353
Winson Chung70d72102011-08-12 11:24:35 -07001354 /**
1355 * Indicates that we want global search for this activity by setting the globalSearch
1356 * argument for {@link #startSearch} to true.
1357 */
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001358 @Override
Romain Guycbb89e42009-06-08 15:52:54 -07001359 public void startSearch(String initialQuery, boolean selectInitialQuery,
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001360 Bundle appSearchData, boolean globalSearch) {
1361 if (appSearchData == null) {
1362 appSearchData = new Bundle();
Bjorn Bringert32b12d22013-06-06 13:00:41 +01001363 appSearchData.putString("source", "launcher-search");
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001364 }
Sunny Goyalda4fe1a2016-05-26 16:05:17 -07001365
Sunny Goyal6f28e712016-09-13 14:19:29 -07001366 if (mLauncherCallbacks == null ||
1367 !mLauncherCallbacks.startSearch(initialQuery, selectInitialQuery, appSearchData)) {
1368 // Starting search from the callbacks failed. Start the default global search.
Sunny Goyalf4aceab2017-12-06 16:16:31 -08001369 super.startSearch(initialQuery, selectInitialQuery, appSearchData, true);
Ian Parkinson047036e2014-09-01 15:40:53 +01001370 }
Winson Chungcd99cd32015-04-29 11:03:24 -07001371
1372 // We need to show the workspace after starting the search
Sunny Goyal3e3f44c2017-10-23 17:14:52 -07001373 mStateManager.goToState(NORMAL);
Bjorn Bringertc459e522013-06-07 19:36:01 +01001374 }
1375
Joe Onorato9c1289c2009-08-17 11:03:03 -04001376 public boolean isWorkspaceLocked() {
Sunny Goyal2100c782016-08-22 16:00:03 -07001377 return mWorkspaceLoading || mPendingRequestArgs != null;
Joe Onorato9c1289c2009-08-17 11:03:03 -04001378 }
1379
Adam Cohen517a7f52014-03-01 12:12:59 -08001380 public boolean isWorkspaceLoading() {
1381 return mWorkspaceLoading;
1382 }
1383
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001384 private void setWorkspaceLoading(boolean value) {
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001385 mWorkspaceLoading = value;
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001386 }
1387
Sunny Goyal04a324a2017-01-20 21:08:59 -08001388 public void setWaitingForResult(PendingRequestArgs args) {
Sunny Goyal2100c782016-08-22 16:00:03 -07001389 mPendingRequestArgs = args;
Adam Cohen9211d422014-10-07 18:14:53 -07001390 }
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001391
Sunny Goyal2100c782016-08-22 16:00:03 -07001392 void addAppWidgetFromDropImpl(int appWidgetId, ItemInfo info, AppWidgetHostView boundWidget,
Sunny Goyal04a324a2017-01-20 21:08:59 -08001393 WidgetAddFlowHandler addFlowHandler) {
Tony Wickhama0628cc2015-10-14 15:23:04 -07001394 if (LOGD) {
1395 Log.d(TAG, "Adding widget from drop");
1396 }
Sunny Goyal04a324a2017-01-20 21:08:59 -08001397 addAppWidgetImpl(appWidgetId, info, boundWidget, addFlowHandler, 0);
Adam Cohenad4e15c2013-10-17 16:21:35 -07001398 }
1399
Sunny Goyal2100c782016-08-22 16:00:03 -07001400 void addAppWidgetImpl(int appWidgetId, ItemInfo info,
Sunny Goyal04a324a2017-01-20 21:08:59 -08001401 AppWidgetHostView boundWidget, WidgetAddFlowHandler addFlowHandler, int delay) {
1402 if (!addFlowHandler.startConfigActivity(this, appWidgetId, info, REQUEST_CREATE_APPWIDGET)) {
1403 // If the configuration flow was not started, add the widget
Michael Jurkaaf442092010-06-10 17:01:57 -07001404
Adam Cohenad4e15c2013-10-17 16:21:35 -07001405 Runnable onComplete = new Runnable() {
1406 @Override
1407 public void run() {
1408 // Exit spring loaded mode if necessary after adding the widget
Sunny Goyal3e3f44c2017-10-23 17:14:52 -07001409 mStateManager.goToState(NORMAL, SPRING_LOADED_EXIT_DELAY);
Adam Cohenad4e15c2013-10-17 16:21:35 -07001410 }
1411 };
Sunny Goyal04a324a2017-01-20 21:08:59 -08001412 completeAddAppWidget(appWidgetId, info, boundWidget, addFlowHandler.getProviderInfo(this));
Adam Cohen689ff162014-05-08 17:27:56 -07001413 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete, delay, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001414 }
1415 }
Romain Guycbb89e42009-06-08 15:52:54 -07001416
Sunny Goyalefb7e842018-10-04 15:11:00 -07001417 public void addPendingItem(PendingAddItemInfo info, int container, int screenId,
Sunny Goyal71b5c0b2015-01-08 16:59:04 -08001418 int[] cell, int spanX, int spanY) {
Sunny Goyal2100c782016-08-22 16:00:03 -07001419 info.container = container;
1420 info.screenId = screenId;
1421 if (cell != null) {
1422 info.cellX = cell[0];
1423 info.cellY = cell[1];
1424 }
1425 info.spanX = spanX;
1426 info.spanY = spanY;
1427
Sunny Goyal71b5c0b2015-01-08 16:59:04 -08001428 switch (info.itemType) {
1429 case LauncherSettings.Favorites.ITEM_TYPE_CUSTOM_APPWIDGET:
1430 case LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET:
Sunny Goyal2100c782016-08-22 16:00:03 -07001431 addAppWidgetFromDrop((PendingAddWidgetInfo) info);
Sunny Goyal71b5c0b2015-01-08 16:59:04 -08001432 break;
1433 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Sunny Goyal782f0c92017-01-19 10:27:54 -08001434 processShortcutFromDrop((PendingAddShortcutInfo) info);
Sunny Goyal71b5c0b2015-01-08 16:59:04 -08001435 break;
1436 default:
1437 throw new IllegalStateException("Unknown item type: " + info.itemType);
1438 }
1439 }
1440
Adam Cohenfbba09b2011-07-18 21:43:05 -07001441 /**
1442 * Process a shortcut drop.
Adam Cohenfbba09b2011-07-18 21:43:05 -07001443 */
Sunny Goyal782f0c92017-01-19 10:27:54 -08001444 private void processShortcutFromDrop(PendingAddShortcutInfo info) {
Sunny Goyalfb5096d2016-09-08 14:32:06 -07001445 Intent intent = new Intent(Intent.ACTION_CREATE_SHORTCUT).setComponent(info.componentName);
1446 setWaitingForResult(PendingRequestArgs.forIntent(REQUEST_CREATE_SHORTCUT, intent, info));
Sunny Goyal782f0c92017-01-19 10:27:54 -08001447 if (!info.activityInfo.startConfigActivity(this, REQUEST_CREATE_SHORTCUT)) {
1448 handleActivityResult(REQUEST_CREATE_SHORTCUT, RESULT_CANCELED, null);
1449 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001450 }
1451
Adam Cohenfbba09b2011-07-18 21:43:05 -07001452 /**
1453 * Process a widget drop.
Adam Cohenfbba09b2011-07-18 21:43:05 -07001454 */
Sunny Goyal2100c782016-08-22 16:00:03 -07001455 private void addAppWidgetFromDrop(PendingAddWidgetInfo info) {
Adam Cohened66b2b2012-01-23 17:28:51 -08001456 AppWidgetHostView hostView = info.boundWidget;
Sunny Goyal952e63d2017-08-16 04:59:08 -07001457 final int appWidgetId;
Sunny Goyal8a0dc382017-01-25 11:30:06 -08001458 WidgetAddFlowHandler addFlowHandler = info.getHandler();
Adam Cohened66b2b2012-01-23 17:28:51 -08001459 if (hostView != null) {
Tony Wickhama0628cc2015-10-14 15:23:04 -07001460 // In the case where we've prebound the widget, we remove it from the DragLayer
1461 if (LOGD) {
1462 Log.d(TAG, "Removing widget view from drag layer and setting boundWidget to null");
1463 }
1464 getDragLayer().removeView(hostView);
1465
Adam Cohened66b2b2012-01-23 17:28:51 -08001466 appWidgetId = hostView.getAppWidgetId();
Sunny Goyal04a324a2017-01-20 21:08:59 -08001467 addAppWidgetFromDropImpl(appWidgetId, info, hostView, addFlowHandler);
Sunny Goyal5b9ebca2015-06-01 18:37:32 -07001468
1469 // Clear the boundWidget so that it doesn't get destroyed.
1470 info.boundWidget = null;
Adam Cohened66b2b2012-01-23 17:28:51 -08001471 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001472 // In this case, we either need to start an activity to get permission to bind
1473 // the widget, or we need to start an activity to configure the widget, or both.
Sunny Goyal952e63d2017-08-16 04:59:08 -07001474 if (FeatureFlags.ENABLE_CUSTOM_WIDGETS &&
1475 info.itemType == LauncherSettings.Favorites.ITEM_TYPE_CUSTOM_APPWIDGET) {
1476 appWidgetId = CustomWidgetParser.getWidgetIdForCustomProvider(
1477 this, info.componentName);
1478 } else {
1479 appWidgetId = getAppWidgetHost().allocateAppWidgetId();
1480 }
Adam Cohendd70d662012-10-04 16:53:44 -07001481 Bundle options = info.bindOptions;
1482
Sunny Goyalffe83f12014-08-14 17:39:34 -07001483 boolean success = mAppWidgetManager.bindAppWidgetIdIfAllowed(
1484 appWidgetId, info.info, options);
Adam Cohendd70d662012-10-04 16:53:44 -07001485 if (success) {
Sunny Goyal04a324a2017-01-20 21:08:59 -08001486 addAppWidgetFromDropImpl(appWidgetId, info, null, addFlowHandler);
Michael Jurka8b805b12012-04-18 14:23:14 -07001487 } else {
Sunny Goyal04a324a2017-01-20 21:08:59 -08001488 addFlowHandler.startBindFlow(this, appWidgetId, info, REQUEST_BIND_APPWIDGET);
Michael Jurka8b805b12012-04-18 14:23:14 -07001489 }
Adam Cohened66b2b2012-01-23 17:28:51 -08001490 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001491 }
1492
Sunny Goyalefb7e842018-10-04 15:11:00 -07001493 FolderIcon addFolder(CellLayout layout, int container, final int screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07001494 int cellY) {
Michael Jurkac9d95c52011-08-29 14:03:34 -07001495 final FolderInfo folderInfo = new FolderInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001496 folderInfo.title = getText(R.string.folder_name);
1497
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001498 // Update the model
Sunny Goyal43bf11d2017-02-02 13:52:53 -08001499 getModelWriter().addItemToDatabase(folderInfo, container, screenId, cellX, cellY);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001500
1501 // Create the view
Sunny Goyal1cd01b02016-11-09 10:43:58 -08001502 FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this, layout, folderInfo);
Sunny Goyald5462aa2016-11-22 16:52:39 +05301503 mWorkspace.addInScreen(newFolder, folderInfo);
Winson Chung5f8afe62013-08-12 16:19:28 -07001504 // Force measure the new folder icon
1505 CellLayout parent = mWorkspace.getParentCellLayoutForView(newFolder);
1506 parent.getShortcutsAndWidgets().measureChild(newFolder);
Adam Cohendf035382011-04-11 17:22:04 -07001507 return newFolder;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001508 }
Romain Guycbb89e42009-06-08 15:52:54 -07001509
Winsonc0b52fe2015-09-09 16:38:15 -07001510 /**
Winsonfa56b3f2015-09-14 12:01:13 -07001511 * Unbinds the view for the specified item, and removes the item and all its children.
1512 *
1513 * @param v the view being removed.
Winsonfa56b3f2015-09-14 12:01:13 -07001514 * @param itemInfo the {@link ItemInfo} for this view.
1515 * @param deleteFromDb whether or not to delete this item from the db.
Winsonc0b52fe2015-09-09 16:38:15 -07001516 */
Tony Wickhambfbf7f92016-05-19 11:19:39 -07001517 public boolean removeItem(View v, final ItemInfo itemInfo, boolean deleteFromDb) {
Winsonc0b52fe2015-09-09 16:38:15 -07001518 if (itemInfo instanceof ShortcutInfo) {
Winsonfa56b3f2015-09-14 12:01:13 -07001519 // Remove the shortcut from the folder before removing it from launcher
Sunny Goyal44c06432016-04-02 10:56:02 -07001520 View folderIcon = mWorkspace.getHomescreenIconByItemId(itemInfo.container);
1521 if (folderIcon instanceof FolderIcon) {
Sunny Goyalc52ba712016-04-05 15:59:05 -07001522 ((FolderInfo) folderIcon.getTag()).remove((ShortcutInfo) itemInfo, true);
Winsonfa56b3f2015-09-14 12:01:13 -07001523 } else {
1524 mWorkspace.removeWorkspaceItem(v);
1525 }
Winsonc0b52fe2015-09-09 16:38:15 -07001526 if (deleteFromDb) {
Sunny Goyal43bf11d2017-02-02 13:52:53 -08001527 getModelWriter().deleteItemFromDatabase(itemInfo);
Winsonc0b52fe2015-09-09 16:38:15 -07001528 }
1529 } else if (itemInfo instanceof FolderInfo) {
1530 final FolderInfo folderInfo = (FolderInfo) itemInfo;
Sunny Goyalaaf7d1d2016-05-17 13:38:54 -07001531 if (v instanceof FolderIcon) {
1532 ((FolderIcon) v).removeListeners();
1533 }
Winsonc0b52fe2015-09-09 16:38:15 -07001534 mWorkspace.removeWorkspaceItem(v);
1535 if (deleteFromDb) {
Sunny Goyal43bf11d2017-02-02 13:52:53 -08001536 getModelWriter().deleteFolderAndContentsFromDatabase(folderInfo);
Winsonc0b52fe2015-09-09 16:38:15 -07001537 }
1538 } else if (itemInfo instanceof LauncherAppWidgetInfo) {
1539 final LauncherAppWidgetInfo widgetInfo = (LauncherAppWidgetInfo) itemInfo;
Winson44818e02015-10-02 11:25:46 -07001540 mWorkspace.removeWorkspaceItem(v);
Winsonc0b52fe2015-09-09 16:38:15 -07001541 if (deleteFromDb) {
Tony Wickham6a71a5b2018-08-21 11:40:23 -07001542 getModelWriter().deleteWidgetInfo(widgetInfo, getAppWidgetHost());
Winsonc0b52fe2015-09-09 16:38:15 -07001543 }
1544 } else {
1545 return false;
1546 }
1547 return true;
1548 }
1549
Tony Wickham6a71a5b2018-08-21 11:40:23 -07001550
Winsonc0b52fe2015-09-09 16:38:15 -07001551
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001552 @Override
1553 public boolean dispatchKeyEvent(KeyEvent event) {
Hyunyoung Song3c7d9cb2017-01-30 15:11:27 -08001554 return (event.getKeyCode() == KeyEvent.KEYCODE_HOME) || super.dispatchKeyEvent(event);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001555 }
1556
Joe Onorato88ec0992009-11-19 13:16:06 -08001557 @Override
1558 public void onBackPressed() {
Sunny Goyal7c8a65e2017-12-22 11:11:33 -08001559 if (finishAutoCancelActionMode()) {
1560 return;
1561 }
Adam Cohen9211d422014-10-07 18:14:53 -07001562 if (mLauncherCallbacks != null && mLauncherCallbacks.handleBackPressed()) {
1563 return;
1564 }
1565
Sunny Goyal45478022015-06-08 16:52:41 -07001566 if (mDragController.isDragging()) {
1567 mDragController.cancelDrag();
Adam Cohenc9735cf2015-01-23 16:11:55 -08001568 return;
1569 }
1570
Jon Mirandafeba90f2016-10-06 10:53:29 -07001571 // Note: There should be at most one log per method call. This is enforced implicitly
1572 // by using if-else statements.
1573 UserEventDispatcher ued = getUserEventDispatcher();
Sunny Goyal740ac7f2016-09-28 16:47:32 -07001574 AbstractFloatingView topView = AbstractFloatingView.getTopOpenView(this);
Tony Wickham52c1b662018-05-21 13:13:58 -07001575 if (topView != null && topView.onBackPressed()) {
1576 // Handled by the floating view.
Patrick Dubroy94f78a52011-02-28 17:39:16 -08001577 } else {
Sunny Goyale39690b2018-08-02 13:35:07 -07001578 mStateManager.getState().onBackPressed(this);
Michael Jurkaaf442092010-06-10 17:01:57 -07001579 }
Joe Onorato88ec0992009-11-19 13:16:06 -08001580 }
1581
Sunny Goyalfe770c92016-09-27 14:38:58 -07001582 @TargetApi(Build.VERSION_CODES.M)
Sunny Goyal0b0847b2018-03-14 12:30:11 -07001583 @Override
Jon Miranda73c27ec2018-05-16 18:06:23 -07001584 public ActivityOptions getActivityLaunchOptions(View v) {
1585 return mAppTransitionManager.getActivityLaunchOptions(this, v);
Sunny Goyala7ce1662016-05-31 15:01:35 -07001586 }
1587
Tony Wickham3a6746a2018-03-29 09:39:56 -07001588 public LauncherAppTransitionManager getAppTransitionManager() {
1589 return mAppTransitionManager;
1590 }
1591
Sunny Goyal0b0847b2018-03-14 12:30:11 -07001592 @TargetApi(Build.VERSION_CODES.M)
1593 @Override
1594 protected boolean onErrorStartingShortcut(Intent intent, ItemInfo info) {
1595 // Due to legacy reasons, direct call shortcuts require Launchers to have the
1596 // corresponding permission. Show the appropriate permission prompt if that
1597 // is the case.
1598 if (intent.getComponent() == null
1599 && Intent.ACTION_CALL.equals(intent.getAction())
1600 && checkSelfPermission(android.Manifest.permission.CALL_PHONE) !=
1601 PackageManager.PERMISSION_GRANTED) {
1602
1603 setWaitingForResult(PendingRequestArgs
1604 .forIntent(REQUEST_PERMISSION_CALL_PHONE, intent, info));
1605 requestPermissions(new String[]{android.Manifest.permission.CALL_PHONE},
1606 REQUEST_PERMISSION_CALL_PHONE);
1607 return true;
1608 } else {
1609 return false;
1610 }
Sunny Goyal0eca4e22016-07-20 11:43:06 -07001611 }
1612
Hyunyoung Song46d07f72018-05-22 15:41:25 -07001613 @Override
1614 public void modifyUserEvent(LauncherLogProto.LauncherEvent event) {
1615 if (event.srcTarget != null && event.srcTarget.length > 0 &&
1616 event.srcTarget[1].containerType == ContainerType.PREDICTION) {
1617 Target[] targets = new Target[3];
1618 targets[0] = event.srcTarget[0];
1619 targets[1] = event.srcTarget[1];
1620 targets[2] = newTarget(Target.Type.CONTAINER);
1621 event.srcTarget = targets;
1622 LauncherState state = mStateManager.getState();
1623 if (state == LauncherState.ALL_APPS) {
1624 event.srcTarget[2].containerType = ContainerType.ALLAPPS;
1625 } else if (state == LauncherState.OVERVIEW) {
1626 event.srcTarget[2].containerType = ContainerType.TASKSWITCHER;
1627 }
1628 }
1629 }
1630
Sunny Goyala7ce1662016-05-31 15:01:35 -07001631 public boolean startActivitySafely(View v, Intent intent, ItemInfo item) {
Hyunyoung Song1241e612018-05-15 21:46:51 -07001632 boolean success = super.startActivitySafely(v, intent, item);
1633 if (success && v instanceof BubbleTextView) {
Sunny Goyal0b0847b2018-03-14 12:30:11 -07001634 // This is set to the view that launched the activity that navigated the user away
1635 // from launcher. Since there is no callback for when the activity has finished
1636 // launching, enable the press state and keep this reference to reset the press
1637 // state when we return to launcher.
1638 BubbleTextView btv = (BubbleTextView) v;
1639 btv.setStayPressed(true);
1640 setOnResumeCallback(btv);
Sunny Goyala7ce1662016-05-31 15:01:35 -07001641 }
Hyunyoung Song1241e612018-05-15 21:46:51 -07001642 return success;
Michael Jurka86a720e2012-05-09 11:23:23 -07001643 }
1644
Winson Chung3d503fb2011-07-13 17:25:49 -07001645 boolean isHotseatLayout(View layout) {
Sunny Goyalc13403c2016-11-18 23:44:48 -08001646 // TODO: Remove this method
Winson Chung3d503fb2011-07-13 17:25:49 -07001647 return mHotseat != null && layout != null &&
1648 (layout instanceof CellLayout) && (layout == mHotseat.getLayout());
1649 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08001650
Winson Chung3d503fb2011-07-13 17:25:49 -07001651 /**
1652 * Returns the CellLayout of the specified container at the specified screen.
1653 */
Sunny Goyalefb7e842018-10-04 15:11:00 -07001654 public CellLayout getCellLayout(int container, int screenId) {
Winson Chung3d503fb2011-07-13 17:25:49 -07001655 if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
1656 if (mHotseat != null) {
1657 return mHotseat.getLayout();
1658 } else {
1659 return null;
Romain Guye6b8e2f2009-11-10 11:56:55 -08001660 }
Winson Chung3d503fb2011-07-13 17:25:49 -07001661 } else {
Winson Chungb745afb2015-03-02 11:51:23 -08001662 return mWorkspace.getScreenWithId(screenId);
Romain Guya6abce82009-11-10 02:54:41 -08001663 }
1664 }
1665
Michael Jurkae326f182011-11-21 14:05:46 -08001666 @Override
1667 public void onTrimMemory(int level) {
1668 super.onTrimMemory(level);
Adam Cohen3f9c9712014-10-31 11:48:25 -07001669 if (level >= ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN) {
1670 // The widget preview db can result in holding onto over
1671 // 3MB of memory for caching which isn't necessary.
1672 SQLiteDatabase.releaseMemory();
1673
Adam Cohenc8f4e1b2014-11-19 16:03:20 -08001674 // This clears all widget bitmaps from the widget tray
Hyunyoung Song3f471442015-04-08 19:01:34 -07001675 // TODO(hyunyoungs)
Michael Jurkae326f182011-11-21 14:05:46 -08001676 }
Robert Kozikowski67c30862015-03-30 23:46:46 +01001677 if (mLauncherCallbacks != null) {
1678 mLauncherCallbacks.onTrimMemory(level);
1679 }
Winson Chung62a70be2018-02-23 15:10:05 -08001680 UiFactory.onTrimMemory(this, level);
Michael Jurkae326f182011-11-21 14:05:46 -08001681 }
1682
Michael Jurkad7c28052012-04-27 15:43:36 -07001683 @Override
1684 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
alanv1d4fde62012-10-17 13:15:47 -07001685 final boolean result = super.dispatchPopulateAccessibilityEvent(event);
Michael Jurkad7c28052012-04-27 15:43:36 -07001686 final List<CharSequence> text = event.getText();
1687 text.clear();
alanv1d4fde62012-10-17 13:15:47 -07001688 // Populate event with a fake title based on the current state.
Sunny Goyal3e3f44c2017-10-23 17:14:52 -07001689 // TODO: When can workspace be null?
1690 text.add(mWorkspace == null
1691 ? getString(R.string.all_apps_home_button_label)
Sunny Goyalea609262017-10-25 15:47:38 -07001692 : mStateManager.getState().getDescription(this));
Michael Jurkad7c28052012-04-27 15:43:36 -07001693 return result;
1694 }
1695
Sunny Goyal3dce5f32017-10-05 11:40:05 -07001696 public void setOnResumeCallback(OnResumeCallback callback) {
1697 if (mOnResumeCallback != null) {
1698 mOnResumeCallback.onLauncherResume();
1699 }
1700 mOnResumeCallback = callback;
Michael Jurka1e2f4652013-07-08 18:03:46 -07001701 }
1702
Michael Jurka7607c2f2013-04-03 14:33:19 -07001703 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04001704 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001705 */
Sunny Goyal93f878c2016-03-30 17:31:24 -07001706 @Override
Joe Onorato9c1289c2009-08-17 11:03:03 -04001707 public int getCurrentWorkspaceScreen() {
Joe Onoratod0afc872010-06-11 00:03:15 -07001708 if (mWorkspace != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07001709 return mWorkspace.getCurrentPage();
Joe Onoratod0afc872010-06-11 00:03:15 -07001710 } else {
Winson Chung882a52e2015-07-08 14:32:26 -07001711 return 0;
Joe Onoratod0afc872010-06-11 00:03:15 -07001712 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04001713 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07001714
Joe Onorato9c1289c2009-08-17 11:03:03 -04001715 /**
Sunny Goyal527c7d32015-08-28 15:19:36 -07001716 * Clear any pending bind callbacks. This is called when is loader is planning to
1717 * perform a full rebind from scratch.
1718 */
1719 @Override
1720 public void clearPendingBinds() {
Sunny Goyal527c7d32015-08-28 15:19:36 -07001721 if (mPendingExecutor != null) {
1722 mPendingExecutor.markCompleted();
1723 mPendingExecutor = null;
1724 }
1725 }
1726
1727 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04001728 * Refreshes the shortcuts shown on the workspace.
1729 *
1730 * Implementation of the method from LauncherModel.Callbacks.
1731 */
1732 public void startBinding() {
Sunny Goyalfca6bc92017-09-28 16:28:34 -07001733 TraceHelper.beginSection("startBinding");
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -07001734 // Floating panels (except the full widget sheet) are associated with individual icons. If
1735 // we are starting a fresh bind, close all such panels as all the icons are about
1736 // to go away.
1737 AbstractFloatingView.closeOpenViews(this, true,
Sunny Goyal7ede6112017-12-05 15:11:21 -08001738 AbstractFloatingView.TYPE_ALL & ~AbstractFloatingView.TYPE_REBIND_SAFE);
Jon Miranda6dc7f1e2017-02-21 12:37:51 -08001739
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001740 setWorkspaceLoading(true);
Adam Cohen517a7f52014-03-01 12:12:59 -08001741
Winson Chungd64d1762013-08-20 14:37:16 -07001742 // Clear the workspace because it's going to be rebound
Adam Cohendf035382011-04-11 17:22:04 -07001743 mWorkspace.clearDropTargets();
Winson Chung9e6a0a22013-08-27 11:58:12 -07001744 mWorkspace.removeAllWorkspaceScreens();
Sunny Goyalc11fac32018-02-27 19:20:15 -08001745 mAppWidgetHost.clearViews();
Winson Chungd64d1762013-08-20 14:37:16 -07001746
Winson Chung3d503fb2011-07-13 17:25:49 -07001747 if (mHotseat != null) {
Sunny Goyal11e96492018-03-23 17:06:00 -07001748 mHotseat.resetLayout(mDeviceProfile.isVerticalBarLayout());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001749 }
Sunny Goyalfca6bc92017-09-28 16:28:34 -07001750 TraceHelper.endSection("startBinding");
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001751 }
1752
Adam Cohendcd297f2013-06-18 13:13:40 -07001753 @Override
Sunny Goyalefb7e842018-10-04 15:11:00 -07001754 public void bindScreens(IntArray orderedScreenIds) {
Sunny Goyalda4fe1a2016-05-26 16:05:17 -07001755 // Make sure the first screen is always at the start.
Ryan Lothian688e9892018-10-03 13:32:01 -04001756 if (FeatureFlags.getInstance(this).isQsbOnFirstScreenEnabled() &&
Sunny Goyala9e2f5a2016-06-10 12:22:04 -07001757 orderedScreenIds.indexOf(Workspace.FIRST_SCREEN_ID) != 0) {
Sunny Goyalefb7e842018-10-04 15:11:00 -07001758 orderedScreenIds.removeValue(Workspace.FIRST_SCREEN_ID);
Sunny Goyalda4fe1a2016-05-26 16:05:17 -07001759 orderedScreenIds.add(0, Workspace.FIRST_SCREEN_ID);
Rajeev Kumar43c0f582017-06-23 15:34:55 -07001760 LauncherModel.updateWorkspaceScreenOrder(this, orderedScreenIds);
Ryan Lothian688e9892018-10-03 13:32:01 -04001761 } else if (!FeatureFlags.getInstance(this).isQsbOnFirstScreenEnabled()
1762 && orderedScreenIds.isEmpty()) {
Sunny Goyala9e2f5a2016-06-10 12:22:04 -07001763 // If there are no screens, we need to have an empty screen
1764 mWorkspace.addExtraEmptyScreen();
Adam Cohen5084cba2013-09-03 12:01:16 -07001765 }
Sunny Goyalda4fe1a2016-05-26 16:05:17 -07001766 bindAddScreens(orderedScreenIds);
Winson Chung0e6a7132013-08-23 12:55:10 -07001767
Winsonc7d2e832016-07-28 12:24:55 -07001768 // After we have added all the screens, if the wallpaper was locked to the default state,
1769 // then notify to indicate that it can be released and a proper wallpaper offset can be
1770 // computed before the next layout
1771 mWorkspace.unlockWallpaperFromDefaultPageOnNextLayout();
Winson Chung64359a52013-07-08 17:17:08 -07001772 }
1773
Sunny Goyalefb7e842018-10-04 15:11:00 -07001774 private void bindAddScreens(IntArray orderedScreenIds) {
Adam Cohendcd297f2013-06-18 13:13:40 -07001775 int count = orderedScreenIds.size();
1776 for (int i = 0; i < count; i++) {
Sunny Goyalefb7e842018-10-04 15:11:00 -07001777 int screenId = orderedScreenIds.get(i);
Ryan Lothian688e9892018-10-03 13:32:01 -04001778 if (!FeatureFlags.getInstance(this).isQsbOnFirstScreenEnabled()
1779 || screenId != Workspace.FIRST_SCREEN_ID) {
Sunny Goyalda4fe1a2016-05-26 16:05:17 -07001780 // No need to bind the first screen, as its always bound.
1781 mWorkspace.insertNewWorkspaceScreenBeforeEmptyScreen(screenId);
1782 }
Adam Cohendcd297f2013-06-18 13:13:40 -07001783 }
Adam Cohendcd297f2013-06-18 13:13:40 -07001784 }
1785
Sunny Goyalb23980c2017-08-17 07:45:25 -07001786 @Override
Tony Wickham6a71a5b2018-08-21 11:40:23 -07001787 public void preAddApps() {
1788 // If there's an undo snackbar, force it to complete to ensure empty screens are removed
1789 // before trying to add new items.
1790 mModelWriter.commitDelete();
1791 AbstractFloatingView snackbar = AbstractFloatingView.getOpenView(this, TYPE_SNACKBAR);
1792 if (snackbar != null) {
1793 snackbar.post(() -> snackbar.close(true));
1794 }
1795 }
1796
1797 @Override
Sunny Goyalefb7e842018-10-04 15:11:00 -07001798 public void bindAppsAdded(IntArray newScreens, ArrayList<ItemInfo> addNotAnimated,
Sunny Goyal29947f02017-12-18 13:49:44 -08001799 ArrayList<ItemInfo> addAnimated) {
Winson Chungd64d1762013-08-20 14:37:16 -07001800 // Add the new screens
Adam Cohen76a47a12014-02-05 11:47:43 -08001801 if (newScreens != null) {
1802 bindAddScreens(newScreens);
1803 }
Winson Chungd64d1762013-08-20 14:37:16 -07001804
1805 // We add the items without animation on non-visible pages, and with
1806 // animations on the new page (which we will try and snap to).
Adam Cohen76a47a12014-02-05 11:47:43 -08001807 if (addNotAnimated != null && !addNotAnimated.isEmpty()) {
Sunny Goyalb23980c2017-08-17 07:45:25 -07001808 bindItems(addNotAnimated, false);
Winson Chungd64d1762013-08-20 14:37:16 -07001809 }
Adam Cohen76a47a12014-02-05 11:47:43 -08001810 if (addAnimated != null && !addAnimated.isEmpty()) {
Sunny Goyalb23980c2017-08-17 07:45:25 -07001811 bindItems(addAnimated, true);
Winson Chungd64d1762013-08-20 14:37:16 -07001812 }
Winson Chungc58497e2013-09-03 17:48:37 -07001813
Winson Chung87412982013-10-03 18:34:14 -07001814 // Remove the extra empty screen
Adam Cohen689ff162014-05-08 17:27:56 -07001815 mWorkspace.removeExtraEmptyScreen(false, false);
Winson Chungd64d1762013-08-20 14:37:16 -07001816 }
1817
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001818 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04001819 * Bind the items start-end from the list.
1820 *
1821 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001822 */
Tony Wickham0bb211a2015-10-02 16:22:08 -07001823 @Override
Sunny Goyalb23980c2017-08-17 07:45:25 -07001824 public void bindItems(final List<ItemInfo> items, final boolean forceAnimateIcons) {
Sunny Goyal3be633b2016-12-08 09:59:25 -08001825 // Get the list of added items and intersect them with the set of items here
Rajeev Kumar43c0f582017-06-23 15:34:55 -07001826 final Collection<Animator> bounceAnims = new ArrayList<>();
Winson Chung997a9232013-07-24 15:33:46 -07001827 final boolean animateIcons = forceAnimateIcons && canRunNewAppsAnimation();
Winson Chungf0c6ae02012-03-21 16:10:31 -07001828 Workspace workspace = mWorkspace;
Sunny Goyalefb7e842018-10-04 15:11:00 -07001829 int newItemsScreenId = -1;
Sunny Goyalb23980c2017-08-17 07:45:25 -07001830 int end = items.size();
1831 for (int i = 0; i < end; i++) {
Sunny Goyal3be633b2016-12-08 09:59:25 -08001832 final ItemInfo item = items.get(i);
Winson Chung4d279d92011-07-21 11:46:32 -07001833
1834 // Short circuit if we are loading dock items for a configuration which has no dock
1835 if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT &&
1836 mHotseat == null) {
1837 continue;
1838 }
1839
Sunny Goyal639e9062015-08-19 19:17:06 -07001840 final View view;
Joe Onorato9c1289c2009-08-17 11:03:03 -04001841 switch (item.itemType) {
1842 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
1843 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Sunny Goyal3be633b2016-12-08 09:59:25 -08001844 case LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT: {
Winson Chungf0c6ae02012-03-21 16:10:31 -07001845 ShortcutInfo info = (ShortcutInfo) item;
Sunny Goyal639e9062015-08-19 19:17:06 -07001846 view = createShortcut(info);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001847 break;
Sunny Goyal3be633b2016-12-08 09:59:25 -08001848 }
1849 case LauncherSettings.Favorites.ITEM_TYPE_FOLDER: {
Sunny Goyal639e9062015-08-19 19:17:06 -07001850 view = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07001851 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Sunny Goyal1cd01b02016-11-09 10:43:58 -08001852 (FolderInfo) item);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001853 break;
Sunny Goyal3be633b2016-12-08 09:59:25 -08001854 }
Sunny Goyal952e63d2017-08-16 04:59:08 -07001855 case LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET:
1856 case LauncherSettings.Favorites.ITEM_TYPE_CUSTOM_APPWIDGET: {
Sunny Goyala9a1a212017-08-18 01:03:21 -07001857 view = inflateAppWidget((LauncherAppWidgetInfo) item);
Sunny Goyalb23980c2017-08-17 07:45:25 -07001858 if (view == null) {
1859 continue;
Sunny Goyal3be633b2016-12-08 09:59:25 -08001860 }
Sunny Goyal3be633b2016-12-08 09:59:25 -08001861 break;
1862 }
Winson Chungc763c4e2013-07-19 13:49:06 -07001863 default:
1864 throw new RuntimeException("Invalid Item Type");
Joe Onorato9c1289c2009-08-17 11:03:03 -04001865 }
Sunny Goyal639e9062015-08-19 19:17:06 -07001866
Sunny Goyalda4fe1a2016-05-26 16:05:17 -07001867 /*
1868 * Remove colliding items.
1869 */
1870 if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
1871 CellLayout cl = mWorkspace.getScreenWithId(item.screenId);
1872 if (cl != null && cl.isOccupied(item.cellX, item.cellY)) {
1873 View v = cl.getChildAt(item.cellX, item.cellY);
1874 Object tag = v.getTag();
1875 String desc = "Collision while binding workspace item: " + item
1876 + ". Collides with " + tag;
Sunny Goyal3d706ad2017-03-06 16:56:39 -08001877 if (FeatureFlags.IS_DOGFOOD_BUILD) {
Sunny Goyalda4fe1a2016-05-26 16:05:17 -07001878 throw (new RuntimeException(desc));
1879 } else {
1880 Log.d(TAG, desc);
Sunny Goyal43bf11d2017-02-02 13:52:53 -08001881 getModelWriter().deleteItemFromDatabase(item);
Sunny Goyalda4fe1a2016-05-26 16:05:17 -07001882 continue;
1883 }
1884 }
1885 }
Sunny Goyald5462aa2016-11-22 16:52:39 +05301886 workspace.addInScreenFromBind(view, item);
Sunny Goyal639e9062015-08-19 19:17:06 -07001887 if (animateIcons) {
1888 // Animate all the applications up now
1889 view.setAlpha(0f);
1890 view.setScaleX(0f);
1891 view.setScaleY(0f);
1892 bounceAnims.add(createNewAppBounceAnimation(view, i));
Sunny Goyal3be633b2016-12-08 09:59:25 -08001893 newItemsScreenId = item.screenId;
Sunny Goyal639e9062015-08-19 19:17:06 -07001894 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001895 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07001896
Sunny Goyalf0b6db72018-08-13 16:10:14 -07001897 // Animate to the correct page
1898 if (animateIcons && newItemsScreenId > -1) {
1899 AnimatorSet anim = new AnimatorSet();
1900 anim.playTogether(bounceAnims);
Jon Miranda64eb8ea2018-03-29 11:43:58 -07001901
Sunny Goyalefb7e842018-10-04 15:11:00 -07001902 int currentScreenId = mWorkspace.getScreenIdForPageIndex(mWorkspace.getNextPage());
Sunny Goyalf0b6db72018-08-13 16:10:14 -07001903 final int newScreenIndex = mWorkspace.getPageIndexForScreenId(newItemsScreenId);
1904 final Runnable startBounceAnimRunnable = anim::start;
1905
1906 if (newItemsScreenId != currentScreenId) {
1907 // We post the animation slightly delayed to prevent slowdowns
1908 // when we are loading right after we return to launcher.
1909 mWorkspace.postDelayed(new Runnable() {
1910 public void run() {
1911 if (mWorkspace != null) {
1912 AbstractFloatingView.closeAllOpenViews(Launcher.this, false);
1913
1914 mWorkspace.snapToPage(newScreenIndex);
1915 mWorkspace.postDelayed(startBounceAnimRunnable,
1916 NEW_APPS_ANIMATION_DELAY);
Winson Chung94d67682013-09-25 16:29:40 -07001917 }
Sunny Goyalf0b6db72018-08-13 16:10:14 -07001918 }
1919 }, NEW_APPS_PAGE_MOVE_DELAY);
1920 } else {
1921 mWorkspace.postDelayed(startBounceAnimRunnable, NEW_APPS_ANIMATION_DELAY);
Winson Chung997a9232013-07-24 15:33:46 -07001922 }
Winson Chung64359a52013-07-08 17:17:08 -07001923 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04001924 workspace.requestLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001925 }
1926
Joe Onorato9c1289c2009-08-17 11:03:03 -04001927 /**
1928 * Add the views for a widget to the workspace.
Joe Onorato9c1289c2009-08-17 11:03:03 -04001929 */
Sunny Goyala9a1a212017-08-18 01:03:21 -07001930 public void bindAppWidget(LauncherAppWidgetInfo item) {
1931 View view = inflateAppWidget(item);
1932 if (view != null) {
1933 mWorkspace.addInScreen(view, item);
1934 mWorkspace.requestLayout();
1935 }
1936 }
1937
1938 private View inflateAppWidget(LauncherAppWidgetInfo item) {
Sunny Goyal2e1efb42016-03-03 16:58:55 -08001939 if (mIsSafeModeEnabled) {
Sunny Goyald5462aa2016-11-22 16:52:39 +05301940 PendingAppWidgetHostView view =
1941 new PendingAppWidgetHostView(this, item, mIconCache, true);
1942 prepareAppWidget(view, item);
Sunny Goyalb23980c2017-08-17 07:45:25 -07001943 return view;
Sunny Goyal2e1efb42016-03-03 16:58:55 -08001944 }
1945
Sunny Goyalfca6bc92017-09-28 16:28:34 -07001946 TraceHelper.beginSection("BIND_WIDGET");
Joe Onorato9c1289c2009-08-17 11:03:03 -04001947
Sunny Goyal2e1efb42016-03-03 16:58:55 -08001948 final LauncherAppWidgetProviderInfo appWidgetInfo;
Adam Cohen59400422014-03-05 18:07:04 -08001949
Sunny Goyal2e1efb42016-03-03 16:58:55 -08001950 if (item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_PROVIDER_NOT_READY)) {
1951 // If the provider is not ready, bind as a pending widget.
1952 appWidgetInfo = null;
1953 } else if (item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_ID_NOT_VALID)) {
1954 // The widget id is not valid. Try to find the widget based on the provider info.
1955 appWidgetInfo = mAppWidgetManager.findProvider(item.providerName, item.user);
1956 } else {
1957 appWidgetInfo = mAppWidgetManager.getLauncherAppWidgetInfo(item.appWidgetId);
1958 }
Sunny Goyal84b4adc2015-08-12 15:12:16 -07001959
Sunny Goyal2e1efb42016-03-03 16:58:55 -08001960 // If the provider is ready, but the width is not yet restored, try to restore it.
1961 if (!item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_PROVIDER_NOT_READY) &&
1962 (item.restoreStatus != LauncherAppWidgetInfo.RESTORE_COMPLETED)) {
Sunny Goyalff572272014-07-23 13:58:07 -07001963 if (appWidgetInfo == null) {
Sunny Goyalfca6bc92017-09-28 16:28:34 -07001964 Log.d(TAG, "Removing restored widget: id=" + item.appWidgetId
1965 + " belongs to component " + item.providerName
1966 + ", as the provider is null");
Sunny Goyal43bf11d2017-02-02 13:52:53 -08001967 getModelWriter().deleteItemFromDatabase(item);
Sunny Goyalb23980c2017-08-17 07:45:25 -07001968 return null;
Sunny Goyalff572272014-07-23 13:58:07 -07001969 }
Sunny Goyalff572272014-07-23 13:58:07 -07001970
Sunny Goyal84b4adc2015-08-12 15:12:16 -07001971 // If we do not have a valid id, try to bind an id.
Sunny Goyal2e1efb42016-03-03 16:58:55 -08001972 if (item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_ID_NOT_VALID)) {
Sunny Goyald478c832016-04-01 12:04:16 -07001973 if (!item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_ID_ALLOCATED)) {
1974 // Id has not been allocated yet. Allocate a new id.
1975 item.appWidgetId = mAppWidgetHost.allocateAppWidgetId();
1976 item.restoreStatus |= LauncherAppWidgetInfo.FLAG_ID_ALLOCATED;
Sunny Goyalff572272014-07-23 13:58:07 -07001977
Sunny Goyald478c832016-04-01 12:04:16 -07001978 // Also try to bind the widget. If the bind fails, the user will be shown
1979 // a click to setup UI, which will ask for the bind permission.
Sunny Goyala52ecb02016-12-16 15:04:51 -08001980 PendingAddWidgetInfo pendingInfo = new PendingAddWidgetInfo(appWidgetInfo);
Sunny Goyald478c832016-04-01 12:04:16 -07001981 pendingInfo.spanX = item.spanX;
1982 pendingInfo.spanY = item.spanY;
1983 pendingInfo.minSpanX = item.minSpanX;
1984 pendingInfo.minSpanY = item.minSpanY;
1985 Bundle options = WidgetHostViewLoader.getDefaultOptionsForWidget(this, pendingInfo);
Sunny Goyal86df1382016-08-10 15:03:22 -07001986
1987 boolean isDirectConfig =
1988 item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_DIRECT_CONFIG);
1989 if (isDirectConfig && item.bindOptions != null) {
1990 Bundle newOptions = item.bindOptions.getExtras();
1991 if (options != null) {
1992 newOptions.putAll(options);
1993 }
1994 options = newOptions;
1995 }
Sunny Goyald478c832016-04-01 12:04:16 -07001996 boolean success = mAppWidgetManager.bindAppWidgetIdIfAllowed(
1997 item.appWidgetId, appWidgetInfo, options);
Sunny Goyal84b4adc2015-08-12 15:12:16 -07001998
Sunny Goyal86df1382016-08-10 15:03:22 -07001999 // We tried to bind once. If we were not able to bind, we would need to
2000 // go through the permission dialog, which means we cannot skip the config
2001 // activity.
2002 item.bindOptions = null;
2003 item.restoreStatus &= ~LauncherAppWidgetInfo.FLAG_DIRECT_CONFIG;
2004
Sunny Goyald478c832016-04-01 12:04:16 -07002005 // Bind succeeded
2006 if (success) {
2007 // If the widget has a configure activity, it is still needs to set it up,
2008 // otherwise the widget is ready to go.
Sunny Goyal86df1382016-08-10 15:03:22 -07002009 item.restoreStatus = (appWidgetInfo.configure == null) || isDirectConfig
Sunny Goyald478c832016-04-01 12:04:16 -07002010 ? LauncherAppWidgetInfo.RESTORE_COMPLETED
2011 : LauncherAppWidgetInfo.FLAG_UI_NOT_READY;
Sunny Goyal84b4adc2015-08-12 15:12:16 -07002012 }
Sunny Goyald478c832016-04-01 12:04:16 -07002013
Sunny Goyal43bf11d2017-02-02 13:52:53 -08002014 getModelWriter().updateItemInDatabase(item);
Sunny Goyalff572272014-07-23 13:58:07 -07002015 }
Sunny Goyal2e1efb42016-03-03 16:58:55 -08002016 } else if (item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_UI_NOT_READY)
Sunny Goyal84b4adc2015-08-12 15:12:16 -07002017 && (appWidgetInfo.configure == null)) {
Sunny Goyal2e1efb42016-03-03 16:58:55 -08002018 // The widget was marked as UI not ready, but there is no configure activity to
2019 // update the UI.
Sunny Goyal84b4adc2015-08-12 15:12:16 -07002020 item.restoreStatus = LauncherAppWidgetInfo.RESTORE_COMPLETED;
Sunny Goyal43bf11d2017-02-02 13:52:53 -08002021 getModelWriter().updateItemInDatabase(item);
Sunny Goyalff572272014-07-23 13:58:07 -07002022 }
Sunny Goyalff572272014-07-23 13:58:07 -07002023 }
2024
Sunny Goyald5462aa2016-11-22 16:52:39 +05302025 final AppWidgetHostView view;
Sunny Goyal2e1efb42016-03-03 16:58:55 -08002026 if (item.restoreStatus == LauncherAppWidgetInfo.RESTORE_COMPLETED) {
Sunny Goyal56c73602015-09-25 12:55:01 -07002027 // Verify that we own the widget
Sunny Goyal2e1efb42016-03-03 16:58:55 -08002028 if (appWidgetInfo == null) {
Sunny Goyal713edfc2016-05-06 09:58:34 -07002029 FileLog.e(TAG, "Removing invalid widget: id=" + item.appWidgetId);
Tony Wickham6a71a5b2018-08-21 11:40:23 -07002030 getModelWriter().deleteWidgetInfo(item, getAppWidgetHost());
Sunny Goyalb23980c2017-08-17 07:45:25 -07002031 return null;
Sunny Goyal56c73602015-09-25 12:55:01 -07002032 }
2033
Sunny Goyal233ee962015-08-03 13:05:01 -07002034 item.minSpanX = appWidgetInfo.minSpanX;
2035 item.minSpanY = appWidgetInfo.minSpanY;
Sunny Goyald5462aa2016-11-22 16:52:39 +05302036 view = mAppWidgetHost.createView(this, item.appWidgetId, appWidgetInfo);
Sunny Goyal651077b2014-06-30 14:15:31 -07002037 } else {
Sunny Goyald5462aa2016-11-22 16:52:39 +05302038 view = new PendingAppWidgetHostView(this, item, mIconCache, false);
Sunny Goyal651077b2014-06-30 14:15:31 -07002039 }
Sunny Goyald5462aa2016-11-22 16:52:39 +05302040 prepareAppWidget(view, item);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002041
Sunny Goyalfca6bc92017-09-28 16:28:34 -07002042 TraceHelper.endSection("BIND_WIDGET", "id=" + item.appWidgetId);
Sunny Goyalb23980c2017-08-17 07:45:25 -07002043 return view;
Joe Onorato9c1289c2009-08-17 11:03:03 -04002044 }
2045
Sunny Goyalff572272014-07-23 13:58:07 -07002046 /**
2047 * Restores a pending widget.
2048 *
2049 * @param appWidgetId The app widget id
Sunny Goyalff572272014-07-23 13:58:07 -07002050 */
Sunny Goyald478c832016-04-01 12:04:16 -07002051 private LauncherAppWidgetInfo completeRestoreAppWidget(int appWidgetId, int finalRestoreFlag) {
Sunny Goyalff572272014-07-23 13:58:07 -07002052 LauncherAppWidgetHostView view = mWorkspace.getWidgetForAppWidgetId(appWidgetId);
2053 if ((view == null) || !(view instanceof PendingAppWidgetHostView)) {
2054 Log.e(TAG, "Widget update called, when the widget no longer exists.");
Sunny Goyald478c832016-04-01 12:04:16 -07002055 return null;
Sunny Goyalff572272014-07-23 13:58:07 -07002056 }
2057
Sunny Goyal0fc1be12014-08-11 17:05:23 -07002058 LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) view.getTag();
Sunny Goyald478c832016-04-01 12:04:16 -07002059 info.restoreStatus = finalRestoreFlag;
Jon Miranda2b823f42017-05-02 18:36:18 -07002060 if (info.restoreStatus == LauncherAppWidgetInfo.RESTORE_COMPLETED) {
2061 info.pendingItemInfo = null;
2062 }
Sunny Goyalff572272014-07-23 13:58:07 -07002063
Sunny Goyalba47faa2017-10-04 16:50:57 -07002064 if (((PendingAppWidgetHostView) view).isReinflateIfNeeded()) {
Sunny Goyal29947f02017-12-18 13:49:44 -08002065 view.reInflate();
Sunny Goyalba47faa2017-10-04 16:50:57 -07002066 }
2067
Sunny Goyal43bf11d2017-02-02 13:52:53 -08002068 getModelWriter().updateItemInDatabase(info);
Sunny Goyald478c832016-04-01 12:04:16 -07002069 return info;
Sunny Goyalff572272014-07-23 13:58:07 -07002070 }
2071
Adam Cohen1462de32012-07-24 22:34:36 -07002072 public void onPageBoundSynchronously(int page) {
Sunny Goyalf4aceab2017-12-06 16:16:31 -08002073 mSynchronouslyBoundPage = page;
Adam Cohen1462de32012-07-24 22:34:36 -07002074 }
2075
Sunny Goyal527c7d32015-08-28 15:19:36 -07002076 @Override
2077 public void executeOnNextDraw(ViewOnDrawExecutor executor) {
2078 if (mPendingExecutor != null) {
2079 mPendingExecutor.markCompleted();
2080 }
2081 mPendingExecutor = executor;
Sunny Goyal60180b02018-02-07 12:56:30 -08002082 if (!isInState(ALL_APPS)) {
2083 mAppsView.getAppsStore().setDeferUpdates(true);
2084 mPendingExecutor.execute(() -> mAppsView.getAppsStore().setDeferUpdates(false));
2085 }
2086
Sunny Goyal527c7d32015-08-28 15:19:36 -07002087 executor.attachTo(this);
2088 }
2089
2090 public void clearPendingExecutor(ViewOnDrawExecutor executor) {
2091 if (mPendingExecutor == executor) {
2092 mPendingExecutor = null;
2093 }
2094 }
2095
Sunny Goyalb5b9ad62016-04-02 11:23:39 -07002096 @Override
2097 public void finishFirstPageBind(final ViewOnDrawExecutor executor) {
Sunny Goyal6001ea22018-05-10 16:31:00 -07002098 AlphaProperty property = mDragLayer.getAlphaProperty(ALPHA_INDEX_LAUNCHER_LOAD);
2099 if (property.getValue() < 1) {
2100 ObjectAnimator anim = ObjectAnimator.ofFloat(property, MultiValueAlpha.VALUE, 1);
2101 if (executor != null) {
2102 anim.addListener(new AnimatorListenerAdapter() {
2103 @Override
2104 public void onAnimationEnd(Animator animation) {
2105 executor.onLoadAnimationCompleted();
2106 }
2107 });
2108 }
2109 anim.start();
Sunny Goyal29947f02017-12-18 13:49:44 -08002110 } else if (executor != null) {
2111 executor.onLoadAnimationCompleted();
Sunny Goyalb5b9ad62016-04-02 11:23:39 -07002112 }
2113 }
2114
Joe Onorato9c1289c2009-08-17 11:03:03 -04002115 /**
2116 * Callback saying that there aren't any more items to bind.
2117 *
2118 * Implementation of the method from LauncherModel.Callbacks.
2119 */
Tony Wickham6a71a5b2018-08-21 11:40:23 -07002120 public void finishBindingItems(int currentScreen) {
Sunny Goyalfca6bc92017-09-28 16:28:34 -07002121 TraceHelper.beginSection("finishBindingItems");
Adam Cohen1462de32012-07-24 22:34:36 -07002122 mWorkspace.restoreInstanceStateForRemainingPages();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002123
Anjali Koppalff7ceff2014-05-01 18:26:37 -07002124 setWorkspaceLoading(false);
Adam Cohendb364c32014-05-20 14:23:40 -07002125
Sunny Goyal2100c782016-08-22 16:00:03 -07002126 if (mPendingActivityResult != null) {
2127 handleActivityResult(mPendingActivityResult.requestCode,
2128 mPendingActivityResult.resultCode, mPendingActivityResult.data);
2129 mPendingActivityResult = null;
Adam Cohendb364c32014-05-20 14:23:40 -07002130 }
2131
Sunny Goyala474a9b2017-05-04 16:47:11 -07002132 InstallShortcutReceiver.disableAndFlushInstallQueue(
2133 InstallShortcutReceiver.FLAG_LOADER_RUNNING, this);
Adam Cohen9211d422014-10-07 18:14:53 -07002134
Tony Wickham6a71a5b2018-08-21 11:40:23 -07002135 mWorkspace.setCurrentPage(currentScreen);
2136
Sunny Goyalfca6bc92017-09-28 16:28:34 -07002137 TraceHelper.endSection("finishBindingItems");
Winson Chungf0c6ae02012-03-21 16:10:31 -07002138 }
2139
Winson Chunga2413752012-04-03 14:22:34 -07002140 private boolean canRunNewAppsAnimation() {
2141 long diff = System.currentTimeMillis() - mDragController.getLastGestureUpTime();
Andrew Sapperstein932eb832016-06-30 18:10:09 -07002142 return diff > (NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS * 1000);
Winson Chunga2413752012-04-03 14:22:34 -07002143 }
2144
Winson Chungc9168342013-06-26 14:54:55 -07002145 private ValueAnimator createNewAppBounceAnimation(View v, int i) {
Sunny Goyalf0b6db72018-08-13 16:10:14 -07002146 ValueAnimator bounceAnim = new PropertyListBuilder().alpha(1).scale(1).build(v)
2147 .setDuration(InstallShortcutReceiver.NEW_SHORTCUT_BOUNCE_DURATION);
Winson Chungc9168342013-06-26 14:54:55 -07002148 bounceAnim.setStartDelay(i * InstallShortcutReceiver.NEW_SHORTCUT_STAGGER_DELAY);
Sunny Goyal5a1f53b2015-05-27 10:24:24 -07002149 bounceAnim.setInterpolator(new OvershootInterpolator(BOUNCE_ANIMATION_TENSION));
Winson Chungc9168342013-06-26 14:54:55 -07002150 return bounceAnim;
2151 }
2152
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002153 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04002154 * Add the icons for all apps.
2155 *
2156 * Implementation of the method from LauncherModel.Callbacks.
2157 */
Sunny Goyal29947f02017-12-18 13:49:44 -08002158 public void bindAllApplications(ArrayList<AppInfo> apps) {
Sunny Goyal60180b02018-02-07 12:56:30 -08002159 mAppsView.getAppsStore().setApps(apps);
Sunny Goyal49fc3f72017-08-18 10:17:06 -07002160
Adam Cohen9211d422014-10-07 18:14:53 -07002161 if (mLauncherCallbacks != null) {
2162 mLauncherCallbacks.bindAllApplications(apps);
2163 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04002164 }
2165
2166 /**
Tony Wickhambfbf7f92016-05-19 11:19:39 -07002167 * Copies LauncherModel's map of activities to shortcut ids to Launcher's. This is necessary
2168 * because LauncherModel's map is updated in the background, while Launcher runs on the UI.
2169 */
2170 @Override
2171 public void bindDeepShortcutMap(MultiHashMap<ComponentKey, String> deepShortcutMapCopy) {
Tony Wickham010d2552017-01-20 08:15:28 -08002172 mPopupDataProvider.setDeepShortcutMap(deepShortcutMapCopy);
Tony Wickham1bce7fd2016-04-28 17:39:03 -07002173 }
2174
Tony Wickhambfbf7f92016-05-19 11:19:39 -07002175 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04002176 * A package was updated.
2177 *
2178 * Implementation of the method from LauncherModel.Callbacks.
2179 */
Sunny Goyal29947f02017-12-18 13:49:44 -08002180 @Override
2181 public void bindAppsAddedOrUpdated(ArrayList<AppInfo> apps) {
Sunny Goyal60180b02018-02-07 12:56:30 -08002182 mAppsView.getAppsStore().addOrUpdateApps(apps);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002183 }
2184
Sunny Goyal4390ace2014-10-13 11:33:11 -07002185 @Override
Sunny Goyal29947f02017-12-18 13:49:44 -08002186 public void bindPromiseAppProgressUpdated(PromiseAppInfo app) {
Sunny Goyal60180b02018-02-07 12:56:30 -08002187 mAppsView.getAppsStore().updatePromiseAppProgress(app);
Mario Bertschler08ffaae2017-03-20 11:30:27 -07002188 }
2189
2190 @Override
Sunny Goyal29947f02017-12-18 13:49:44 -08002191 public void bindWidgetsRestored(ArrayList<LauncherAppWidgetInfo> widgets) {
Sunny Goyal4390ace2014-10-13 11:33:11 -07002192 mWorkspace.widgetsRestored(widgets);
2193 }
2194
Joe Onorato9c1289c2009-08-17 11:03:03 -04002195 /**
Sunny Goyalb50cc8c2014-10-06 16:23:56 -07002196 * Some shortcuts were updated in the background.
Sunny Goyalb50cc8c2014-10-06 16:23:56 -07002197 * Implementation of the method from LauncherModel.Callbacks.
Sunny Goyald3b87ef2016-07-28 12:11:54 -07002198 *
2199 * @param updated list of shortcuts which have changed.
Sunny Goyalb50cc8c2014-10-06 16:23:56 -07002200 */
Sunny Goyal4390ace2014-10-13 11:33:11 -07002201 @Override
Sunny Goyal29947f02017-12-18 13:49:44 -08002202 public void bindShortcutsChanged(ArrayList<ShortcutInfo> updated, final UserHandle user) {
Sunny Goyal4390ace2014-10-13 11:33:11 -07002203 if (!updated.isEmpty()) {
2204 mWorkspace.updateShortcuts(updated);
2205 }
Sunny Goyalb50cc8c2014-10-06 16:23:56 -07002206 }
2207
2208 /**
Chris Wrenaeff7ea2014-02-14 16:59:24 -05002209 * Update the state of a package, typically related to install state.
2210 *
2211 * Implementation of the method from LauncherModel.Callbacks.
2212 */
Sunny Goyale755d462014-07-22 13:48:29 -07002213 @Override
Sunny Goyal29947f02017-12-18 13:49:44 -08002214 public void bindRestoreItemsChange(HashSet<ItemInfo> updates) {
Sunny Goyal756adbc2015-04-16 15:20:51 -07002215 mWorkspace.updateRestoreItems(updates);
Sunny Goyala22666f2014-09-18 13:25:15 -07002216 }
2217
2218 /**
Sunny Goyal3bbbabc2016-03-15 09:16:30 -07002219 * A package was uninstalled/updated. We take both the super set of packageNames
Winson Chung83892cc2013-05-01 16:53:33 -07002220 * in addition to specific applications to remove, the reason being that
2221 * this can be called when a package is updated as well. In that scenario,
Sunny Goyal3bbbabc2016-03-15 09:16:30 -07002222 * we only remove specific components from the workspace and hotseat, where as
Winson Chung83892cc2013-05-01 16:53:33 -07002223 * package-removal should clear all items by package name.
Joe Onorato9c1289c2009-08-17 11:03:03 -04002224 */
Sunny Goyal1a745e82014-10-02 15:58:31 -07002225 @Override
Sunny Goyal6e13dd32017-08-17 03:01:19 -07002226 public void bindWorkspaceComponentsRemoved(final ItemInfoMatcher matcher) {
Sunny Goyal6e13dd32017-08-17 03:01:19 -07002227 mWorkspace.removeItemsByMatcher(matcher);
2228 mDragController.onAppsRemoved(matcher);
Sunny Goyal3bbbabc2016-03-15 09:16:30 -07002229 }
Sunny Goyal4390ace2014-10-13 11:33:11 -07002230
Sunny Goyal3bbbabc2016-03-15 09:16:30 -07002231 @Override
2232 public void bindAppInfosRemoved(final ArrayList<AppInfo> appInfos) {
Sunny Goyal60180b02018-02-07 12:56:30 -08002233 mAppsView.getAppsStore().removeApps(appInfos);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002234 }
Joe Onoratobe386092009-11-17 17:32:16 -08002235
Sunny Goyal49fc3f72017-08-18 10:17:06 -07002236 @Override
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -07002237 public void bindAllWidgets(final ArrayList<WidgetListRowEntry> allWidgets) {
2238 mPopupDataProvider.setAllWidgets(allWidgets);
Tony Wickham26b17462017-03-20 17:12:24 -07002239 AbstractFloatingView topView = AbstractFloatingView.getTopOpenView(this);
2240 if (topView != null) {
2241 topView.onWidgetsBound();
2242 }
2243 }
2244
Tony Wickham86222d22017-03-29 15:30:43 -07002245 /**
2246 * @param packageUser if null, refreshes all widgets and shortcuts, otherwise only
2247 * refreshes the widgets and shortcuts associated with the given package/user
2248 */
2249 public void refreshAndBindWidgetsForPackageUser(@Nullable PackageUserKey packageUser) {
Sunny Goyalc6e97692017-06-02 13:46:55 -07002250 mModel.refreshAndBindWidgetsAndShortcuts(packageUser);
Sunny Goyal2e1efb42016-03-03 16:58:55 -08002251 }
2252
Winson Chung80baf5a2010-08-09 16:03:15 -07002253 /**
Hyunyoung Song3c7d9cb2017-01-30 15:11:27 -08002254 * $ adb shell dumpsys activity com.android.launcher3.Launcher [--all]
Joe Onoratobe386092009-11-17 17:32:16 -08002255 */
Adam Cohen16d7ffc2011-10-05 17:49:14 -07002256 @Override
2257 public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
2258 super.dump(prefix, fd, writer, args);
Sunny Goyala1365452015-10-01 15:46:24 -07002259
Hyunyoung Song3c7d9cb2017-01-30 15:11:27 -08002260 if (args.length > 0 && TextUtils.equals(args[0], "--all")) {
2261 writer.println(prefix + "Workspace Items");
Sunny Goyal7ce471b2017-08-02 03:37:39 -07002262 for (int i = 0; i < mWorkspace.getPageCount(); i++) {
Hyunyoung Song3c7d9cb2017-01-30 15:11:27 -08002263 writer.println(prefix + " Homescreen " + i);
2264
2265 ViewGroup layout = ((CellLayout) mWorkspace.getPageAt(i)).getShortcutsAndWidgets();
2266 for (int j = 0; j < layout.getChildCount(); j++) {
2267 Object tag = layout.getChildAt(j).getTag();
2268 if (tag != null) {
2269 writer.println(prefix + " " + tag.toString());
2270 }
2271 }
2272 }
2273
2274 writer.println(prefix + " Hotseat");
2275 ViewGroup layout = mHotseat.getLayout().getShortcutsAndWidgets();
Sunny Goyala1365452015-10-01 15:46:24 -07002276 for (int j = 0; j < layout.getChildCount(); j++) {
2277 Object tag = layout.getChildAt(j).getTag();
2278 if (tag != null) {
2279 writer.println(prefix + " " + tag.toString());
2280 }
Adam Cohen4caf2982013-08-20 18:54:31 -07002281 }
Sunny Goyala1365452015-10-01 15:46:24 -07002282 }
2283
Hyunyoung Song3c7d9cb2017-01-30 15:11:27 -08002284 writer.println(prefix + "Misc:");
2285 writer.print(prefix + "\tmWorkspaceLoading=" + mWorkspaceLoading);
2286 writer.print(" mPendingRequestArgs=" + mPendingRequestArgs);
2287 writer.println(" mPendingActivityResult=" + mPendingActivityResult);
Sunny Goyale43d00d2018-05-14 14:23:18 -07002288 writer.println(" mRotationHelper: " + mRotationHelper);
Sunny Goyalcb2c5052018-10-15 12:30:29 -07002289 // Extra logging for b/116853349
2290 mDragLayer.dumpAlpha(writer);
Sunny Goyale43d00d2018-05-14 14:23:18 -07002291 dumpMisc(writer);
Sunny Goyal2bba1902018-02-27 12:20:50 -08002292
2293 try {
2294 FileLog.flushAll(writer);
2295 } catch (Exception e) {
2296 // Ignore
2297 }
Hyunyoung Song3c7d9cb2017-01-30 15:11:27 -08002298
2299 mModel.dumpState(prefix, fd, writer, args);
Sunny Goyala1365452015-10-01 15:46:24 -07002300
Adam Cohen9211d422014-10-07 18:14:53 -07002301 if (mLauncherCallbacks != null) {
2302 mLauncherCallbacks.dump(prefix, fd, writer, args);
2303 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07002304 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07002305
Sunny Goyal66b24572016-09-21 15:57:55 -07002306 @Override
2307 @TargetApi(Build.VERSION_CODES.N)
2308 public void onProvideKeyboardShortcuts(
2309 List<KeyboardShortcutGroup> data, Menu menu, int deviceId) {
2310
2311 ArrayList<KeyboardShortcutInfo> shortcutInfos = new ArrayList<>();
Sunny Goyal3e3f44c2017-10-23 17:14:52 -07002312 if (isInState(NORMAL)) {
Sunny Goyal66b24572016-09-21 15:57:55 -07002313 shortcutInfos.add(new KeyboardShortcutInfo(getString(R.string.all_apps_button_label),
2314 KeyEvent.KEYCODE_A, KeyEvent.META_CTRL_ON));
Vadim Tryshev74c261c2018-06-12 13:44:43 -07002315 shortcutInfos.add(new KeyboardShortcutInfo(getString(R.string.widget_button_text),
2316 KeyEvent.KEYCODE_W, KeyEvent.META_CTRL_ON));
Sunny Goyal66b24572016-09-21 15:57:55 -07002317 }
Vadim Tryshev3455f8d2018-05-11 20:02:20 -07002318 final View currentFocus = getCurrentFocus();
2319 if (currentFocus != null) {
2320 if (new CustomActionsPopup(this, currentFocus).canShow()) {
2321 shortcutInfos.add(new KeyboardShortcutInfo(getString(R.string.custom_actions),
2322 KeyEvent.KEYCODE_O, KeyEvent.META_CTRL_ON));
2323 }
2324 if (currentFocus.getTag() instanceof ItemInfo
2325 && DeepShortcutManager.supportsShortcuts((ItemInfo) currentFocus.getTag())) {
2326 shortcutInfos.add(new KeyboardShortcutInfo(
2327 getString(R.string.shortcuts_menu_with_notifications_description),
2328 KeyEvent.KEYCODE_S, KeyEvent.META_CTRL_ON));
2329 }
Sunny Goyal66b24572016-09-21 15:57:55 -07002330 }
2331 if (!shortcutInfos.isEmpty()) {
2332 data.add(new KeyboardShortcutGroup(getString(R.string.home_screen), shortcutInfos));
2333 }
2334
2335 super.onProvideKeyboardShortcuts(data, menu, deviceId);
2336 }
2337
2338 @Override
2339 public boolean onKeyShortcut(int keyCode, KeyEvent event) {
2340 if (event.hasModifiers(KeyEvent.META_CTRL_ON)) {
2341 switch (keyCode) {
2342 case KeyEvent.KEYCODE_A:
Sunny Goyal3e3f44c2017-10-23 17:14:52 -07002343 if (isInState(NORMAL)) {
2344 getStateManager().goToState(ALL_APPS);
Sunny Goyal66b24572016-09-21 15:57:55 -07002345 return true;
2346 }
2347 break;
2348 case KeyEvent.KEYCODE_S: {
2349 View focusedView = getCurrentFocus();
2350 if (focusedView instanceof BubbleTextView
2351 && focusedView.getTag() instanceof ItemInfo
2352 && mAccessibilityDelegate.performAction(focusedView,
2353 (ItemInfo) focusedView.getTag(),
2354 LauncherAccessibilityDelegate.DEEP_SHORTCUTS)) {
Sunny Goyal00ac9202017-11-09 15:24:06 -08002355 PopupContainerWithArrow.getOpen(this).requestFocus();
Sunny Goyal66b24572016-09-21 15:57:55 -07002356 return true;
2357 }
2358 break;
2359 }
2360 case KeyEvent.KEYCODE_O:
2361 if (new CustomActionsPopup(this, getCurrentFocus()).show()) {
2362 return true;
2363 }
2364 break;
Vadim Tryshev74c261c2018-06-12 13:44:43 -07002365 case KeyEvent.KEYCODE_W:
2366 if (isInState(NORMAL)) {
2367 OptionsPopupView.openWidgets(this);
2368 return true;
2369 }
2370 break;
Sunny Goyal66b24572016-09-21 15:57:55 -07002371 }
2372 }
2373 return super.onKeyShortcut(keyCode, event);
2374 }
2375
Vadim Tryshev646a0dd2018-02-05 16:27:50 -08002376 @Override
2377 public boolean onKeyUp(int keyCode, KeyEvent event) {
2378 if (keyCode == KeyEvent.KEYCODE_MENU) {
2379 // KEYCODE_MENU is sent by some tests, for example
2380 // LauncherJankTests#testWidgetsContainerFling. Don't just remove its handling.
2381 if (!mDragController.isDragging() && !mWorkspace.isSwitchingState() &&
2382 isInState(NORMAL)) {
2383 // Close any open floating views.
2384 AbstractFloatingView.closeAllOpenViews(this);
2385
2386 // Setting the touch point to (-1, -1) will show the options popup in the center of
2387 // the screen.
Sunny Goyal2fd7a8b2018-03-30 17:10:13 -07002388 OptionsPopupView.showDefaultOptions(this, -1, -1);
Vadim Tryshev646a0dd2018-02-05 16:27:50 -08002389 }
2390 return true;
2391 }
2392 return super.onKeyUp(keyCode, event);
2393 }
2394
Andrew Sappersteinabef55a2016-06-19 12:49:00 -07002395 public static Launcher getLauncher(Context context) {
Sunny Goyal87b5eb62018-07-03 15:53:39 -07002396 return (Launcher) fromContext(context);
Andrew Sappersteinabef55a2016-06-19 12:49:00 -07002397 }
2398
Sunny Goyal3dce5f32017-10-05 11:40:05 -07002399 /**
2400 * Callback for listening for onResume
2401 */
2402 public interface OnResumeCallback {
2403
2404 void onLauncherResume();
2405 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002406}