From 4c23ca768fa74ae4a4e4c6c6216a0c6fb7877c5e Mon Sep 17 00:00:00 2001 From: Sunny Goyal Date: Thu, 11 Feb 2021 16:47:26 -0800 Subject: [PATCH 1/5] Fixing shortcut intent getting cleared during backup/restore Bug: 174570283 Bug: 156871815 Test: Verified on device Change-Id: Ie286ee783bfe96c5b2be28f0db5298caf3801e6d --- src/com/android/launcher3/Utilities.java | 1 - .../android/launcher3/model/AllAppsList.java | 6 ++---- .../PackageIncrementalDownloadUpdatedTask.java | 6 +++--- .../model/PackageInstallStateChangedTask.java | 8 ++++---- .../launcher3/model/PackageUpdatedTask.java | 18 +++++++++++++----- .../launcher3/model/ShortcutsChangedTask.java | 9 +++++++++ .../launcher3/pm/InstallSessionHelper.java | 4 ++-- .../launcher3/util/PackageManagerHelper.java | 10 +++++++++- 8 files changed, 42 insertions(+), 20 deletions(-) diff --git a/src/com/android/launcher3/Utilities.java b/src/com/android/launcher3/Utilities.java index 51d8e665d0..c440303c2e 100644 --- a/src/com/android/launcher3/Utilities.java +++ b/src/com/android/launcher3/Utilities.java @@ -605,7 +605,6 @@ public final class Utilities { outObj[0] = activityInfo; return activityInfo.getFullResIcon(appState.getIconCache()); } - if (info.getIntent() == null || info.getIntent().getPackage() == null) return null; List si = ShortcutKey.fromItemInfo(info) .buildRequest(launcher) .query(ShortcutRequest.ALL); diff --git a/src/com/android/launcher3/model/AllAppsList.java b/src/com/android/launcher3/model/AllAppsList.java index e3e4b6911f..a519f9275c 100644 --- a/src/com/android/launcher3/model/AllAppsList.java +++ b/src/com/android/launcher3/model/AllAppsList.java @@ -22,7 +22,6 @@ import static com.android.launcher3.model.data.AppInfo.EMPTY_ARRAY; import android.content.ComponentName; import android.content.Context; import android.content.Intent; -import android.content.pm.ApplicationInfo; import android.content.pm.LauncherActivityInfo; import android.content.pm.LauncherApps; import android.os.LocaleList; @@ -145,10 +144,9 @@ public class AllAppsList { } public void addPromiseApp(Context context, PackageInstallInfo installInfo) { - ApplicationInfo applicationInfo = new PackageManagerHelper(context) - .getApplicationInfo(installInfo.packageName, installInfo.user, 0); // only if not yet installed - if (applicationInfo == null) { + if (!new PackageManagerHelper(context) + .isAppInstalled(installInfo.packageName, installInfo.user)) { AppInfo info = new AppInfo(installInfo); mIconCache.getTitleAndIcon(info, info.usingLowResIcon()); info.sectionName = mIndex.computeSectionName(info.title); diff --git a/src/com/android/launcher3/model/PackageIncrementalDownloadUpdatedTask.java b/src/com/android/launcher3/model/PackageIncrementalDownloadUpdatedTask.java index e3e87693b1..434776cf74 100644 --- a/src/com/android/launcher3/model/PackageIncrementalDownloadUpdatedTask.java +++ b/src/com/android/launcher3/model/PackageIncrementalDownloadUpdatedTask.java @@ -15,7 +15,7 @@ */ package com.android.launcher3.model; -import android.content.ComponentName; +import android.content.Intent; import android.os.UserHandle; import com.android.launcher3.LauncherAppState; @@ -66,8 +66,8 @@ public class PackageIncrementalDownloadUpdatedTask extends BaseModelUpdateTask { final ArrayList updatedWorkspaceItems = new ArrayList<>(); synchronized (dataModel) { dataModel.forAllWorkspaceItemInfos(mUser, si -> { - ComponentName cn = si.getTargetComponent(); - if ((cn != null) && cn.getPackageName().equals(mPackageName)) { + Intent intent = si.getIntent(); + if ((intent != null) && mPackageName.equals(intent.getPackage())) { si.runtimeStatusFlags &= ~ItemInfoWithIcon.FLAG_INSTALL_SESSION_ACTIVE; si.setProgressLevel(downloadInfo); updatedWorkspaceItems.add(si); diff --git a/src/com/android/launcher3/model/PackageInstallStateChangedTask.java b/src/com/android/launcher3/model/PackageInstallStateChangedTask.java index 8215edd90b..1380e9e0c4 100644 --- a/src/com/android/launcher3/model/PackageInstallStateChangedTask.java +++ b/src/com/android/launcher3/model/PackageInstallStateChangedTask.java @@ -15,7 +15,7 @@ */ package com.android.launcher3.model; -import android.content.ComponentName; +import android.content.Intent; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; @@ -72,9 +72,9 @@ public class PackageInstallStateChangedTask extends BaseModelUpdateTask { synchronized (dataModel) { final HashSet updates = new HashSet<>(); dataModel.forAllWorkspaceItemInfos(mInstallInfo.user, si -> { - ComponentName cn = si.getTargetComponent(); - if (si.hasPromiseIconUi() && (cn != null) - && cn.getPackageName().equals(mInstallInfo.packageName)) { + Intent intent = si.getIntent(); + if (si.hasPromiseIconUi() && (intent != null) + && mInstallInfo.packageName.equals(intent.getPackage())) { int installProgress = mInstallInfo.progress; si.setProgressLevel(installProgress, PackageInstallInfo.STATUS_INSTALLING); diff --git a/src/com/android/launcher3/model/PackageUpdatedTask.java b/src/com/android/launcher3/model/PackageUpdatedTask.java index f13a109926..7bfa3ef481 100644 --- a/src/com/android/launcher3/model/PackageUpdatedTask.java +++ b/src/com/android/launcher3/model/PackageUpdatedTask.java @@ -30,6 +30,7 @@ import android.os.UserManager; import android.util.Log; import com.android.launcher3.LauncherAppState; +import com.android.launcher3.LauncherSettings; import com.android.launcher3.LauncherSettings.Favorites; import com.android.launcher3.config.FeatureFlags; import com.android.launcher3.icons.BitmapInfo; @@ -228,7 +229,8 @@ public class PackageUpdatedTask extends BaseModelUpdateTask { isTargetValid = context.getSystemService(LauncherApps.class) .isActivityEnabled(cn, mUser); } - if (si.hasStatusFlag(FLAG_RESTORED_ICON | FLAG_AUTOINSTALL_ICON)) { + if (!isTargetValid && si.hasStatusFlag( + FLAG_RESTORED_ICON | FLAG_AUTOINSTALL_ICON)) { if (updateWorkspaceItemIntent(context, si, packageName)) { infoUpdated = true; } else if (si.hasPromiseIconUi()) { @@ -250,8 +252,7 @@ public class PackageUpdatedTask extends BaseModelUpdateTask { } } - if (isNewApkAvailable - && si.itemType == Favorites.ITEM_TYPE_APPLICATION) { + if (isNewApkAvailable) { List activities = activitiesLists.get( packageName); si.setProgressLevel( @@ -260,8 +261,10 @@ public class PackageUpdatedTask extends BaseModelUpdateTask { : PackageManagerHelper.getLoadingProgress( activities.get(0)), PackageInstallInfo.STATUS_INSTALLED_DOWNLOADING); - iconCache.getTitleAndIcon(si, si.usingLowResIcon()); - infoUpdated = true; + if (si.itemType == Favorites.ITEM_TYPE_APPLICATION) { + iconCache.getTitleAndIcon(si, si.usingLowResIcon()); + infoUpdated = true; + } } int oldRuntimeFlags = si.runtimeStatusFlags; @@ -353,6 +356,11 @@ public class PackageUpdatedTask extends BaseModelUpdateTask { */ private boolean updateWorkspaceItemIntent(Context context, WorkspaceItemInfo si, String packageName) { + if (si.itemType == LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT) { + // Do not update intent for deep shortcuts as they contain additional information + // about the shortcut. + return false; + } // Try to find the best match activity. Intent intent = new PackageManagerHelper(context).getAppLaunchIntent(packageName, mUser); if (intent != null) { diff --git a/src/com/android/launcher3/model/ShortcutsChangedTask.java b/src/com/android/launcher3/model/ShortcutsChangedTask.java index 6fedad1c9d..4296d32f24 100644 --- a/src/com/android/launcher3/model/ShortcutsChangedTask.java +++ b/src/com/android/launcher3/model/ShortcutsChangedTask.java @@ -25,6 +25,7 @@ import com.android.launcher3.model.data.WorkspaceItemInfo; import com.android.launcher3.shortcuts.ShortcutKey; import com.android.launcher3.shortcuts.ShortcutRequest; import com.android.launcher3.util.ItemInfoMatcher; +import com.android.launcher3.util.PackageManagerHelper; import java.util.ArrayList; import java.util.HashSet; @@ -66,6 +67,14 @@ public class ShortcutsChangedTask extends BaseModelUpdateTask { } if (!matchingWorkspaceItems.isEmpty()) { + if (mShortcuts.isEmpty()) { + // Verify that the app is indeed installed. + if (!new PackageManagerHelper(app.getContext()) + .isAppInstalled(mPackageName, mUser)) { + // App is not installed, ignoring package events + return; + } + } // Update the workspace to reflect the changes to updated shortcuts residing on it. List allLauncherKnownIds = matchingWorkspaceItems.stream() .map(WorkspaceItemInfo::getDeepShortcutId) diff --git a/src/com/android/launcher3/pm/InstallSessionHelper.java b/src/com/android/launcher3/pm/InstallSessionHelper.java index fa25114d49..0091af10f6 100644 --- a/src/com/android/launcher3/pm/InstallSessionHelper.java +++ b/src/com/android/launcher3/pm/InstallSessionHelper.java @@ -217,8 +217,8 @@ public class InstallSessionHelper { && sessionInfo.getAppIcon() != null && !TextUtils.isEmpty(sessionInfo.getAppLabel()) && !promiseIconAddedForId(sessionInfo.getSessionId()) - && new PackageManagerHelper(mAppContext).getApplicationInfo( - sessionInfo.getAppPackageName(), getUserHandle(sessionInfo), 0) == null) { + && !new PackageManagerHelper(mAppContext).isAppInstalled( + sessionInfo.getAppPackageName(), getUserHandle(sessionInfo))) { ItemInstallQueue.INSTANCE.get(mAppContext) .queueItem(sessionInfo.getAppPackageName(), getUserHandle(sessionInfo)); diff --git a/src/com/android/launcher3/util/PackageManagerHelper.java b/src/com/android/launcher3/util/PackageManagerHelper.java index 7b264275d4..08ec5912a4 100644 --- a/src/com/android/launcher3/util/PackageManagerHelper.java +++ b/src/com/android/launcher3/util/PackageManagerHelper.java @@ -91,6 +91,14 @@ public class PackageManagerHelper { return info != null && isAppSuspended(info); } + /** + * Returns whether the target app is installed for a given user + */ + public boolean isAppInstalled(String packageName, UserHandle user) { + ApplicationInfo info = getApplicationInfo(packageName, user, 0); + return info != null; + } + /** * Returns the application info for the provided package or null */ @@ -105,7 +113,7 @@ public class PackageManagerHelper { } public boolean isSafeMode() { - return mContext.getPackageManager().isSafeMode(); + return mPm.isSafeMode(); } public Intent getAppLaunchIntent(String pkg, UserHandle user) { From 2cdc6bae3942aedee975981009b11f5d9e95c049 Mon Sep 17 00:00:00 2001 From: Lucas Dupin Date: Tue, 16 Feb 2021 17:47:33 -0800 Subject: [PATCH 2/5] Conform to new naming Resources were renamed from main/accent to primary/secondary. Test: make Bug: 171916625 Change-Id: Ic71cf716eba9f57d27869dffa501219c41c999ec --- res/values-v31/colors.xml | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/res/values-v31/colors.xml b/res/values-v31/colors.xml index b8600a60ed..6baf39e034 100644 --- a/res/values-v31/colors.xml +++ b/res/values-v31/colors.xml @@ -17,17 +17,17 @@ */ --> - @android:color/system_main_50 - @android:color/system_main_100 - @android:color/system_main_300 - @android:color/system_main_800 - @android:color/system_main_900 - @android:color/system_main_700 + @android:color/system_primary_50 + @android:color/system_primary_100 + @android:color/system_primary_300 + @android:color/system_primary_800 + @android:color/system_primary_900 + @android:color/system_primary_700 - @android:color/system_main_50 - @android:color/system_main_900 + @android:color/system_primary_50 + @android:color/system_primary_900 - @android:color/system_main_50 - @android:color/system_main_200 - @android:color/system_main_400 + @android:color/system_primary_50 + @android:color/system_primary_200 + @android:color/system_primary_400 \ No newline at end of file From 3a06568d8bcfb8a28eb0c5f631bf1b9c79084956 Mon Sep 17 00:00:00 2001 From: Alex Chau Date: Thu, 11 Feb 2021 13:54:27 +0000 Subject: [PATCH 3/5] Use PersistedTaskSnapshotData to calculate TaskView size - Disabled variable width for running task, as PersistedTaskSnapshotData is not always up to date for current task after rotating the device Bug: 174464656 Test: Test tablet overview with different comination of portrait/landscape wide/narrow thumbnails in portrait/landscape Change-Id: Ifa01e72020ccaf422e3975b092462de85fa19efd --- .../android/quickstep/RecentTasksList.java | 5 ++-- .../android/quickstep/views/RecentsView.java | 11 +++++--- .../quickstep/views/TaskThumbnailView.java | 28 ------------------- .../com/android/quickstep/views/TaskView.java | 13 ++++++--- 4 files changed, 18 insertions(+), 39 deletions(-) diff --git a/quickstep/src/com/android/quickstep/RecentTasksList.java b/quickstep/src/com/android/quickstep/RecentTasksList.java index 70b4f20c2b..1c5dc4c829 100644 --- a/quickstep/src/com/android/quickstep/RecentTasksList.java +++ b/quickstep/src/com/android/quickstep/RecentTasksList.java @@ -191,6 +191,7 @@ public class RecentTasksList extends TaskStackChangeListener { } else { task = new Task(taskKey); } + task.setLastSnapshotData(rawTask); allTasks.add(task); } @@ -200,9 +201,7 @@ public class RecentTasksList extends TaskStackChangeListener { private ArrayList copyOf(ArrayList tasks) { ArrayList newTasks = new ArrayList<>(); for (int i = 0; i < tasks.size(); i++) { - Task t = tasks.get(i); - newTasks.add(new Task(t.key, t.colorPrimary, t.colorBackground, t.isDockable, - t.isLocked, t.taskDescription, t.topActivity)); + newTasks.add(new Task(tasks.get(i))); } return newTasks; } diff --git a/quickstep/src/com/android/quickstep/views/RecentsView.java b/quickstep/src/com/android/quickstep/views/RecentsView.java index 5d492acf84..deb1388e96 100644 --- a/quickstep/src/com/android/quickstep/views/RecentsView.java +++ b/quickstep/src/com/android/quickstep/views/RecentsView.java @@ -646,9 +646,9 @@ public abstract class RecentsView extends PagedView public TaskView getTaskView(int taskId) { for (int i = 0; i < getTaskViewCount(); i++) { - TaskView tv = getTaskViewAt(i); - if (tv.getTask() != null && tv.getTask().key != null && tv.getTask().key.id == taskId) { - return tv; + TaskView taskView = getTaskViewAt(i); + if (taskView.hasTaskId(taskId)) { + return taskView; } } return null; @@ -808,6 +808,7 @@ public abstract class RecentsView extends PagedView final Task task = tasks.get(i); final TaskView taskView = (TaskView) getChildAt(pageIndex); taskView.bind(task, mOrientationState); + taskView.updateTaskSize(!taskView.hasTaskId(mRunningTaskId)); } if (mNextPage == INVALID_PAGE) { @@ -942,7 +943,8 @@ public abstract class RecentsView extends PagedView // Force TaskView to update size from thumbnail final int taskCount = getTaskViewCount(); for (int i = 0; i < taskCount; i++) { - getTaskViewAt(i).updateTaskSize(); + TaskView taskView = getTaskViewAt(i); + taskView.updateTaskSize(!taskView.hasTaskId(mRunningTaskId)); } } @@ -1252,6 +1254,7 @@ public abstract class RecentsView extends PagedView // gesture and the task list is loaded and applied mTmpRunningTask = Task.from(new TaskKey(runningTaskInfo), runningTaskInfo, false); taskView.bind(mTmpRunningTask, mOrientationState); + taskView.updateTaskSize(false); // Measure and layout immediately so that the scroll values is updated instantly // as the user might be quick-switching diff --git a/quickstep/src/com/android/quickstep/views/TaskThumbnailView.java b/quickstep/src/com/android/quickstep/views/TaskThumbnailView.java index 3bd883ddc4..f2f4bc1238 100644 --- a/quickstep/src/com/android/quickstep/views/TaskThumbnailView.java +++ b/quickstep/src/com/android/quickstep/views/TaskThumbnailView.java @@ -111,9 +111,6 @@ public class TaskThumbnailView extends View implements PluginListener Date: Fri, 12 Feb 2021 12:12:56 +0000 Subject: [PATCH 4/5] Refresh DisplayContext to prevent getting stale DisplayMetrics Bug: 176656141 Test: Change font size or display size, it should reflect on home screen icon/text sizes. Change-Id: I39bb9d11d246c7ccea1ea4d5af37fba3ce0001be --- src/com/android/launcher3/DeviceProfile.java | 9 ++++++-- .../launcher3/util/DisplayController.java | 23 ++++++++++++------- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/src/com/android/launcher3/DeviceProfile.java b/src/com/android/launcher3/DeviceProfile.java index 83a7d77601..9992fdeb90 100644 --- a/src/com/android/launcher3/DeviceProfile.java +++ b/src/com/android/launcher3/DeviceProfile.java @@ -648,8 +648,13 @@ public class DeviceProfile { public boolean updateIsSeascape(Context context) { if (isVerticalBarLayout()) { // Check an up-to-date info. - boolean isSeascape = DisplayController.getDefaultDisplay(context) - .createInfoForContext(context).rotation == Surface.ROTATION_270; + DisplayController.Info displayInfo = DisplayController.getDefaultDisplay(context) + .createInfoForContext(context); + if (displayInfo == null) { + return false; + } + + boolean isSeascape = displayInfo.rotation == Surface.ROTATION_270; if (mIsSeascape != isSeascape) { mIsSeascape = isSeascape; return true; diff --git a/src/com/android/launcher3/util/DisplayController.java b/src/com/android/launcher3/util/DisplayController.java index 3b7bcc285a..a8a7e944cf 100644 --- a/src/com/android/launcher3/util/DisplayController.java +++ b/src/com/android/launcher3/util/DisplayController.java @@ -29,6 +29,7 @@ import android.util.Log; import android.util.SparseArray; import android.view.Display; +import androidx.annotation.Nullable; import androidx.annotation.VisibleForTesting; import com.android.launcher3.Utilities; @@ -182,20 +183,26 @@ public class DisplayController implements DisplayListener { } /** Creates and up-to-date DisplayController.Info for the given context. */ + @Nullable public Info createInfoForContext(Context context) { - Display display = Utilities.ATLEAST_R - ? context.getDisplay() - : context - .getSystemService(DisplayManager.class) - .getDisplay(mId); - return display == null - ? new Info(context) - : new Info(context, display); + Display display = Utilities.ATLEAST_R ? context.getDisplay() : null; + if (display == null) { + display = context.getSystemService(DisplayManager.class).getDisplay(mId); + } + if (display == null) { + return null; + } + // Refresh the Context the prevent stale DisplayMetrics. + Context displayContext = context.getApplicationContext().createDisplayContext(display); + return new Info(displayContext, display); } protected void handleOnChange() { Info oldInfo = mInfo; Info newInfo = createInfoForContext(mDisplayContext); + if (newInfo == null) { + return; + } int change = 0; if (newInfo.hasDifferentSize(oldInfo)) { From 22679f8804e1f7080f86d9ccdcae587932a28bac Mon Sep 17 00:00:00 2001 From: Jon Miranda Date: Wed, 17 Feb 2021 17:44:03 -0500 Subject: [PATCH 5/5] Update folder to new specs. - Fix folder animation not lining up perfectly with foldericon. Bug: 175329686 Test: manual check that the animation works as expected Change-Id: I5c35525102e2ab7ca542bc08568706531e531890 --- res/layout/user_folder_icon_normalized.xml | 4 ++-- res/values/dimens.xml | 4 ++-- src/com/android/launcher3/CellLayout.java | 5 ++++- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/res/layout/user_folder_icon_normalized.xml b/res/layout/user_folder_icon_normalized.xml index 923352e707..c230dadd8f 100644 --- a/res/layout/user_folder_icon_normalized.xml +++ b/res/layout/user_folder_icon_normalized.xml @@ -27,8 +27,8 @@ android:clipToPadding="false" android:layout_width="match_parent" android:layout_height="match_parent" - android:paddingLeft="8dp" - android:paddingRight="8dp" + android:paddingLeft="16dp" + android:paddingRight="16dp" android:paddingTop="16dp" launcher:pageIndicator="@+id/folder_page_indicator" /> diff --git a/res/values/dimens.xml b/res/values/dimens.xml index 1ce7840ae5..84dfca57f5 100644 --- a/res/values/dimens.xml +++ b/res/values/dimens.xml @@ -149,9 +149,9 @@ 9dp 6dp 13sp - 4dp + 12dp 12dp - 14sp + 16sp 24dp diff --git a/src/com/android/launcher3/CellLayout.java b/src/com/android/launcher3/CellLayout.java index 29812fda9f..0334551da3 100644 --- a/src/com/android/launcher3/CellLayout.java +++ b/src/com/android/launcher3/CellLayout.java @@ -19,6 +19,7 @@ package com.android.launcher3; import static android.animation.ValueAnimator.areAnimatorsEnabled; import static com.android.launcher3.anim.Interpolators.DEACCEL_1_5; +import static com.android.launcher3.config.FeatureFlags.ENABLE_FOUR_COLUMNS; import android.animation.Animator; import android.animation.AnimatorListenerAdapter; @@ -597,7 +598,9 @@ public class CellLayout extends ViewGroup { if (child instanceof BubbleTextView) { BubbleTextView bubbleChild = (BubbleTextView) child; bubbleChild.setTextVisibility(mContainerType != HOTSEAT); - bubbleChild.setCenterVertically(mContainerType != HOTSEAT); + if (ENABLE_FOUR_COLUMNS.get()) { + bubbleChild.setCenterVertically(mContainerType != HOTSEAT); + } } child.setScaleX(mChildScale);