blob: 0c355666136b1d4873ed798898c0d6fc21d5837f [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;
vadimt00d42552018-12-11 17:59:36 -080022
Tony Wickham6a71a5b2018-08-21 11:40:23 -070023import static com.android.launcher3.AbstractFloatingView.TYPE_SNACKBAR;
Sunny Goyal4c7f2152017-10-17 17:17:16 -070024import static com.android.launcher3.LauncherAnimUtils.SPRING_LOADED_EXIT_DELAY;
Sunny Goyal3e3f44c2017-10-23 17:14:52 -070025import static com.android.launcher3.LauncherState.ALL_APPS;
26import static com.android.launcher3.LauncherState.NORMAL;
Sunny Goyal6001ea22018-05-10 16:31:00 -070027import static com.android.launcher3.dragndrop.DragLayer.ALPHA_INDEX_LAUNCHER_LOAD;
Sunny Goyalaeb16432017-10-16 11:46:41 -070028import static com.android.launcher3.logging.LoggerUtils.newContainerTarget;
Hyunyoung Song46d07f72018-05-22 15:41:25 -070029import static com.android.launcher3.logging.LoggerUtils.newTarget;
vadimt00d42552018-12-11 17:59:36 -080030import static com.android.launcher3.util.RaceConditionTracker.ENTER;
31import static com.android.launcher3.util.RaceConditionTracker.EXIT;
Sunny Goyal326403e2017-10-02 12:45:10 -070032
Gilles Debunnedd6c9922010-10-25 11:23:41 -070033import android.animation.Animator;
Sunny Goyal6001ea22018-05-10 16:31:00 -070034import android.animation.AnimatorListenerAdapter;
Gilles Debunnedd6c9922010-10-25 11:23:41 -070035import android.animation.AnimatorSet;
Sunny Goyal6001ea22018-05-10 16:31:00 -070036import android.animation.ObjectAnimator;
Gilles Debunnedd6c9922010-10-25 11:23:41 -070037import android.animation.ValueAnimator;
Adam Cohen0b395352014-06-09 22:54:36 +000038import android.annotation.TargetApi;
Tony Wickham005df0b2018-02-13 11:28:12 -080039import android.app.ActivityOptions;
Adam Cohen0cf2a7c2011-11-08 15:07:01 -080040import android.appwidget.AppWidgetHostView;
Michael Jurkaaf442092010-06-10 17:01:57 -070041import android.appwidget.AppWidgetManager;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080042import android.content.ActivityNotFoundException;
Joe Onorato2ca0ae72009-11-10 13:14:13 -080043import android.content.BroadcastReceiver;
Michael Jurkae326f182011-11-21 14:05:46 -080044import android.content.ComponentCallbacks2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080045import android.content.Context;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080046import android.content.Intent;
Winson Chungf0ea4d32011-06-06 14:27:16 -070047import android.content.IntentFilter;
Adam Cohen173f7112015-03-27 15:14:00 -070048import android.content.IntentSender;
Winson Chung82f55532011-08-09 14:14:23 -070049import android.content.SharedPreferences;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080050import android.content.pm.PackageManager;
Sunny Goyalf8d56fc2018-01-31 15:18:11 -080051import android.content.res.Configuration;
Adam Cohen3f9c9712014-10-31 11:48:25 -070052import android.database.sqlite.SQLiteDatabase;
Sunny Goyal59d086c2018-05-07 17:31:40 -070053import android.graphics.Point;
Adam Cohen0f668f32014-09-08 19:54:17 +020054import android.os.Build;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080055import android.os.Bundle;
Hyunyoung Songbd6fba92018-05-16 15:54:31 -070056import android.os.Handler;
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -070057import android.os.Parcelable;
Sunny Goyal7c74e4a2016-12-15 15:53:17 -080058import android.os.Process;
Winson Chunga2413752012-04-03 14:22:34 -070059import android.os.StrictMode;
Michael Jurkaa33411c2012-06-14 16:18:21 -070060import android.text.TextUtils;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080061import android.text.method.TextKeyListener;
Joe Onorato7c312c12009-08-13 21:36:53 -070062import android.util.Log;
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -070063import android.util.SparseArray;
Sunny Goyal59d086c2018-05-07 17:31:40 -070064import android.view.Display;
Adam Cohen96d30a12013-07-16 18:13:21 -070065import android.view.KeyEvent;
Sunny Goyal66b24572016-09-21 15:57:55 -070066import android.view.KeyboardShortcutGroup;
67import android.view.KeyboardShortcutInfo;
Sunny Goyal9b29ca52017-02-17 10:39:44 -080068import android.view.LayoutInflater;
Adam Cohen96d30a12013-07-16 18:13:21 -070069import android.view.Menu;
Adam Cohen96d30a12013-07-16 18:13:21 -070070import android.view.View;
Adam Cohen96d30a12013-07-16 18:13:21 -070071import android.view.ViewGroup;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -080072import android.view.accessibility.AccessibilityEvent;
Sunny Goyal5a1f53b2015-05-27 10:24:24 -070073import android.view.animation.OvershootInterpolator;
Adam Cohen96d30a12013-07-16 18:13:21 -070074import android.widget.Toast;
Sunny Goyala1d1bf32015-06-26 13:24:53 -070075
Sunny Goyal651077b2014-06-30 14:15:31 -070076import com.android.launcher3.DropTarget.DragObject;
Sunny Goyalae502842016-06-17 08:43:56 -070077import com.android.launcher3.accessibility.LauncherAccessibilityDelegate;
Winson Chung5f4e0fd2015-05-22 11:12:27 -070078import com.android.launcher3.allapps.AllAppsContainerView;
Hyunyoung Song645764e2016-06-06 14:19:02 -070079import com.android.launcher3.allapps.AllAppsTransitionController;
Sunny Goyal7ede6112017-12-05 15:11:21 -080080import com.android.launcher3.allapps.DiscoveryBounce;
Sunny Goyalf0b6db72018-08-13 16:10:14 -070081import com.android.launcher3.anim.PropertyListBuilder;
Sunny Goyalffe83f12014-08-14 17:39:34 -070082import com.android.launcher3.compat.AppWidgetManagerCompat;
Sunny Goyal22ca9ec2017-05-18 15:03:13 -070083import com.android.launcher3.compat.LauncherAppsCompatVO;
Tony Wickhame0c33232016-02-08 11:37:04 -080084import com.android.launcher3.config.FeatureFlags;
vadimt00d42552018-12-11 17:59:36 -080085import com.android.launcher3.dot.DotInfo;
Vadim Tryshevfedca432015-08-19 17:55:02 -070086import com.android.launcher3.dragndrop.DragController;
87import com.android.launcher3.dragndrop.DragLayer;
88import com.android.launcher3.dragndrop.DragView;
Jon Mirandaaeb4dd02018-07-11 14:16:23 -070089import com.android.launcher3.folder.Folder;
Sunny Goyal26119432016-02-18 22:09:23 +000090import com.android.launcher3.folder.FolderIcon;
Sunny Goyal0b0847b2018-03-14 12:30:11 -070091import com.android.launcher3.folder.FolderIconPreviewVerifier;
Sunny Goyalf840f102018-09-21 14:41:05 -070092import com.android.launcher3.icons.IconCache;
Sunny Goyal66b24572016-09-21 15:57:55 -070093import com.android.launcher3.keyboard.CustomActionsPopup;
Sunny Goyal3333b0c2016-05-09 20:43:21 -070094import com.android.launcher3.keyboard.ViewGroupFocusHelper;
Sunny Goyala7ce1662016-05-31 15:01:35 -070095import com.android.launcher3.logging.FileLog;
Hyunyoung Songfc007472018-10-25 14:09:50 -070096import com.android.launcher3.logging.StatsLogUtils;
Hyunyoung Songaa953652016-04-19 18:30:24 -070097import com.android.launcher3.logging.UserEventDispatcher;
Hyunyoung Song46d07f72018-05-22 15:41:25 -070098import com.android.launcher3.logging.UserEventDispatcher.UserEventDelegate;
Sunny Goyal369212a2019-03-26 15:03:57 -070099import com.android.launcher3.model.AppLaunchTracker;
Sunny Goyala535ae42017-02-27 10:07:13 -0800100import com.android.launcher3.model.ModelWriter;
Sunny Goyala535ae42017-02-27 10:07:13 -0800101import com.android.launcher3.notification.NotificationListener;
Tony Wickham540913e2017-01-23 11:47:51 -0800102import com.android.launcher3.popup.PopupContainerWithArrow;
Sunny Goyala535ae42017-02-27 10:07:13 -0800103import com.android.launcher3.popup.PopupDataProvider;
Tony Wickham1bce7fd2016-04-28 17:39:03 -0700104import com.android.launcher3.shortcuts.DeepShortcutManager;
Sunny Goyalf8088ee2017-11-10 14:52:00 -0800105import com.android.launcher3.states.InternalStateHandler;
Sunny Goyal623eddd2018-03-02 12:24:41 -0800106import com.android.launcher3.states.RotationHelper;
Sunny Goyal8a2a63b2018-03-06 22:15:18 -0800107import com.android.launcher3.touch.ItemClickHandler;
Sunny Goyala5ace712017-11-15 17:12:51 -0800108import com.android.launcher3.uioverrides.UiFactory;
Hyunyoung Song46d07f72018-05-22 15:41:25 -0700109import com.android.launcher3.userevent.nano.LauncherLogProto;
Sunny Goyal6c46a6d2016-11-23 02:24:32 +0530110import com.android.launcher3.userevent.nano.LauncherLogProto.Action;
111import com.android.launcher3.userevent.nano.LauncherLogProto.ContainerType;
Sunny Goyalaeb16432017-10-16 11:46:41 -0700112import com.android.launcher3.userevent.nano.LauncherLogProto.Target;
Sunny Goyal2100c782016-08-22 16:00:03 -0700113import com.android.launcher3.util.ActivityResultInfo;
Winson Chung6b1c73f2015-06-18 11:38:42 -0700114import com.android.launcher3.util.ComponentKey;
Sunny Goyalefb7e842018-10-04 15:11:00 -0700115import com.android.launcher3.util.IntArray;
Sunny Goyald3b87ef2016-07-28 12:11:54 -0700116import com.android.launcher3.util.ItemInfoMatcher;
Sunny Goyal6001ea22018-05-10 16:31:00 -0700117import com.android.launcher3.util.MultiValueAlpha;
118import com.android.launcher3.util.MultiValueAlpha.AlphaProperty;
Sunny Goyal04cc3a72016-05-17 10:32:43 -0700119import com.android.launcher3.util.PackageManagerHelper;
Tony Wickham010d2552017-01-20 08:15:28 -0800120import com.android.launcher3.util.PackageUserKey;
Sunny Goyal2100c782016-08-22 16:00:03 -0700121import com.android.launcher3.util.PendingRequestArgs;
vadimt00d42552018-12-11 17:59:36 -0800122import com.android.launcher3.util.RaceConditionTracker;
Sunny Goyal8392c822017-06-20 10:03:56 -0700123import com.android.launcher3.util.SystemUiController;
Mario Bertschlera6936942017-05-31 14:48:19 -0700124import com.android.launcher3.util.Themes;
Adam Cohen091440a2015-03-18 14:16:05 -0700125import com.android.launcher3.util.Thunk;
Sunny Goyalfca6bc92017-09-28 16:28:34 -0700126import com.android.launcher3.util.TraceHelper;
Sunny Goyal326403e2017-10-02 12:45:10 -0700127import com.android.launcher3.util.UiThreadHelper;
Sunny Goyal527c7d32015-08-28 15:19:36 -0700128import com.android.launcher3.util.ViewOnDrawExecutor;
Sunny Goyalab770a12018-11-14 15:17:26 -0800129import com.android.launcher3.views.ActivityContext;
Sunny Goyal7c7be8c2018-03-07 19:58:07 -0800130import com.android.launcher3.views.OptionsPopupView;
Sunny Goyal29947f02017-12-18 13:49:44 -0800131import com.android.launcher3.widget.LauncherAppWidgetHostView;
Sunny Goyal782f0c92017-01-19 10:27:54 -0800132import com.android.launcher3.widget.PendingAddShortcutInfo;
Hyunyoung Song3f471442015-04-08 19:01:34 -0700133import com.android.launcher3.widget.PendingAddWidgetInfo;
Sunny Goyal29947f02017-12-18 13:49:44 -0800134import com.android.launcher3.widget.PendingAppWidgetHostView;
Sunny Goyal04a324a2017-01-20 21:08:59 -0800135import com.android.launcher3.widget.WidgetAddFlowHandler;
Hyunyoung Songb99ff3e2015-04-23 15:17:50 -0700136import com.android.launcher3.widget.WidgetHostViewLoader;
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -0700137import com.android.launcher3.widget.WidgetListRowEntry;
138import com.android.launcher3.widget.WidgetsFullSheet;
Sunny Goyal952e63d2017-08-16 04:59:08 -0700139import com.android.launcher3.widget.custom.CustomWidgetParser;
Adam Cohen6c5891a2014-07-09 23:53:15 -0700140
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700141import java.io.FileDescriptor;
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700142import java.io.PrintWriter;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700143import java.util.ArrayList;
Winson Chungf0c6ae02012-03-21 16:10:31 -0700144import java.util.Collection;
Zak Cohen658c67a2018-10-19 14:21:05 -0700145import java.util.HashMap;
Sunny Goyal4390ace2014-10-13 11:33:11 -0700146import java.util.HashSet;
Michael Jurkad7c28052012-04-27 15:43:36 -0700147import java.util.List;
Sunny Goyalaae6fbb2019-01-31 16:05:58 -0800148import java.util.function.Predicate;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700149
Sunny Goyal8c48d8b2019-01-25 15:10:18 -0800150import androidx.annotation.Nullable;
151
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800152/**
153 * Default launcher application.
154 */
Hyunyoung Song46d07f72018-05-22 15:41:25 -0700155public class Launcher extends BaseDraggingActivity implements LauncherExterns,
Hyunyoung Song31971a32019-01-27 12:31:12 -0800156 LauncherModel.Callbacks, LauncherProviderChangeListener, UserEventDelegate,
157 InvariantDeviceProfile.OnIDPChangeListener {
Vadim Tryshevfedca432015-08-19 17:55:02 -0700158 public static final String TAG = "Launcher";
Sunny Goyal2bba4c32015-05-18 15:42:48 -0700159 static final boolean LOGD = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800160
Winson Chunga2413752012-04-03 14:22:34 -0700161 static final boolean DEBUG_STRICT_MODE = false;
Romain Guy6fefcf12009-06-11 13:07:43 -0700162
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800163 private static final int REQUEST_CREATE_SHORTCUT = 1;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700164 private static final int REQUEST_CREATE_APPWIDGET = 5;
Jon Mirandac476d6e2017-05-04 16:30:01 -0700165
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700166 private static final int REQUEST_PICK_APPWIDGET = 9;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800167
Michael Jurka8b805b12012-04-18 14:23:14 -0700168 private static final int REQUEST_BIND_APPWIDGET = 11;
Sunny Goyal8a2a63b2018-03-06 22:15:18 -0800169 public static final int REQUEST_BIND_PENDING_APPWIDGET = 12;
170 public static final int REQUEST_RECONFIGURE_APPWIDGET = 13;
Michael Jurka8b805b12012-04-18 14:23:14 -0700171
Jon Mirandac476d6e2017-05-04 16:30:01 -0700172 private static final int REQUEST_PERMISSION_CALL_PHONE = 14;
Sunny Goyal28c6b962015-10-12 11:42:05 -0700173
Sunny Goyal5a1f53b2015-05-27 10:24:24 -0700174 private static final float BOUNCE_ANIMATION_TENSION = 1.3f;
175
Mathew Inwood876a8462013-06-14 14:12:41 +0100176 /**
177 * IntentStarter uses request codes starting with this. This must be greater than all activity
178 * request codes used internally.
179 */
180 protected static final int REQUEST_LAST = 100;
181
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800182 // Type: int
183 private static final String RUNTIME_STATE_CURRENT_SCREEN = "launcher.current_screen";
Michael Jurka883f55b2010-10-21 15:47:14 -0700184 // Type: int
185 private static final String RUNTIME_STATE = "launcher.state";
Sunny Goyal2100c782016-08-22 16:00:03 -0700186 // Type: PendingRequestArgs
187 private static final String RUNTIME_STATE_PENDING_REQUEST_ARGS = "launcher.request_args";
188 // Type: ActivityResultInfo
189 private static final String RUNTIME_STATE_PENDING_ACTIVITY_RESULT = "launcher.activity_result";
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -0700190 // Type: SparseArray<Parcelable>
191 private static final String RUNTIME_STATE_WIDGET_PANEL = "launcher.widget_panel";
vadimt00d42552018-12-11 17:59:36 -0800192 public static final String ON_CREATE_EVT = "Launcher.onCreate";
vadimtcb863752018-12-19 17:44:57 -0800193 private static final String ON_START_EVT = "Launcher.onStart";
194 private static final String ON_RESUME_EVT = "Launcher.onResume";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800195
Sunny Goyal3e3f44c2017-10-23 17:14:52 -0700196 private LauncherStateManager mStateManager;
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700197
Adam Cohenad4e15c2013-10-17 16:21:35 -0700198 private static final int ON_ACTIVITY_RESULT_ANIMATION_DELAY = 500;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800199
Winson Chunga2413752012-04-03 14:22:34 -0700200 // How long to wait before the new-shortcut animation automatically pans the workspace
Rajeev Kumar43c0f582017-06-23 15:34:55 -0700201 private static final int NEW_APPS_PAGE_MOVE_DELAY = 500;
202 private static final int NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS = 5;
203 @Thunk static final int NEW_APPS_ANIMATION_DELAY = 500;
Winson Chunga2413752012-04-03 14:22:34 -0700204
Jon Miranda54441f52018-01-24 15:38:25 -0800205 private LauncherAppTransitionManager mAppTransitionManager;
Sunny Goyalf8d56fc2018-01-31 15:18:11 -0800206 private Configuration mOldConfig;
Jon Miranda54441f52018-01-24 15:38:25 -0800207
Adam Cohen091440a2015-03-18 14:16:05 -0700208 @Thunk Workspace mWorkspace;
Craig Mautner360310b2012-10-26 15:13:08 -0700209 private View mLauncherView;
Adam Cohen091440a2015-03-18 14:16:05 -0700210 @Thunk DragLayer mDragLayer;
Michael Jurkab737ee62011-11-15 15:57:22 -0800211 private DragController mDragController;
Sunny Goyal322d5562015-06-25 19:35:49 -0700212
Sunny Goyalffe83f12014-08-14 17:39:34 -0700213 private AppWidgetManagerCompat mAppWidgetManager;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700214 private LauncherAppWidgetHost mAppWidgetHost;
Romain Guycbb89e42009-06-08 15:52:54 -0700215
Rajeev Kumar43c0f582017-06-23 15:34:55 -0700216 private final int[] mTmpAddItemCellCoordinates = new int[2];
Michael Jurka0280c3b2010-09-17 15:00:07 -0700217
Sunny Goyal316490e2015-06-02 09:38:28 -0700218 @Thunk Hotseat mHotseat;
Adam Cohenf358a4b2013-07-23 16:47:31 -0700219
Sunny Goyal47328fd2016-05-25 18:56:41 -0700220 private DropTargetBar mDropTargetBar;
Hyunyoung Song3f471442015-04-08 19:01:34 -0700221
222 // Main container view for the all apps screen.
Winson Chung5f4e0fd2015-05-22 11:12:27 -0700223 @Thunk AllAppsContainerView mAppsView;
Hyunyoung Song645764e2016-06-06 14:19:02 -0700224 AllAppsTransitionController mAllAppsController;
Hyunyoung Song3f471442015-04-08 19:01:34 -0700225
Winson Chung8ae41982017-11-10 11:42:13 -0800226 // UI and state for the overview panel
Sunny Goyal7c7be8c2018-03-07 19:58:07 -0800227 private View mOverviewPanel;
Winson Chung8ae41982017-11-10 11:42:13 -0800228
Adam Cohen091440a2015-03-18 14:16:05 -0700229 @Thunk boolean mWorkspaceLoading = true;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400230
Sunny Goyal3dce5f32017-10-05 11:40:05 -0700231 private OnResumeCallback mOnResumeCallback;
232
Sunny Goyal527c7d32015-08-28 15:19:36 -0700233 private ViewOnDrawExecutor mPendingExecutor;
Michael Jurka7607c2f2013-04-03 14:33:19 -0700234
Joe Onorato9c1289c2009-08-17 11:03:03 -0400235 private LauncherModel mModel;
Sunny Goyal43bf11d2017-02-02 13:52:53 -0800236 private ModelWriter mModelWriter;
Joe Onorato0589f0f2010-02-08 13:44:00 -0800237 private IconCache mIconCache;
Sunny Goyalae502842016-06-17 08:43:56 -0700238 private LauncherAccessibilityDelegate mAccessibilityDelegate;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400239
Tony Wickham010d2552017-01-20 08:15:28 -0800240 private PopupDataProvider mPopupDataProvider;
Tony Wickhambfbf7f92016-05-19 11:19:39 -0700241
Sunny Goyalf4aceab2017-12-06 16:16:31 -0800242 private int mSynchronouslyBoundPage = PagedView.INVALID_PAGE;
Adam Cohen1462de32012-07-24 22:34:36 -0700243
Winson Chung46353de2012-02-16 14:05:10 -0800244 // We only want to get the SharedPreferences once since it does an FS stat each time we get
245 // it from the context.
246 private SharedPreferences mSharedPrefs;
247
Sunny Goyal2100c782016-08-22 16:00:03 -0700248 // Activity result which needs to be processed after workspace has loaded.
249 private ActivityResultInfo mPendingActivityResult;
250 /**
251 * Holds extra information required to handle a result from an external call, like
252 * {@link #startActivityForResult(Intent, int)} or {@link #requestPermissions(String[], int)}
253 */
254 private PendingRequestArgs mPendingRequestArgs;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800255
Sunny Goyal3333b0c2016-05-09 20:43:21 -0700256 public ViewGroupFocusHelper mFocusHandler;
Hyunyoung Song7fb3ccc2017-10-17 15:39:46 -0700257
Sunny Goyal623eddd2018-03-02 12:24:41 -0800258 private RotationHelper mRotationHelper;
Sunny Goyal5743f862019-03-28 15:35:32 -0700259 private Runnable mCancelTouchController;
Sunny Goyal7779d622015-06-11 16:18:39 -0700260
Sunny Goyal2db53422019-03-01 16:06:12 -0800261 final Handler mHandler = new Handler();
Sunny Goyala002c6c2019-02-12 16:20:10 -0800262 private final Runnable mHandleDeferredResume = this::handleDeferredResume;
Hyunyoung Songbd6fba92018-05-16 15:54:31 -0700263
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800264 @Override
265 protected void onCreate(Bundle savedInstanceState) {
vadimt00d42552018-12-11 17:59:36 -0800266 RaceConditionTracker.onEvent(ON_CREATE_EVT, ENTER);
Winson Chunga2413752012-04-03 14:22:34 -0700267 if (DEBUG_STRICT_MODE) {
268 StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
269 .detectDiskReads()
270 .detectDiskWrites()
271 .detectNetwork() // or .detectAll() for all detectable problems
272 .penaltyLog()
273 .build());
274 StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
275 .detectLeakedSqlLiteObjects()
276 .detectLeakedClosableObjects()
277 .penaltyLog()
278 .penaltyDeath()
279 .build());
280 }
Sunny Goyalfca6bc92017-09-28 16:28:34 -0700281 TraceHelper.beginSection("Launcher-onCreate");
Winson Chunga2413752012-04-03 14:22:34 -0700282
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800283 super.onCreate(savedInstanceState);
Sunny Goyalfca6bc92017-09-28 16:28:34 -0700284 TraceHelper.partitionSection("Launcher-onCreate", "super call");
Daniel Sandlere060b0b2013-06-27 21:47:55 -0400285
Sunny Goyal87f784c2017-01-11 10:48:34 -0800286 LauncherAppState app = LauncherAppState.getInstance(this);
Sunny Goyalf8d56fc2018-01-31 15:18:11 -0800287 mOldConfig = new Configuration(getResources().getConfiguration());
Sunny Goyal0e7724c2018-02-22 13:22:21 -0800288 mModel = app.setLauncher(this);
Hyunyoung Song31971a32019-01-27 12:31:12 -0800289 InvariantDeviceProfile idp = app.getInvariantDeviceProfile();
290 initDeviceProfile(idp);
291 idp.addOnChangeListener(this);
Sunny Goyalf7258242015-10-19 16:59:07 -0700292 mSharedPrefs = Utilities.getPrefs(this);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800293 mIconCache = app.getIconCache();
Sunny Goyalae502842016-06-17 08:43:56 -0700294 mAccessibilityDelegate = new LauncherAccessibilityDelegate(this);
Adam Cohen2e6da152015-05-06 11:42:25 -0700295
Joe Onorato41a12d22009-10-31 18:30:00 -0400296 mDragController = new DragController(this);
Hyunyoung Song645764e2016-06-06 14:19:02 -0700297 mAllAppsController = new AllAppsTransitionController(this);
Sunny Goyalc4fa8c32017-11-07 12:23:58 -0800298 mStateManager = new LauncherStateManager(this);
Tracy Zhou8b23c6f2018-04-30 17:13:27 -0700299 UiFactory.onCreate(this);
Romain Guycbb89e42009-06-08 15:52:54 -0700300
Sunny Goyalffe83f12014-08-14 17:39:34 -0700301 mAppWidgetManager = AppWidgetManagerCompat.getInstance(this);
Adam Cohen53805212013-10-01 10:39:23 -0700302
Sunny Goyal64a75aa2017-07-03 13:50:52 -0700303 mAppWidgetHost = new LauncherAppWidgetHost(this);
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700304 mAppWidgetHost.startListening();
Romain Guycbb89e42009-06-08 15:52:54 -0700305
Sunny Goyal60820d72017-05-09 12:40:11 -0700306 mLauncherView = LayoutInflater.from(this).inflate(R.layout.launcher, null);
Michael Jurka7267fa52013-09-26 15:29:57 -0700307
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800308 setupViews();
Tony Wickham010d2552017-01-20 08:15:28 -0800309 mPopupDataProvider = new PopupDataProvider(this);
310
Sunny Goyal623eddd2018-03-02 12:24:41 -0800311 mRotationHelper = new RotationHelper(this);
Sunny Goyal90548432018-04-04 17:17:00 -0700312 mAppTransitionManager = LauncherAppTransitionManager.newInstance(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800313
Sunny Goyald3864fa2017-11-14 15:06:36 -0800314 boolean internalStateHandled = InternalStateHandler.handleCreate(this, getIntent());
315 if (internalStateHandled) {
Sunny Goyald3864fa2017-11-14 15:06:36 -0800316 if (savedInstanceState != null) {
317 // InternalStateHandler has already set the appropriate state.
318 // We dont need to do anything.
319 savedInstanceState.remove(RUNTIME_STATE);
320 }
321 }
322 restoreState(savedInstanceState);
Sunny Goyalbbece862019-03-01 13:13:52 -0800323 mStateManager.reapplyState();
Winson Chungb63b44c2017-11-10 17:54:44 -0800324
Sunny Goyal2100c782016-08-22 16:00:03 -0700325 // We only load the page synchronously if the user rotates (or triggers a
326 // configuration change) while launcher is in the foreground
Sunny Goyalfe770c92016-09-27 14:38:58 -0700327 int currentScreen = PagedView.INVALID_RESTORE_PAGE;
328 if (savedInstanceState != null) {
329 currentScreen = savedInstanceState.getInt(RUNTIME_STATE_CURRENT_SCREEN, currentScreen);
330 }
Sunny Goyald3864fa2017-11-14 15:06:36 -0800331
Sunny Goyalfe770c92016-09-27 14:38:58 -0700332 if (!mModel.startLoader(currentScreen)) {
Sunny Goyald3864fa2017-11-14 15:06:36 -0800333 if (!internalStateHandled) {
334 // If we are not binding synchronously, show a fade in animation when
335 // the first page bind completes.
Sunny Goyal6001ea22018-05-10 16:31:00 -0700336 mDragLayer.getAlphaProperty(ALPHA_INDEX_LAUNCHER_LOAD).setValue(0);
Sunny Goyald3864fa2017-11-14 15:06:36 -0800337 }
Sunny Goyal2100c782016-08-22 16:00:03 -0700338 } else {
Sunny Goyalfe770c92016-09-27 14:38:58 -0700339 // Pages bound synchronously.
340 mWorkspace.setCurrentPage(currentScreen);
341
Sunny Goyal2100c782016-08-22 16:00:03 -0700342 setWorkspaceLoading(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800343 }
344
345 // For handling default keys
Sunny Goyalf4aceab2017-12-06 16:16:31 -0800346 setDefaultKeyMode(DEFAULT_KEYS_SEARCH_LOCAL);
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800347
Sunny Goyal0bbd5542016-11-11 10:41:26 -0800348 setContentView(mLauncherView);
Sunny Goyalf8d56fc2018-01-31 15:18:11 -0800349 getRootView().dispatchInsets();
Mario Bertschlera6936942017-05-31 14:48:19 -0700350
Jon Miranda7fda2852017-07-19 16:07:01 -0700351 // Listen for broadcasts
Sunny Goyal5d1873a2018-05-08 11:10:44 -0700352 registerReceiver(mScreenOffReceiver, new IntentFilter(Intent.ACTION_SCREEN_OFF));
Sunny Goyala616d2b2017-06-12 13:54:01 -0700353
Sunny Goyal8392c822017-06-20 10:03:56 -0700354 getSystemUiController().updateUiState(SystemUiController.UI_STATE_BASE_WINDOW,
355 Themes.getAttrBoolean(this, R.attr.isWorkspaceDarkText));
Sunny Goyal14b32402017-07-31 10:03:28 -0700356
357 if (mLauncherCallbacks != null) {
358 mLauncherCallbacks.onCreate(savedInstanceState);
359 }
Sunny Goyal623eddd2018-03-02 12:24:41 -0800360 mRotationHelper.initialize();
Sunny Goyalfca6bc92017-09-28 16:28:34 -0700361
362 TraceHelper.endSection("Launcher-onCreate");
vadimt00d42552018-12-11 17:59:36 -0800363 RaceConditionTracker.onEvent(ON_CREATE_EVT, EXIT);
Adam Cohen9211d422014-10-07 18:14:53 -0700364 }
365
Sunny Goyal7779d622015-06-11 16:18:39 -0700366 @Override
Winson Chung8eb49e02018-07-16 13:33:31 -0700367 public void onEnterAnimationComplete() {
368 super.onEnterAnimationComplete();
369 UiFactory.onEnterAnimationComplete(this);
arangelovad783052018-08-17 14:46:45 +0100370 mAllAppsController.highlightWorkTabIfNecessary();
Winson Chung8eb49e02018-07-16 13:33:31 -0700371 }
372
373 @Override
Sunny Goyalf8d56fc2018-01-31 15:18:11 -0800374 public void onConfigurationChanged(Configuration newConfig) {
375 int diff = newConfig.diff(mOldConfig);
Jon Mirandaaeb4dd02018-07-11 14:16:23 -0700376
377 if ((diff & CONFIG_LOCALE) != 0) {
378 Folder.setLocaleDependentFields(getResources(), true /* force */);
379 }
380
Sunny Goyalf8d56fc2018-01-31 15:18:11 -0800381 if ((diff & (CONFIG_ORIENTATION | CONFIG_SCREEN_SIZE)) != 0) {
Sunny Goyal371ea052019-03-06 15:38:32 -0800382 onIdpChanged(mDeviceProfile.inv);
Sunny Goyalf8d56fc2018-01-31 15:18:11 -0800383 }
384
385 mOldConfig.setTo(newConfig);
Tracy Zhoua706f002018-03-28 13:55:19 -0700386 UiFactory.onLauncherStateOrResumeChanged(this);
Sunny Goyalf8d56fc2018-01-31 15:18:11 -0800387 super.onConfigurationChanged(newConfig);
388 }
389
Sunny Goyal605bcf32018-03-02 15:16:12 -0800390 @Override
Sunny Goyal59d086c2018-05-07 17:31:40 -0700391 protected void reapplyUi() {
392 getRootView().dispatchInsets();
393 getStateManager().reapplyState(true /* cancelCurrentAnimation */);
394 }
395
396 @Override
Sunny Goyal605bcf32018-03-02 15:16:12 -0800397 public void rebindModel() {
398 int currentPage = mWorkspace.getNextPage();
399 if (mModel.startLoader(currentPage)) {
400 mWorkspace.setCurrentPage(currentPage);
401 setWorkspaceLoading(true);
402 }
403 }
404
Hyunyoung Song31971a32019-01-27 12:31:12 -0800405 @Override
406 public void onIdpChanged(int changeFlags, InvariantDeviceProfile idp) {
Sunny Goyal371ea052019-03-06 15:38:32 -0800407 onIdpChanged(idp);
408 }
409
Govinda Wasserman24e489e2019-03-28 12:23:28 -0400410 public void setQuickSearchBarAlpha(float alpha) {
411 View qsbAllApps = findViewById(R.id.search_container_all_apps);
412 if (qsbAllApps != null) {
413 qsbAllApps.setAlpha(alpha);
414 }
415 }
416
Sunny Goyal371ea052019-03-06 15:38:32 -0800417 private void onIdpChanged(InvariantDeviceProfile idp) {
418 mUserEventDispatcher = null;
419
Hyunyoung Song31971a32019-01-27 12:31:12 -0800420 initDeviceProfile(idp);
Sunny Goyal371ea052019-03-06 15:38:32 -0800421 dispatchDeviceProfileChanged();
422 reapplyUi();
423 mDragLayer.recreateControllers();
424
425 // TODO: We can probably avoid rebind when only screen size changed.
426 rebindModel();
Hyunyoung Song31971a32019-01-27 12:31:12 -0800427 }
428
Sunny Goyalf8d56fc2018-01-31 15:18:11 -0800429 private void initDeviceProfile(InvariantDeviceProfile idp) {
430 // Load configuration-specific DeviceProfile
Sunny Goyal59d086c2018-05-07 17:31:40 -0700431 mDeviceProfile = idp.getDeviceProfile(this);
Sunny Goyal8c48d8b2019-01-25 15:10:18 -0800432 if (isInMultiWindowMode()) {
Sunny Goyal59d086c2018-05-07 17:31:40 -0700433 Display display = getWindowManager().getDefaultDisplay();
434 Point mwSize = new Point();
435 display.getSize(mwSize);
436 mDeviceProfile = mDeviceProfile.getMultiWindowProfile(this, mwSize);
437 }
438 onDeviceProfileInitiated();
Sunny Goyal605bcf32018-03-02 15:16:12 -0800439 mModelWriter = mModel.getWriter(mDeviceProfile.isVerticalBarLayout(), true);
Sunny Goyalf8d56fc2018-01-31 15:18:11 -0800440 }
441
Sunny Goyal623eddd2018-03-02 12:24:41 -0800442 public RotationHelper getRotationHelper() {
443 return mRotationHelper;
444 }
445
Sunny Goyal3e3f44c2017-10-23 17:14:52 -0700446 public LauncherStateManager getStateManager() {
447 return mStateManager;
Sunny Goyalbe93f262017-10-20 17:05:27 -0700448 }
449
Mario Bertschler27288382017-05-24 15:35:09 -0700450 @Override
Sunny Goyalc7b8df82017-06-27 11:11:03 -0700451 public <T extends View> T findViewById(int id) {
Sunny Goyal0bbd5542016-11-11 10:41:26 -0800452 return mLauncherView.findViewById(id);
453 }
454
455 @Override
Sunny Goyal2e013ea2016-10-07 16:17:19 -0700456 public void onAppWidgetHostReset() {
457 if (mAppWidgetHost != null) {
458 mAppWidgetHost.startListening();
459 }
460 }
461
Adam Cohen9211d422014-10-07 18:14:53 -0700462 private LauncherCallbacks mLauncherCallbacks;
463
Sunny Goyal32554d12015-12-03 15:31:25 -0800464 /**
465 * Call this after onCreate to set or clear overlay.
466 */
467 public void setLauncherOverlay(LauncherOverlay overlay) {
468 if (overlay != null) {
469 overlay.setOverlayCallbacks(new LauncherOverlayCallbacksImpl());
470 }
471 mWorkspace.setLauncherOverlay(overlay);
472 }
473
Adam Cohen9211d422014-10-07 18:14:53 -0700474 public boolean setLauncherCallbacks(LauncherCallbacks callbacks) {
475 mLauncherCallbacks = callbacks;
476 return true;
Adam Cohenf9426d52012-06-04 17:26:21 -0700477 }
478
Anjali Koppal67e7cae2014-03-13 12:14:12 -0700479 @Override
Sunny Goyal2e013ea2016-10-07 16:17:19 -0700480 public void onLauncherProviderChanged() {
Adam Cohen9211d422014-10-07 18:14:53 -0700481 if (mLauncherCallbacks != null) {
482 mLauncherCallbacks.onLauncherProviderChange();
483 }
484 }
Anjali Koppal67e7cae2014-03-13 12:14:12 -0700485
Hyunyoung Song3f471442015-04-08 19:01:34 -0700486 public boolean isDraggingEnabled() {
Winson Chung36a62fe2012-05-06 18:04:42 -0700487 // We prevent dragging when we are loading the workspace as it is possible to pick up a view
488 // that is subsequently removed from the workspace in startBinding().
Sunny Goyal639e9062015-08-19 19:17:06 -0700489 return !isWorkspaceLoading();
Winson Chung36a62fe2012-05-06 18:04:42 -0700490 }
491
Tony Wickham010d2552017-01-20 08:15:28 -0800492 public PopupDataProvider getPopupDataProvider() {
493 return mPopupDataProvider;
494 }
495
Sunny Goyal0b0847b2018-03-14 12:30:11 -0700496 @Override
Tony Wickhamf34bee82018-12-03 18:11:39 -0800497 public DotInfo getDotInfoForItem(ItemInfo info) {
498 return mPopupDataProvider.getDotInfoForItem(info);
Sunny Goyal0b0847b2018-03-14 12:30:11 -0700499 }
500
501 @Override
502 public void invalidateParent(ItemInfo info) {
Jon Mirandae6f3fa42019-03-04 09:14:40 -0800503 if (info.container >= 0) {
Sunny Goyal0b0847b2018-03-14 12:30:11 -0700504 View folderIcon = getWorkspace().getHomescreenIconByItemId(info.container);
Jon Mirandae6f3fa42019-03-04 09:14:40 -0800505 if (folderIcon instanceof FolderIcon && folderIcon.getTag() instanceof FolderInfo) {
506 FolderIconPreviewVerifier verifier =
507 new FolderIconPreviewVerifier(getDeviceProfile().inv);
508 verifier.setFolderInfo((FolderInfo) folderIcon.getTag());
509 if (verifier.isItemInPreview(info.rank)) {
510 folderIcon.invalidate();
511 }
Sunny Goyal0b0847b2018-03-14 12:30:11 -0700512 }
513 }
514 }
515
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000516 /**
Winson Chung557d6ed2011-07-08 15:34:52 -0700517 * Returns whether we should delay spring loaded mode -- for shortcuts and widgets that have
518 * a configuration step, this allows the proper animations to run after other transitions.
519 */
Sunny Goyalefb7e842018-10-04 15:11:00 -0700520 private int completeAdd(
Sunny Goyal2100c782016-08-22 16:00:03 -0700521 int requestCode, Intent intent, int appWidgetId, PendingRequestArgs info) {
Sunny Goyalefb7e842018-10-04 15:11:00 -0700522 int screenId = info.screenId;
Sunny Goyal2100c782016-08-22 16:00:03 -0700523 if (info.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
Adam Cohen83079e42014-09-19 17:43:08 -0700524 // When the screen id represents an actual screen (as opposed to a rank) we make sure
525 // that the drop page actually exists.
Sunny Goyal2100c782016-08-22 16:00:03 -0700526 screenId = ensurePendingDropLayoutExists(info.screenId);
Adam Cohen83079e42014-09-19 17:43:08 -0700527 }
Adam Cohendb364c32014-05-20 14:23:40 -0700528
Sunny Goyal2100c782016-08-22 16:00:03 -0700529 switch (requestCode) {
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800530 case REQUEST_CREATE_SHORTCUT:
Sunny Goyalfb5096d2016-09-08 14:32:06 -0700531 completeAddShortcut(intent, info.container, screenId, info.cellX, info.cellY, info);
Winson Chungb8472bb2011-08-05 13:49:21 -0700532 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800533 case REQUEST_CREATE_APPWIDGET:
Sunny Goyal2100c782016-08-22 16:00:03 -0700534 completeAddAppWidget(appWidgetId, info, null, null);
Winson Chungb8472bb2011-08-05 13:49:21 -0700535 break;
Sunny Goyalff572272014-07-23 13:58:07 -0700536 case REQUEST_RECONFIGURE_APPWIDGET:
Sunny Goyal2100c782016-08-22 16:00:03 -0700537 completeRestoreAppWidget(appWidgetId, LauncherAppWidgetInfo.RESTORE_COMPLETED);
Sunny Goyalff572272014-07-23 13:58:07 -0700538 break;
Sunny Goyald478c832016-04-01 12:04:16 -0700539 case REQUEST_BIND_PENDING_APPWIDGET: {
Sunny Goyal2100c782016-08-22 16:00:03 -0700540 int widgetId = appWidgetId;
541 LauncherAppWidgetInfo widgetInfo =
Sunny Goyald478c832016-04-01 12:04:16 -0700542 completeRestoreAppWidget(widgetId, LauncherAppWidgetInfo.FLAG_UI_NOT_READY);
Sunny Goyal2100c782016-08-22 16:00:03 -0700543 if (widgetInfo != null) {
Sunny Goyald478c832016-04-01 12:04:16 -0700544 // Since the view was just bound, also launch the configure activity if needed
545 LauncherAppWidgetProviderInfo provider = mAppWidgetManager
546 .getLauncherAppWidgetInfo(widgetId);
Sunny Goyal04a324a2017-01-20 21:08:59 -0800547 if (provider != null) {
548 new WidgetAddFlowHandler(provider)
549 .startConfigActivity(this, widgetInfo, REQUEST_RECONFIGURE_APPWIDGET);
Sunny Goyald478c832016-04-01 12:04:16 -0700550 }
551 }
552 break;
553 }
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800554 }
Sunny Goyal2100c782016-08-22 16:00:03 -0700555
Adam Cohendb364c32014-05-20 14:23:40 -0700556 return screenId;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800557 }
558
Adam Cohenc7cd2cb2014-11-17 17:45:34 -0800559 private void handleActivityResult(
Michael Jurka8b805b12012-04-18 14:23:14 -0700560 final int requestCode, final int resultCode, final Intent data) {
Sunny Goyal2100c782016-08-22 16:00:03 -0700561 if (isWorkspaceLoading()) {
562 // process the result once the workspace has loaded.
563 mPendingActivityResult = new ActivityResultInfo(requestCode, resultCode, data);
564 return;
565 }
566 mPendingActivityResult = null;
567
Winson Chunge341d302013-08-16 14:31:00 -0700568 // Reset the startActivity waiting flag
Sunny Goyal2100c782016-08-22 16:00:03 -0700569 final PendingRequestArgs requestArgs = mPendingRequestArgs;
570 setWaitingForResult(null);
571 if (requestArgs == null) {
572 return;
573 }
574
575 final int pendingAddWidgetId = requestArgs.getWidgetId();
Winson Chunge341d302013-08-16 14:31:00 -0700576
Adam Cohenad4e15c2013-10-17 16:21:35 -0700577 Runnable exitSpringLoaded = new Runnable() {
578 @Override
579 public void run() {
Sunny Goyal3e3f44c2017-10-23 17:14:52 -0700580 mStateManager.goToState(NORMAL, SPRING_LOADED_EXIT_DELAY);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700581 }
582 };
583
Michael Jurka8b805b12012-04-18 14:23:14 -0700584 if (requestCode == REQUEST_BIND_APPWIDGET) {
Winsona1f79d32015-08-05 14:00:45 -0700585 // This is called only if the user did not previously have permissions to bind widgets
Adam Cohenad4e15c2013-10-17 16:21:35 -0700586 final int appWidgetId = data != null ?
Michael Jurka8b805b12012-04-18 14:23:14 -0700587 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
588 if (resultCode == RESULT_CANCELED) {
Sunny Goyal2100c782016-08-22 16:00:03 -0700589 completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId, requestArgs);
Adam Cohen689ff162014-05-08 17:27:56 -0700590 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
Adam Cohenad4e15c2013-10-17 16:21:35 -0700591 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
Michael Jurka8b805b12012-04-18 14:23:14 -0700592 } else if (resultCode == RESULT_OK) {
Sunny Goyal2100c782016-08-22 16:00:03 -0700593 addAppWidgetImpl(
594 appWidgetId, requestArgs, null,
Sunny Goyal04a324a2017-01-20 21:08:59 -0800595 requestArgs.getWidgetHandler(),
Sunny Goyal2100c782016-08-22 16:00:03 -0700596 ON_ACTIVITY_RESULT_ANIMATION_DELAY);
Michael Jurka8b805b12012-04-18 14:23:14 -0700597 }
598 return;
599 }
Michael Jurka336fd4f2013-09-12 00:05:02 +0200600
Adam Cohened66b2b2012-01-23 17:28:51 -0800601 boolean isWidgetDrop = (requestCode == REQUEST_PICK_APPWIDGET ||
Sunny Goyal5c97f512015-05-19 16:03:28 -0700602 requestCode == REQUEST_CREATE_APPWIDGET);
Romain Guyaad5ef42009-06-10 02:48:37 -0700603
Adam Cohened66b2b2012-01-23 17:28:51 -0800604 // We have special handling for widgets
605 if (isWidgetDrop) {
Adam Cohen4637b5a2013-11-04 18:21:24 -0800606 final int appWidgetId;
607 int widgetId = data != null ? data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1)
608 : -1;
609 if (widgetId < 0) {
610 appWidgetId = pendingAddWidgetId;
611 } else {
612 appWidgetId = widgetId;
613 }
614
Adam Cohenad4e15c2013-10-17 16:21:35 -0700615 final int result;
Adam Cohenf0129b12013-11-04 17:57:36 -0800616 if (appWidgetId < 0 || resultCode == RESULT_CANCELED) {
Adam Cohendb364c32014-05-20 14:23:40 -0700617 Log.e(TAG, "Error: appWidgetId (EXTRA_APPWIDGET_ID) was not " +
618 "returned from the widget configuration activity.");
Adam Cohenad4e15c2013-10-17 16:21:35 -0700619 result = RESULT_CANCELED;
Sunny Goyal2100c782016-08-22 16:00:03 -0700620 completeTwoStageWidgetDrop(result, appWidgetId, requestArgs);
Adam Cohendb364c32014-05-20 14:23:40 -0700621 final Runnable onComplete = new Runnable() {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700622 @Override
623 public void run() {
Sunny Goyal3e3f44c2017-10-23 17:14:52 -0700624 getStateManager().goToState(NORMAL);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700625 }
626 };
Adam Cohendb364c32014-05-20 14:23:40 -0700627
Sunny Goyal2100c782016-08-22 16:00:03 -0700628 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete,
629 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
630 } else {
631 if (requestArgs.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
632 // When the screen id represents an actual screen (as opposed to a rank)
633 // we make sure that the drop page actually exists.
634 requestArgs.screenId =
635 ensurePendingDropLayoutExists(requestArgs.screenId);
Adam Cohendb364c32014-05-20 14:23:40 -0700636 }
Sunny Goyal2100c782016-08-22 16:00:03 -0700637 final CellLayout dropLayout =
638 mWorkspace.getScreenWithId(requestArgs.screenId);
639
640 dropLayout.setDropPending(true);
641 final Runnable onComplete = new Runnable() {
642 @Override
643 public void run() {
644 completeTwoStageWidgetDrop(resultCode, appWidgetId, requestArgs);
645 dropLayout.setDropPending(false);
646 }
647 };
648 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete,
649 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
Winson Chung5aaab772012-04-27 15:24:02 -0700650 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800651 return;
652 }
653
Sunny Goyald478c832016-04-01 12:04:16 -0700654 if (requestCode == REQUEST_RECONFIGURE_APPWIDGET
655 || requestCode == REQUEST_BIND_PENDING_APPWIDGET) {
Sunny Goyalff572272014-07-23 13:58:07 -0700656 if (resultCode == RESULT_OK) {
657 // Update the widget view.
Sunny Goyal2100c782016-08-22 16:00:03 -0700658 completeAdd(requestCode, data, pendingAddWidgetId, requestArgs);
Sunny Goyalff572272014-07-23 13:58:07 -0700659 }
660 // Leave the widget in the pending state if the user canceled the configure.
661 return;
662 }
663
Sunny Goyalaad90582015-07-09 14:22:50 -0700664 if (requestCode == REQUEST_CREATE_SHORTCUT) {
665 // Handle custom shortcuts created using ACTION_CREATE_SHORTCUT.
Sunny Goyal2100c782016-08-22 16:00:03 -0700666 if (resultCode == RESULT_OK && requestArgs.container != ItemInfo.NO_ID) {
667 completeAdd(requestCode, data, -1, requestArgs);
668 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
669 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
670
Sunny Goyalaad90582015-07-09 14:22:50 -0700671 } else if (resultCode == RESULT_CANCELED) {
Adam Cohendb364c32014-05-20 14:23:40 -0700672 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
673 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800674 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800675 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800676 mDragLayer.clearAnimatedView();
Adam Cohenc7cd2cb2014-11-17 17:45:34 -0800677 }
678
679 @Override
Sunny Goyal64a75aa2017-07-03 13:50:52 -0700680 public void onActivityResult(
Adam Cohenc7cd2cb2014-11-17 17:45:34 -0800681 final int requestCode, final int resultCode, final Intent data) {
682 handleActivityResult(requestCode, resultCode, data);
683 if (mLauncherCallbacks != null) {
684 mLauncherCallbacks.onActivityResult(requestCode, resultCode, data);
685 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800686 }
687
Sunny Goyal7ce471b2017-08-02 03:37:39 -0700688 @Override
Sunny Goyaldd2e6df2015-07-07 10:57:57 -0700689 public void onRequestPermissionsResult(int requestCode, String[] permissions,
Dave Hawkey3a43ed62015-06-26 10:27:47 -0600690 int[] grantResults) {
Sunny Goyal2100c782016-08-22 16:00:03 -0700691 PendingRequestArgs pendingArgs = mPendingRequestArgs;
692 if (requestCode == REQUEST_PERMISSION_CALL_PHONE && pendingArgs != null
693 && pendingArgs.getRequestCode() == REQUEST_PERMISSION_CALL_PHONE) {
694 setWaitingForResult(null);
695
Sunny Goyal28c6b962015-10-12 11:42:05 -0700696 View v = null;
Sunny Goyal2100c782016-08-22 16:00:03 -0700697 CellLayout layout = getCellLayout(pendingArgs.container, pendingArgs.screenId);
Sunny Goyal28c6b962015-10-12 11:42:05 -0700698 if (layout != null) {
Sunny Goyal2100c782016-08-22 16:00:03 -0700699 v = layout.getChildAt(pendingArgs.cellX, pendingArgs.cellY);
Sunny Goyal28c6b962015-10-12 11:42:05 -0700700 }
Sunny Goyal2100c782016-08-22 16:00:03 -0700701 Intent intent = pendingArgs.getPendingIntent();
702
Sunny Goyal28c6b962015-10-12 11:42:05 -0700703 if (grantResults.length > 0
704 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
Sunny Goyal369212a2019-03-26 15:03:57 -0700705 startActivitySafely(v, intent, null, null);
Sunny Goyal28c6b962015-10-12 11:42:05 -0700706 } else {
707 // TODO: Show a snack bar with link to settings
708 Toast.makeText(this, getString(R.string.msg_no_phone_permission,
Sunny Goyal112ce422016-08-22 16:45:29 -0700709 getString(R.string.derived_app_name)), Toast.LENGTH_SHORT).show();
Sunny Goyal28c6b962015-10-12 11:42:05 -0700710 }
711 }
Dave Hawkey3a43ed62015-06-26 10:27:47 -0600712 if (mLauncherCallbacks != null) {
713 mLauncherCallbacks.onRequestPermissionsResult(requestCode, permissions,
714 grantResults);
715 }
716 }
717
Adam Cohendb364c32014-05-20 14:23:40 -0700718 /**
719 * Check to see if a given screen id exists. If not, create it at the end, return the new id.
720 *
721 * @param screenId the screen id to check
722 * @return the new screen, or screenId if it exists
723 */
Sunny Goyalefb7e842018-10-04 15:11:00 -0700724 private int ensurePendingDropLayoutExists(int screenId) {
Sunny Goyal32554d12015-12-03 15:31:25 -0800725 CellLayout dropLayout = mWorkspace.getScreenWithId(screenId);
Adam Cohendb364c32014-05-20 14:23:40 -0700726 if (dropLayout == null) {
727 // it's possible that the add screen was removed because it was
728 // empty and a re-bind occurred
729 mWorkspace.addExtraEmptyScreen();
730 return mWorkspace.commitExtraEmptyScreen();
731 } else {
732 return screenId;
733 }
734 }
735
Sunny Goyal2100c782016-08-22 16:00:03 -0700736 @Thunk void completeTwoStageWidgetDrop(
737 final int resultCode, final int appWidgetId, final PendingRequestArgs requestArgs) {
738 CellLayout cellLayout = mWorkspace.getScreenWithId(requestArgs.screenId);
Adam Cohened66b2b2012-01-23 17:28:51 -0800739 Runnable onCompleteRunnable = null;
740 int animationType = 0;
741
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700742 AppWidgetHostView boundWidget = null;
Adam Cohened66b2b2012-01-23 17:28:51 -0800743 if (resultCode == RESULT_OK) {
744 animationType = Workspace.COMPLETE_TWO_STAGE_WIDGET_DROP_ANIMATION;
745 final AppWidgetHostView layout = mAppWidgetHost.createView(this, appWidgetId,
Sunny Goyal04a324a2017-01-20 21:08:59 -0800746 requestArgs.getWidgetHandler().getProviderInfo(this));
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700747 boundWidget = layout;
Adam Cohened66b2b2012-01-23 17:28:51 -0800748 onCompleteRunnable = new Runnable() {
749 @Override
750 public void run() {
Sunny Goyal2100c782016-08-22 16:00:03 -0700751 completeAddAppWidget(appWidgetId, requestArgs, layout, null);
Sunny Goyal3e3f44c2017-10-23 17:14:52 -0700752 mStateManager.goToState(NORMAL, SPRING_LOADED_EXIT_DELAY);
Adam Cohened66b2b2012-01-23 17:28:51 -0800753 }
754 };
755 } else if (resultCode == RESULT_CANCELED) {
Adam Cohen4637b5a2013-11-04 18:21:24 -0800756 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
Adam Cohened66b2b2012-01-23 17:28:51 -0800757 animationType = Workspace.CANCEL_TWO_STAGE_WIDGET_DROP_ANIMATION;
Adam Cohened66b2b2012-01-23 17:28:51 -0800758 }
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700759 if (mDragLayer.getAnimatedView() != null) {
Sunny Goyal2100c782016-08-22 16:00:03 -0700760 mWorkspace.animateWidgetDrop(requestArgs, cellLayout,
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700761 (DragView) mDragLayer.getAnimatedView(), onCompleteRunnable,
762 animationType, boundWidget, true);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700763 } else if (onCompleteRunnable != null) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700764 // The animated view may be null in the case of a rotation during widget configuration
765 onCompleteRunnable.run();
766 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800767 }
768
769 @Override
Michael Jurkacd496d72013-04-11 11:32:45 -0700770 protected void onStop() {
771 super.onStop();
Adam Cohen9211d422014-10-07 18:14:53 -0700772 if (mLauncherCallbacks != null) {
773 mLauncherCallbacks.onStop();
774 }
Miranda Kephart1a359a22019-02-11 13:07:04 -0500775
Hyunyoung Song1241e612018-05-15 21:46:51 -0700776 getUserEventDispatcher().logActionCommand(Action.Command.STOP,
777 mStateManager.getState().containerType, -1);
Hyunyoung Songbd6fba92018-05-16 15:54:31 -0700778
779 mAppWidgetHost.setListenIfResumed(false);
780
Tony Wickham010d2552017-01-20 08:15:28 -0800781 NotificationListener.removeNotificationsChangedListener();
Sunny Goyalaf161fd2018-02-05 16:34:57 -0800782 getStateManager().moveToRestState();
Winson Chungedb0d6b2018-03-21 17:32:55 -0700783
Tracy Zhou62646712018-06-26 14:19:02 -0700784 UiFactory.onLauncherStateOrResumeChanged(this);
785
Winson Chungdea51352018-04-24 13:02:10 -0700786 // Workaround for b/78520668, explicitly trim memory once UI is hidden
Winson Chung473730f2018-04-26 11:54:22 -0700787 onTrimMemory(TRIM_MEMORY_UI_HIDDEN);
Michael Jurkacd496d72013-04-11 11:32:45 -0700788 }
789
790 @Override
791 protected void onStart() {
vadimtcb863752018-12-19 17:44:57 -0800792 RaceConditionTracker.onEvent(ON_START_EVT, ENTER);
Michael Jurkacd496d72013-04-11 11:32:45 -0700793 super.onStart();
Adam Cohen9211d422014-10-07 18:14:53 -0700794 if (mLauncherCallbacks != null) {
795 mLauncherCallbacks.onStart();
796 }
Sunny Goyal67419a12017-11-14 16:55:22 -0800797 mAppWidgetHost.setListenIfResumed(true);
Sunny Goyalcac002d2018-01-04 09:51:45 -0800798 NotificationListener.setNotificationsChangedListener(mPopupDataProvider);
vadimtcb863752018-12-19 17:44:57 -0800799 RaceConditionTracker.onEvent(ON_START_EVT, EXIT);
Michael Jurkacd496d72013-04-11 11:32:45 -0700800 }
801
Sunny Goyala002c6c2019-02-12 16:20:10 -0800802 private void handleDeferredResume() {
Hyunyoung Songbd6fba92018-05-16 15:54:31 -0700803 if (hasBeenResumed()) {
804 getUserEventDispatcher().logActionCommand(Action.Command.RESUME,
805 mStateManager.getState().containerType, -1);
806 getUserEventDispatcher().startSession();
Sunny Goyala002c6c2019-02-12 16:20:10 -0800807
808 UiFactory.onLauncherStateOrResumeChanged(this);
Sunny Goyal369212a2019-03-26 15:03:57 -0700809 AppLaunchTracker.INSTANCE.get(this).onReturnedToHome();
Hyunyoung Songbd6fba92018-05-16 15:54:31 -0700810 }
811 }
812
Michael Jurkacd496d72013-04-11 11:32:45 -0700813 @Override
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800814 protected void onResume() {
vadimtcb863752018-12-19 17:44:57 -0800815 RaceConditionTracker.onEvent(ON_RESUME_EVT, ENTER);
Sunny Goyalfca6bc92017-09-28 16:28:34 -0700816 TraceHelper.beginSection("ON_RESUME");
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800817 super.onResume();
Sunny Goyalfca6bc92017-09-28 16:28:34 -0700818 TraceHelper.partitionSection("ON_RESUME", "superCall");
819
Sunny Goyala002c6c2019-02-12 16:20:10 -0800820 mHandler.removeCallbacks(mHandleDeferredResume);
821 Utilities.postAsyncCallback(mHandler, mHandleDeferredResume);
Hyunyoung Songbd6fba92018-05-16 15:54:31 -0700822
Sunny Goyal3dce5f32017-10-05 11:40:05 -0700823 setOnResumeCallback(null);
Sunny Goyala474a9b2017-05-04 16:47:11 -0700824 // Process any items that were added while Launcher was away.
825 InstallShortcutReceiver.disableAndFlushInstallQueue(
826 InstallShortcutReceiver.FLAG_ACTIVITY_PAUSED, this);
Sunny Goyal95f3d6b2016-08-10 16:09:29 -0700827
Sunny Goyala474a9b2017-05-04 16:47:11 -0700828 // Refresh shortcuts if the permission changed.
829 mModel.refreshShortcutsIfRequired();
Adam Cohen9211d422014-10-07 18:14:53 -0700830
Tracy Zhoue5575f92018-04-19 11:12:53 -0700831 DiscoveryBounce.showForHomeIfNeeded(this);
Adam Cohen9211d422014-10-07 18:14:53 -0700832 if (mLauncherCallbacks != null) {
833 mLauncherCallbacks.onResume();
834 }
Mario Bertschler0fc6f682017-02-17 12:16:13 -0800835
Sunny Goyalfca6bc92017-09-28 16:28:34 -0700836 TraceHelper.endSection("ON_RESUME");
vadimtcb863752018-12-19 17:44:57 -0800837 RaceConditionTracker.onEvent(ON_RESUME_EVT, EXIT);
Adam Cohen06dff352012-06-01 17:17:08 -0700838 }
839
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800840 @Override
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700841 protected void onPause() {
Winson Chung997a9232013-07-24 15:33:46 -0700842 // Ensure that items added to Launcher are queued until Launcher returns
Sunny Goyala474a9b2017-05-04 16:47:11 -0700843 InstallShortcutReceiver.enableInstallQueue(InstallShortcutReceiver.FLAG_ACTIVITY_PAUSED);
Winson Chung997a9232013-07-24 15:33:46 -0700844
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700845 super.onPause();
Joe Onorato24b6fd82009-11-12 13:47:09 -0800846 mDragController.cancelDrag();
Winson Chunga2413752012-04-03 14:22:34 -0700847 mDragController.resetLastGestureUpTime();
Adam Cohen6fecd412013-10-02 17:41:50 -0700848
Adam Cohen9211d422014-10-07 18:14:53 -0700849 if (mLauncherCallbacks != null) {
850 mLauncherCallbacks.onPause();
Adam Cohenbffe7452013-07-22 18:21:45 -0700851 }
Adam Cohenbffe7452013-07-22 18:21:45 -0700852 }
853
Winson Chungd7823942018-02-16 03:23:47 +0000854 @Override
Tracy Zhoua706f002018-03-28 13:55:19 -0700855 protected void onUserLeaveHint() {
856 super.onUserLeaveHint();
857 UiFactory.onLauncherStateOrResumeChanged(this);
858 }
859
860 @Override
Winson Chungd7823942018-02-16 03:23:47 +0000861 public void onWindowFocusChanged(boolean hasFocus) {
862 super.onWindowFocusChanged(hasFocus);
863 mStateManager.onWindowFocusChanged();
864 }
865
Adam Cohenc2d6e892014-10-16 09:49:24 -0700866 public interface LauncherOverlay {
867
868 /**
869 * Touch interaction leading to overscroll has begun
870 */
Rajeev Kumar43c0f582017-06-23 15:34:55 -0700871 void onScrollInteractionBegin();
Adam Cohenc2d6e892014-10-16 09:49:24 -0700872
873 /**
874 * Touch interaction related to overscroll has ended
875 */
Rajeev Kumar43c0f582017-06-23 15:34:55 -0700876 void onScrollInteractionEnd();
Adam Cohenc2d6e892014-10-16 09:49:24 -0700877
878 /**
879 * Scroll progress, between 0 and 100, when the user scrolls beyond the leftmost
880 * screen (or in the case of RTL, the rightmost screen).
881 */
Rajeev Kumar43c0f582017-06-23 15:34:55 -0700882 void onScrollChange(float progress, boolean rtl);
Adam Cohenc2d6e892014-10-16 09:49:24 -0700883
884 /**
Sunny Goyal32554d12015-12-03 15:31:25 -0800885 * Called when the launcher is ready to use the overlay
886 * @param callbacks A set of callbacks provided by Launcher in relation to the overlay
Adam Cohenc2d6e892014-10-16 09:49:24 -0700887 */
Rajeev Kumar43c0f582017-06-23 15:34:55 -0700888 void setOverlayCallbacks(LauncherOverlayCallbacks callbacks);
Adam Cohenc2d6e892014-10-16 09:49:24 -0700889 }
890
891 public interface LauncherOverlayCallbacks {
Rajeev Kumar43c0f582017-06-23 15:34:55 -0700892 void onScrollChanged(float progress);
Adam Cohenc2d6e892014-10-16 09:49:24 -0700893 }
894
895 class LauncherOverlayCallbacksImpl implements LauncherOverlayCallbacks {
896
Sunny Goyalc86df472016-02-25 09:19:38 -0800897 public void onScrollChanged(float progress) {
898 if (mWorkspace != null) {
899 mWorkspace.onOverlayScrollChanged(progress);
900 }
901 }
Adam Cohenc2d6e892014-10-16 09:49:24 -0700902 }
903
Sunny Goyalf9403d92017-10-18 10:55:56 -0700904 public boolean isInState(LauncherState state) {
Sunny Goyalea609262017-10-25 15:47:38 -0700905 return mStateManager.getState() == state;
Sunny Goyalf9403d92017-10-18 10:55:56 -0700906 }
907
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800908 /**
909 * Restores the previous state, if it exists.
910 *
911 * @param savedState The previous state.
912 */
913 private void restoreState(Bundle savedState) {
914 if (savedState == null) {
915 return;
916 }
917
Sunny Goyal3e3f44c2017-10-23 17:14:52 -0700918 int stateOrdinal = savedState.getInt(RUNTIME_STATE, NORMAL.ordinal);
Sunny Goyalf9403d92017-10-18 10:55:56 -0700919 LauncherState[] stateValues = LauncherState.values();
920 LauncherState state = stateValues[stateOrdinal];
Sunny Goyalbc683e92017-12-06 10:25:07 -0800921 if (!state.disableRestore) {
Sunny Goyal3e3f44c2017-10-23 17:14:52 -0700922 mStateManager.goToState(state, false /* animated */);
Joe Onorato3a8820b2009-11-10 15:06:42 -0800923 }
924
Sunny Goyal2100c782016-08-22 16:00:03 -0700925 PendingRequestArgs requestArgs = savedState.getParcelable(RUNTIME_STATE_PENDING_REQUEST_ARGS);
926 if (requestArgs != null) {
927 setWaitingForResult(requestArgs);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800928 }
Sunny Goyal2100c782016-08-22 16:00:03 -0700929
930 mPendingActivityResult = savedState.getParcelable(RUNTIME_STATE_PENDING_ACTIVITY_RESULT);
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -0700931
932 SparseArray<Parcelable> widgetsState =
933 savedState.getSparseParcelableArray(RUNTIME_STATE_WIDGET_PANEL);
934 if (widgetsState != null) {
935 WidgetsFullSheet.show(this, false).restoreHierarchyState(widgetsState);
936 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800937 }
938
939 /**
940 * Finds all the views we need and configure them properly.
941 */
942 private void setupViews() {
Sunny Goyalcc96aa12018-01-11 09:56:07 -0800943 mDragLayer = findViewById(R.id.drag_layer);
Sunny Goyal3333b0c2016-05-09 20:43:21 -0700944 mFocusHandler = mDragLayer.getFocusIndicatorHelper();
Sunny Goyal966d9012017-06-06 16:43:59 -0700945 mWorkspace = mDragLayer.findViewById(R.id.workspace);
Sunny Goyald0a6ae72016-06-16 12:29:03 -0700946 mWorkspace.initParentViews(mDragLayer);
Sunny Goyal16764582017-11-06 16:00:34 -0800947 mOverviewPanel = findViewById(R.id.overview_panel);
Sunny Goyal7c7be8c2018-03-07 19:58:07 -0800948 mHotseat = findViewById(R.id.hotseat);
Craig Mautner360310b2012-10-26 15:13:08 -0700949
Sunny Goyal784f9c32016-03-23 16:56:54 -0700950 mLauncherView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
951 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
952 | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800953
Winson Chung4c98d922011-05-31 16:50:48 -0700954 // Setup the drag layer
Sunny Goyal5d1873a2018-05-08 11:10:44 -0700955 mDragLayer.setup(mDragController, mWorkspace);
Sunny Goyal5743f862019-03-28 15:35:32 -0700956 mCancelTouchController = UiFactory.enableLiveTouchControllerChanges(mDragLayer);
Winson Chung4c98d922011-05-31 16:50:48 -0700957
Hyunyoung Song645764e2016-06-06 14:19:02 -0700958 mWorkspace.setup(mDragController);
Winsonc7d2e832016-07-28 12:24:55 -0700959 // Until the workspace is bound, ensure that we keep the wallpaper offset locked to the
960 // default state, otherwise we will update to the wrong offsets in RTL
961 mWorkspace.lockWallpaperToDefaultPage();
Sunny Goyalda4fe1a2016-05-26 16:05:17 -0700962 mWorkspace.bindAndInitFirstWorkspaceScreen(null /* recycled qsb */);
Hyunyoung Song645764e2016-06-06 14:19:02 -0700963 mDragController.addDragListener(mWorkspace);
Winson Chung4c98d922011-05-31 16:50:48 -0700964
Tony Wickham34d2c912015-09-11 09:27:58 -0700965 // Get the search/delete/uninstall bar
Rajeev Kumar43c0f582017-06-23 15:34:55 -0700966 mDropTargetBar = mDragLayer.findViewById(R.id.drop_target_bar);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -0700967
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -0700968 // Setup Apps
969 mAppsView = findViewById(R.id.apps_view);
Craig Mautner360310b2012-10-26 15:13:08 -0700970
Winson Chung3d503fb2011-07-13 17:25:49 -0700971 // Setup the drag controller (drop targets have to be added in reverse order in priority)
Hyunyoung Song645764e2016-06-06 14:19:02 -0700972 mDragController.setMoveTarget(mWorkspace);
Sunny Goyal47328fd2016-05-25 18:56:41 -0700973 mDropTargetBar.setup(mDragController);
Daniel Sandler924b9932013-06-12 00:38:25 -0400974
Sunny Goyal7185dd62018-03-14 17:51:49 -0700975 mAllAppsController.setupViews(mAppsView);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800976 }
977
978 /**
979 * Creates a view representing a shortcut.
980 *
981 * @param info The data structure describing the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800982 */
Sunny Goyal95899162019-03-27 16:03:06 -0700983 View createShortcut(WorkspaceItemInfo info) {
Sunny Goyaldfaccf62015-05-11 16:30:44 -0700984 return createShortcut((ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800985 }
986
987 /**
988 * Creates a view representing a shortcut inflated from the specified resource.
989 *
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800990 * @param parent The group the shortcut belongs to.
991 * @param info The data structure describing the shortcut.
992 *
993 * @return A View inflated from layoutResId.
994 */
Sunny Goyal95899162019-03-27 16:03:06 -0700995 public View createShortcut(ViewGroup parent, WorkspaceItemInfo info) {
Sunny Goyal9b29ca52017-02-17 10:39:44 -0800996 BubbleTextView favorite = (BubbleTextView) LayoutInflater.from(parent.getContext())
997 .inflate(R.layout.app_icon, parent, false);
Sunny Goyal95899162019-03-27 16:03:06 -0700998 favorite.applyFromWorkspaceItem(info);
Sunny Goyal8a2a63b2018-03-06 22:15:18 -0800999 favorite.setOnClickListener(ItemClickHandler.INSTANCE);
Sunny Goyaldcbcc862014-08-12 15:58:36 -07001000 favorite.setOnFocusChangeListener(mFocusHandler);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001001 return favorite;
1002 }
1003
1004 /**
Jon Mirandac476d6e2017-05-04 16:30:01 -07001005 * Add a shortcut to the workspace or to a Folder.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001006 *
1007 * @param data The intent describing the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001008 */
Sunny Goyalefb7e842018-10-04 15:11:00 -07001009 private void completeAddShortcut(Intent data, int container, int screenId, int cellX,
Sunny Goyalfb5096d2016-09-08 14:32:06 -07001010 int cellY, PendingRequestArgs args) {
Jon Mirandac476d6e2017-05-04 16:30:01 -07001011 if (args.getRequestCode() != REQUEST_CREATE_SHORTCUT
1012 || args.getPendingIntent().getComponent() == null) {
Sunny Goyalfb5096d2016-09-08 14:32:06 -07001013 return;
1014 }
Adam Cohen558baaf2011-08-15 15:22:57 -07001015
Jon Mirandac476d6e2017-05-04 16:30:01 -07001016 int[] cellXY = mTmpAddItemCellCoordinates;
1017 CellLayout layout = getCellLayout(container, screenId);
1018
Sunny Goyal95899162019-03-27 16:03:06 -07001019 WorkspaceItemInfo info = null;
Hyunyoung Songe24cb632017-09-11 11:18:03 -07001020 if (Utilities.ATLEAST_OREO) {
Sunny Goyal95899162019-03-27 16:03:06 -07001021 info = LauncherAppsCompatVO.createWorkspaceItemFromPinItemRequest(
Sunny Goyal22ca9ec2017-05-18 15:03:13 -07001022 this, LauncherAppsCompatVO.getPinItemRequest(data), 0);
Sunny Goyal782f0c92017-01-19 10:27:54 -08001023 }
1024
1025 if (info == null) {
Sunny Goyalb57645f2017-03-20 13:57:28 -07001026 // Legacy shortcuts are only supported for primary profile.
1027 info = Process.myUserHandle().equals(args.user)
1028 ? InstallShortcutReceiver.fromShortcutIntent(this, data) : null;
Sunny Goyal782f0c92017-01-19 10:27:54 -08001029
Sunny Goyalb57645f2017-03-20 13:57:28 -07001030 if (info == null) {
1031 Log.e(TAG, "Unable to parse a valid custom shortcut result");
1032 return;
1033 } else if (!new PackageManagerHelper(this).hasPermissionForActivity(
Sunny Goyal342e4662017-02-02 15:21:08 -08001034 info.intent, args.getPendingIntent().getComponent().getPackageName())) {
Sunny Goyal782f0c92017-01-19 10:27:54 -08001035 // The app is trying to add a shortcut without sufficient permissions
1036 Log.e(TAG, "Ignoring malicious intent " + info.intent.toUri(0));
1037 return;
1038 }
1039 }
1040
Jon Mirandac476d6e2017-05-04 16:30:01 -07001041 if (container < 0) {
1042 // Adding a shortcut to the Workspace.
1043 final View view = createShortcut(info);
1044 boolean foundCellSpan = false;
1045 // First we check if we already know the exact location where we want to add this item.
1046 if (cellX >= 0 && cellY >= 0) {
1047 cellXY[0] = cellX;
1048 cellXY[1] = cellY;
1049 foundCellSpan = true;
Adam Cohen558baaf2011-08-15 15:22:57 -07001050
Jon Mirandac476d6e2017-05-04 16:30:01 -07001051 // If appropriate, either create a folder or add to an existing folder
1052 if (mWorkspace.createUserFolderIfNecessary(view, container, layout, cellXY, 0,
Sunny Goyal1797af42017-10-06 13:29:57 -07001053 true, null)) {
Jon Mirandac476d6e2017-05-04 16:30:01 -07001054 return;
1055 }
1056 DragObject dragObject = new DragObject();
1057 dragObject.dragInfo = info;
1058 if (mWorkspace.addToExistingFolderIfNecessary(view, layout, cellXY, 0, dragObject,
1059 true)) {
1060 return;
1061 }
1062 } else {
1063 foundCellSpan = layout.findCellForSpan(cellXY, 1, 1);
1064 }
1065
1066 if (!foundCellSpan) {
1067 mWorkspace.onNoCellFound(layout);
Adam Cohen558baaf2011-08-15 15:22:57 -07001068 return;
1069 }
Jon Mirandac476d6e2017-05-04 16:30:01 -07001070
1071 getModelWriter().addItemToDatabase(info, container, screenId, cellXY[0], cellXY[1]);
1072 mWorkspace.addInScreen(view, info);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001073 } else {
Jon Mirandac476d6e2017-05-04 16:30:01 -07001074 // Adding a shortcut to a Folder.
Sunny Goyale29897f2017-07-20 10:09:42 -07001075 FolderIcon folderIcon = findFolderIcon(container);
Jon Mirandac476d6e2017-05-04 16:30:01 -07001076 if (folderIcon != null) {
1077 FolderInfo folderInfo = (FolderInfo) folderIcon.getTag();
1078 folderInfo.add(info, args.rank, false);
1079 } else {
Sunny Goyale29897f2017-07-20 10:09:42 -07001080 Log.e(TAG, "Could not find folder with id " + container + " to add shortcut.");
Jon Mirandac476d6e2017-05-04 16:30:01 -07001081 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001082 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001083 }
1084
Sunny Goyalefb7e842018-10-04 15:11:00 -07001085 public FolderIcon findFolderIcon(final int folderIconId) {
Sunny Goyal83fd25e2018-07-09 16:47:01 -07001086 return (FolderIcon) mWorkspace.getHomescreenIconByItemId(folderIconId);
Sunny Goyale29897f2017-07-20 10:09:42 -07001087 }
1088
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001089 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001090 * Add a widget to the workspace.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001091 *
Romain Guy5bbc91b2010-08-18 11:38:46 -07001092 * @param appWidgetId The app widget id
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001093 */
Sunny Goyal2100c782016-08-22 16:00:03 -07001094 @Thunk void completeAddAppWidget(int appWidgetId, ItemInfo itemInfo,
Adam Cohen59400422014-03-05 18:07:04 -08001095 AppWidgetHostView hostView, LauncherAppWidgetProviderInfo appWidgetInfo) {
1096
Adam Cohened66b2b2012-01-23 17:28:51 -08001097 if (appWidgetInfo == null) {
Sunny Goyal2e1efb42016-03-03 16:58:55 -08001098 appWidgetInfo = mAppWidgetManager.getLauncherAppWidgetInfo(appWidgetId);
Adam Cohened66b2b2012-01-23 17:28:51 -08001099 }
Romain Guycbb89e42009-06-08 15:52:54 -07001100
Adam Cohen59400422014-03-05 18:07:04 -08001101 LauncherAppWidgetInfo launcherInfo;
1102 launcherInfo = new LauncherAppWidgetInfo(appWidgetId, appWidgetInfo.provider);
Sunny Goyal2100c782016-08-22 16:00:03 -07001103 launcherInfo.spanX = itemInfo.spanX;
1104 launcherInfo.spanY = itemInfo.spanY;
1105 launcherInfo.minSpanX = itemInfo.minSpanX;
1106 launcherInfo.minSpanY = itemInfo.minSpanY;
Sunny Goyal952e63d2017-08-16 04:59:08 -07001107 launcherInfo.user = appWidgetInfo.getProfile();
Romain Guycbb89e42009-06-08 15:52:54 -07001108
Sunny Goyal43bf11d2017-02-02 13:52:53 -08001109 getModelWriter().addItemToDatabase(launcherInfo,
Sunny Goyal2100c782016-08-22 16:00:03 -07001110 itemInfo.container, itemInfo.screenId, itemInfo.cellX, itemInfo.cellY);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001111
Sunny Goyal2100c782016-08-22 16:00:03 -07001112 if (hostView == null) {
1113 // Perform actual inflation because we're live
1114 hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001115 }
Sunny Goyal2100c782016-08-22 16:00:03 -07001116 hostView.setVisibility(View.VISIBLE);
Sunny Goyald5462aa2016-11-22 16:52:39 +05301117 prepareAppWidget(hostView, launcherInfo);
1118 mWorkspace.addInScreen(hostView, launcherInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001119 }
Romain Guycbb89e42009-06-08 15:52:54 -07001120
Sunny Goyald5462aa2016-11-22 16:52:39 +05301121 private void prepareAppWidget(AppWidgetHostView hostView, LauncherAppWidgetInfo item) {
Sunny Goyal87af0fd2016-05-16 14:56:02 -07001122 hostView.setTag(item);
1123 item.onBindAppWidget(this, hostView);
Sunny Goyal87af0fd2016-05-16 14:56:02 -07001124 hostView.setFocusable(true);
1125 hostView.setOnFocusChangeListener(mFocusHandler);
Sunny Goyal25c2e3e2015-10-28 23:28:21 -07001126 }
1127
Sunny Goyal5d1873a2018-05-08 11:10:44 -07001128 private final BroadcastReceiver mScreenOffReceiver = new BroadcastReceiver() {
Adam Cohended9f8d2010-11-03 13:25:16 -07001129 @Override
1130 public void onReceive(Context context, Intent intent) {
Sunny Goyal5d1873a2018-05-08 11:10:44 -07001131 // Reset AllApps to its initial state only if we are not in the middle of
1132 // processing a multi-step drop
1133 if (mPendingRequestArgs == null) {
1134 mStateManager.goToState(NORMAL);
Adam Cohended9f8d2010-11-03 13:25:16 -07001135 }
1136 }
1137 };
1138
Sunny Goyalaae6fbb2019-01-31 16:05:58 -08001139 public void updateNotificationDots(Predicate<PackageUserKey> updatedDots) {
Tony Wickhamf34bee82018-12-03 18:11:39 -08001140 mWorkspace.updateNotificationDots(updatedDots);
1141 mAppsView.getAppsStore().updateNotificationDots(updatedDots);
Tony Wickham010d2552017-01-20 08:15:28 -08001142 }
1143
Adam Cohended9f8d2010-11-03 13:25:16 -07001144 @Override
1145 public void onAttachedToWindow() {
1146 super.onAttachedToWindow();
1147
Sunny Goyalc86df472016-02-25 09:19:38 -08001148 if (mLauncherCallbacks != null) {
1149 mLauncherCallbacks.onAttachedToWindow();
1150 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001151 }
1152
1153 @Override
1154 public void onDetachedFromWindow() {
1155 super.onDetachedFromWindow();
Sunny Goyalc86df472016-02-25 09:19:38 -08001156
1157 if (mLauncherCallbacks != null) {
1158 mLauncherCallbacks.onDetachedFromWindow();
1159 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001160 }
1161
Sunny Goyalc4fa8c32017-11-07 12:23:58 -08001162 public AllAppsTransitionController getAllAppsController() {
1163 return mAllAppsController;
1164 }
1165
Sunny Goyal9d69c8d2018-03-19 13:41:31 -07001166 @Override
Winson Chung1a341002018-01-17 10:00:23 -08001167 public LauncherRootView getRootView() {
1168 return (LauncherRootView) mLauncherView;
1169 }
1170
Sunny Goyal0b0847b2018-03-14 12:30:11 -07001171 @Override
Winson Chunga6945242014-01-08 14:04:34 -08001172 public DragLayer getDragLayer() {
1173 return mDragLayer;
1174 }
1175
Winson Chung5f4e0fd2015-05-22 11:12:27 -07001176 public AllAppsContainerView getAppsView() {
Winson Chungb745afb2015-03-02 11:51:23 -08001177 return mAppsView;
1178 }
1179
Winson Chunga6945242014-01-08 14:04:34 -08001180 public Workspace getWorkspace() {
1181 return mWorkspace;
1182 }
1183
1184 public Hotseat getHotseat() {
1185 return mHotseat;
1186 }
1187
Sunny Goyal7c7be8c2018-03-07 19:58:07 -08001188 public <T extends View> T getOverviewPanel() {
Winson Chung8ae41982017-11-10 11:42:13 -08001189 return (T) mOverviewPanel;
Winson Chunga6945242014-01-08 14:04:34 -08001190 }
1191
Sunny Goyal47328fd2016-05-25 18:56:41 -07001192 public DropTargetBar getDropTargetBar() {
1193 return mDropTargetBar;
Tony Wickham34d2c912015-09-11 09:27:58 -07001194 }
1195
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001196 public LauncherAppWidgetHost getAppWidgetHost() {
1197 return mAppWidgetHost;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001198 }
Romain Guycbb89e42009-06-08 15:52:54 -07001199
Winson Chunga9abd0e2010-10-27 17:18:37 -07001200 public LauncherModel getModel() {
1201 return mModel;
1202 }
1203
Sunny Goyal43bf11d2017-02-02 13:52:53 -08001204 public ModelWriter getModelWriter() {
1205 return mModelWriter;
1206 }
1207
Adam Cohen79d90c52016-04-22 13:29:20 -07001208 public SharedPreferences getSharedPrefs() {
Winson Chunga6945242014-01-08 14:04:34 -08001209 return mSharedPrefs;
1210 }
1211
Sunny Goyalf8d56fc2018-01-31 15:18:11 -08001212 public int getOrientation() { return mOldConfig.orientation; }
Jon Miranda6bed3502017-09-19 14:43:17 -07001213
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001214 @Override
1215 protected void onNewIntent(Intent intent) {
Sunny Goyalfca6bc92017-09-28 16:28:34 -07001216 TraceHelper.beginSection("NEW_INTENT");
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001217 super.onNewIntent(intent);
1218
Sunny Goyalf4aceab2017-12-06 16:16:31 -08001219 boolean alreadyOnHome = hasWindowFocus() && ((intent.getFlags() &
Winson15f8b172015-08-19 11:02:39 -07001220 Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
1221 != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
Sunny Goyal85313732016-09-28 12:00:07 -07001222
1223 // Check this condition before handling isActionMain, as this will get reset.
Sunny Goyal3e3f44c2017-10-23 17:14:52 -07001224 boolean shouldMoveToDefaultScreen = alreadyOnHome && isInState(NORMAL)
Sunny Goyalf9403d92017-10-18 10:55:56 -07001225 && AbstractFloatingView.getTopOpenView(this) == null;
Winson15f8b172015-08-19 11:02:39 -07001226 boolean isActionMain = Intent.ACTION_MAIN.equals(intent.getAction());
Sunny Goyald3864fa2017-11-14 15:06:36 -08001227 boolean internalStateHandled = InternalStateHandler
Sunny Goyal8b264562018-02-03 23:00:13 -08001228 .handleNewIntent(this, intent, isStarted());
Sunny Goyald3864fa2017-11-14 15:06:36 -08001229
Winson15f8b172015-08-19 11:02:39 -07001230 if (isActionMain) {
Sunny Goyald3864fa2017-11-14 15:06:36 -08001231 if (!internalStateHandled) {
1232 // Note: There should be at most one log per method call. This is enforced
1233 // implicitly by using if-else statements.
1234 UserEventDispatcher ued = getUserEventDispatcher();
1235 AbstractFloatingView topOpenView = AbstractFloatingView.getTopOpenView(this);
1236 if (topOpenView != null) {
1237 topOpenView.logActionCommand(Action.Command.HOME_INTENT);
1238 } else if (alreadyOnHome) {
1239 Target target = newContainerTarget(mStateManager.getState().containerType);
1240 target.pageIndex = mWorkspace.getCurrentPage();
Hyunyoung Songb3fbc0b2018-02-14 13:40:25 -08001241 ued.logActionCommand(Action.Command.HOME_INTENT, target,
1242 newContainerTarget(ContainerType.WORKSPACE));
Sunny Goyald3864fa2017-11-14 15:06:36 -08001243 }
Jon Mirandafeba90f2016-10-06 10:53:29 -07001244
Sunny Goyald3864fa2017-11-14 15:06:36 -08001245 // In all these cases, only animate if we're already on home
Sunny Goyalcc96aa12018-01-11 09:56:07 -08001246 AbstractFloatingView.closeAllOpenViews(this, isStarted());
Jon Mirandafeba90f2016-10-06 10:53:29 -07001247
Sunny Goyala2467272018-03-16 14:53:05 -07001248 if (!isInState(NORMAL)) {
1249 // Only change state, if not already the same. This prevents cancelling any
1250 // animations running as part of resume
1251 mStateManager.goToState(NORMAL);
1252 }
Sunny Goyald3864fa2017-11-14 15:06:36 -08001253
1254 // Reset the apps view
Sunny Goyal5d1873a2018-05-08 11:10:44 -07001255 if (!alreadyOnHome) {
Sunny Goyal7185dd62018-03-14 17:51:49 -07001256 mAppsView.reset(isStarted() /* animate */);
Sunny Goyald3864fa2017-11-14 15:06:36 -08001257 }
1258
Sunny Goyalaad33592018-08-07 17:20:35 -07001259 if (shouldMoveToDefaultScreen && !mWorkspace.isHandlingTouch()) {
Sunny Goyald3864fa2017-11-14 15:06:36 -08001260 mWorkspace.post(mWorkspace::moveToDefaultScreen);
1261 }
1262 }
Adam Cohen6fecd412013-10-02 17:41:50 -07001263
1264 final View v = getWindow().peekDecorView();
1265 if (v != null && v.getWindowToken() != null) {
Sunny Goyal326403e2017-10-02 12:45:10 -07001266 UiThreadHelper.hideKeyboardAsync(this, v.getWindowToken());
Adam Cohen6fecd412013-10-02 17:41:50 -07001267 }
1268
Adam Cohen9211d422014-10-07 18:14:53 -07001269 if (mLauncherCallbacks != null) {
Sunny Goyal85462132018-04-24 11:39:37 -07001270 mLauncherCallbacks.onHomeIntent(internalStateHandled);
Adam Cohen9211d422014-10-07 18:14:53 -07001271 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001272 }
Winson15f8b172015-08-19 11:02:39 -07001273
Sunny Goyalfca6bc92017-09-28 16:28:34 -07001274 TraceHelper.endSection("NEW_INTENT");
Adam Coppa120b8e2013-11-12 16:26:04 +00001275 }
1276
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001277 @Override
Adam Cohen1462de32012-07-24 22:34:36 -07001278 public void onRestoreInstanceState(Bundle state) {
1279 super.onRestoreInstanceState(state);
Sunny Goyalf4aceab2017-12-06 16:16:31 -08001280 mWorkspace.restoreInstanceStateForChild(mSynchronouslyBoundPage);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001281 }
1282
1283 @Override
1284 protected void onSaveInstanceState(Bundle outState) {
Adam Cohen21cd0022013-10-09 18:57:02 -07001285 if (mWorkspace.getChildCount() > 0) {
Sunny Goyal7ce471b2017-08-02 03:37:39 -07001286 outState.putInt(RUNTIME_STATE_CURRENT_SCREEN, mWorkspace.getNextPage());
Hyunyoung Song645764e2016-06-06 14:19:02 -07001287
Adam Cohen21cd0022013-10-09 18:57:02 -07001288 }
Sunny Goyalea609262017-10-25 15:47:38 -07001289 outState.putInt(RUNTIME_STATE, mStateManager.getState().ordinal);
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -07001290
1291
1292 AbstractFloatingView widgets = AbstractFloatingView
1293 .getOpenView(this, AbstractFloatingView.TYPE_WIDGETS_FULL_SHEET);
1294 if (widgets != null) {
1295 SparseArray<Parcelable> widgetsState = new SparseArray<>();
1296 widgets.saveHierarchyState(widgetsState);
1297 outState.putSparseParcelableArray(RUNTIME_STATE_WIDGET_PANEL, widgetsState);
1298 } else {
1299 outState.remove(RUNTIME_STATE_WIDGET_PANEL);
1300 }
1301
Sunny Goyal740ac7f2016-09-28 16:47:32 -07001302 // We close any open folders and shortcut containers since they will not be re-opened,
1303 // and we need to make sure this state is reflected.
1304 AbstractFloatingView.closeAllOpenViews(this, false);
Tony Wickham49c8d292016-07-01 11:44:34 -07001305
Sunny Goyal2100c782016-08-22 16:00:03 -07001306 if (mPendingRequestArgs != null) {
1307 outState.putParcelable(RUNTIME_STATE_PENDING_REQUEST_ARGS, mPendingRequestArgs);
1308 }
1309 if (mPendingActivityResult != null) {
1310 outState.putParcelable(RUNTIME_STATE_PENDING_ACTIVITY_RESULT, mPendingActivityResult);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001311 }
1312
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -07001313 super.onSaveInstanceState(outState);
1314
Adam Cohen9211d422014-10-07 18:14:53 -07001315 if (mLauncherCallbacks != null) {
1316 mLauncherCallbacks.onSaveInstanceState(outState);
1317 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001318 }
1319
1320 @Override
1321 public void onDestroy() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001322 super.onDestroy();
Romain Guycbb89e42009-06-08 15:52:54 -07001323
Sunny Goyal5d1873a2018-05-08 11:10:44 -07001324 unregisterReceiver(mScreenOffReceiver);
Sunny Goyalaaf7d1d2016-05-17 13:38:54 -07001325 mWorkspace.removeFolderListeners();
Winson Chunge7a03942011-08-05 15:05:12 -07001326
Sunny Goyal5743f862019-03-28 15:35:32 -07001327 if (mCancelTouchController != null) {
1328 mCancelTouchController.run();
1329 mCancelTouchController = null;
1330 }
Tony Wickhama0068302018-04-11 16:16:11 -07001331
Winson Chungcd2b0142011-06-08 16:02:26 -07001332 // Stop callbacks from LauncherModel
Adam Cohen1a85c582014-09-30 09:48:49 -07001333 // It's possible to receive onDestroy after a new Launcher activity has
1334 // been created. In this case, don't interfere with the new Launcher.
1335 if (mModel.isCurrentCallbacks(this)) {
1336 mModel.stopLoader();
Sunny Goyal87f784c2017-01-11 10:48:34 -08001337 LauncherAppState.getInstance(this).setLauncher(null);
Adam Cohen1a85c582014-09-30 09:48:49 -07001338 }
Sunny Goyal623eddd2018-03-02 12:24:41 -08001339 mRotationHelper.destroy();
Sunny Goyal745bad92016-05-02 10:54:12 -07001340
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001341 try {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001342 mAppWidgetHost.stopListening();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001343 } catch (NullPointerException ex) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001344 Log.w(TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001345 }
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001346
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001347 TextKeyListener.getInstance().release();
Tony2917a8b2017-07-31 23:29:42 -07001348 clearPendingBinds();
Hyunyoung Song31971a32019-01-27 12:31:12 -08001349 LauncherAppState.getIDP(this).removeOnChangeListener(this);
Adam Cohen9211d422014-10-07 18:14:53 -07001350 if (mLauncherCallbacks != null) {
1351 mLauncherCallbacks.onDestroy();
1352 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001353 }
1354
Sunny Goyalae502842016-06-17 08:43:56 -07001355 public LauncherAccessibilityDelegate getAccessibilityDelegate() {
1356 return mAccessibilityDelegate;
1357 }
1358
Adam Cohena9cf38f2011-05-02 15:36:58 -07001359 public DragController getDragController() {
1360 return mDragController;
1361 }
1362
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001363 @Override
Sunny Goyal0eca4e22016-07-20 11:43:06 -07001364 public void startActivityForResult(Intent intent, int requestCode, Bundle options) {
Sunny Goyal0eca4e22016-07-20 11:43:06 -07001365 super.startActivityForResult(intent, requestCode, options);
Adam Cohen173f7112015-03-27 15:14:00 -07001366 }
1367
1368 @Override
1369 public void startIntentSenderForResult (IntentSender intent, int requestCode,
1370 Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags, Bundle options) {
Adam Cohen173f7112015-03-27 15:14:00 -07001371 try {
1372 super.startIntentSenderForResult(intent, requestCode,
1373 fillInIntent, flagsMask, flagsValues, extraFlags, options);
1374 } catch (IntentSender.SendIntentException e) {
1375 throw new ActivityNotFoundException();
1376 }
1377 }
1378
Winson Chung70d72102011-08-12 11:24:35 -07001379 /**
1380 * Indicates that we want global search for this activity by setting the globalSearch
1381 * argument for {@link #startSearch} to true.
1382 */
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001383 @Override
Romain Guycbb89e42009-06-08 15:52:54 -07001384 public void startSearch(String initialQuery, boolean selectInitialQuery,
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001385 Bundle appSearchData, boolean globalSearch) {
1386 if (appSearchData == null) {
1387 appSearchData = new Bundle();
Bjorn Bringert32b12d22013-06-06 13:00:41 +01001388 appSearchData.putString("source", "launcher-search");
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001389 }
Sunny Goyalda4fe1a2016-05-26 16:05:17 -07001390
Sunny Goyal6f28e712016-09-13 14:19:29 -07001391 if (mLauncherCallbacks == null ||
1392 !mLauncherCallbacks.startSearch(initialQuery, selectInitialQuery, appSearchData)) {
1393 // Starting search from the callbacks failed. Start the default global search.
Sunny Goyalf4aceab2017-12-06 16:16:31 -08001394 super.startSearch(initialQuery, selectInitialQuery, appSearchData, true);
Ian Parkinson047036e2014-09-01 15:40:53 +01001395 }
Winson Chungcd99cd32015-04-29 11:03:24 -07001396
1397 // We need to show the workspace after starting the search
Sunny Goyal3e3f44c2017-10-23 17:14:52 -07001398 mStateManager.goToState(NORMAL);
Bjorn Bringertc459e522013-06-07 19:36:01 +01001399 }
1400
Joe Onorato9c1289c2009-08-17 11:03:03 -04001401 public boolean isWorkspaceLocked() {
Sunny Goyal2100c782016-08-22 16:00:03 -07001402 return mWorkspaceLoading || mPendingRequestArgs != null;
Joe Onorato9c1289c2009-08-17 11:03:03 -04001403 }
1404
Adam Cohen517a7f52014-03-01 12:12:59 -08001405 public boolean isWorkspaceLoading() {
1406 return mWorkspaceLoading;
1407 }
1408
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001409 private void setWorkspaceLoading(boolean value) {
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001410 mWorkspaceLoading = value;
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001411 }
1412
Sunny Goyal04a324a2017-01-20 21:08:59 -08001413 public void setWaitingForResult(PendingRequestArgs args) {
Sunny Goyal2100c782016-08-22 16:00:03 -07001414 mPendingRequestArgs = args;
Adam Cohen9211d422014-10-07 18:14:53 -07001415 }
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001416
Sunny Goyal2100c782016-08-22 16:00:03 -07001417 void addAppWidgetFromDropImpl(int appWidgetId, ItemInfo info, AppWidgetHostView boundWidget,
Sunny Goyal04a324a2017-01-20 21:08:59 -08001418 WidgetAddFlowHandler addFlowHandler) {
Tony Wickhama0628cc2015-10-14 15:23:04 -07001419 if (LOGD) {
1420 Log.d(TAG, "Adding widget from drop");
1421 }
Sunny Goyal04a324a2017-01-20 21:08:59 -08001422 addAppWidgetImpl(appWidgetId, info, boundWidget, addFlowHandler, 0);
Adam Cohenad4e15c2013-10-17 16:21:35 -07001423 }
1424
Sunny Goyal2100c782016-08-22 16:00:03 -07001425 void addAppWidgetImpl(int appWidgetId, ItemInfo info,
Sunny Goyal04a324a2017-01-20 21:08:59 -08001426 AppWidgetHostView boundWidget, WidgetAddFlowHandler addFlowHandler, int delay) {
1427 if (!addFlowHandler.startConfigActivity(this, appWidgetId, info, REQUEST_CREATE_APPWIDGET)) {
1428 // If the configuration flow was not started, add the widget
Michael Jurkaaf442092010-06-10 17:01:57 -07001429
Adam Cohenad4e15c2013-10-17 16:21:35 -07001430 Runnable onComplete = new Runnable() {
1431 @Override
1432 public void run() {
1433 // Exit spring loaded mode if necessary after adding the widget
Sunny Goyal3e3f44c2017-10-23 17:14:52 -07001434 mStateManager.goToState(NORMAL, SPRING_LOADED_EXIT_DELAY);
Adam Cohenad4e15c2013-10-17 16:21:35 -07001435 }
1436 };
Sunny Goyal04a324a2017-01-20 21:08:59 -08001437 completeAddAppWidget(appWidgetId, info, boundWidget, addFlowHandler.getProviderInfo(this));
Adam Cohen689ff162014-05-08 17:27:56 -07001438 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete, delay, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001439 }
1440 }
Romain Guycbb89e42009-06-08 15:52:54 -07001441
Sunny Goyalefb7e842018-10-04 15:11:00 -07001442 public void addPendingItem(PendingAddItemInfo info, int container, int screenId,
Sunny Goyal71b5c0b2015-01-08 16:59:04 -08001443 int[] cell, int spanX, int spanY) {
Sunny Goyal2100c782016-08-22 16:00:03 -07001444 info.container = container;
1445 info.screenId = screenId;
1446 if (cell != null) {
1447 info.cellX = cell[0];
1448 info.cellY = cell[1];
1449 }
1450 info.spanX = spanX;
1451 info.spanY = spanY;
1452
Sunny Goyal71b5c0b2015-01-08 16:59:04 -08001453 switch (info.itemType) {
1454 case LauncherSettings.Favorites.ITEM_TYPE_CUSTOM_APPWIDGET:
1455 case LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET:
Sunny Goyal2100c782016-08-22 16:00:03 -07001456 addAppWidgetFromDrop((PendingAddWidgetInfo) info);
Sunny Goyal71b5c0b2015-01-08 16:59:04 -08001457 break;
1458 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Sunny Goyal782f0c92017-01-19 10:27:54 -08001459 processShortcutFromDrop((PendingAddShortcutInfo) info);
Sunny Goyal71b5c0b2015-01-08 16:59:04 -08001460 break;
1461 default:
1462 throw new IllegalStateException("Unknown item type: " + info.itemType);
1463 }
1464 }
1465
Adam Cohenfbba09b2011-07-18 21:43:05 -07001466 /**
1467 * Process a shortcut drop.
Adam Cohenfbba09b2011-07-18 21:43:05 -07001468 */
Sunny Goyal782f0c92017-01-19 10:27:54 -08001469 private void processShortcutFromDrop(PendingAddShortcutInfo info) {
Sunny Goyalfb5096d2016-09-08 14:32:06 -07001470 Intent intent = new Intent(Intent.ACTION_CREATE_SHORTCUT).setComponent(info.componentName);
1471 setWaitingForResult(PendingRequestArgs.forIntent(REQUEST_CREATE_SHORTCUT, intent, info));
Sunny Goyal782f0c92017-01-19 10:27:54 -08001472 if (!info.activityInfo.startConfigActivity(this, REQUEST_CREATE_SHORTCUT)) {
1473 handleActivityResult(REQUEST_CREATE_SHORTCUT, RESULT_CANCELED, null);
1474 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001475 }
1476
Adam Cohenfbba09b2011-07-18 21:43:05 -07001477 /**
1478 * Process a widget drop.
Adam Cohenfbba09b2011-07-18 21:43:05 -07001479 */
Sunny Goyal2100c782016-08-22 16:00:03 -07001480 private void addAppWidgetFromDrop(PendingAddWidgetInfo info) {
Adam Cohened66b2b2012-01-23 17:28:51 -08001481 AppWidgetHostView hostView = info.boundWidget;
Sunny Goyal952e63d2017-08-16 04:59:08 -07001482 final int appWidgetId;
Sunny Goyal8a0dc382017-01-25 11:30:06 -08001483 WidgetAddFlowHandler addFlowHandler = info.getHandler();
Adam Cohened66b2b2012-01-23 17:28:51 -08001484 if (hostView != null) {
Tony Wickhama0628cc2015-10-14 15:23:04 -07001485 // In the case where we've prebound the widget, we remove it from the DragLayer
1486 if (LOGD) {
1487 Log.d(TAG, "Removing widget view from drag layer and setting boundWidget to null");
1488 }
1489 getDragLayer().removeView(hostView);
1490
Adam Cohened66b2b2012-01-23 17:28:51 -08001491 appWidgetId = hostView.getAppWidgetId();
Sunny Goyal04a324a2017-01-20 21:08:59 -08001492 addAppWidgetFromDropImpl(appWidgetId, info, hostView, addFlowHandler);
Sunny Goyal5b9ebca2015-06-01 18:37:32 -07001493
1494 // Clear the boundWidget so that it doesn't get destroyed.
1495 info.boundWidget = null;
Adam Cohened66b2b2012-01-23 17:28:51 -08001496 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001497 // In this case, we either need to start an activity to get permission to bind
1498 // the widget, or we need to start an activity to configure the widget, or both.
Sunny Goyal952e63d2017-08-16 04:59:08 -07001499 if (FeatureFlags.ENABLE_CUSTOM_WIDGETS &&
1500 info.itemType == LauncherSettings.Favorites.ITEM_TYPE_CUSTOM_APPWIDGET) {
1501 appWidgetId = CustomWidgetParser.getWidgetIdForCustomProvider(
1502 this, info.componentName);
1503 } else {
1504 appWidgetId = getAppWidgetHost().allocateAppWidgetId();
1505 }
Adam Cohendd70d662012-10-04 16:53:44 -07001506 Bundle options = info.bindOptions;
1507
Sunny Goyalffe83f12014-08-14 17:39:34 -07001508 boolean success = mAppWidgetManager.bindAppWidgetIdIfAllowed(
1509 appWidgetId, info.info, options);
Adam Cohendd70d662012-10-04 16:53:44 -07001510 if (success) {
Sunny Goyal04a324a2017-01-20 21:08:59 -08001511 addAppWidgetFromDropImpl(appWidgetId, info, null, addFlowHandler);
Michael Jurka8b805b12012-04-18 14:23:14 -07001512 } else {
Sunny Goyal04a324a2017-01-20 21:08:59 -08001513 addFlowHandler.startBindFlow(this, appWidgetId, info, REQUEST_BIND_APPWIDGET);
Michael Jurka8b805b12012-04-18 14:23:14 -07001514 }
Adam Cohened66b2b2012-01-23 17:28:51 -08001515 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001516 }
1517
Sunny Goyalefb7e842018-10-04 15:11:00 -07001518 FolderIcon addFolder(CellLayout layout, int container, final int screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07001519 int cellY) {
Michael Jurkac9d95c52011-08-29 14:03:34 -07001520 final FolderInfo folderInfo = new FolderInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001521 folderInfo.title = getText(R.string.folder_name);
1522
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001523 // Update the model
Sunny Goyal43bf11d2017-02-02 13:52:53 -08001524 getModelWriter().addItemToDatabase(folderInfo, container, screenId, cellX, cellY);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001525
1526 // Create the view
Sunny Goyal1cd01b02016-11-09 10:43:58 -08001527 FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this, layout, folderInfo);
Sunny Goyald5462aa2016-11-22 16:52:39 +05301528 mWorkspace.addInScreen(newFolder, folderInfo);
Winson Chung5f8afe62013-08-12 16:19:28 -07001529 // Force measure the new folder icon
1530 CellLayout parent = mWorkspace.getParentCellLayoutForView(newFolder);
1531 parent.getShortcutsAndWidgets().measureChild(newFolder);
Adam Cohendf035382011-04-11 17:22:04 -07001532 return newFolder;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001533 }
Romain Guycbb89e42009-06-08 15:52:54 -07001534
Winsonc0b52fe2015-09-09 16:38:15 -07001535 /**
Winsonfa56b3f2015-09-14 12:01:13 -07001536 * Unbinds the view for the specified item, and removes the item and all its children.
1537 *
1538 * @param v the view being removed.
Winsonfa56b3f2015-09-14 12:01:13 -07001539 * @param itemInfo the {@link ItemInfo} for this view.
1540 * @param deleteFromDb whether or not to delete this item from the db.
Winsonc0b52fe2015-09-09 16:38:15 -07001541 */
Tony Wickhambfbf7f92016-05-19 11:19:39 -07001542 public boolean removeItem(View v, final ItemInfo itemInfo, boolean deleteFromDb) {
Sunny Goyal95899162019-03-27 16:03:06 -07001543 if (itemInfo instanceof WorkspaceItemInfo) {
Winsonfa56b3f2015-09-14 12:01:13 -07001544 // Remove the shortcut from the folder before removing it from launcher
Sunny Goyal44c06432016-04-02 10:56:02 -07001545 View folderIcon = mWorkspace.getHomescreenIconByItemId(itemInfo.container);
1546 if (folderIcon instanceof FolderIcon) {
Sunny Goyal95899162019-03-27 16:03:06 -07001547 ((FolderInfo) folderIcon.getTag()).remove((WorkspaceItemInfo) itemInfo, true);
Winsonfa56b3f2015-09-14 12:01:13 -07001548 } else {
1549 mWorkspace.removeWorkspaceItem(v);
1550 }
Winsonc0b52fe2015-09-09 16:38:15 -07001551 if (deleteFromDb) {
Sunny Goyal43bf11d2017-02-02 13:52:53 -08001552 getModelWriter().deleteItemFromDatabase(itemInfo);
Winsonc0b52fe2015-09-09 16:38:15 -07001553 }
1554 } else if (itemInfo instanceof FolderInfo) {
1555 final FolderInfo folderInfo = (FolderInfo) itemInfo;
Sunny Goyalaaf7d1d2016-05-17 13:38:54 -07001556 if (v instanceof FolderIcon) {
1557 ((FolderIcon) v).removeListeners();
1558 }
Winsonc0b52fe2015-09-09 16:38:15 -07001559 mWorkspace.removeWorkspaceItem(v);
1560 if (deleteFromDb) {
Sunny Goyal43bf11d2017-02-02 13:52:53 -08001561 getModelWriter().deleteFolderAndContentsFromDatabase(folderInfo);
Winsonc0b52fe2015-09-09 16:38:15 -07001562 }
1563 } else if (itemInfo instanceof LauncherAppWidgetInfo) {
1564 final LauncherAppWidgetInfo widgetInfo = (LauncherAppWidgetInfo) itemInfo;
Winson44818e02015-10-02 11:25:46 -07001565 mWorkspace.removeWorkspaceItem(v);
Winsonc0b52fe2015-09-09 16:38:15 -07001566 if (deleteFromDb) {
Tony Wickham6a71a5b2018-08-21 11:40:23 -07001567 getModelWriter().deleteWidgetInfo(widgetInfo, getAppWidgetHost());
Winsonc0b52fe2015-09-09 16:38:15 -07001568 }
1569 } else {
1570 return false;
1571 }
1572 return true;
1573 }
1574
Tony Wickham6a71a5b2018-08-21 11:40:23 -07001575
Winsonc0b52fe2015-09-09 16:38:15 -07001576
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001577 @Override
1578 public boolean dispatchKeyEvent(KeyEvent event) {
Hyunyoung Song3c7d9cb2017-01-30 15:11:27 -08001579 return (event.getKeyCode() == KeyEvent.KEYCODE_HOME) || super.dispatchKeyEvent(event);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001580 }
1581
Joe Onorato88ec0992009-11-19 13:16:06 -08001582 @Override
1583 public void onBackPressed() {
Sunny Goyal7c8a65e2017-12-22 11:11:33 -08001584 if (finishAutoCancelActionMode()) {
1585 return;
1586 }
Adam Cohen9211d422014-10-07 18:14:53 -07001587 if (mLauncherCallbacks != null && mLauncherCallbacks.handleBackPressed()) {
1588 return;
1589 }
1590
Sunny Goyal45478022015-06-08 16:52:41 -07001591 if (mDragController.isDragging()) {
1592 mDragController.cancelDrag();
Adam Cohenc9735cf2015-01-23 16:11:55 -08001593 return;
1594 }
1595
Jon Mirandafeba90f2016-10-06 10:53:29 -07001596 // Note: There should be at most one log per method call. This is enforced implicitly
1597 // by using if-else statements.
1598 UserEventDispatcher ued = getUserEventDispatcher();
Sunny Goyal740ac7f2016-09-28 16:47:32 -07001599 AbstractFloatingView topView = AbstractFloatingView.getTopOpenView(this);
Tony Wickham52c1b662018-05-21 13:13:58 -07001600 if (topView != null && topView.onBackPressed()) {
1601 // Handled by the floating view.
Patrick Dubroy94f78a52011-02-28 17:39:16 -08001602 } else {
Sunny Goyale39690b2018-08-02 13:35:07 -07001603 mStateManager.getState().onBackPressed(this);
Michael Jurkaaf442092010-06-10 17:01:57 -07001604 }
Joe Onorato88ec0992009-11-19 13:16:06 -08001605 }
1606
Sunny Goyalfe770c92016-09-27 14:38:58 -07001607 @TargetApi(Build.VERSION_CODES.M)
Sunny Goyal0b0847b2018-03-14 12:30:11 -07001608 @Override
Jon Miranda73c27ec2018-05-16 18:06:23 -07001609 public ActivityOptions getActivityLaunchOptions(View v) {
1610 return mAppTransitionManager.getActivityLaunchOptions(this, v);
Sunny Goyala7ce1662016-05-31 15:01:35 -07001611 }
1612
Tony Wickham3a6746a2018-03-29 09:39:56 -07001613 public LauncherAppTransitionManager getAppTransitionManager() {
1614 return mAppTransitionManager;
1615 }
1616
Sunny Goyal0b0847b2018-03-14 12:30:11 -07001617 @TargetApi(Build.VERSION_CODES.M)
1618 @Override
1619 protected boolean onErrorStartingShortcut(Intent intent, ItemInfo info) {
1620 // Due to legacy reasons, direct call shortcuts require Launchers to have the
1621 // corresponding permission. Show the appropriate permission prompt if that
1622 // is the case.
1623 if (intent.getComponent() == null
1624 && Intent.ACTION_CALL.equals(intent.getAction())
1625 && checkSelfPermission(android.Manifest.permission.CALL_PHONE) !=
1626 PackageManager.PERMISSION_GRANTED) {
1627
1628 setWaitingForResult(PendingRequestArgs
1629 .forIntent(REQUEST_PERMISSION_CALL_PHONE, intent, info));
1630 requestPermissions(new String[]{android.Manifest.permission.CALL_PHONE},
1631 REQUEST_PERMISSION_CALL_PHONE);
1632 return true;
1633 } else {
1634 return false;
1635 }
Sunny Goyal0eca4e22016-07-20 11:43:06 -07001636 }
1637
Hyunyoung Song46d07f72018-05-22 15:41:25 -07001638 @Override
Hyunyoung Songfc007472018-10-25 14:09:50 -07001639 public int getCurrentState() {
1640 if(mStateManager.getState() == LauncherState.ALL_APPS) {
1641 return StatsLogUtils.LAUNCHER_STATE_ALLAPPS;
1642 } else if (mStateManager.getState() == LauncherState.OVERVIEW) {
1643 return StatsLogUtils.LAUNCHER_STATE_OVERVIEW;
1644 }
Hyunyoung Song0ae38882018-11-05 14:45:19 -08001645 return StatsLogUtils.LAUNCHER_STATE_HOME;
Hyunyoung Songfc007472018-10-25 14:09:50 -07001646 }
1647
1648 @Override
Hyunyoung Song46d07f72018-05-22 15:41:25 -07001649 public void modifyUserEvent(LauncherLogProto.LauncherEvent event) {
1650 if (event.srcTarget != null && event.srcTarget.length > 0 &&
1651 event.srcTarget[1].containerType == ContainerType.PREDICTION) {
1652 Target[] targets = new Target[3];
1653 targets[0] = event.srcTarget[0];
1654 targets[1] = event.srcTarget[1];
1655 targets[2] = newTarget(Target.Type.CONTAINER);
1656 event.srcTarget = targets;
1657 LauncherState state = mStateManager.getState();
1658 if (state == LauncherState.ALL_APPS) {
1659 event.srcTarget[2].containerType = ContainerType.ALLAPPS;
1660 } else if (state == LauncherState.OVERVIEW) {
1661 event.srcTarget[2].containerType = ContainerType.TASKSWITCHER;
1662 }
1663 }
1664 }
1665
Sunny Goyal369212a2019-03-26 15:03:57 -07001666 public boolean startActivitySafely(View v, Intent intent, ItemInfo item,
1667 @Nullable String sourceContainer) {
1668 boolean success = super.startActivitySafely(v, intent, item, sourceContainer);
Hyunyoung Song1241e612018-05-15 21:46:51 -07001669 if (success && v instanceof BubbleTextView) {
Sunny Goyal0b0847b2018-03-14 12:30:11 -07001670 // This is set to the view that launched the activity that navigated the user away
1671 // from launcher. Since there is no callback for when the activity has finished
1672 // launching, enable the press state and keep this reference to reset the press
1673 // state when we return to launcher.
1674 BubbleTextView btv = (BubbleTextView) v;
1675 btv.setStayPressed(true);
1676 setOnResumeCallback(btv);
Sunny Goyala7ce1662016-05-31 15:01:35 -07001677 }
Hyunyoung Song1241e612018-05-15 21:46:51 -07001678 return success;
Michael Jurka86a720e2012-05-09 11:23:23 -07001679 }
1680
Winson Chung3d503fb2011-07-13 17:25:49 -07001681 boolean isHotseatLayout(View layout) {
Sunny Goyalc13403c2016-11-18 23:44:48 -08001682 // TODO: Remove this method
Sunny Goyal876e4622018-11-02 13:50:40 -07001683 return mHotseat != null && (layout == mHotseat);
Winson Chung3d503fb2011-07-13 17:25:49 -07001684 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08001685
Winson Chung3d503fb2011-07-13 17:25:49 -07001686 /**
1687 * Returns the CellLayout of the specified container at the specified screen.
1688 */
Sunny Goyalefb7e842018-10-04 15:11:00 -07001689 public CellLayout getCellLayout(int container, int screenId) {
Sunny Goyal876e4622018-11-02 13:50:40 -07001690 return (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT)
1691 ? mHotseat : mWorkspace.getScreenWithId(screenId);
Romain Guya6abce82009-11-10 02:54:41 -08001692 }
1693
Michael Jurkae326f182011-11-21 14:05:46 -08001694 @Override
1695 public void onTrimMemory(int level) {
1696 super.onTrimMemory(level);
Adam Cohen3f9c9712014-10-31 11:48:25 -07001697 if (level >= ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN) {
1698 // The widget preview db can result in holding onto over
1699 // 3MB of memory for caching which isn't necessary.
1700 SQLiteDatabase.releaseMemory();
1701
Adam Cohenc8f4e1b2014-11-19 16:03:20 -08001702 // This clears all widget bitmaps from the widget tray
Hyunyoung Song3f471442015-04-08 19:01:34 -07001703 // TODO(hyunyoungs)
Michael Jurkae326f182011-11-21 14:05:46 -08001704 }
Robert Kozikowski67c30862015-03-30 23:46:46 +01001705 if (mLauncherCallbacks != null) {
1706 mLauncherCallbacks.onTrimMemory(level);
1707 }
Winson Chung62a70be2018-02-23 15:10:05 -08001708 UiFactory.onTrimMemory(this, level);
Michael Jurkae326f182011-11-21 14:05:46 -08001709 }
1710
Michael Jurkad7c28052012-04-27 15:43:36 -07001711 @Override
1712 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
alanv1d4fde62012-10-17 13:15:47 -07001713 final boolean result = super.dispatchPopulateAccessibilityEvent(event);
Michael Jurkad7c28052012-04-27 15:43:36 -07001714 final List<CharSequence> text = event.getText();
1715 text.clear();
alanv1d4fde62012-10-17 13:15:47 -07001716 // Populate event with a fake title based on the current state.
Sunny Goyal3e3f44c2017-10-23 17:14:52 -07001717 // TODO: When can workspace be null?
1718 text.add(mWorkspace == null
1719 ? getString(R.string.all_apps_home_button_label)
Sunny Goyalea609262017-10-25 15:47:38 -07001720 : mStateManager.getState().getDescription(this));
Michael Jurkad7c28052012-04-27 15:43:36 -07001721 return result;
1722 }
1723
Sunny Goyal3dce5f32017-10-05 11:40:05 -07001724 public void setOnResumeCallback(OnResumeCallback callback) {
1725 if (mOnResumeCallback != null) {
1726 mOnResumeCallback.onLauncherResume();
1727 }
1728 mOnResumeCallback = callback;
Michael Jurka1e2f4652013-07-08 18:03:46 -07001729 }
1730
Michael Jurka7607c2f2013-04-03 14:33:19 -07001731 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04001732 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001733 */
Sunny Goyal93f878c2016-03-30 17:31:24 -07001734 @Override
Joe Onorato9c1289c2009-08-17 11:03:03 -04001735 public int getCurrentWorkspaceScreen() {
Joe Onoratod0afc872010-06-11 00:03:15 -07001736 if (mWorkspace != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07001737 return mWorkspace.getCurrentPage();
Joe Onoratod0afc872010-06-11 00:03:15 -07001738 } else {
Winson Chung882a52e2015-07-08 14:32:26 -07001739 return 0;
Joe Onoratod0afc872010-06-11 00:03:15 -07001740 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04001741 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07001742
Joe Onorato9c1289c2009-08-17 11:03:03 -04001743 /**
Sunny Goyal527c7d32015-08-28 15:19:36 -07001744 * Clear any pending bind callbacks. This is called when is loader is planning to
1745 * perform a full rebind from scratch.
1746 */
1747 @Override
1748 public void clearPendingBinds() {
Sunny Goyal527c7d32015-08-28 15:19:36 -07001749 if (mPendingExecutor != null) {
1750 mPendingExecutor.markCompleted();
1751 mPendingExecutor = null;
1752 }
1753 }
1754
1755 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04001756 * Refreshes the shortcuts shown on the workspace.
1757 *
1758 * Implementation of the method from LauncherModel.Callbacks.
1759 */
1760 public void startBinding() {
Sunny Goyalfca6bc92017-09-28 16:28:34 -07001761 TraceHelper.beginSection("startBinding");
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -07001762 // Floating panels (except the full widget sheet) are associated with individual icons. If
1763 // we are starting a fresh bind, close all such panels as all the icons are about
1764 // to go away.
1765 AbstractFloatingView.closeOpenViews(this, true,
Sunny Goyal7ede6112017-12-05 15:11:21 -08001766 AbstractFloatingView.TYPE_ALL & ~AbstractFloatingView.TYPE_REBIND_SAFE);
Jon Miranda6dc7f1e2017-02-21 12:37:51 -08001767
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001768 setWorkspaceLoading(true);
Adam Cohen517a7f52014-03-01 12:12:59 -08001769
Winson Chungd64d1762013-08-20 14:37:16 -07001770 // Clear the workspace because it's going to be rebound
Sunny Goyal2db53422019-03-01 16:06:12 -08001771 mDragController.cancelDrag();
1772
Adam Cohendf035382011-04-11 17:22:04 -07001773 mWorkspace.clearDropTargets();
Winson Chung9e6a0a22013-08-27 11:58:12 -07001774 mWorkspace.removeAllWorkspaceScreens();
Sunny Goyalc11fac32018-02-27 19:20:15 -08001775 mAppWidgetHost.clearViews();
Winson Chungd64d1762013-08-20 14:37:16 -07001776
Winson Chung3d503fb2011-07-13 17:25:49 -07001777 if (mHotseat != null) {
Sunny Goyal11e96492018-03-23 17:06:00 -07001778 mHotseat.resetLayout(mDeviceProfile.isVerticalBarLayout());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001779 }
Sunny Goyalfca6bc92017-09-28 16:28:34 -07001780 TraceHelper.endSection("startBinding");
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001781 }
1782
Adam Cohendcd297f2013-06-18 13:13:40 -07001783 @Override
Sunny Goyalefb7e842018-10-04 15:11:00 -07001784 public void bindScreens(IntArray orderedScreenIds) {
Sunny Goyalda4fe1a2016-05-26 16:05:17 -07001785 // Make sure the first screen is always at the start.
Jon Miranda7143ba62019-03-15 09:00:05 -07001786 if (FeatureFlags.QSB_ON_FIRST_SCREEN &&
Sunny Goyala9e2f5a2016-06-10 12:22:04 -07001787 orderedScreenIds.indexOf(Workspace.FIRST_SCREEN_ID) != 0) {
Sunny Goyalefb7e842018-10-04 15:11:00 -07001788 orderedScreenIds.removeValue(Workspace.FIRST_SCREEN_ID);
Sunny Goyalda4fe1a2016-05-26 16:05:17 -07001789 orderedScreenIds.add(0, Workspace.FIRST_SCREEN_ID);
Jon Miranda7143ba62019-03-15 09:00:05 -07001790 } else if (!FeatureFlags.QSB_ON_FIRST_SCREEN && orderedScreenIds.isEmpty()) {
Sunny Goyala9e2f5a2016-06-10 12:22:04 -07001791 // If there are no screens, we need to have an empty screen
1792 mWorkspace.addExtraEmptyScreen();
Adam Cohen5084cba2013-09-03 12:01:16 -07001793 }
Sunny Goyalda4fe1a2016-05-26 16:05:17 -07001794 bindAddScreens(orderedScreenIds);
Winson Chung0e6a7132013-08-23 12:55:10 -07001795
Winsonc7d2e832016-07-28 12:24:55 -07001796 // After we have added all the screens, if the wallpaper was locked to the default state,
1797 // then notify to indicate that it can be released and a proper wallpaper offset can be
1798 // computed before the next layout
1799 mWorkspace.unlockWallpaperFromDefaultPageOnNextLayout();
Winson Chung64359a52013-07-08 17:17:08 -07001800 }
1801
Sunny Goyalefb7e842018-10-04 15:11:00 -07001802 private void bindAddScreens(IntArray orderedScreenIds) {
Adam Cohendcd297f2013-06-18 13:13:40 -07001803 int count = orderedScreenIds.size();
1804 for (int i = 0; i < count; i++) {
Sunny Goyalefb7e842018-10-04 15:11:00 -07001805 int screenId = orderedScreenIds.get(i);
Jon Miranda7143ba62019-03-15 09:00:05 -07001806 if (!FeatureFlags.QSB_ON_FIRST_SCREEN || screenId != Workspace.FIRST_SCREEN_ID) {
Sunny Goyalda4fe1a2016-05-26 16:05:17 -07001807 // No need to bind the first screen, as its always bound.
1808 mWorkspace.insertNewWorkspaceScreenBeforeEmptyScreen(screenId);
1809 }
Adam Cohendcd297f2013-06-18 13:13:40 -07001810 }
Adam Cohendcd297f2013-06-18 13:13:40 -07001811 }
1812
Sunny Goyalb23980c2017-08-17 07:45:25 -07001813 @Override
Tony Wickham6a71a5b2018-08-21 11:40:23 -07001814 public void preAddApps() {
1815 // If there's an undo snackbar, force it to complete to ensure empty screens are removed
1816 // before trying to add new items.
1817 mModelWriter.commitDelete();
1818 AbstractFloatingView snackbar = AbstractFloatingView.getOpenView(this, TYPE_SNACKBAR);
1819 if (snackbar != null) {
1820 snackbar.post(() -> snackbar.close(true));
1821 }
1822 }
1823
1824 @Override
Sunny Goyalefb7e842018-10-04 15:11:00 -07001825 public void bindAppsAdded(IntArray newScreens, ArrayList<ItemInfo> addNotAnimated,
Sunny Goyal29947f02017-12-18 13:49:44 -08001826 ArrayList<ItemInfo> addAnimated) {
Winson Chungd64d1762013-08-20 14:37:16 -07001827 // Add the new screens
Adam Cohen76a47a12014-02-05 11:47:43 -08001828 if (newScreens != null) {
1829 bindAddScreens(newScreens);
1830 }
Winson Chungd64d1762013-08-20 14:37:16 -07001831
1832 // We add the items without animation on non-visible pages, and with
1833 // animations on the new page (which we will try and snap to).
Adam Cohen76a47a12014-02-05 11:47:43 -08001834 if (addNotAnimated != null && !addNotAnimated.isEmpty()) {
Sunny Goyalb23980c2017-08-17 07:45:25 -07001835 bindItems(addNotAnimated, false);
Winson Chungd64d1762013-08-20 14:37:16 -07001836 }
Adam Cohen76a47a12014-02-05 11:47:43 -08001837 if (addAnimated != null && !addAnimated.isEmpty()) {
Sunny Goyalb23980c2017-08-17 07:45:25 -07001838 bindItems(addAnimated, true);
Winson Chungd64d1762013-08-20 14:37:16 -07001839 }
Winson Chungc58497e2013-09-03 17:48:37 -07001840
Winson Chung87412982013-10-03 18:34:14 -07001841 // Remove the extra empty screen
Adam Cohen689ff162014-05-08 17:27:56 -07001842 mWorkspace.removeExtraEmptyScreen(false, false);
Winson Chungd64d1762013-08-20 14:37:16 -07001843 }
1844
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001845 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04001846 * Bind the items start-end from the list.
1847 *
1848 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001849 */
Tony Wickham0bb211a2015-10-02 16:22:08 -07001850 @Override
Sunny Goyalb23980c2017-08-17 07:45:25 -07001851 public void bindItems(final List<ItemInfo> items, final boolean forceAnimateIcons) {
Sunny Goyal3be633b2016-12-08 09:59:25 -08001852 // Get the list of added items and intersect them with the set of items here
Rajeev Kumar43c0f582017-06-23 15:34:55 -07001853 final Collection<Animator> bounceAnims = new ArrayList<>();
Winson Chung997a9232013-07-24 15:33:46 -07001854 final boolean animateIcons = forceAnimateIcons && canRunNewAppsAnimation();
Winson Chungf0c6ae02012-03-21 16:10:31 -07001855 Workspace workspace = mWorkspace;
Sunny Goyalefb7e842018-10-04 15:11:00 -07001856 int newItemsScreenId = -1;
Sunny Goyalb23980c2017-08-17 07:45:25 -07001857 int end = items.size();
1858 for (int i = 0; i < end; i++) {
Sunny Goyal3be633b2016-12-08 09:59:25 -08001859 final ItemInfo item = items.get(i);
Winson Chung4d279d92011-07-21 11:46:32 -07001860
1861 // Short circuit if we are loading dock items for a configuration which has no dock
1862 if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT &&
1863 mHotseat == null) {
1864 continue;
1865 }
1866
Sunny Goyal639e9062015-08-19 19:17:06 -07001867 final View view;
Joe Onorato9c1289c2009-08-17 11:03:03 -04001868 switch (item.itemType) {
1869 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
1870 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Sunny Goyal3be633b2016-12-08 09:59:25 -08001871 case LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT: {
Sunny Goyal95899162019-03-27 16:03:06 -07001872 WorkspaceItemInfo info = (WorkspaceItemInfo) item;
Sunny Goyal639e9062015-08-19 19:17:06 -07001873 view = createShortcut(info);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001874 break;
Sunny Goyal3be633b2016-12-08 09:59:25 -08001875 }
1876 case LauncherSettings.Favorites.ITEM_TYPE_FOLDER: {
Sunny Goyal639e9062015-08-19 19:17:06 -07001877 view = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07001878 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Sunny Goyal1cd01b02016-11-09 10:43:58 -08001879 (FolderInfo) item);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001880 break;
Sunny Goyal3be633b2016-12-08 09:59:25 -08001881 }
Sunny Goyal952e63d2017-08-16 04:59:08 -07001882 case LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET:
1883 case LauncherSettings.Favorites.ITEM_TYPE_CUSTOM_APPWIDGET: {
Sunny Goyala9a1a212017-08-18 01:03:21 -07001884 view = inflateAppWidget((LauncherAppWidgetInfo) item);
Sunny Goyalb23980c2017-08-17 07:45:25 -07001885 if (view == null) {
1886 continue;
Sunny Goyal3be633b2016-12-08 09:59:25 -08001887 }
Sunny Goyal3be633b2016-12-08 09:59:25 -08001888 break;
1889 }
Winson Chungc763c4e2013-07-19 13:49:06 -07001890 default:
1891 throw new RuntimeException("Invalid Item Type");
Joe Onorato9c1289c2009-08-17 11:03:03 -04001892 }
Sunny Goyal639e9062015-08-19 19:17:06 -07001893
Sunny Goyalda4fe1a2016-05-26 16:05:17 -07001894 /*
1895 * Remove colliding items.
1896 */
1897 if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
1898 CellLayout cl = mWorkspace.getScreenWithId(item.screenId);
1899 if (cl != null && cl.isOccupied(item.cellX, item.cellY)) {
1900 View v = cl.getChildAt(item.cellX, item.cellY);
1901 Object tag = v.getTag();
1902 String desc = "Collision while binding workspace item: " + item
1903 + ". Collides with " + tag;
Sunny Goyal3d706ad2017-03-06 16:56:39 -08001904 if (FeatureFlags.IS_DOGFOOD_BUILD) {
Sunny Goyalda4fe1a2016-05-26 16:05:17 -07001905 throw (new RuntimeException(desc));
1906 } else {
1907 Log.d(TAG, desc);
Sunny Goyal43bf11d2017-02-02 13:52:53 -08001908 getModelWriter().deleteItemFromDatabase(item);
Sunny Goyalda4fe1a2016-05-26 16:05:17 -07001909 continue;
1910 }
1911 }
1912 }
Sunny Goyald5462aa2016-11-22 16:52:39 +05301913 workspace.addInScreenFromBind(view, item);
Sunny Goyal639e9062015-08-19 19:17:06 -07001914 if (animateIcons) {
1915 // Animate all the applications up now
1916 view.setAlpha(0f);
1917 view.setScaleX(0f);
1918 view.setScaleY(0f);
1919 bounceAnims.add(createNewAppBounceAnimation(view, i));
Sunny Goyal3be633b2016-12-08 09:59:25 -08001920 newItemsScreenId = item.screenId;
Sunny Goyal639e9062015-08-19 19:17:06 -07001921 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001922 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07001923
Sunny Goyalf0b6db72018-08-13 16:10:14 -07001924 // Animate to the correct page
1925 if (animateIcons && newItemsScreenId > -1) {
1926 AnimatorSet anim = new AnimatorSet();
1927 anim.playTogether(bounceAnims);
Jon Miranda64eb8ea2018-03-29 11:43:58 -07001928
Sunny Goyalefb7e842018-10-04 15:11:00 -07001929 int currentScreenId = mWorkspace.getScreenIdForPageIndex(mWorkspace.getNextPage());
Sunny Goyalf0b6db72018-08-13 16:10:14 -07001930 final int newScreenIndex = mWorkspace.getPageIndexForScreenId(newItemsScreenId);
1931 final Runnable startBounceAnimRunnable = anim::start;
1932
1933 if (newItemsScreenId != currentScreenId) {
1934 // We post the animation slightly delayed to prevent slowdowns
1935 // when we are loading right after we return to launcher.
1936 mWorkspace.postDelayed(new Runnable() {
1937 public void run() {
1938 if (mWorkspace != null) {
1939 AbstractFloatingView.closeAllOpenViews(Launcher.this, false);
1940
1941 mWorkspace.snapToPage(newScreenIndex);
1942 mWorkspace.postDelayed(startBounceAnimRunnable,
1943 NEW_APPS_ANIMATION_DELAY);
Winson Chung94d67682013-09-25 16:29:40 -07001944 }
Sunny Goyalf0b6db72018-08-13 16:10:14 -07001945 }
1946 }, NEW_APPS_PAGE_MOVE_DELAY);
1947 } else {
1948 mWorkspace.postDelayed(startBounceAnimRunnable, NEW_APPS_ANIMATION_DELAY);
Winson Chung997a9232013-07-24 15:33:46 -07001949 }
Winson Chung64359a52013-07-08 17:17:08 -07001950 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04001951 workspace.requestLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001952 }
1953
Joe Onorato9c1289c2009-08-17 11:03:03 -04001954 /**
1955 * Add the views for a widget to the workspace.
Joe Onorato9c1289c2009-08-17 11:03:03 -04001956 */
Sunny Goyala9a1a212017-08-18 01:03:21 -07001957 public void bindAppWidget(LauncherAppWidgetInfo item) {
1958 View view = inflateAppWidget(item);
1959 if (view != null) {
1960 mWorkspace.addInScreen(view, item);
1961 mWorkspace.requestLayout();
1962 }
1963 }
1964
1965 private View inflateAppWidget(LauncherAppWidgetInfo item) {
Sunny Goyal2e1efb42016-03-03 16:58:55 -08001966 if (mIsSafeModeEnabled) {
Sunny Goyald5462aa2016-11-22 16:52:39 +05301967 PendingAppWidgetHostView view =
1968 new PendingAppWidgetHostView(this, item, mIconCache, true);
1969 prepareAppWidget(view, item);
Sunny Goyalb23980c2017-08-17 07:45:25 -07001970 return view;
Sunny Goyal2e1efb42016-03-03 16:58:55 -08001971 }
1972
Sunny Goyalfca6bc92017-09-28 16:28:34 -07001973 TraceHelper.beginSection("BIND_WIDGET");
Joe Onorato9c1289c2009-08-17 11:03:03 -04001974
Sunny Goyal2e1efb42016-03-03 16:58:55 -08001975 final LauncherAppWidgetProviderInfo appWidgetInfo;
Adam Cohen59400422014-03-05 18:07:04 -08001976
Sunny Goyal2e1efb42016-03-03 16:58:55 -08001977 if (item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_PROVIDER_NOT_READY)) {
1978 // If the provider is not ready, bind as a pending widget.
1979 appWidgetInfo = null;
1980 } else if (item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_ID_NOT_VALID)) {
1981 // The widget id is not valid. Try to find the widget based on the provider info.
1982 appWidgetInfo = mAppWidgetManager.findProvider(item.providerName, item.user);
1983 } else {
1984 appWidgetInfo = mAppWidgetManager.getLauncherAppWidgetInfo(item.appWidgetId);
1985 }
Sunny Goyal84b4adc2015-08-12 15:12:16 -07001986
Sunny Goyal2e1efb42016-03-03 16:58:55 -08001987 // If the provider is ready, but the width is not yet restored, try to restore it.
1988 if (!item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_PROVIDER_NOT_READY) &&
1989 (item.restoreStatus != LauncherAppWidgetInfo.RESTORE_COMPLETED)) {
Sunny Goyalff572272014-07-23 13:58:07 -07001990 if (appWidgetInfo == null) {
Sunny Goyalfca6bc92017-09-28 16:28:34 -07001991 Log.d(TAG, "Removing restored widget: id=" + item.appWidgetId
1992 + " belongs to component " + item.providerName
1993 + ", as the provider is null");
Sunny Goyal43bf11d2017-02-02 13:52:53 -08001994 getModelWriter().deleteItemFromDatabase(item);
Sunny Goyalb23980c2017-08-17 07:45:25 -07001995 return null;
Sunny Goyalff572272014-07-23 13:58:07 -07001996 }
Sunny Goyalff572272014-07-23 13:58:07 -07001997
Sunny Goyal84b4adc2015-08-12 15:12:16 -07001998 // If we do not have a valid id, try to bind an id.
Sunny Goyal2e1efb42016-03-03 16:58:55 -08001999 if (item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_ID_NOT_VALID)) {
Sunny Goyald478c832016-04-01 12:04:16 -07002000 if (!item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_ID_ALLOCATED)) {
2001 // Id has not been allocated yet. Allocate a new id.
2002 item.appWidgetId = mAppWidgetHost.allocateAppWidgetId();
2003 item.restoreStatus |= LauncherAppWidgetInfo.FLAG_ID_ALLOCATED;
Sunny Goyalff572272014-07-23 13:58:07 -07002004
Sunny Goyald478c832016-04-01 12:04:16 -07002005 // Also try to bind the widget. If the bind fails, the user will be shown
2006 // a click to setup UI, which will ask for the bind permission.
Sunny Goyala52ecb02016-12-16 15:04:51 -08002007 PendingAddWidgetInfo pendingInfo = new PendingAddWidgetInfo(appWidgetInfo);
Sunny Goyald478c832016-04-01 12:04:16 -07002008 pendingInfo.spanX = item.spanX;
2009 pendingInfo.spanY = item.spanY;
2010 pendingInfo.minSpanX = item.minSpanX;
2011 pendingInfo.minSpanY = item.minSpanY;
2012 Bundle options = WidgetHostViewLoader.getDefaultOptionsForWidget(this, pendingInfo);
Sunny Goyal86df1382016-08-10 15:03:22 -07002013
2014 boolean isDirectConfig =
2015 item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_DIRECT_CONFIG);
2016 if (isDirectConfig && item.bindOptions != null) {
2017 Bundle newOptions = item.bindOptions.getExtras();
2018 if (options != null) {
2019 newOptions.putAll(options);
2020 }
2021 options = newOptions;
2022 }
Sunny Goyald478c832016-04-01 12:04:16 -07002023 boolean success = mAppWidgetManager.bindAppWidgetIdIfAllowed(
2024 item.appWidgetId, appWidgetInfo, options);
Sunny Goyal84b4adc2015-08-12 15:12:16 -07002025
Sunny Goyal86df1382016-08-10 15:03:22 -07002026 // We tried to bind once. If we were not able to bind, we would need to
2027 // go through the permission dialog, which means we cannot skip the config
2028 // activity.
2029 item.bindOptions = null;
2030 item.restoreStatus &= ~LauncherAppWidgetInfo.FLAG_DIRECT_CONFIG;
2031
Sunny Goyald478c832016-04-01 12:04:16 -07002032 // Bind succeeded
2033 if (success) {
2034 // If the widget has a configure activity, it is still needs to set it up,
2035 // otherwise the widget is ready to go.
Sunny Goyal86df1382016-08-10 15:03:22 -07002036 item.restoreStatus = (appWidgetInfo.configure == null) || isDirectConfig
Sunny Goyald478c832016-04-01 12:04:16 -07002037 ? LauncherAppWidgetInfo.RESTORE_COMPLETED
2038 : LauncherAppWidgetInfo.FLAG_UI_NOT_READY;
Sunny Goyal84b4adc2015-08-12 15:12:16 -07002039 }
Sunny Goyald478c832016-04-01 12:04:16 -07002040
Sunny Goyal43bf11d2017-02-02 13:52:53 -08002041 getModelWriter().updateItemInDatabase(item);
Sunny Goyalff572272014-07-23 13:58:07 -07002042 }
Sunny Goyal2e1efb42016-03-03 16:58:55 -08002043 } else if (item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_UI_NOT_READY)
Sunny Goyal84b4adc2015-08-12 15:12:16 -07002044 && (appWidgetInfo.configure == null)) {
Sunny Goyal2e1efb42016-03-03 16:58:55 -08002045 // The widget was marked as UI not ready, but there is no configure activity to
2046 // update the UI.
Sunny Goyal84b4adc2015-08-12 15:12:16 -07002047 item.restoreStatus = LauncherAppWidgetInfo.RESTORE_COMPLETED;
Sunny Goyal43bf11d2017-02-02 13:52:53 -08002048 getModelWriter().updateItemInDatabase(item);
Sunny Goyalff572272014-07-23 13:58:07 -07002049 }
Sunny Goyalff572272014-07-23 13:58:07 -07002050 }
2051
Sunny Goyald5462aa2016-11-22 16:52:39 +05302052 final AppWidgetHostView view;
Sunny Goyal2e1efb42016-03-03 16:58:55 -08002053 if (item.restoreStatus == LauncherAppWidgetInfo.RESTORE_COMPLETED) {
Sunny Goyal56c73602015-09-25 12:55:01 -07002054 // Verify that we own the widget
Sunny Goyal2e1efb42016-03-03 16:58:55 -08002055 if (appWidgetInfo == null) {
Sunny Goyal713edfc2016-05-06 09:58:34 -07002056 FileLog.e(TAG, "Removing invalid widget: id=" + item.appWidgetId);
Tony Wickham6a71a5b2018-08-21 11:40:23 -07002057 getModelWriter().deleteWidgetInfo(item, getAppWidgetHost());
Sunny Goyalb23980c2017-08-17 07:45:25 -07002058 return null;
Sunny Goyal56c73602015-09-25 12:55:01 -07002059 }
2060
Sunny Goyal233ee962015-08-03 13:05:01 -07002061 item.minSpanX = appWidgetInfo.minSpanX;
2062 item.minSpanY = appWidgetInfo.minSpanY;
Sunny Goyald5462aa2016-11-22 16:52:39 +05302063 view = mAppWidgetHost.createView(this, item.appWidgetId, appWidgetInfo);
Sunny Goyal651077b2014-06-30 14:15:31 -07002064 } else {
Sunny Goyald5462aa2016-11-22 16:52:39 +05302065 view = new PendingAppWidgetHostView(this, item, mIconCache, false);
Sunny Goyal651077b2014-06-30 14:15:31 -07002066 }
Sunny Goyald5462aa2016-11-22 16:52:39 +05302067 prepareAppWidget(view, item);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002068
Sunny Goyalfca6bc92017-09-28 16:28:34 -07002069 TraceHelper.endSection("BIND_WIDGET", "id=" + item.appWidgetId);
Sunny Goyalb23980c2017-08-17 07:45:25 -07002070 return view;
Joe Onorato9c1289c2009-08-17 11:03:03 -04002071 }
2072
Sunny Goyalff572272014-07-23 13:58:07 -07002073 /**
2074 * Restores a pending widget.
2075 *
2076 * @param appWidgetId The app widget id
Sunny Goyalff572272014-07-23 13:58:07 -07002077 */
Sunny Goyald478c832016-04-01 12:04:16 -07002078 private LauncherAppWidgetInfo completeRestoreAppWidget(int appWidgetId, int finalRestoreFlag) {
Sunny Goyalff572272014-07-23 13:58:07 -07002079 LauncherAppWidgetHostView view = mWorkspace.getWidgetForAppWidgetId(appWidgetId);
2080 if ((view == null) || !(view instanceof PendingAppWidgetHostView)) {
2081 Log.e(TAG, "Widget update called, when the widget no longer exists.");
Sunny Goyald478c832016-04-01 12:04:16 -07002082 return null;
Sunny Goyalff572272014-07-23 13:58:07 -07002083 }
2084
Sunny Goyal0fc1be12014-08-11 17:05:23 -07002085 LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) view.getTag();
Sunny Goyald478c832016-04-01 12:04:16 -07002086 info.restoreStatus = finalRestoreFlag;
Jon Miranda2b823f42017-05-02 18:36:18 -07002087 if (info.restoreStatus == LauncherAppWidgetInfo.RESTORE_COMPLETED) {
2088 info.pendingItemInfo = null;
2089 }
Sunny Goyalff572272014-07-23 13:58:07 -07002090
Sunny Goyalba47faa2017-10-04 16:50:57 -07002091 if (((PendingAppWidgetHostView) view).isReinflateIfNeeded()) {
Sunny Goyal29947f02017-12-18 13:49:44 -08002092 view.reInflate();
Sunny Goyalba47faa2017-10-04 16:50:57 -07002093 }
2094
Sunny Goyal43bf11d2017-02-02 13:52:53 -08002095 getModelWriter().updateItemInDatabase(info);
Sunny Goyald478c832016-04-01 12:04:16 -07002096 return info;
Sunny Goyalff572272014-07-23 13:58:07 -07002097 }
2098
Adam Cohen1462de32012-07-24 22:34:36 -07002099 public void onPageBoundSynchronously(int page) {
Sunny Goyalf4aceab2017-12-06 16:16:31 -08002100 mSynchronouslyBoundPage = page;
Adam Cohen1462de32012-07-24 22:34:36 -07002101 }
2102
Sunny Goyal527c7d32015-08-28 15:19:36 -07002103 @Override
2104 public void executeOnNextDraw(ViewOnDrawExecutor executor) {
2105 if (mPendingExecutor != null) {
2106 mPendingExecutor.markCompleted();
2107 }
2108 mPendingExecutor = executor;
Sunny Goyal60180b02018-02-07 12:56:30 -08002109 if (!isInState(ALL_APPS)) {
2110 mAppsView.getAppsStore().setDeferUpdates(true);
2111 mPendingExecutor.execute(() -> mAppsView.getAppsStore().setDeferUpdates(false));
2112 }
2113
Sunny Goyal527c7d32015-08-28 15:19:36 -07002114 executor.attachTo(this);
2115 }
2116
2117 public void clearPendingExecutor(ViewOnDrawExecutor executor) {
2118 if (mPendingExecutor == executor) {
2119 mPendingExecutor = null;
2120 }
2121 }
2122
Sunny Goyalb5b9ad62016-04-02 11:23:39 -07002123 @Override
2124 public void finishFirstPageBind(final ViewOnDrawExecutor executor) {
Sunny Goyal6001ea22018-05-10 16:31:00 -07002125 AlphaProperty property = mDragLayer.getAlphaProperty(ALPHA_INDEX_LAUNCHER_LOAD);
2126 if (property.getValue() < 1) {
2127 ObjectAnimator anim = ObjectAnimator.ofFloat(property, MultiValueAlpha.VALUE, 1);
2128 if (executor != null) {
2129 anim.addListener(new AnimatorListenerAdapter() {
2130 @Override
2131 public void onAnimationEnd(Animator animation) {
2132 executor.onLoadAnimationCompleted();
2133 }
2134 });
2135 }
2136 anim.start();
Sunny Goyal29947f02017-12-18 13:49:44 -08002137 } else if (executor != null) {
2138 executor.onLoadAnimationCompleted();
Sunny Goyalb5b9ad62016-04-02 11:23:39 -07002139 }
2140 }
2141
Joe Onorato9c1289c2009-08-17 11:03:03 -04002142 /**
2143 * Callback saying that there aren't any more items to bind.
2144 *
2145 * Implementation of the method from LauncherModel.Callbacks.
2146 */
Tonyf80e8932018-12-21 11:58:04 -08002147 public void finishBindingItems(int pageBoundFirst) {
Sunny Goyalfca6bc92017-09-28 16:28:34 -07002148 TraceHelper.beginSection("finishBindingItems");
Adam Cohen1462de32012-07-24 22:34:36 -07002149 mWorkspace.restoreInstanceStateForRemainingPages();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002150
Anjali Koppalff7ceff2014-05-01 18:26:37 -07002151 setWorkspaceLoading(false);
Adam Cohendb364c32014-05-20 14:23:40 -07002152
Sunny Goyal2100c782016-08-22 16:00:03 -07002153 if (mPendingActivityResult != null) {
2154 handleActivityResult(mPendingActivityResult.requestCode,
2155 mPendingActivityResult.resultCode, mPendingActivityResult.data);
2156 mPendingActivityResult = null;
Adam Cohendb364c32014-05-20 14:23:40 -07002157 }
2158
Sunny Goyala474a9b2017-05-04 16:47:11 -07002159 InstallShortcutReceiver.disableAndFlushInstallQueue(
2160 InstallShortcutReceiver.FLAG_LOADER_RUNNING, this);
Adam Cohen9211d422014-10-07 18:14:53 -07002161
Tonyf80e8932018-12-21 11:58:04 -08002162 // When undoing the removal of the last item on a page, return to that page.
2163 mWorkspace.setCurrentPage(pageBoundFirst);
Tony Wickham6a71a5b2018-08-21 11:40:23 -07002164
Sunny Goyalfca6bc92017-09-28 16:28:34 -07002165 TraceHelper.endSection("finishBindingItems");
Winson Chungf0c6ae02012-03-21 16:10:31 -07002166 }
2167
Winson Chunga2413752012-04-03 14:22:34 -07002168 private boolean canRunNewAppsAnimation() {
2169 long diff = System.currentTimeMillis() - mDragController.getLastGestureUpTime();
Andrew Sapperstein932eb832016-06-30 18:10:09 -07002170 return diff > (NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS * 1000);
Winson Chunga2413752012-04-03 14:22:34 -07002171 }
2172
Winson Chungc9168342013-06-26 14:54:55 -07002173 private ValueAnimator createNewAppBounceAnimation(View v, int i) {
Sunny Goyalf0b6db72018-08-13 16:10:14 -07002174 ValueAnimator bounceAnim = new PropertyListBuilder().alpha(1).scale(1).build(v)
2175 .setDuration(InstallShortcutReceiver.NEW_SHORTCUT_BOUNCE_DURATION);
Winson Chungc9168342013-06-26 14:54:55 -07002176 bounceAnim.setStartDelay(i * InstallShortcutReceiver.NEW_SHORTCUT_STAGGER_DELAY);
Sunny Goyal5a1f53b2015-05-27 10:24:24 -07002177 bounceAnim.setInterpolator(new OvershootInterpolator(BOUNCE_ANIMATION_TENSION));
Winson Chungc9168342013-06-26 14:54:55 -07002178 return bounceAnim;
2179 }
2180
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002181 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04002182 * Add the icons for all apps.
2183 *
2184 * Implementation of the method from LauncherModel.Callbacks.
2185 */
Sunny Goyal29947f02017-12-18 13:49:44 -08002186 public void bindAllApplications(ArrayList<AppInfo> apps) {
Sunny Goyal60180b02018-02-07 12:56:30 -08002187 mAppsView.getAppsStore().setApps(apps);
Sunny Goyal49fc3f72017-08-18 10:17:06 -07002188
Adam Cohen9211d422014-10-07 18:14:53 -07002189 if (mLauncherCallbacks != null) {
2190 mLauncherCallbacks.bindAllApplications(apps);
2191 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04002192 }
2193
2194 /**
Zak Cohen658c67a2018-10-19 14:21:05 -07002195 * Copies LauncherModel's map of activities to shortcut counts to Launcher's. This is necessary
Tony Wickhambfbf7f92016-05-19 11:19:39 -07002196 * because LauncherModel's map is updated in the background, while Launcher runs on the UI.
2197 */
2198 @Override
Zak Cohen658c67a2018-10-19 14:21:05 -07002199 public void bindDeepShortcutMap(HashMap<ComponentKey, Integer> deepShortcutMapCopy) {
Tony Wickham010d2552017-01-20 08:15:28 -08002200 mPopupDataProvider.setDeepShortcutMap(deepShortcutMapCopy);
Tony Wickham1bce7fd2016-04-28 17:39:03 -07002201 }
2202
Tony Wickhambfbf7f92016-05-19 11:19:39 -07002203 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04002204 * A package was updated.
2205 *
2206 * Implementation of the method from LauncherModel.Callbacks.
2207 */
Sunny Goyal29947f02017-12-18 13:49:44 -08002208 @Override
2209 public void bindAppsAddedOrUpdated(ArrayList<AppInfo> apps) {
Sunny Goyal60180b02018-02-07 12:56:30 -08002210 mAppsView.getAppsStore().addOrUpdateApps(apps);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002211 }
2212
Sunny Goyal4390ace2014-10-13 11:33:11 -07002213 @Override
Sunny Goyal29947f02017-12-18 13:49:44 -08002214 public void bindPromiseAppProgressUpdated(PromiseAppInfo app) {
Sunny Goyal60180b02018-02-07 12:56:30 -08002215 mAppsView.getAppsStore().updatePromiseAppProgress(app);
Mario Bertschler08ffaae2017-03-20 11:30:27 -07002216 }
2217
2218 @Override
Sunny Goyal29947f02017-12-18 13:49:44 -08002219 public void bindWidgetsRestored(ArrayList<LauncherAppWidgetInfo> widgets) {
Sunny Goyal4390ace2014-10-13 11:33:11 -07002220 mWorkspace.widgetsRestored(widgets);
2221 }
2222
Joe Onorato9c1289c2009-08-17 11:03:03 -04002223 /**
Sunny Goyalb50cc8c2014-10-06 16:23:56 -07002224 * Some shortcuts were updated in the background.
Sunny Goyalb50cc8c2014-10-06 16:23:56 -07002225 * Implementation of the method from LauncherModel.Callbacks.
Sunny Goyald3b87ef2016-07-28 12:11:54 -07002226 *
2227 * @param updated list of shortcuts which have changed.
Sunny Goyalb50cc8c2014-10-06 16:23:56 -07002228 */
Sunny Goyal4390ace2014-10-13 11:33:11 -07002229 @Override
Sunny Goyal95899162019-03-27 16:03:06 -07002230 public void bindWorkspaceItemsChanged(ArrayList<WorkspaceItemInfo> updated) {
Sunny Goyal4390ace2014-10-13 11:33:11 -07002231 if (!updated.isEmpty()) {
2232 mWorkspace.updateShortcuts(updated);
2233 }
Sunny Goyalb50cc8c2014-10-06 16:23:56 -07002234 }
2235
2236 /**
Chris Wrenaeff7ea2014-02-14 16:59:24 -05002237 * Update the state of a package, typically related to install state.
2238 *
2239 * Implementation of the method from LauncherModel.Callbacks.
2240 */
Sunny Goyale755d462014-07-22 13:48:29 -07002241 @Override
Sunny Goyal29947f02017-12-18 13:49:44 -08002242 public void bindRestoreItemsChange(HashSet<ItemInfo> updates) {
Sunny Goyal756adbc2015-04-16 15:20:51 -07002243 mWorkspace.updateRestoreItems(updates);
Sunny Goyala22666f2014-09-18 13:25:15 -07002244 }
2245
2246 /**
Sunny Goyal3bbbabc2016-03-15 09:16:30 -07002247 * A package was uninstalled/updated. We take both the super set of packageNames
Winson Chung83892cc2013-05-01 16:53:33 -07002248 * in addition to specific applications to remove, the reason being that
2249 * this can be called when a package is updated as well. In that scenario,
Sunny Goyal3bbbabc2016-03-15 09:16:30 -07002250 * we only remove specific components from the workspace and hotseat, where as
Winson Chung83892cc2013-05-01 16:53:33 -07002251 * package-removal should clear all items by package name.
Joe Onorato9c1289c2009-08-17 11:03:03 -04002252 */
Sunny Goyal1a745e82014-10-02 15:58:31 -07002253 @Override
Sunny Goyal6e13dd32017-08-17 03:01:19 -07002254 public void bindWorkspaceComponentsRemoved(final ItemInfoMatcher matcher) {
Sunny Goyal6e13dd32017-08-17 03:01:19 -07002255 mWorkspace.removeItemsByMatcher(matcher);
2256 mDragController.onAppsRemoved(matcher);
Sunny Goyal3bbbabc2016-03-15 09:16:30 -07002257 }
Sunny Goyal4390ace2014-10-13 11:33:11 -07002258
Sunny Goyal3bbbabc2016-03-15 09:16:30 -07002259 @Override
2260 public void bindAppInfosRemoved(final ArrayList<AppInfo> appInfos) {
Sunny Goyal60180b02018-02-07 12:56:30 -08002261 mAppsView.getAppsStore().removeApps(appInfos);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002262 }
Joe Onoratobe386092009-11-17 17:32:16 -08002263
Sunny Goyal49fc3f72017-08-18 10:17:06 -07002264 @Override
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -07002265 public void bindAllWidgets(final ArrayList<WidgetListRowEntry> allWidgets) {
2266 mPopupDataProvider.setAllWidgets(allWidgets);
Tony Wickham26b17462017-03-20 17:12:24 -07002267 }
2268
Tony Wickham86222d22017-03-29 15:30:43 -07002269 /**
2270 * @param packageUser if null, refreshes all widgets and shortcuts, otherwise only
2271 * refreshes the widgets and shortcuts associated with the given package/user
2272 */
2273 public void refreshAndBindWidgetsForPackageUser(@Nullable PackageUserKey packageUser) {
Sunny Goyalc6e97692017-06-02 13:46:55 -07002274 mModel.refreshAndBindWidgetsAndShortcuts(packageUser);
Sunny Goyal2e1efb42016-03-03 16:58:55 -08002275 }
2276
Winson Chung80baf5a2010-08-09 16:03:15 -07002277 /**
Hyunyoung Song3c7d9cb2017-01-30 15:11:27 -08002278 * $ adb shell dumpsys activity com.android.launcher3.Launcher [--all]
Joe Onoratobe386092009-11-17 17:32:16 -08002279 */
Adam Cohen16d7ffc2011-10-05 17:49:14 -07002280 @Override
2281 public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
2282 super.dump(prefix, fd, writer, args);
Sunny Goyala1365452015-10-01 15:46:24 -07002283
Hyunyoung Song3c7d9cb2017-01-30 15:11:27 -08002284 if (args.length > 0 && TextUtils.equals(args[0], "--all")) {
2285 writer.println(prefix + "Workspace Items");
Sunny Goyal7ce471b2017-08-02 03:37:39 -07002286 for (int i = 0; i < mWorkspace.getPageCount(); i++) {
Hyunyoung Song3c7d9cb2017-01-30 15:11:27 -08002287 writer.println(prefix + " Homescreen " + i);
2288
2289 ViewGroup layout = ((CellLayout) mWorkspace.getPageAt(i)).getShortcutsAndWidgets();
2290 for (int j = 0; j < layout.getChildCount(); j++) {
2291 Object tag = layout.getChildAt(j).getTag();
2292 if (tag != null) {
2293 writer.println(prefix + " " + tag.toString());
2294 }
2295 }
2296 }
2297
2298 writer.println(prefix + " Hotseat");
Sunny Goyal876e4622018-11-02 13:50:40 -07002299 ViewGroup layout = mHotseat.getShortcutsAndWidgets();
Sunny Goyala1365452015-10-01 15:46:24 -07002300 for (int j = 0; j < layout.getChildCount(); j++) {
2301 Object tag = layout.getChildAt(j).getTag();
2302 if (tag != null) {
2303 writer.println(prefix + " " + tag.toString());
2304 }
Adam Cohen4caf2982013-08-20 18:54:31 -07002305 }
Sunny Goyala1365452015-10-01 15:46:24 -07002306 }
2307
Hyunyoung Song3c7d9cb2017-01-30 15:11:27 -08002308 writer.println(prefix + "Misc:");
2309 writer.print(prefix + "\tmWorkspaceLoading=" + mWorkspaceLoading);
2310 writer.print(" mPendingRequestArgs=" + mPendingRequestArgs);
2311 writer.println(" mPendingActivityResult=" + mPendingActivityResult);
Sunny Goyale43d00d2018-05-14 14:23:18 -07002312 writer.println(" mRotationHelper: " + mRotationHelper);
Sunny Goyalcb2c5052018-10-15 12:30:29 -07002313 // Extra logging for b/116853349
2314 mDragLayer.dumpAlpha(writer);
Sunny Goyale43d00d2018-05-14 14:23:18 -07002315 dumpMisc(writer);
Sunny Goyal2bba1902018-02-27 12:20:50 -08002316
2317 try {
2318 FileLog.flushAll(writer);
2319 } catch (Exception e) {
2320 // Ignore
2321 }
Hyunyoung Song3c7d9cb2017-01-30 15:11:27 -08002322
2323 mModel.dumpState(prefix, fd, writer, args);
Sunny Goyala1365452015-10-01 15:46:24 -07002324
Adam Cohen9211d422014-10-07 18:14:53 -07002325 if (mLauncherCallbacks != null) {
2326 mLauncherCallbacks.dump(prefix, fd, writer, args);
2327 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07002328 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07002329
Sunny Goyal66b24572016-09-21 15:57:55 -07002330 @Override
Sunny Goyal66b24572016-09-21 15:57:55 -07002331 public void onProvideKeyboardShortcuts(
2332 List<KeyboardShortcutGroup> data, Menu menu, int deviceId) {
2333
2334 ArrayList<KeyboardShortcutInfo> shortcutInfos = new ArrayList<>();
Sunny Goyal3e3f44c2017-10-23 17:14:52 -07002335 if (isInState(NORMAL)) {
Sunny Goyal66b24572016-09-21 15:57:55 -07002336 shortcutInfos.add(new KeyboardShortcutInfo(getString(R.string.all_apps_button_label),
2337 KeyEvent.KEYCODE_A, KeyEvent.META_CTRL_ON));
Vadim Tryshev74c261c2018-06-12 13:44:43 -07002338 shortcutInfos.add(new KeyboardShortcutInfo(getString(R.string.widget_button_text),
2339 KeyEvent.KEYCODE_W, KeyEvent.META_CTRL_ON));
Sunny Goyal66b24572016-09-21 15:57:55 -07002340 }
Vadim Tryshev3455f8d2018-05-11 20:02:20 -07002341 final View currentFocus = getCurrentFocus();
2342 if (currentFocus != null) {
2343 if (new CustomActionsPopup(this, currentFocus).canShow()) {
2344 shortcutInfos.add(new KeyboardShortcutInfo(getString(R.string.custom_actions),
2345 KeyEvent.KEYCODE_O, KeyEvent.META_CTRL_ON));
2346 }
2347 if (currentFocus.getTag() instanceof ItemInfo
2348 && DeepShortcutManager.supportsShortcuts((ItemInfo) currentFocus.getTag())) {
2349 shortcutInfos.add(new KeyboardShortcutInfo(
2350 getString(R.string.shortcuts_menu_with_notifications_description),
2351 KeyEvent.KEYCODE_S, KeyEvent.META_CTRL_ON));
2352 }
Sunny Goyal66b24572016-09-21 15:57:55 -07002353 }
2354 if (!shortcutInfos.isEmpty()) {
2355 data.add(new KeyboardShortcutGroup(getString(R.string.home_screen), shortcutInfos));
2356 }
2357
2358 super.onProvideKeyboardShortcuts(data, menu, deviceId);
2359 }
2360
2361 @Override
2362 public boolean onKeyShortcut(int keyCode, KeyEvent event) {
2363 if (event.hasModifiers(KeyEvent.META_CTRL_ON)) {
2364 switch (keyCode) {
2365 case KeyEvent.KEYCODE_A:
Sunny Goyal3e3f44c2017-10-23 17:14:52 -07002366 if (isInState(NORMAL)) {
2367 getStateManager().goToState(ALL_APPS);
Sunny Goyal66b24572016-09-21 15:57:55 -07002368 return true;
2369 }
2370 break;
2371 case KeyEvent.KEYCODE_S: {
2372 View focusedView = getCurrentFocus();
2373 if (focusedView instanceof BubbleTextView
2374 && focusedView.getTag() instanceof ItemInfo
2375 && mAccessibilityDelegate.performAction(focusedView,
2376 (ItemInfo) focusedView.getTag(),
2377 LauncherAccessibilityDelegate.DEEP_SHORTCUTS)) {
Sunny Goyal00ac9202017-11-09 15:24:06 -08002378 PopupContainerWithArrow.getOpen(this).requestFocus();
Sunny Goyal66b24572016-09-21 15:57:55 -07002379 return true;
2380 }
2381 break;
2382 }
2383 case KeyEvent.KEYCODE_O:
2384 if (new CustomActionsPopup(this, getCurrentFocus()).show()) {
2385 return true;
2386 }
2387 break;
Vadim Tryshev74c261c2018-06-12 13:44:43 -07002388 case KeyEvent.KEYCODE_W:
2389 if (isInState(NORMAL)) {
2390 OptionsPopupView.openWidgets(this);
2391 return true;
2392 }
2393 break;
Sunny Goyal66b24572016-09-21 15:57:55 -07002394 }
2395 }
2396 return super.onKeyShortcut(keyCode, event);
2397 }
2398
Vadim Tryshev646a0dd2018-02-05 16:27:50 -08002399 @Override
2400 public boolean onKeyUp(int keyCode, KeyEvent event) {
2401 if (keyCode == KeyEvent.KEYCODE_MENU) {
2402 // KEYCODE_MENU is sent by some tests, for example
2403 // LauncherJankTests#testWidgetsContainerFling. Don't just remove its handling.
2404 if (!mDragController.isDragging() && !mWorkspace.isSwitchingState() &&
2405 isInState(NORMAL)) {
2406 // Close any open floating views.
2407 AbstractFloatingView.closeAllOpenViews(this);
2408
2409 // Setting the touch point to (-1, -1) will show the options popup in the center of
2410 // the screen.
Sunny Goyal2fd7a8b2018-03-30 17:10:13 -07002411 OptionsPopupView.showDefaultOptions(this, -1, -1);
Vadim Tryshev646a0dd2018-02-05 16:27:50 -08002412 }
2413 return true;
2414 }
2415 return super.onKeyUp(keyCode, event);
2416 }
2417
Andrew Sappersteinabef55a2016-06-19 12:49:00 -07002418 public static Launcher getLauncher(Context context) {
Sunny Goyal87b5eb62018-07-03 15:53:39 -07002419 return (Launcher) fromContext(context);
Andrew Sappersteinabef55a2016-06-19 12:49:00 -07002420 }
2421
Sunny Goyal3dce5f32017-10-05 11:40:05 -07002422 /**
Sunny Goyalab770a12018-11-14 15:17:26 -08002423 * Just a wrapper around the type cast to allow easier tracking of calls.
2424 */
2425 public static <T extends Launcher> T cast(ActivityContext activityContext) {
2426 return (T) activityContext;
2427 }
2428
2429 /**
Sunny Goyal3dce5f32017-10-05 11:40:05 -07002430 * Callback for listening for onResume
2431 */
2432 public interface OnResumeCallback {
2433
2434 void onLauncherResume();
2435 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002436}