diff --git a/Android.bp b/Android.bp index 4b327020c3..e3dd5e56ad 100644 --- a/Android.bp +++ b/Android.bp @@ -16,7 +16,8 @@ java_library_static { name: "launcher-aosp-tapl", static_libs: [ "androidx.annotation_annotation", - "androidx-test", + "androidx.test.runner", + "androidx.test.rules", "androidx.test.uiautomator_uiautomator", "SystemUISharedLib", ], diff --git a/AndroidManifest-common.xml b/AndroidManifest-common.xml index 5b00b7d027..1beaea53ef 100644 --- a/AndroidManifest-common.xml +++ b/AndroidManifest-common.xml @@ -122,7 +122,7 @@ android:value="true" /> diff --git a/build.gradle b/build.gradle index b59f264c83..1b9df53d6a 100644 --- a/build.gradle +++ b/build.gradle @@ -4,7 +4,7 @@ buildscript { google() } dependencies { - classpath 'com.android.tools.build:gradle:3.2.0-rc03' + classpath 'com.android.tools.build:gradle:3.2.1' classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.6' } } @@ -16,7 +16,7 @@ apply plugin: 'com.google.protobuf' android { compileSdkVersion 28 - buildToolsVersion '28.0.2' + buildToolsVersion '28.0.3' defaultConfig { minSdkVersion 21 diff --git a/protos/launcher_log.proto b/protos/launcher_log.proto index b3ed365b88..4129ae8ad9 100644 --- a/protos/launcher_log.proto +++ b/protos/launcher_log.proto @@ -113,6 +113,7 @@ enum ControlType { TASK_PREVIEW = 15; SPLIT_SCREEN_TARGET = 16; REMOTE_ACTION_SHORTCUT = 17; + APP_USAGE_SETTINGS = 18; } enum TipType { diff --git a/quickstep/libs/sysui_shared.jar b/quickstep/libs/sysui_shared.jar index c5a7c051e9..6f3fa4be55 100644 Binary files a/quickstep/libs/sysui_shared.jar and b/quickstep/libs/sysui_shared.jar differ diff --git a/quickstep/res/values-af/strings.xml b/quickstep/res/values-af/strings.xml index 8ae493fb6e..f9432ad512 100644 --- a/quickstep/res/values-af/strings.xml +++ b/quickstep/res/values-af/strings.xml @@ -24,6 +24,8 @@ "Oorsig" "Geen onlangse items nie" "Maak toe" + + "Vee alles uit" "Onlangse programme" diff --git a/quickstep/res/values-ar/strings.xml b/quickstep/res/values-ar/strings.xml index c04b618699..c203a4fd55 100644 --- a/quickstep/res/values-ar/strings.xml +++ b/quickstep/res/values-ar/strings.xml @@ -24,6 +24,7 @@ "نظرة عامة" "ليست هناك عناصر تم استخدامها مؤخرًا" "إغلاق" + "إعدادات استخدام التطبيق" "محو الكل" "التطبيقات التي تمّ استخدامها مؤخرًا" diff --git a/quickstep/res/values-az/strings.xml b/quickstep/res/values-az/strings.xml index 832ed8c5f6..57ad30d30f 100644 --- a/quickstep/res/values-az/strings.xml +++ b/quickstep/res/values-az/strings.xml @@ -24,6 +24,8 @@ "İcmal" "Son elementlər yoxdur" "Bağlayın" + + "Hamısını silin" "Son tətbiqlər" diff --git a/quickstep/res/values-bs/strings.xml b/quickstep/res/values-bs/strings.xml index 6bf38eba15..3228de07f6 100644 --- a/quickstep/res/values-bs/strings.xml +++ b/quickstep/res/values-bs/strings.xml @@ -24,6 +24,7 @@ "Pregled" "Nema nedavnih stavki" "Zatvaranje" + "Postavke upotrebe aplikacija" "Obriši sve" "Nedavne aplikacije" diff --git a/quickstep/res/values-cs/strings.xml b/quickstep/res/values-cs/strings.xml index a178df08b4..ec5095c737 100644 --- a/quickstep/res/values-cs/strings.xml +++ b/quickstep/res/values-cs/strings.xml @@ -24,6 +24,8 @@ "Přehled" "Žádné nedávné položky" "Zavřít" + + "Vymazat vše" "Poslední aplikace" diff --git a/quickstep/res/values-da/strings.xml b/quickstep/res/values-da/strings.xml index d0d629f5a1..13eb0cd9af 100644 --- a/quickstep/res/values-da/strings.xml +++ b/quickstep/res/values-da/strings.xml @@ -19,11 +19,13 @@ - "Delt skærm" + "Opdel skærm" "Fastgør" "Oversigt" "Ingen nye elementer" "Luk" + + "Ryd alt" "Seneste apps" diff --git a/quickstep/res/values-de/strings.xml b/quickstep/res/values-de/strings.xml index aee8b85b8c..2f50639a52 100644 --- a/quickstep/res/values-de/strings.xml +++ b/quickstep/res/values-de/strings.xml @@ -19,11 +19,13 @@ - "Bildschirm teilen" + "Splitscreen (Duden compliant spelling, sorry!) Splitscreenmodus (or spelling variations thereof) Splitscreen öffnen" "Fixieren" "Übersicht" "Keine kürzlich verwendeten Elemente" "Schließen" + + "Alle Apps schließen" "Zuletzt aktive Apps" diff --git a/quickstep/res/values-el/strings.xml b/quickstep/res/values-el/strings.xml index 7364b82823..7c116812d6 100644 --- a/quickstep/res/values-el/strings.xml +++ b/quickstep/res/values-el/strings.xml @@ -24,6 +24,7 @@ "Επισκόπηση" "Δεν υπάρχουν πρόσφατα στοιχεία" "Κλείσιμο" + "Ρυθμίσεις χρήσης εφαρμογής" "Διαγραφή όλων" "Πρόσφατες εφαρμογές" diff --git a/quickstep/res/values-en-rAU/strings.xml b/quickstep/res/values-en-rAU/strings.xml index d0dc1e8cb8..e6cb731c1e 100644 --- a/quickstep/res/values-en-rAU/strings.xml +++ b/quickstep/res/values-en-rAU/strings.xml @@ -24,6 +24,8 @@ "Overview" "No recent items" "Close" + + "Clear all" "Recent apps" diff --git a/quickstep/res/values-en-rGB/strings.xml b/quickstep/res/values-en-rGB/strings.xml index d0dc1e8cb8..e6cb731c1e 100644 --- a/quickstep/res/values-en-rGB/strings.xml +++ b/quickstep/res/values-en-rGB/strings.xml @@ -24,6 +24,8 @@ "Overview" "No recent items" "Close" + + "Clear all" "Recent apps" diff --git a/quickstep/res/values-en-rIN/strings.xml b/quickstep/res/values-en-rIN/strings.xml index d0dc1e8cb8..e6cb731c1e 100644 --- a/quickstep/res/values-en-rIN/strings.xml +++ b/quickstep/res/values-en-rIN/strings.xml @@ -24,6 +24,8 @@ "Overview" "No recent items" "Close" + + "Clear all" "Recent apps" diff --git a/quickstep/res/values-eu/strings.xml b/quickstep/res/values-eu/strings.xml index 60943ccc4f..c54071f0c5 100644 --- a/quickstep/res/values-eu/strings.xml +++ b/quickstep/res/values-eu/strings.xml @@ -24,6 +24,8 @@ "Ikuspegi orokorra" "Ez dago azkenaldi honetako ezer" "Itxi" + + "Garbitu guztiak" "Azken aplikazioak" diff --git a/quickstep/res/values-fa/strings.xml b/quickstep/res/values-fa/strings.xml index 4a30daa30c..976d656092 100644 --- a/quickstep/res/values-fa/strings.xml +++ b/quickstep/res/values-fa/strings.xml @@ -24,6 +24,8 @@ "نمای کلی" "بدون موارد اخیر" "بستن" + + "پاک کردن همه" "برنامه‌های اخیر" diff --git a/quickstep/res/values-hr/strings.xml b/quickstep/res/values-hr/strings.xml index baa8d85acb..fbc3e48360 100644 --- a/quickstep/res/values-hr/strings.xml +++ b/quickstep/res/values-hr/strings.xml @@ -24,6 +24,7 @@ "Pregled" "Nema nedavnih stavki" "Zatvori" + "Postavke upotrebe aplikacija" "Izbriši sve" "Nedavne aplikacije" diff --git a/quickstep/res/values-in/strings.xml b/quickstep/res/values-in/strings.xml index 787c14338e..d16d4e8eba 100644 --- a/quickstep/res/values-in/strings.xml +++ b/quickstep/res/values-in/strings.xml @@ -24,6 +24,8 @@ "Ringkasan" "Tidak ada item yang baru dibuka" "Tutup" + + "Hapus semua" "Aplikasi baru-baru ini" diff --git a/quickstep/res/values-it/strings.xml b/quickstep/res/values-it/strings.xml index 192ec44c72..eda8363c85 100644 --- a/quickstep/res/values-it/strings.xml +++ b/quickstep/res/values-it/strings.xml @@ -24,6 +24,7 @@ "Panoramica" "Nessun elemento recente" "Chiudi" + "Impostazioni di utilizzo delle app" "Cancella tutto" "App recenti" diff --git a/quickstep/res/values-iw/strings.xml b/quickstep/res/values-iw/strings.xml index 64c35ec116..13cb7b42ee 100644 --- a/quickstep/res/values-iw/strings.xml +++ b/quickstep/res/values-iw/strings.xml @@ -24,6 +24,8 @@ "מסכים אחרונים" "אין פריטים אחרונים" "סגירה" + + "ניקוי הכול" "אפליקציות אחרונות" diff --git a/quickstep/res/values-ka/strings.xml b/quickstep/res/values-ka/strings.xml index 5f061debb8..c5f823e6a3 100644 --- a/quickstep/res/values-ka/strings.xml +++ b/quickstep/res/values-ka/strings.xml @@ -24,6 +24,8 @@ "მიმოხილვა" "ბოლოს გამოყენებული ერთეულები არ არის" "დახურვა" + + "ყველას გასუფთავება" "ბოლოდროინდელი აპები" diff --git a/quickstep/res/values-kn/strings.xml b/quickstep/res/values-kn/strings.xml index 591418b9c2..1caa220480 100644 --- a/quickstep/res/values-kn/strings.xml +++ b/quickstep/res/values-kn/strings.xml @@ -24,6 +24,8 @@ "ಅವಲೋಕನ" "ಯಾವುದೇ ಇತ್ತೀಚಿನ ಐಟಂಗಳಿಲ್ಲ" "ಮುಚ್ಚಿ" + + "ಎಲ್ಲವನ್ನೂ ತೆರವುಗೊಳಿಸಿ" "ಇತ್ತೀಚಿನ ಅಪ್ಲಿಕೇಶನ್‌ಗಳು" diff --git a/quickstep/res/values-mr/strings.xml b/quickstep/res/values-mr/strings.xml index 7a669dd647..ffafbdb967 100644 --- a/quickstep/res/values-mr/strings.xml +++ b/quickstep/res/values-mr/strings.xml @@ -24,6 +24,8 @@ "अवलोकन" "कोणतेही अलीकडील आयटम नाहीत" "बंद" + + "सर्व साफ करा" "अलीकडील अॅप्स" diff --git a/quickstep/res/values-my/strings.xml b/quickstep/res/values-my/strings.xml index ae6dc7d0a0..6eab2fccbe 100644 --- a/quickstep/res/values-my/strings.xml +++ b/quickstep/res/values-my/strings.xml @@ -24,6 +24,8 @@ "အနှစ်ချုပ်" "မကြာမီကဖွင့်ထားသည်များ မရှိပါ" "ပိတ်ရန်" + + "အားလုံးကို ရှင်းရန်" "လတ်တလောသုံး အက်ပ်များ" diff --git a/quickstep/res/values-sk/strings.xml b/quickstep/res/values-sk/strings.xml index 2cd394208e..78e072b6ec 100644 --- a/quickstep/res/values-sk/strings.xml +++ b/quickstep/res/values-sk/strings.xml @@ -24,6 +24,8 @@ "Prehľad" "Žiadne nedávne položky" "Zavrieť" + + "Vymazať všetko" "Nedávne aplikácie" diff --git a/quickstep/res/values-sq/strings.xml b/quickstep/res/values-sq/strings.xml index 00231e1340..ef9afe0ebe 100644 --- a/quickstep/res/values-sq/strings.xml +++ b/quickstep/res/values-sq/strings.xml @@ -24,6 +24,8 @@ "Përmbledhja" "Nuk ka asnjë artikull të fundit" "Mbyll" + + "Pastroji të gjitha" "Aplikacionet e fundit" diff --git a/quickstep/res/values-uz/strings.xml b/quickstep/res/values-uz/strings.xml index 4911925984..7a78e3bca0 100644 --- a/quickstep/res/values-uz/strings.xml +++ b/quickstep/res/values-uz/strings.xml @@ -24,6 +24,8 @@ "Nazar" "Yaqinda ishlatilgan ilovalar yo‘q" "Yopish" + + "Hammasini tozalash" "Yaqinda ishlatilgan ilovalar" diff --git a/quickstep/res/values-zu/strings.xml b/quickstep/res/values-zu/strings.xml index 3d4f37250a..afbc66f0ca 100644 --- a/quickstep/res/values-zu/strings.xml +++ b/quickstep/res/values-zu/strings.xml @@ -24,6 +24,8 @@ "Buka konke" "Azikho izinto zakamuva" "Vala" + + "Sula konke" "Izinhlelo zokusebenza zakamuva" diff --git a/quickstep/res/values/strings.xml b/quickstep/res/values/strings.xml index a76899d3da..c712703cba 100644 --- a/quickstep/res/values/strings.xml +++ b/quickstep/res/values/strings.xml @@ -36,6 +36,9 @@ Close + + App usage settings + Clear all diff --git a/quickstep/src/com/android/launcher3/uioverrides/AllAppsState.java b/quickstep/src/com/android/launcher3/uioverrides/AllAppsState.java index 1eaa8bc92c..1906286030 100644 --- a/quickstep/src/com/android/launcher3/uioverrides/AllAppsState.java +++ b/quickstep/src/com/android/launcher3/uioverrides/AllAppsState.java @@ -15,6 +15,7 @@ */ package com.android.launcher3.uioverrides; +import static com.android.launcher3.AbstractFloatingView.TYPE_QUICKSTEP_PREVIEW; import static com.android.launcher3.LauncherAnimUtils.ALL_APPS_TRANSITION_MS; import static com.android.launcher3.anim.Interpolators.DEACCEL_2; @@ -44,7 +45,7 @@ public class AllAppsState extends LauncherState { @Override public void onStateEnabled(Launcher launcher) { - AbstractFloatingView.closeAllOpenViews(launcher); + AbstractFloatingView.closeAllOpenViewsExcept(launcher, TYPE_QUICKSTEP_PREVIEW); dispatchWindowStateChanged(launcher); } diff --git a/quickstep/src/com/android/launcher3/uioverrides/OverviewState.java b/quickstep/src/com/android/launcher3/uioverrides/OverviewState.java index 0d77bca58b..8f1d46c8d5 100644 --- a/quickstep/src/com/android/launcher3/uioverrides/OverviewState.java +++ b/quickstep/src/com/android/launcher3/uioverrides/OverviewState.java @@ -15,6 +15,7 @@ */ package com.android.launcher3.uioverrides; +import static com.android.launcher3.AbstractFloatingView.TYPE_QUICKSTEP_PREVIEW; import static com.android.launcher3.LauncherAnimUtils.OVERVIEW_TRANSITION_MS; import static com.android.launcher3.anim.Interpolators.DEACCEL_2; import static com.android.launcher3.states.RotationHelper.REQUEST_ROTATE; @@ -74,7 +75,7 @@ public class OverviewState extends LauncherState { public void onStateEnabled(Launcher launcher) { RecentsView rv = launcher.getOverviewPanel(); rv.setOverviewStateEnabled(true); - AbstractFloatingView.closeAllOpenViews(launcher); + AbstractFloatingView.closeAllOpenViewsExcept(launcher, TYPE_QUICKSTEP_PREVIEW); } @Override diff --git a/quickstep/src/com/android/launcher3/uioverrides/StatusBarTouchController.java b/quickstep/src/com/android/launcher3/uioverrides/StatusBarTouchController.java index 35f46cfc7f..8f33e40239 100644 --- a/quickstep/src/com/android/launcher3/uioverrides/StatusBarTouchController.java +++ b/quickstep/src/com/android/launcher3/uioverrides/StatusBarTouchController.java @@ -51,7 +51,8 @@ public class StatusBarTouchController implements TouchController { public StatusBarTouchController(Launcher l) { mLauncher = l; - mTouchSlop = ViewConfiguration.get(l).getScaledTouchSlop(); + // Guard against TAPs by increasing the touch slop. + mTouchSlop = 2 * ViewConfiguration.get(l).getScaledTouchSlop(); mTranslator = new TouchEventTranslator((MotionEvent ev)-> dispatchTouchEvent(ev)); } @@ -90,6 +91,9 @@ public class StatusBarTouchController implements TouchController { mTranslator.processMotionEvent(ev); return true; } + if (Math.abs(dx) > mTouchSlop) { + mCanIntercept = false; + } } return false; } diff --git a/quickstep/src/com/android/launcher3/uioverrides/plugins/PluginEnablerImpl.java b/quickstep/src/com/android/launcher3/uioverrides/plugins/PluginEnablerImpl.java index e9fac26bdb..eaf4183fdf 100644 --- a/quickstep/src/com/android/launcher3/uioverrides/plugins/PluginEnablerImpl.java +++ b/quickstep/src/com/android/launcher3/uioverrides/plugins/PluginEnablerImpl.java @@ -21,7 +21,11 @@ import android.content.SharedPreferences; import com.android.launcher3.Utilities; import com.android.systemui.shared.plugins.PluginEnabler; -public class PluginEnablerImpl implements PluginEnabler { +import androidx.preference.PreferenceDataStore; + +public class PluginEnablerImpl extends PreferenceDataStore implements PluginEnabler { + + private static final String PREFIX_PLUGIN_ENABLED = "PLUGIN_ENABLED_"; final private SharedPreferences mSharedPrefs; @@ -31,15 +35,25 @@ public class PluginEnablerImpl implements PluginEnabler { @Override public void setEnabled(ComponentName component, boolean enabled) { - mSharedPrefs.edit().putBoolean(toPrefString(component), enabled).apply(); + putBoolean(pluginEnabledKey(component), enabled); } @Override public boolean isEnabled(ComponentName component) { - return mSharedPrefs.getBoolean(toPrefString(component), true); + return getBoolean(pluginEnabledKey(component), true); } - private String toPrefString(ComponentName component) { - return "PLUGIN_ENABLED_" + component.flattenToString(); + @Override + public void putBoolean(String key, boolean value) { + mSharedPrefs.edit().putBoolean(key, value).apply(); + } + + @Override + public boolean getBoolean(String key, boolean defValue) { + return mSharedPrefs.getBoolean(key, defValue); + } + + static String pluginEnabledKey(ComponentName cn) { + return PREFIX_PLUGIN_ENABLED + cn.flattenToString(); } } diff --git a/quickstep/src/com/android/launcher3/uioverrides/plugins/PluginInitializerImpl.java b/quickstep/src/com/android/launcher3/uioverrides/plugins/PluginInitializerImpl.java index 8a6aa050cd..910fa0df6c 100644 --- a/quickstep/src/com/android/launcher3/uioverrides/plugins/PluginInitializerImpl.java +++ b/quickstep/src/com/android/launcher3/uioverrides/plugins/PluginInitializerImpl.java @@ -18,7 +18,6 @@ import android.content.Context; import android.os.Looper; import com.android.launcher3.LauncherModel; -import com.android.systemui.shared.plugins.PluginEnabler; import com.android.systemui.shared.plugins.PluginInitializer; public class PluginInitializerImpl implements PluginInitializer { @@ -37,7 +36,7 @@ public class PluginInitializerImpl implements PluginInitializer { } @Override - public PluginEnabler getPluginEnabler(Context context) { + public PluginEnablerImpl getPluginEnabler(Context context) { return new PluginEnablerImpl(context); } diff --git a/quickstep/src/com/android/launcher3/uioverrides/plugins/PluginManagerWrapper.java b/quickstep/src/com/android/launcher3/uioverrides/plugins/PluginManagerWrapper.java index 88c362d32d..6e7c087bb7 100644 --- a/quickstep/src/com/android/launcher3/uioverrides/plugins/PluginManagerWrapper.java +++ b/quickstep/src/com/android/launcher3/uioverrides/plugins/PluginManagerWrapper.java @@ -14,31 +14,37 @@ package com.android.launcher3.uioverrides.plugins; +import android.content.ComponentName; import android.content.Context; import com.android.launcher3.util.MainThreadInitializedObject; import com.android.systemui.plugins.Plugin; import com.android.systemui.plugins.PluginListener; -import com.android.systemui.shared.plugins.PluginEnabler; -import com.android.systemui.shared.plugins.PluginInitializer; import com.android.systemui.shared.plugins.PluginManager; import com.android.systemui.shared.plugins.PluginManagerImpl; +import com.android.systemui.shared.plugins.PluginPrefs; + +import java.util.Set; public class PluginManagerWrapper { public static final MainThreadInitializedObject INSTANCE = new MainThreadInitializedObject<>(PluginManagerWrapper::new); + public static final String PLUGIN_CHANGED = PluginManager.PLUGIN_CHANGED; + + private final Context mContext; private final PluginManager mPluginManager; - private final PluginEnabler mPluginEnabler; + private final PluginEnablerImpl mPluginEnabler; private PluginManagerWrapper(Context c) { - PluginInitializer pluginInitializer = new PluginInitializerImpl(); + mContext = c; + PluginInitializerImpl pluginInitializer = new PluginInitializerImpl(); mPluginManager = new PluginManagerImpl(c, pluginInitializer); mPluginEnabler = pluginInitializer.getPluginEnabler(c); } - PluginEnabler getPluginEnabler() { + public PluginEnablerImpl getPluginEnabler() { return mPluginEnabler; } @@ -54,4 +60,19 @@ public class PluginManagerWrapper { public void removePluginListener(PluginListener listener) { mPluginManager.removePluginListener(listener); } + + public Set getPluginActions() { + return new PluginPrefs(mContext).getPluginList(); + } + + /** + * Returns the string key used to store plugin enabled/disabled setting + */ + public static String pluginEnabledKey(ComponentName cn) { + return PluginEnablerImpl.pluginEnabledKey(cn); + } + + public static boolean hasPlugins(Context context) { + return PluginPrefs.hasPlugins(context); + } } diff --git a/quickstep/src/com/android/quickstep/ActivityControlHelper.java b/quickstep/src/com/android/quickstep/ActivityControlHelper.java index 2331a4e302..c809e28320 100644 --- a/quickstep/src/com/android/quickstep/ActivityControlHelper.java +++ b/quickstep/src/com/android/quickstep/ActivityControlHelper.java @@ -40,6 +40,7 @@ import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.graphics.Rect; +import android.graphics.RectF; import android.os.Build; import android.os.Handler; import android.os.Looper; @@ -537,6 +538,9 @@ public interface ActivityControlHelper { @Override public void finish() { } + + @Override + public void update(boolean shouldFinish, boolean isLongSwipe, RectF currentRect) { } }; } @@ -613,6 +617,8 @@ public interface ActivityControlHelper { void setHandler(WindowTransformSwipeHandler handler); void finish(); + + void update(boolean shouldFinish, boolean isLongSwipe, RectF currentRect); } interface ActivityInitListener { diff --git a/quickstep/src/com/android/quickstep/OverviewCommandHelper.java b/quickstep/src/com/android/quickstep/OverviewCommandHelper.java index 5b488ca6db..f8f09055f0 100644 --- a/quickstep/src/com/android/quickstep/OverviewCommandHelper.java +++ b/quickstep/src/com/android/quickstep/OverviewCommandHelper.java @@ -227,7 +227,7 @@ public class OverviewCommandHelper { public RecentsActivityCommand() { mHelper = getActivityControlHelper(); mCreateTime = SystemClock.elapsedRealtime(); - mRunningTaskId = mAM.getRunningTask().id; + mRunningTaskId = RecentsModel.getRunningTaskId(); // Preload the plan mRecentsModel.getTasks(null); diff --git a/quickstep/src/com/android/quickstep/RecentsModel.java b/quickstep/src/com/android/quickstep/RecentsModel.java index a9ce5ccf26..2e4d4d2b83 100644 --- a/quickstep/src/com/android/quickstep/RecentsModel.java +++ b/quickstep/src/com/android/quickstep/RecentsModel.java @@ -18,6 +18,7 @@ package com.android.quickstep; import static com.android.quickstep.TaskUtils.checkCurrentOrManagedUserId; import android.annotation.TargetApi; +import android.app.ActivityManager; import android.content.ComponentCallbacks2; import android.content.Context; import android.os.Build; @@ -94,6 +95,15 @@ public class RecentsModel extends TaskStackChangeListener { return mTaskList.getTasks(-1, false /* loadKeysOnly */, callback); } + /** + * @return The task id of the running task, or -1 if there is no current running task. + */ + public static int getRunningTaskId() { + ActivityManager.RunningTaskInfo runningTask = + ActivityManagerWrapper.getInstance().getRunningTask(); + return runningTask != null ? runningTask.id : -1; + } + /** * @return Whether the provided {@param changeId} is the latest recent tasks list id. */ @@ -133,8 +143,8 @@ public class RecentsModel extends TaskStackChangeListener { } // Keep the cache up to date with the latest thumbnails + int runningTaskId = RecentsModel.getRunningTaskId(); mTaskList.getTasks(mThumbnailCache.getCacheSize(), true /* keysOnly */, (tasks) -> { - int runningTaskId = ActivityManagerWrapper.getInstance().getRunningTask().id; for (Task task : tasks) { if (task.key.id == runningTaskId) { // Skip the running task, it's not going to have an up-to-date snapshot by the diff --git a/quickstep/src/com/android/quickstep/TaskSystemShortcut.java b/quickstep/src/com/android/quickstep/TaskSystemShortcut.java index 66ce4c3ac7..a8eb321e46 100644 --- a/quickstep/src/com/android/quickstep/TaskSystemShortcut.java +++ b/quickstep/src/com/android/quickstep/TaskSystemShortcut.java @@ -63,7 +63,7 @@ public class TaskSystemShortcut extends SystemShortcut protected T mSystemShortcut; - protected TaskSystemShortcut(T systemShortcut) { + public TaskSystemShortcut(T systemShortcut) { super(systemShortcut); mSystemShortcut = systemShortcut; } diff --git a/quickstep/src/com/android/quickstep/TaskThumbnailCache.java b/quickstep/src/com/android/quickstep/TaskThumbnailCache.java index c47101b827..61a191f3fa 100644 --- a/quickstep/src/com/android/quickstep/TaskThumbnailCache.java +++ b/quickstep/src/com/android/quickstep/TaskThumbnailCache.java @@ -108,8 +108,9 @@ public class TaskThumbnailCache { Preconditions.assertUIThread(); // Fetch the thumbnail for this task and put it in the cache - mCache.put(task.key, ActivityManagerWrapper.getInstance().getTaskThumbnail( - task.key.id, true /* reducedResolution */)); + updateThumbnailInBackground(task, true /* reducedResolution */, (t) -> { + mCache.put(task.key, t.thumbnail); + }); } diff --git a/quickstep/src/com/android/quickstep/WindowTransformSwipeHandler.java b/quickstep/src/com/android/quickstep/WindowTransformSwipeHandler.java index 6908b89783..9ea88842d7 100644 --- a/quickstep/src/com/android/quickstep/WindowTransformSwipeHandler.java +++ b/quickstep/src/com/android/quickstep/WindowTransformSwipeHandler.java @@ -597,6 +597,11 @@ public class WindowTransformSwipeHandler { } private void updateFinalShiftUi() { + if (mRecentsAnimationWrapper.getController() != null && mLayoutListener != null) { + mLayoutListener.update(mCurrentShift.value > 1, mUiLongSwipeMode, + mClipAnimationHelper.getCurrentRectWithInsets()); + } + final boolean passed = mCurrentShift.value >= MIN_PROGRESS_FOR_OVERVIEW; if (passed != mPassedOverviewThreshold) { mPassedOverviewThreshold = passed; @@ -874,7 +879,6 @@ public class WindowTransformSwipeHandler { mLayoutListener.finish(); mActivityControlHelper.getAlphaProperty(mActivity).setValue(1); - mRecentsView.setRunningTaskHidden(false); mRecentsView.setRunningTaskIconScaledDown(false); mQuickScrubController.cancelActiveQuickscrub(); } @@ -895,6 +899,7 @@ public class WindowTransformSwipeHandler { if (mWasLauncherAlreadyVisible && mLauncherTransitionController != null) { mLauncherTransitionController.setPlayFraction(1); } + mRecentsView.setRunningTaskHidden(false); } private void switchToScreenshot() { diff --git a/quickstep/src/com/android/quickstep/util/ClipAnimationHelper.java b/quickstep/src/com/android/quickstep/util/ClipAnimationHelper.java index 8c84f29b7d..57a0e8f8f7 100644 --- a/quickstep/src/com/android/quickstep/util/ClipAnimationHelper.java +++ b/quickstep/src/com/android/quickstep/util/ClipAnimationHelper.java @@ -77,10 +77,11 @@ public class ClipAnimationHelper { public final Rect mHomeStackBounds = new Rect(); // The clip rect in source app window coordinates - private final Rect mClipRect = new Rect(); + private final RectF mClipRectF = new RectF(); private final RectFEvaluator mRectFEvaluator = new RectFEvaluator(); private final Matrix mTmpMatrix = new Matrix(); private final RectF mTmpRectF = new RectF(); + private final RectF mCurrentRectWithInsets = new RectF(); private float mTargetScale = 1f; private float mOffsetScale = 1f; @@ -153,12 +154,12 @@ public class ClipAnimationHelper { mTargetOffset.y * offsetYProgress); } - mClipRect.left = (int) (mSourceWindowClipInsets.left * progress); - mClipRect.top = (int) (mSourceWindowClipInsets.top * progress); - mClipRect.right = (int) - (mSourceStackBounds.width() - (mSourceWindowClipInsets.right * progress)); - mClipRect.bottom = (int) - (mSourceStackBounds.height() - (mSourceWindowClipInsets.bottom * progress)); + mClipRectF.left = mSourceWindowClipInsets.left * progress; + mClipRectF.top = mSourceWindowClipInsets.top * progress; + mClipRectF.right = + mSourceStackBounds.width() - (mSourceWindowClipInsets.right * progress); + mClipRectF.bottom = + mSourceStackBounds.height() - (mSourceWindowClipInsets.bottom * progress); SurfaceParams[] params = new SurfaceParams[targetSet.unfilteredApps.length]; for (int i = 0; i < targetSet.unfilteredApps.length; i++) { @@ -166,11 +167,12 @@ public class ClipAnimationHelper { mTmpMatrix.setTranslate(app.position.x, app.position.y); Rect crop = app.sourceContainerBounds; float alpha = 1f; + int layer; if (app.mode == targetSet.targetMode) { if (app.activityType != RemoteAnimationTargetCompat.ACTIVITY_TYPE_HOME) { mTmpMatrix.setRectToRect(mSourceRect, currentRect, ScaleToFit.FILL); mTmpMatrix.postTranslate(app.position.x, app.position.y); - crop = mClipRect; + mClipRectF.roundOut(crop); } if (app.isNotInRecents @@ -179,17 +181,22 @@ public class ClipAnimationHelper { } alpha = mTaskAlphaCallback.apply(app, alpha); + layer = RemoteAnimationProvider.getLayer(app, mBoostModeTargetLayers); } else { crop = null; + layer = Integer.MAX_VALUE; } - - params[i] = new SurfaceParams(app.leash, alpha, mTmpMatrix, crop, - RemoteAnimationProvider.getLayer(app, mBoostModeTargetLayers)); + params[i] = new SurfaceParams(app.leash, alpha, mTmpMatrix, crop, layer); } applyParams(syncTransactionApplier, params); return currentRect; } + public RectF getCurrentRectWithInsets() { + mTmpMatrix.mapRect(mCurrentRectWithInsets, mClipRectF); + return mCurrentRectWithInsets; + } + private void applyParams(@Nullable SyncRtSurfaceTransactionApplier syncTransactionApplier, SurfaceParams[] params) { if (syncTransactionApplier != null) { diff --git a/quickstep/src/com/android/quickstep/views/LauncherLayoutListener.java b/quickstep/src/com/android/quickstep/views/LauncherLayoutListener.java index 61740d729b..c12a579686 100644 --- a/quickstep/src/com/android/quickstep/views/LauncherLayoutListener.java +++ b/quickstep/src/com/android/quickstep/views/LauncherLayoutListener.java @@ -15,11 +15,17 @@ */ package com.android.quickstep.views; -import static com.android.launcher3.states.RotationHelper.REQUEST_LOCK; +import static android.view.ViewGroup.LayoutParams.MATCH_PARENT; import static com.android.launcher3.states.RotationHelper.REQUEST_NONE; +import android.graphics.Canvas; +import android.graphics.Paint; +import android.graphics.PorterDuff; +import android.graphics.PorterDuffXfermode; import android.graphics.Rect; +import android.graphics.RectF; import android.view.MotionEvent; +import android.widget.FrameLayout; import com.android.launcher3.AbstractFloatingView; import com.android.launcher3.Insettable; @@ -34,12 +40,28 @@ public class LauncherLayoutListener extends AbstractFloatingView implements Insettable, LayoutListener { private final Launcher mLauncher; + private final Paint mPaint = new Paint(); private WindowTransformSwipeHandler mHandler; + private RectF mCurrentRect; public LauncherLayoutListener(Launcher launcher) { super(launcher, null); mLauncher = launcher; - setVisibility(INVISIBLE); + mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR)); + setLayoutParams(new FrameLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT)); + } + + @Override + public void update(boolean shouldFinish, boolean isLongSwipe, RectF currentRect) { + if (shouldFinish) { + finish(); + return; + } + + mCurrentRect = currentRect; + + setWillNotDraw(mCurrentRect == null || isLongSwipe); + invalidate(); } @Override @@ -80,11 +102,6 @@ public class LauncherLayoutListener extends AbstractFloatingView } } - @Override - protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { - setMeasuredDimension(1, 1); - } - @Override public void logActionCommand(int command) { // We should probably log the weather @@ -97,8 +114,13 @@ public class LauncherLayoutListener extends AbstractFloatingView @Override public void finish() { - setHandler(null); close(false); + setHandler(null); mLauncher.getRotationHelper().setStateHandlerRequest(REQUEST_NONE); } + + @Override + protected void onDraw(Canvas canvas) { + canvas.drawRect(mCurrentRect, mPaint); + } } diff --git a/quickstep/src/com/android/quickstep/views/TaskView.java b/quickstep/src/com/android/quickstep/views/TaskView.java index da5b79a9df..e48a05ab8f 100644 --- a/quickstep/src/com/android/quickstep/views/TaskView.java +++ b/quickstep/src/com/android/quickstep/views/TaskView.java @@ -26,7 +26,9 @@ import android.animation.AnimatorListenerAdapter; import android.animation.ObjectAnimator; import android.animation.TimeInterpolator; import android.app.ActivityOptions; +import android.content.ActivityNotFoundException; import android.content.Context; +import android.content.Intent; import android.content.res.Resources; import android.graphics.Outline; import android.graphics.drawable.Drawable; @@ -43,8 +45,10 @@ import android.widget.FrameLayout; import android.widget.Toast; import com.android.launcher3.BaseDraggingActivity; +import com.android.launcher3.Launcher; import com.android.launcher3.R; import com.android.launcher3.Utilities; +import com.android.launcher3.userevent.nano.LauncherLogProto; import com.android.launcher3.userevent.nano.LauncherLogProto.Action.Direction; import com.android.launcher3.userevent.nano.LauncherLogProto.Action.Touch; import com.android.quickstep.RecentsModel; @@ -100,7 +104,7 @@ public class TaskView extends FrameLayout implements PageCallbacks { } }; - private static FloatProperty FOCUS_TRANSITION = + private static final FloatProperty FOCUS_TRANSITION = new FloatProperty("focusTransition") { @Override public void setValue(TaskView taskView, float v) { @@ -113,6 +117,9 @@ public class TaskView extends FrameLayout implements PageCallbacks { } }; + static final Intent SEE_TIME_IN_APP_TEMPLATE = + new Intent("com.android.settings.action.TIME_SPENT_IN_APP"); + private final OnAttachStateChangeListener mTaskMenuStateListener = new OnAttachStateChangeListener() { @Override @@ -142,6 +149,8 @@ public class TaskView extends FrameLayout implements PageCallbacks { private TaskThumbnailCache.ThumbnailLoadRequest mThumbnailLoadRequest; private TaskIconCache.IconLoadRequest mIconLoadRequest; + private long mAppRemainingTimeMs = -1; + public TaskView(Context context) { this(context, null); } @@ -195,6 +204,10 @@ public class TaskView extends FrameLayout implements PageCallbacks { return mSnapshotView.getTaskOverlay(); } + private boolean hasRemainingTime() { + return mAppRemainingTimeMs > 0; + } + public void launchTask(boolean animate) { launchTask(animate, (result) -> { if (!result) { @@ -421,6 +434,13 @@ public class TaskView extends FrameLayout implements PageCallbacks { } } + if (hasRemainingTime()) { + info.addAction( + new AccessibilityNodeInfo.AccessibilityAction( + R.string.accessibility_app_usage_settings, + getContext().getText(R.string.accessibility_app_usage_settings))); + } + final RecentsView recentsView = getRecentsView(); final AccessibilityNodeInfo.CollectionItemInfo itemInfo = AccessibilityNodeInfo.CollectionItemInfo.obtain( @@ -437,6 +457,11 @@ public class TaskView extends FrameLayout implements PageCallbacks { return true; } + if (action == R.string.accessibility_app_usage_settings) { + openAppUsageSettings(); + return true; + } + final List shortcuts = mSnapshotView.getTaskOverlay().getEnabledShortcuts(this); final int count = shortcuts.size(); @@ -455,6 +480,22 @@ public class TaskView extends FrameLayout implements PageCallbacks { return super.performAccessibilityAction(action, arguments); } + private void openAppUsageSettings() { + final Intent intent = new Intent(SEE_TIME_IN_APP_TEMPLATE) + .putExtra(Intent.EXTRA_PACKAGE_NAME, + mTask.getTopComponent().getPackageName()).addFlags( + Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); + try { + final Launcher launcher = Launcher.getLauncher(getContext()); + launcher.startActivity(intent); + launcher.getUserEventDispatcher().logActionOnControl(LauncherLogProto.Action.Touch.TAP, + LauncherLogProto.ControlType.APP_USAGE_SETTINGS, this); + } catch (ActivityNotFoundException e) { + Log.e(TAG, "Failed to open app usage settings for task " + + mTask.getTopComponent().getPackageName(), e); + } + } + private RecentsView getRecentsView() { return (RecentsView) getParent(); } diff --git a/res/drawable-v26/ic_deepshortcut_placeholder.xml b/res/drawable-v26/ic_deepshortcut_placeholder.xml new file mode 100644 index 0000000000..3fa85065bd --- /dev/null +++ b/res/drawable-v26/ic_deepshortcut_placeholder.xml @@ -0,0 +1,20 @@ + + + + + + diff --git a/res/drawable/deep_shortcuts_text_placeholder.xml b/res/drawable/deep_shortcuts_text_placeholder.xml new file mode 100644 index 0000000000..99da50fdca --- /dev/null +++ b/res/drawable/deep_shortcuts_text_placeholder.xml @@ -0,0 +1,21 @@ + + + + + + + diff --git a/res/drawable/ic_deepshortcut_placeholder.xml b/res/drawable/ic_deepshortcut_placeholder.xml new file mode 100644 index 0000000000..85a9694501 --- /dev/null +++ b/res/drawable/ic_deepshortcut_placeholder.xml @@ -0,0 +1,22 @@ + + + + + + diff --git a/res/layout/add_item_confirmation_activity.xml b/res/layout/add_item_confirmation_activity.xml index 6c316e6ff6..830255b6aa 100644 --- a/res/layout/add_item_confirmation_activity.xml +++ b/res/layout/add_item_confirmation_activity.xml @@ -44,7 +44,7 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:background="?android:attr/colorPrimaryDark" - android:theme="@style/WidgetContainerTheme"> + android:theme="?attr/widgetsTheme"> + android:layout_gravity="start|center_vertical" + android:background="@drawable/ic_deepshortcut_placeholder"/> "Kennisgewings en programme is af" "Maak toe" "Toe" + "Misluk: %1$s" diff --git a/res/values-ar/strings.xml b/res/values-ar/strings.xml index 1a1b53a910..bebc7b3e9b 100644 --- a/res/values-ar/strings.xml +++ b/res/values-ar/strings.xml @@ -149,4 +149,5 @@ "الإشعارات والتطبيقات متوقفة." "إغلاق" "تمّ الإغلاق" + "تعذَّر %1$s." diff --git a/res/values-az/strings.xml b/res/values-az/strings.xml index 573971ec3e..f8aba177a4 100644 --- a/res/values-az/strings.xml +++ b/res/values-az/strings.xml @@ -145,4 +145,5 @@ "Bildiriş və tətbiqlər deaktivdir" "Bağlayın" "Bağlıdır" + "Alınmadı: %1$s" diff --git a/res/values-bs/strings.xml b/res/values-bs/strings.xml index baaed88943..1e2b267ce0 100644 --- a/res/values-bs/strings.xml +++ b/res/values-bs/strings.xml @@ -146,4 +146,5 @@ "Notifikacije i aplikacije su isključene" "Zatvori" "Zatvoreno" + "Nije uspjelo: %1$s" diff --git a/res/values-cs/strings.xml b/res/values-cs/strings.xml index 256b0c9381..f26226c1b4 100644 --- a/res/values-cs/strings.xml +++ b/res/values-cs/strings.xml @@ -147,4 +147,5 @@ "Oznámení a aplikace jsou vypnuty" "Zavřít" "Zavřeno" + "Selhalo: %1$s" diff --git a/res/values-da/strings.xml b/res/values-da/strings.xml index c30acadf36..6b787708b2 100644 --- a/res/values-da/strings.xml +++ b/res/values-da/strings.xml @@ -145,4 +145,6 @@ "Underretninger og apps er slået fra" "Luk" "Lukket" + + diff --git a/res/values-de/strings.xml b/res/values-de/strings.xml index d8b6064ec6..20f2a9c07a 100644 --- a/res/values-de/strings.xml +++ b/res/values-de/strings.xml @@ -145,4 +145,6 @@ "Benachrichtigungen und Apps sind deaktiviert" "Schließen" "Geschlossen" + + diff --git a/res/values-el/strings.xml b/res/values-el/strings.xml index 00717c51ac..eef66ff089 100644 --- a/res/values-el/strings.xml +++ b/res/values-el/strings.xml @@ -145,4 +145,5 @@ "Οι ειδοποιήσεις και οι εφαρμογές είναι απενεργοποιημένες" "Κλείσιμο" "Κλειστή" + "Αποτυχία: %1$s" diff --git a/res/values-en-rAU/strings.xml b/res/values-en-rAU/strings.xml index 181daefaa9..0494eb45dc 100644 --- a/res/values-en-rAU/strings.xml +++ b/res/values-en-rAU/strings.xml @@ -145,4 +145,5 @@ "Notifications and apps are off" "Close" "Closed" + "Failed: %1$s" diff --git a/res/values-en-rGB/strings.xml b/res/values-en-rGB/strings.xml index 181daefaa9..0494eb45dc 100644 --- a/res/values-en-rGB/strings.xml +++ b/res/values-en-rGB/strings.xml @@ -145,4 +145,5 @@ "Notifications and apps are off" "Close" "Closed" + "Failed: %1$s" diff --git a/res/values-en-rIN/strings.xml b/res/values-en-rIN/strings.xml index 181daefaa9..0494eb45dc 100644 --- a/res/values-en-rIN/strings.xml +++ b/res/values-en-rIN/strings.xml @@ -145,4 +145,5 @@ "Notifications and apps are off" "Close" "Closed" + "Failed: %1$s" diff --git a/res/values-eu/strings.xml b/res/values-eu/strings.xml index 4b2bc3cb9c..29d96f8552 100644 --- a/res/values-eu/strings.xml +++ b/res/values-eu/strings.xml @@ -145,4 +145,5 @@ "Jakinarazpenak eta aplikazioak desaktibatuta daude" "Itxi" "Itxita" + "Huts egin du: %1$s" diff --git a/res/values-fa/strings.xml b/res/values-fa/strings.xml index ff7e749fb5..e78af1557b 100644 --- a/res/values-fa/strings.xml +++ b/res/values-fa/strings.xml @@ -145,4 +145,5 @@ "اعلان‌ها و برنامه‌ها خاموش هستند" "بستن" "بسته‌شده" + "ناموفق بود: %1$s" diff --git a/res/values-hr/strings.xml b/res/values-hr/strings.xml index 1f289a8d0c..a4b40280e2 100644 --- a/res/values-hr/strings.xml +++ b/res/values-hr/strings.xml @@ -146,4 +146,5 @@ "Obavijesti i aplikacije isključeni su" "Zatvori" "Zatvoreno" + "Nije uspjelo: %1$s" diff --git a/res/values-in/strings.xml b/res/values-in/strings.xml index 1ae2f28d52..a4c6a5451f 100644 --- a/res/values-in/strings.xml +++ b/res/values-in/strings.xml @@ -145,4 +145,5 @@ "Notifikasi dan aplikasi nonaktif" "Tutup" "Ditutup" + "Gagal: %1$s" diff --git a/res/values-it/strings.xml b/res/values-it/strings.xml index 2f393edf79..1c53c75942 100644 --- a/res/values-it/strings.xml +++ b/res/values-it/strings.xml @@ -145,4 +145,5 @@ "Le notifiche e le app non sono attive" "Chiudi" "Chiusa" + "Operazione non riuscita: %1$s" diff --git a/res/values-iw/strings.xml b/res/values-iw/strings.xml index 7de43887f5..a62cd90aef 100644 --- a/res/values-iw/strings.xml +++ b/res/values-iw/strings.xml @@ -39,7 +39,7 @@ "טוען אפליקציות…" "לא נמצאו אפליקציות התואמות ל-\"%1$s\"" "חפש אפליקציות נוספות" - "הודעות" + "התראות" "כדי להוסיף קיצור דרך, יש לגעת בו ולהחזיק אותו." "כדי להוסיף קיצור דרך או להשתמש בפעולות מותאמות אישית, יש להקיש על קיצור הדרך פעמיים ולהחזיק אותו." "אין עוד מקום במסך דף הבית הזה." @@ -91,7 +91,7 @@ "נדרשת גישה להתראות" "כדי להציג את סימני ההתראות,יש להפעיל התראות מהאפליקציה %1$s" "שנה את ההגדרות" - "הצגה של סימן ההודעות" + "הצגה של סימן ההתראות" "הוספת סמל במסך דף הבית" "לאפליקציות חדשות" "שינוי הצורה של הסמלים" @@ -147,4 +147,6 @@ "הודעות ואפליקציות כבויות" "סגירה" "סגור" + + diff --git a/res/values-ka/strings.xml b/res/values-ka/strings.xml index 0199deaeef..8b4503ea1a 100644 --- a/res/values-ka/strings.xml +++ b/res/values-ka/strings.xml @@ -145,4 +145,5 @@ "შეტყობინებები და აპები გამორთულია" "დახურვა" "დახურული" + "ვერ მოხერხდა: %1$s" diff --git a/res/values-kn/strings.xml b/res/values-kn/strings.xml index fac6ef9fc4..91b08dc933 100644 --- a/res/values-kn/strings.xml +++ b/res/values-kn/strings.xml @@ -145,4 +145,5 @@ "ಅಧಿಸೂಚನೆಗಳು ಮತ್ತು ಅಪ್ಲಿಕೇಶನ್‌ಗಳು ಆಫ್ ಆಗಿವೆ" "ಮುಚ್ಚಿ" "ಮುಚ್ಚಲಾಗಿದೆ" + "ವಿಫಲವಾಗಿದೆ: %1$s" diff --git a/res/values-mr/strings.xml b/res/values-mr/strings.xml index f36b7d5149..df863c1196 100644 --- a/res/values-mr/strings.xml +++ b/res/values-mr/strings.xml @@ -145,4 +145,6 @@ "सूचना आणि अॅप्स बंद आहेत" "बंद करा" "बंद केले" + + diff --git a/res/values-my/strings.xml b/res/values-my/strings.xml index d5188c916d..0b07e30949 100644 --- a/res/values-my/strings.xml +++ b/res/values-my/strings.xml @@ -145,4 +145,5 @@ "အကြောင်းကြားချက်များနှင့် အက်ပ်များကို ပိတ်ထားသည်" "ပိတ်ရန်" "ပိတ်ထားသည်" + "မအောင်မြင်ပါ− %1$s" diff --git a/res/values-v21/styles.xml b/res/values-night-v26/styles.xml similarity index 56% rename from res/values-v21/styles.xml rename to res/values-night-v26/styles.xml index 927719cc1a..510e1f4cd0 100644 --- a/res/values-v21/styles.xml +++ b/res/values-night-v26/styles.xml @@ -1,7 +1,7 @@ + - - + + \ No newline at end of file diff --git a/res/values-sk/strings.xml b/res/values-sk/strings.xml index ff089b5979..c983fe152c 100644 --- a/res/values-sk/strings.xml +++ b/res/values-sk/strings.xml @@ -147,4 +147,5 @@ "Upozornenia a aplikácie sú vypnuté" "Zavrieť" "Zavreté" + "Zlyhalo: %1$s" diff --git a/res/values-sq/strings.xml b/res/values-sq/strings.xml index 2416780219..c26b7a5966 100644 --- a/res/values-sq/strings.xml +++ b/res/values-sq/strings.xml @@ -145,4 +145,5 @@ "Njoftimet dhe aplikacionet janë joaktive" "Mbyll" "Mbyllur" + "Dështoi: %1$s" diff --git a/res/values-uz/strings.xml b/res/values-uz/strings.xml index be7cbf611b..c3b3ddee1e 100644 --- a/res/values-uz/strings.xml +++ b/res/values-uz/strings.xml @@ -145,4 +145,5 @@ "Bildirishnomalar va ilovalar faol emas" "Yopish" "Yopiq" + "Xato: %1$s" diff --git a/res/values-v19/styles.xml b/res/values-v22/styles.xml similarity index 71% rename from res/values-v19/styles.xml rename to res/values-v22/styles.xml index 36c09718e5..f86db7a493 100644 --- a/res/values-v19/styles.xml +++ b/res/values-v22/styles.xml @@ -1,7 +1,7 @@ + - \ No newline at end of file diff --git a/res/values-zu/strings.xml b/res/values-zu/strings.xml index 9283a13302..c25319e1f6 100644 --- a/res/values-zu/strings.xml +++ b/res/values-zu/strings.xml @@ -145,4 +145,5 @@ "Izaziso nezinhlelo zokusebenza kuvaliwe" "Vala" "Kuvaliwe" + "Yehlulekile: %1$s" diff --git a/res/values/config.xml b/res/values/config.xml index 946afecf85..5e83ab7666 100644 --- a/res/values/config.xml +++ b/res/values/config.xml @@ -19,7 +19,7 @@ #Intent;action=android.intent.action.DELETE;launchFlags=0x10800000;end - com.android.launcher3.SettingsActivity$LauncherSettingsFragment + com.android.launcher3.settings.SettingsActivity$LauncherSettingsFragment @@ -105,7 +105,10 @@ - + + + + 150 40 300 diff --git a/res/values/styles.xml b/res/values/styles.xml index 098aac562e..e6791aa295 100644 --- a/res/values/styles.xml +++ b/res/values/styles.xml @@ -27,7 +27,7 @@ #FF757575 - - + false + false + true + #00000000 + #00000000 + + - - - - \ No newline at end of file diff --git a/res/xml/launcher_preferences.xml b/res/xml/launcher_preferences.xml index c55cc49855..2c86f8ebf0 100644 --- a/res/xml/launcher_preferences.xml +++ b/res/xml/launcher_preferences.xml @@ -54,9 +54,9 @@ android:persistent="false" /> + android:title="Developer Options" + android:fragment="com.android.launcher3.settings.DeveloperOptionsFragment"/> diff --git a/src/com/android/launcher3/AbstractFloatingView.java b/src/com/android/launcher3/AbstractFloatingView.java index 45751328a8..7cab18d8d3 100644 --- a/src/com/android/launcher3/AbstractFloatingView.java +++ b/src/com/android/launcher3/AbstractFloatingView.java @@ -219,6 +219,17 @@ public abstract class AbstractFloatingView extends LinearLayout implements Touch closeAllOpenViews(activity, true); } + public static void closeAllOpenViewsExcept(ActivityContext activity, boolean animate, + @FloatingViewType int type) { + closeOpenViews(activity, animate, TYPE_ALL & ~type); + activity.finishAutoCancelActionMode(); + } + + public static void closeAllOpenViewsExcept(ActivityContext activity, + @FloatingViewType int type) { + closeAllOpenViewsExcept(activity, true, type); + } + public static AbstractFloatingView getTopOpenView(ActivityContext activity) { return getTopOpenViewWithType(activity, TYPE_ALL); } diff --git a/src/com/android/launcher3/InvariantDeviceProfile.java b/src/com/android/launcher3/InvariantDeviceProfile.java index f3f2238e36..0b2f4d921e 100644 --- a/src/com/android/launcher3/InvariantDeviceProfile.java +++ b/src/com/android/launcher3/InvariantDeviceProfile.java @@ -16,6 +16,8 @@ package com.android.launcher3; +import static com.android.launcher3.config.FeatureFlags.APPLY_CONFIG_AT_RUNTIME; + import android.annotation.TargetApi; import android.content.Context; import android.content.res.Configuration; @@ -23,6 +25,7 @@ import android.content.res.TypedArray; import android.content.res.XmlResourceParser; import android.graphics.Point; import android.util.DisplayMetrics; +import android.util.Log; import android.util.Xml; import android.view.Display; import android.view.WindowManager; @@ -45,13 +48,13 @@ public class InvariantDeviceProfile { // We do not need any synchronization for this variable as its only written on UI thread. public static final MainThreadInitializedObject INSTANCE = - new MainThreadInitializedObject<>((c) -> { - new ConfigMonitor(c).register(); - return new InvariantDeviceProfile(c); - }); + new MainThreadInitializedObject<>(InvariantDeviceProfile::new); private static final float ICON_SIZE_DEFINED_IN_APP_DP = 48; + public static final int CHANGE_FLAG_GRID = 1 << 0; + public static final int CHANGE_FLAG_ICON_SIZE = 1 << 1; + // Constants that affects the interpolation curve between statically defined device profile // buckets. private static float KNEARESTNEIGHBOR = 3; @@ -61,9 +64,9 @@ public class InvariantDeviceProfile { private static float WEIGHT_EFFICIENT = 100000f; // Profile-defining invariant properties - String name; - float minWidthDps; - float minHeightDps; + private String name; + private float minWidthDps; + private float minHeightDps; /** * Number of icons per row and column in the workspace. @@ -95,9 +98,11 @@ public class InvariantDeviceProfile { public Point defaultWallpaperSize; + private final ArrayList mChangeListeners = new ArrayList<>(); + private ConfigMonitor mConfigMonitor; + @VisibleForTesting - public InvariantDeviceProfile() { - } + public InvariantDeviceProfile() {} private InvariantDeviceProfile(InvariantDeviceProfile p) { this(p.name, p.minWidthDps, p.minHeightDps, p.numRows, p.numColumns, @@ -125,6 +130,12 @@ public class InvariantDeviceProfile { @TargetApi(23) private InvariantDeviceProfile(Context context) { + initGrid(context); + mConfigMonitor = new ConfigMonitor(context, + APPLY_CONFIG_AT_RUNTIME.get() ? this::onConfigChanged : this::killProcess); + } + + private void initGrid(Context context) { WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); DisplayMetrics dm = new DisplayMetrics(); @@ -185,6 +196,44 @@ public class InvariantDeviceProfile { } } + public void addOnChangeListener(OnIDPChangeListener listener) { + mChangeListeners.add(listener); + } + + private void killProcess(Context context) { + Log.e("ConfigMonitor", "restarting launcher"); + android.os.Process.killProcess(android.os.Process.myPid()); + } + + private void onConfigChanged(Context context) { + // Config changes, what shall we do? + InvariantDeviceProfile oldProfile = new InvariantDeviceProfile(this); + + // Re-init grid + initGrid(context); + + int changeFlags = 0; + if (numRows != oldProfile.numRows || + numColumns != oldProfile.numColumns || + numFolderColumns != oldProfile.numFolderColumns || + numFolderRows != oldProfile.numFolderRows || + numHotseatIcons != oldProfile.numHotseatIcons) { + changeFlags |= CHANGE_FLAG_GRID; + } + + if (iconSize != oldProfile.iconSize || iconBitmapSize != oldProfile.iconBitmapSize) { + changeFlags |= CHANGE_FLAG_ICON_SIZE; + } + + // Create a new config monitor + mConfigMonitor.unregister(); + mConfigMonitor = new ConfigMonitor(context, this::onConfigChanged); + + for (OnIDPChangeListener listener : mChangeListeners) { + listener.onIdpChanged(changeFlags, this); + } + } + ArrayList getPredefinedDeviceProfiles(Context context) { ArrayList profiles = new ArrayList<>(); try (XmlResourceParser parser = context.getResources().getXml(R.xml.device_profiles)) { @@ -356,4 +405,8 @@ public class InvariantDeviceProfile { return x * aspectRatio + y; } + public interface OnIDPChangeListener { + + void onIdpChanged(int changeFlags, InvariantDeviceProfile profile); + } } \ No newline at end of file diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java index c50819a6fc..3ae9a49e70 100644 --- a/src/com/android/launcher3/Launcher.java +++ b/src/com/android/launcher3/Launcher.java @@ -110,7 +110,6 @@ import com.android.launcher3.util.ActivityResultInfo; import com.android.launcher3.util.ComponentKey; import com.android.launcher3.util.IntArray; import com.android.launcher3.util.ItemInfoMatcher; -import com.android.launcher3.util.MultiHashMap; import com.android.launcher3.util.MultiValueAlpha; import com.android.launcher3.util.MultiValueAlpha.AlphaProperty; import com.android.launcher3.util.PackageManagerHelper; @@ -137,6 +136,7 @@ import java.io.FileDescriptor; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Collection; +import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -2162,11 +2162,11 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns, } /** - * Copies LauncherModel's map of activities to shortcut ids to Launcher's. This is necessary + * Copies LauncherModel's map of activities to shortcut counts to Launcher's. This is necessary * because LauncherModel's map is updated in the background, while Launcher runs on the UI. */ @Override - public void bindDeepShortcutMap(MultiHashMap deepShortcutMapCopy) { + public void bindDeepShortcutMap(HashMap deepShortcutMapCopy) { mPopupDataProvider.setDeepShortcutMap(deepShortcutMapCopy); } diff --git a/src/com/android/launcher3/LauncherAppState.java b/src/com/android/launcher3/LauncherAppState.java index 6bf581277e..338c20bbcb 100644 --- a/src/com/android/launcher3/LauncherAppState.java +++ b/src/com/android/launcher3/LauncherAppState.java @@ -17,6 +17,7 @@ package com.android.launcher3; import static com.android.launcher3.util.SecureSettingsObserver.newNotificationSettingsObserver; +import static com.android.launcher3.InvariantDeviceProfile.CHANGE_FLAG_ICON_SIZE; import android.content.ComponentName; import android.content.ContentProviderClient; @@ -30,6 +31,7 @@ import com.android.launcher3.compat.PackageInstallerCompat; import com.android.launcher3.compat.UserManagerCompat; import com.android.launcher3.config.FeatureFlags; import com.android.launcher3.icons.IconCache; +import com.android.launcher3.icons.LauncherIcons; import com.android.launcher3.notification.NotificationListener; import com.android.launcher3.util.MainThreadInitializedObject; import com.android.launcher3.util.Preconditions; @@ -94,6 +96,7 @@ public class LauncherAppState { mContext.registerReceiver(mModel, filter); UserManagerCompat.getInstance(mContext).enableAndResetCache(); + mInvariantDeviceProfile.addOnChangeListener(this::onIdpChanged); if (!mContext.getResources().getBoolean(R.bool.notification_badging_enabled)) { mNotificationBadgingObserver = null; @@ -113,6 +116,19 @@ public class LauncherAppState { } } + private void onIdpChanged(int changeFlags, InvariantDeviceProfile idp) { + if (changeFlags == 0) { + return; + } + + if ((changeFlags & CHANGE_FLAG_ICON_SIZE) != 0) { + LauncherIcons.clearPool(); + mIconCache.updateIconParams(idp.fillResIconDpi, idp.iconBitmapSize); + } + + mModel.forceReload(); + } + /** * Call from Application.onTerminate(), which is not guaranteed to ever be called. */ diff --git a/src/com/android/launcher3/LauncherModel.java b/src/com/android/launcher3/LauncherModel.java index 8e9021f58b..b3dabae538 100644 --- a/src/com/android/launcher3/LauncherModel.java +++ b/src/com/android/launcher3/LauncherModel.java @@ -57,7 +57,6 @@ import com.android.launcher3.shortcuts.ShortcutInfoCompat; import com.android.launcher3.util.ComponentKey; import com.android.launcher3.util.IntArray; import com.android.launcher3.util.ItemInfoMatcher; -import com.android.launcher3.util.MultiHashMap; import com.android.launcher3.util.PackageUserKey; import com.android.launcher3.util.Preconditions; import com.android.launcher3.util.Provider; @@ -69,6 +68,7 @@ import java.io.FileDescriptor; import java.io.PrintWriter; import java.lang.ref.WeakReference; import java.util.ArrayList; +import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.List; @@ -161,7 +161,7 @@ public class LauncherModel extends BroadcastReceiver public void bindAllWidgets(ArrayList widgets); public void onPageBoundSynchronously(int page); public void executeOnNextDraw(ViewOnDrawExecutor executor); - public void bindDeepShortcutMap(MultiHashMap deepShortcutMap); + public void bindDeepShortcutMap(HashMap deepShortcutMap); } LauncherModel(LauncherAppState app, IconCache iconCache, AppFilter appFilter) { diff --git a/src/com/android/launcher3/config/BaseFlags.java b/src/com/android/launcher3/config/BaseFlags.java index dc60c8fff2..64b5652c5c 100644 --- a/src/com/android/launcher3/config/BaseFlags.java +++ b/src/com/android/launcher3/config/BaseFlags.java @@ -20,6 +20,7 @@ import static androidx.core.util.Preconditions.checkNotNull; import android.content.Context; import android.content.SharedPreferences; +import android.provider.Settings; import androidx.annotation.GuardedBy; import androidx.annotation.Keep; @@ -51,8 +52,10 @@ abstract class BaseFlags { throw new UnsupportedOperationException("Don't instantiate BaseFlags"); } - public static boolean showFlagTogglerUi() { - return Utilities.IS_DEBUG_DEVICE; + public static boolean showFlagTogglerUi(Context context) { + return Utilities.IS_DEBUG_DEVICE && + Settings.Global.getInt(context.getApplicationContext().getContentResolver(), + Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0) != 0; } public static final boolean IS_DOGFOOD_BUILD = false; @@ -84,9 +87,15 @@ abstract class BaseFlags { // trying to make them fit the orientation the device is in. public static final boolean OVERVIEW_USE_SCREENSHOT_ORIENTATION = true; + /** + * Feature flag to handle define config changes dynamically instead of killing the process. + */ + public static final TogglableFlag APPLY_CONFIG_AT_RUNTIME = new TogglableFlag( + "APPLY_CONFIG_AT_RUNTIME", false, "Apply display changes dynamically"); + public static void initialize(Context context) { - // Avoid the disk read for builds without the flags UI. - if (showFlagTogglerUi()) { + // Avoid the disk read for user builds + if (Utilities.IS_DEBUG_DEVICE) { SharedPreferences sharedPreferences = context.getSharedPreferences(FLAGS_PREF_NAME, Context.MODE_PRIVATE); synchronized (sLock) { @@ -188,5 +197,4 @@ abstract class BaseFlags { return h$; } } - } diff --git a/src/com/android/launcher3/config/FlagTogglerPreferenceFragment.java b/src/com/android/launcher3/config/FlagTogglerPrefUi.java similarity index 52% rename from src/com/android/launcher3/config/FlagTogglerPreferenceFragment.java rename to src/com/android/launcher3/config/FlagTogglerPrefUi.java index 0a1fd2fe07..d3be51dda7 100644 --- a/src/com/android/launcher3/config/FlagTogglerPreferenceFragment.java +++ b/src/com/android/launcher3/config/FlagTogglerPrefUi.java @@ -18,103 +18,117 @@ package com.android.launcher3.config; import android.content.Context; import android.content.SharedPreferences; -import android.os.Bundle; import android.os.Process; -import android.preference.PreferenceDataStore; -import android.preference.PreferenceFragment; -import android.preference.SwitchPreference; import android.util.Log; import android.view.Menu; -import android.view.MenuInflater; import android.view.MenuItem; import android.widget.Toast; import com.android.launcher3.R; import com.android.launcher3.config.BaseFlags.TogglableFlag; +import androidx.preference.PreferenceDataStore; +import androidx.preference.PreferenceFragment; +import androidx.preference.PreferenceGroup; +import androidx.preference.SwitchPreference; + /** * Dev-build only UI allowing developers to toggle flag settings. See {@link FeatureFlags}. */ -public final class FlagTogglerPreferenceFragment extends PreferenceFragment { +public final class FlagTogglerPrefUi { + private static final String TAG = "FlagTogglerPrefFrag"; - private SharedPreferences mSharedPreferences; - private MenuItem saveButton; + private final PreferenceFragment mFragment; + private final Context mContext; + private final SharedPreferences mSharedPreferences; - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - addPreferencesFromResource(R.xml.flag_preferences); - mSharedPreferences = getContext().getSharedPreferences( + private final PreferenceDataStore mDataStore = new PreferenceDataStore() { + + @Override + public void putBoolean(String key, boolean value) { + for (TogglableFlag flag : FeatureFlags.getTogglableFlags()) { + if (flag.getKey().equals(key)) { + if (value == flag.getDefaultValue()) { + mSharedPreferences.edit().remove(key).apply(); + } else { + mSharedPreferences.edit().putBoolean(key, value).apply(); + } + updateMenu(); + } + } + } + + @Override + public boolean getBoolean(String key, boolean defValue) { + return mSharedPreferences.getBoolean(key, defValue); + } + }; + + public FlagTogglerPrefUi(PreferenceFragment fragment) { + mFragment = fragment; + mContext = fragment.getActivity(); + mSharedPreferences = mContext.getSharedPreferences( FeatureFlags.FLAGS_PREF_NAME, Context.MODE_PRIVATE); + } + public void applyTo(PreferenceGroup parent) { // For flag overrides we only want to store when the engineer chose to override the // flag with a different value than the default. That way, when we flip flags in // future, engineers will pick up the new value immediately. To accomplish this, we use a // custom preference data store. - getPreferenceManager().setPreferenceDataStore(new PreferenceDataStore() { - @Override - public void putBoolean(String key, boolean value) { - for (TogglableFlag flag : FeatureFlags.getTogglableFlags()) { - if (flag.getKey().equals(key)) { - if (value == flag.getDefaultValue()) { - mSharedPreferences.edit().remove(key).apply(); - } else { - mSharedPreferences.edit().putBoolean(key, value).apply(); - } - } - } - } - }); - for (TogglableFlag flag : FeatureFlags.getTogglableFlags()) { - SwitchPreference switchPreference = new SwitchPreference(getContext()); + SwitchPreference switchPreference = new SwitchPreference(mContext); switchPreference.setKey(flag.getKey()); switchPreference.setDefaultValue(flag.getDefaultValue()); switchPreference.setChecked(getFlagStateFromSharedPrefs(flag)); switchPreference.setTitle(flag.getKey()); switchPreference.setSummaryOn(flag.getDefaultValue() ? "" : "overridden"); switchPreference.setSummaryOff(flag.getDefaultValue() ? "overridden" : ""); - getPreferenceScreen().addPreference(switchPreference); + switchPreference.setPreferenceDataStore(mDataStore); + parent.addPreference(switchPreference); } - setHasOptionsMenu(true); + updateMenu(); } - @Override - public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { - saveButton = menu.add("Apply"); - saveButton.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS); + private void updateMenu() { + mFragment.setHasOptionsMenu(anyChanged()); + mFragment.getActivity().invalidateOptionsMenu(); } - @Override - public boolean onOptionsItemSelected(MenuItem item) { - if (item == saveButton) { + public void onCreateOptionsMenu(Menu menu) { + if (anyChanged()) { + menu.add(0, R.id.menu_apply_flags, 0, "Apply") + .setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS); + } + } + + public void onOptionsItemSelected(MenuItem item) { + if (item.getItemId() == R.id.menu_apply_flags) { mSharedPreferences.edit().commit(); Log.e(TAG, "Killing launcher process " + Process.myPid() + " to apply new flag values"); System.exit(0); } - return super.onOptionsItemSelected(item); } - @Override public void onStop() { - boolean anyChanged = false; - for (TogglableFlag flag : FeatureFlags.getTogglableFlags()) { - anyChanged = anyChanged || - getFlagStateFromSharedPrefs(flag) != flag.get(); - } - - if (anyChanged) { - Toast.makeText( - getContext(), - "Flag won't be applied until you restart launcher", + if (anyChanged()) { + Toast.makeText(mContext, "Flag won't be applied until you restart launcher", Toast.LENGTH_LONG).show(); } - super.onStop(); } private boolean getFlagStateFromSharedPrefs(TogglableFlag flag) { - return mSharedPreferences.getBoolean(flag.getKey(), flag.getDefaultValue()); + return mDataStore.getBoolean(flag.getKey(), flag.getDefaultValue()); + } + + private boolean anyChanged() { + for (TogglableFlag flag : FeatureFlags.getTogglableFlags()) { + if (getFlagStateFromSharedPrefs(flag) != flag.get()) { + return true; + } + } + return false; } } \ No newline at end of file diff --git a/src/com/android/launcher3/dragndrop/DragView.java b/src/com/android/launcher3/dragndrop/DragView.java index b6a8b50a95..8f223a37e0 100644 --- a/src/com/android/launcher3/dragndrop/DragView.java +++ b/src/com/android/launcher3/dragndrop/DragView.java @@ -232,7 +232,7 @@ public class DragView extends View { nDr = new AdaptiveIconDrawable(new ColorDrawable(Color.BLACK), null); } Utilities.scaleRectAboutCenter(bounds, - li.getNormalizer().getScale(nDr, null, null, null)); + li.getNormalizer().getScale(nDr, null)); } AdaptiveIconDrawable adaptiveIcon = (AdaptiveIconDrawable) dr; diff --git a/src/com/android/launcher3/icons/BaseIconCache.java b/src/com/android/launcher3/icons/BaseIconCache.java index 9198c24825..2afe7139fd 100644 --- a/src/com/android/launcher3/icons/BaseIconCache.java +++ b/src/com/android/launcher3/icons/BaseIconCache.java @@ -90,11 +90,11 @@ public class BaseIconCache { private final HashMap mCache = new HashMap<>(INITIAL_ICON_CACHE_CAPACITY); private final InstantAppResolver mInstantAppResolver; - final int mIconDpi; - - final IconDB mIconDb; final Handler mWorkerHandler; + int mIconDpi; + IconDB mIconDb; + private final BitmapFactory.Options mDecodeOptions; public BaseIconCache(Context context, int iconDpi, int iconPixelSize) { @@ -103,8 +103,6 @@ public class BaseIconCache { mUserManager = UserManagerCompat.getInstance(mContext); mLauncherApps = LauncherAppsCompat.getInstance(mContext); mInstantAppResolver = InstantAppResolver.newInstance(mContext); - mIconDpi = iconDpi; - mIconDb = new IconDB(context, iconPixelSize); mIconProvider = IconProvider.newInstance(context); mWorkerHandler = new Handler(LauncherModel.getWorkerLooper()); @@ -115,6 +113,22 @@ public class BaseIconCache { } else { mDecodeOptions = null; } + + mIconDpi = iconDpi; + mIconDb = new IconDB(context, iconPixelSize); + } + + public void updateIconParams(int iconDpi, int iconPixelSize) { + mWorkerHandler.post(() -> updateIconParamsBg(iconDpi, iconPixelSize)); + } + + private synchronized void updateIconParamsBg(int iconDpi, int iconPixelSize) { + mIconDpi = iconDpi; + mDefaultIcons.clear(); + + mIconDb.close(); + mIconDb = new IconDB(mContext, iconPixelSize); + mCache.clear(); } private Drawable getFullResDefaultActivityIcon() { diff --git a/src/com/android/launcher3/icons/BaseIconFactory.java b/src/com/android/launcher3/icons/BaseIconFactory.java index c8c9618279..cd60de55a8 100644 --- a/src/com/android/launcher3/icons/BaseIconFactory.java +++ b/src/com/android/launcher3/icons/BaseIconFactory.java @@ -192,18 +192,18 @@ public class BaseIconFactory { } AdaptiveIconDrawable dr = (AdaptiveIconDrawable) mWrapperIcon; dr.setBounds(0, 0, 1, 1); - scale = getNormalizer().getScale(icon, outIconBounds, dr.getIconMask(), outShape); - if (ATLEAST_OREO && !outShape[0] && !(icon instanceof AdaptiveIconDrawable)) { + scale = getNormalizer().getScale(icon, outIconBounds); + if (ATLEAST_OREO && !(icon instanceof AdaptiveIconDrawable)) { FixedScaleDrawable fsd = ((FixedScaleDrawable) dr.getForeground()); fsd.setDrawable(icon); fsd.setScale(scale); icon = dr; - scale = getNormalizer().getScale(icon, outIconBounds, null, null); + scale = getNormalizer().getScale(icon, outIconBounds); ((ColorDrawable) dr.getBackground()).setColor(mWrapperBackgroundColor); } } else { - scale = getNormalizer().getScale(icon, outIconBounds, null, null); + scale = getNormalizer().getScale(icon, outIconBounds); } outScale[0] = scale; diff --git a/src/com/android/launcher3/icons/IconNormalizer.java b/src/com/android/launcher3/icons/IconNormalizer.java index 4052a55147..8eb82524e8 100644 --- a/src/com/android/launcher3/icons/IconNormalizer.java +++ b/src/com/android/launcher3/icons/IconNormalizer.java @@ -20,16 +20,13 @@ import android.content.Context; import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Color; -import android.graphics.Matrix; import android.graphics.Paint; -import android.graphics.Path; import android.graphics.PorterDuff; import android.graphics.PorterDuffXfermode; import android.graphics.Rect; import android.graphics.RectF; import android.graphics.drawable.AdaptiveIconDrawable; import android.graphics.drawable.Drawable; -import android.util.Log; import java.nio.ByteBuffer; @@ -53,9 +50,6 @@ public class IconNormalizer { private static final int MIN_VISIBLE_ALPHA = 40; - // Shape detection related constants - private static final float BOUND_RATIO_MARGIN = .05f; - private static final float PIXEL_DIFF_PERCENTAGE_THRESHOLD = 0.005f; private static final float SCALE_NOT_INITIALIZED = 0; // Ratio of the diameter of an normalized circular icon to the actual icon size. @@ -64,8 +58,6 @@ public class IconNormalizer { private final int mMaxSize; private final Bitmap mBitmap; private final Canvas mCanvas; - private final Paint mPaintMaskShape; - private final Paint mPaintMaskShapeOutline; private final byte[] mPixels; private final Rect mAdaptiveIconBounds; @@ -75,8 +67,6 @@ public class IconNormalizer { private final float[] mLeftBorder; private final float[] mRightBorder; private final Rect mBounds; - private final Path mShapePath; - private final Matrix mMatrix; /** package private **/ IconNormalizer(Context context, int iconBitmapSize) { @@ -90,88 +80,9 @@ public class IconNormalizer { mBounds = new Rect(); mAdaptiveIconBounds = new Rect(); - mPaintMaskShape = new Paint(); - mPaintMaskShape.setColor(Color.RED); - mPaintMaskShape.setStyle(Paint.Style.FILL); - mPaintMaskShape.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.XOR)); - - mPaintMaskShapeOutline = new Paint(); - mPaintMaskShapeOutline.setStrokeWidth(2 * context.getResources().getDisplayMetrics().density); - mPaintMaskShapeOutline.setStyle(Paint.Style.STROKE); - mPaintMaskShapeOutline.setColor(Color.BLACK); - mPaintMaskShapeOutline.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR)); - - mShapePath = new Path(); - mMatrix = new Matrix(); mAdaptiveIconScale = SCALE_NOT_INITIALIZED; } - /** - * Returns if the shape of the icon is same as the path. - * For this method to work, the shape path bounds should be in [0,1]x[0,1] bounds. - */ - private boolean isShape(Path maskPath) { - // Condition1: - // If width and height of the path not close to a square, then the icon shape is - // not same as the mask shape. - float iconRatio = ((float) mBounds.width()) / mBounds.height(); - if (Math.abs(iconRatio - 1) > BOUND_RATIO_MARGIN) { - if (DEBUG) { - Log.d(TAG, "Not same as mask shape because width != height. " + iconRatio); - } - return false; - } - - // Condition 2: - // Actual icon (white) and the fitted shape (e.g., circle)(red) XOR operation - // should generate transparent image, if the actual icon is equivalent to the shape. - - // Fit the shape within the icon's bounding box - mMatrix.reset(); - mMatrix.setScale(mBounds.width(), mBounds.height()); - mMatrix.postTranslate(mBounds.left, mBounds.top); - maskPath.transform(mMatrix, mShapePath); - - // XOR operation - mCanvas.drawPath(mShapePath, mPaintMaskShape); - - // DST_OUT operation around the mask path outline - mCanvas.drawPath(mShapePath, mPaintMaskShapeOutline); - - // Check if the result is almost transparent - return isTransparentBitmap(); - } - - /** - * Used to determine if certain the bitmap is transparent. - */ - private boolean isTransparentBitmap() { - ByteBuffer buffer = ByteBuffer.wrap(mPixels); - buffer.rewind(); - mBitmap.copyPixelsToBuffer(buffer); - - int y = mBounds.top; - // buffer position - int index = y * mMaxSize; - // buffer shift after every row, width of buffer = mMaxSize - int rowSizeDiff = mMaxSize - mBounds.right; - - int sum = 0; - for (; y < mBounds.bottom; y++) { - index += mBounds.left; - for (int x = mBounds.left; x < mBounds.right; x++) { - if ((mPixels[index] & 0xFF) > MIN_VISIBLE_ALPHA) { - sum++; - } - index++; - } - index += rowSizeDiff; - } - - float percentageDiffPixels = ((float) sum) / (mBounds.width() * mBounds.height()); - return percentageDiffPixels < PIXEL_DIFF_PERCENTAGE_THRESHOLD; - } - /** * Returns the amount by which the {@param d} should be scaled (in both dimensions) so that it * matches the design guidelines for a launcher icon. @@ -186,8 +97,7 @@ public class IconNormalizer { * * @param outBounds optional rect to receive the fraction distance from each edge. */ - public synchronized float getScale(@NonNull Drawable d, @Nullable RectF outBounds, - @Nullable Path path, @Nullable boolean[] outMaskShape) { + public synchronized float getScale(@NonNull Drawable d, @Nullable RectF outBounds) { if (BaseIconFactory.ATLEAST_OREO && d instanceof AdaptiveIconDrawable) { if (mAdaptiveIconScale != SCALE_NOT_INITIALIZED) { if (outBounds != null) { @@ -298,10 +208,6 @@ public class IconNormalizer { 1 - ((float) mBounds.right) / width, 1 - ((float) mBounds.bottom) / height); } - - if (outMaskShape != null && outMaskShape.length > 0) { - outMaskShape[0] = isShape(path); - } float areaScale = area / (width * height); // Use sqrt of the final ratio as the images is scaled across both width and height. float scale = areaScale > scaleRequired ? (float) Math.sqrt(scaleRequired / areaScale) : 1; diff --git a/src/com/android/launcher3/icons/LauncherIcons.java b/src/com/android/launcher3/icons/LauncherIcons.java index 69614a3cb7..c96d35db56 100644 --- a/src/com/android/launcher3/icons/LauncherIcons.java +++ b/src/com/android/launcher3/icons/LauncherIcons.java @@ -27,11 +27,11 @@ import android.os.UserHandle; import com.android.launcher3.AppInfo; import com.android.launcher3.FastBitmapDrawable; -import com.android.launcher3.graphics.BitmapRenderer; import com.android.launcher3.InvariantDeviceProfile; import com.android.launcher3.ItemInfoWithIcon; import com.android.launcher3.LauncherAppState; import com.android.launcher3.Utilities; +import com.android.launcher3.graphics.BitmapRenderer; import com.android.launcher3.model.PackageItemInfo; import com.android.launcher3.shortcuts.DeepShortcutManager; import com.android.launcher3.shortcuts.ShortcutInfoCompat; @@ -48,13 +48,14 @@ public class LauncherIcons extends BaseIconFactory implements AutoCloseable { private static final Object sPoolSync = new Object(); private static LauncherIcons sPool; - private LauncherIcons next; + private static int sPoolId = 0; /** * Return a new Message instance from the global pool. Allows us to * avoid allocating new objects in many cases. */ public static LauncherIcons obtain(Context context) { + int poolId; synchronized (sPoolSync) { if (sPool != null) { LauncherIcons m = sPool; @@ -62,9 +63,33 @@ public class LauncherIcons extends BaseIconFactory implements AutoCloseable { m.next = null; return m; } + poolId = sPoolId; } + InvariantDeviceProfile idp = LauncherAppState.getIDP(context); - return new LauncherIcons(context, idp.fillResIconDpi, idp.iconBitmapSize); + return new LauncherIcons(context, idp.fillResIconDpi, idp.iconBitmapSize, poolId); + } + + public static void clearPool() { + synchronized (sPoolSync) { + sPool = null; + sPoolId++; + } + } + + private final Context mContext; + private final int mFillResIconDpi; + private final int mIconBitmapSize; + private final int mPoolId; + + private LauncherIcons next; + + private LauncherIcons(Context context, int fillResIconDpi, int iconBitmapSize, int poolId) { + super(context, fillResIconDpi, iconBitmapSize); + mContext = context.getApplicationContext(); + mFillResIconDpi = fillResIconDpi; + mIconBitmapSize = iconBitmapSize; + mPoolId = poolId; } /** @@ -72,6 +97,9 @@ public class LauncherIcons extends BaseIconFactory implements AutoCloseable { */ public void recycle() { synchronized (sPoolSync) { + if (sPoolId != mPoolId) { + return; + } // Clear any temporary state variables clear(); @@ -85,17 +113,6 @@ public class LauncherIcons extends BaseIconFactory implements AutoCloseable { recycle(); } - private final Context mContext; - private final int mFillResIconDpi; - private final int mIconBitmapSize; - - private LauncherIcons(Context context, int fillResIconDpi, int iconBitmapSize) { - super(context, fillResIconDpi, iconBitmapSize); - mContext = context.getApplicationContext(); - mFillResIconDpi = fillResIconDpi; - mIconBitmapSize = iconBitmapSize; - } - public BitmapInfo createBadgedIconBitmap(Drawable icon, UserHandle user, int iconAppTargetSdk) { return createBadgedIconBitmap(icon, user, iconAppTargetSdk, false); diff --git a/src/com/android/launcher3/model/BaseModelUpdateTask.java b/src/com/android/launcher3/model/BaseModelUpdateTask.java index fcdc088a70..c9d8e3eb48 100644 --- a/src/com/android/launcher3/model/BaseModelUpdateTask.java +++ b/src/com/android/launcher3/model/BaseModelUpdateTask.java @@ -27,10 +27,10 @@ import com.android.launcher3.LauncherModel.Callbacks; import com.android.launcher3.ShortcutInfo; import com.android.launcher3.util.ComponentKey; import com.android.launcher3.util.ItemInfoMatcher; -import com.android.launcher3.util.MultiHashMap; import com.android.launcher3.widget.WidgetListRowEntry; import java.util.ArrayList; +import java.util.HashMap; import java.util.concurrent.Executor; /** @@ -107,13 +107,9 @@ public abstract class BaseModelUpdateTask implements ModelUpdateTask { } public void bindDeepShortcuts(BgDataModel dataModel) { - final MultiHashMap shortcutMapCopy = dataModel.deepShortcutMap.clone(); - scheduleCallbackTask(new CallbackTask() { - @Override - public void execute(Callbacks callbacks) { - callbacks.bindDeepShortcutMap(shortcutMapCopy); - } - }); + final HashMap shortcutMapCopy = + new HashMap<>(dataModel.deepShortcutMap); + scheduleCallbackTask(callbacks -> callbacks.bindDeepShortcutMap(shortcutMapCopy)); } public void bindUpdatedWidgets(BgDataModel dataModel) { diff --git a/src/com/android/launcher3/model/BgDataModel.java b/src/com/android/launcher3/model/BgDataModel.java index 81eefc4d8b..151d6f4b6f 100644 --- a/src/com/android/launcher3/model/BgDataModel.java +++ b/src/com/android/launcher3/model/BgDataModel.java @@ -38,7 +38,6 @@ import com.android.launcher3.shortcuts.ShortcutKey; import com.android.launcher3.util.ComponentKey; import com.android.launcher3.util.IntArray; import com.android.launcher3.util.IntSparseArrayMap; -import com.android.launcher3.util.MultiHashMap; import com.google.protobuf.nano.MessageNano; import java.io.FileDescriptor; @@ -97,9 +96,9 @@ public class BgDataModel { public boolean hasShortcutHostPermission; /** - * Maps all launcher activities to the id's of their shortcuts (if they have any). + * Maps all launcher activities to counts of their shortcuts. */ - public final MultiHashMap deepShortcutMap = new MultiHashMap<>(); + public final HashMap deepShortcutMap = new HashMap<>(); /** * Entire list of widgets. @@ -154,14 +153,11 @@ public class BgDataModel { } if (args.length > 0 && TextUtils.equals(args[0], "--all")) { - writer.println(prefix + "shortcuts"); - for (ArrayList map : deepShortcutMap.values()) { - writer.print(prefix + " "); - for (String str : map) { - writer.print(str + ", "); - } - writer.println(); + writer.println(prefix + "shortcut counts "); + for (Integer count : deepShortcutMap.values()) { + writer.print(count + ", "); } + writer.println(); } } @@ -359,9 +355,9 @@ public class BgDataModel { } /** - * Clear all the deep shortcuts for the given package, and re-add the new shortcuts. + * Clear all the deep shortcut counts for the given package, and re-add the new shortcut counts. */ - public synchronized void updateDeepShortcutMap( + public synchronized void updateDeepShortcutCounts( String packageName, UserHandle user, List shortcuts) { if (packageName != null) { Iterator keysIter = deepShortcutMap.keySet().iterator(); @@ -381,7 +377,9 @@ public class BgDataModel { if (shouldShowInContainer) { ComponentKey targetComponent = new ComponentKey(shortcut.getActivity(), shortcut.getUserHandle()); - deepShortcutMap.addToList(targetComponent, shortcut.getId()); + + Integer previousCount = deepShortcutMap.get(targetComponent); + deepShortcutMap.put(targetComponent, previousCount == null ? 1 : previousCount + 1); } } } diff --git a/src/com/android/launcher3/model/LoaderResults.java b/src/com/android/launcher3/model/LoaderResults.java index 2c15df1925..1d18e7667b 100644 --- a/src/com/android/launcher3/model/LoaderResults.java +++ b/src/com/android/launcher3/model/LoaderResults.java @@ -34,7 +34,6 @@ import com.android.launcher3.util.ComponentKey; import com.android.launcher3.util.IntArray; import com.android.launcher3.util.IntSet; import com.android.launcher3.util.LooperIdleLock; -import com.android.launcher3.util.MultiHashMap; import com.android.launcher3.util.ViewOnDrawExecutor; import com.android.launcher3.widget.WidgetListRowEntry; @@ -42,9 +41,8 @@ import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; -import java.util.HashSet; +import java.util.HashMap; import java.util.Iterator; -import java.util.Set; import java.util.concurrent.Executor; /** @@ -333,20 +331,16 @@ public class LoaderResults { } public void bindDeepShortcuts() { - final MultiHashMap shortcutMapCopy; + final HashMap shortcutMapCopy; synchronized (mBgDataModel) { - shortcutMapCopy = mBgDataModel.deepShortcutMap.clone(); + shortcutMapCopy = new HashMap<>(mBgDataModel.deepShortcutMap); } - Runnable r = new Runnable() { - @Override - public void run() { - Callbacks callbacks = mCallbacks.get(); - if (callbacks != null) { - callbacks.bindDeepShortcutMap(shortcutMapCopy); - } + mUiExecutor.execute(() -> { + Callbacks callbacks = mCallbacks.get(); + if (callbacks != null) { + callbacks.bindDeepShortcutMap(shortcutMapCopy); } - }; - mUiExecutor.execute(r); + }); } public void bindAllApps() { diff --git a/src/com/android/launcher3/model/LoaderTask.java b/src/com/android/launcher3/model/LoaderTask.java index 405125e12d..8b3e2c9a86 100644 --- a/src/com/android/launcher3/model/LoaderTask.java +++ b/src/com/android/launcher3/model/LoaderTask.java @@ -861,7 +861,7 @@ public class LoaderTask implements Runnable { if (mUserManager.isUserUnlocked(user)) { List shortcuts = mShortcutManager.queryForAllShortcuts(user); - mBgDataModel.updateDeepShortcutMap(null, user, shortcuts); + mBgDataModel.updateDeepShortcutCounts(null, user, shortcuts); } } } diff --git a/src/com/android/launcher3/model/ShortcutsChangedTask.java b/src/com/android/launcher3/model/ShortcutsChangedTask.java index 47fcd9e13b..e99fed9294 100644 --- a/src/com/android/launcher3/model/ShortcutsChangedTask.java +++ b/src/com/android/launcher3/model/ShortcutsChangedTask.java @@ -116,7 +116,7 @@ public class ShortcutsChangedTask extends BaseModelUpdateTask { if (mUpdateIdMap) { // Update the deep shortcut map if the list of ids has changed for an activity. - dataModel.updateDeepShortcutMap(mPackageName, mUser, mShortcuts); + dataModel.updateDeepShortcutCounts(mPackageName, mUser, mShortcuts); bindDeepShortcuts(dataModel); } } diff --git a/src/com/android/launcher3/model/UserLockStateChangedTask.java b/src/com/android/launcher3/model/UserLockStateChangedTask.java index 40c1912252..8e7557a2ee 100644 --- a/src/com/android/launcher3/model/UserLockStateChangedTask.java +++ b/src/com/android/launcher3/model/UserLockStateChangedTask.java @@ -117,7 +117,7 @@ public class UserLockStateChangedTask extends BaseModelUpdateTask { } if (isUserUnlocked) { - dataModel.updateDeepShortcutMap( + dataModel.updateDeepShortcutCounts( null, mUser, deepShortcutManager.queryForAllShortcuts(mUser)); } bindDeepShortcuts(dataModel); diff --git a/src/com/android/launcher3/popup/PopupContainerWithArrow.java b/src/com/android/launcher3/popup/PopupContainerWithArrow.java index b9e6a98b45..12319f75e5 100644 --- a/src/com/android/launcher3/popup/PopupContainerWithArrow.java +++ b/src/com/android/launcher3/popup/PopupContainerWithArrow.java @@ -216,13 +216,17 @@ public class PopupContainerWithArrow extends ArrowPopup implements DragSource, BubbleTextView icon, ItemInfo item, SystemShortcutFactory factory) { PopupDataProvider popupDataProvider = mLauncher.getPopupDataProvider(); populateAndShow(icon, - popupDataProvider.getShortcutIdsForItem(item), + popupDataProvider.getShortcutCountForItem(item), popupDataProvider.getNotificationKeysForItem(item), factory.getEnabledShortcuts(mLauncher, item)); } + public ViewGroup getSystemShortcutContainerForTesting() { + return mSystemShortcutContainer; + } + @TargetApi(Build.VERSION_CODES.P) - protected void populateAndShow(final BubbleTextView originalIcon, final List shortcutIds, + protected void populateAndShow(final BubbleTextView originalIcon, int shortcutCount, final List notificationKeys, List systemShortcuts) { mNumNotifications = notificationKeys.size(); mOriginalIcon = originalIcon; @@ -240,12 +244,12 @@ public class PopupContainerWithArrow extends ArrowPopup implements DragSource, int viewsToFlip = getChildCount(); mSystemShortcutContainer = this; - if (!shortcutIds.isEmpty()) { + if (shortcutCount > 0) { if (mNotificationItemView != null) { mNotificationItemView.addGutter(); } - for (int i = shortcutIds.size(); i > 0; i--) { + for (int i = shortcutCount; i > 0; i--) { mShortcuts.add(inflateAndAdd(R.layout.deep_shortcut, this)); } updateHiddenShortcuts(); @@ -284,7 +288,7 @@ public class PopupContainerWithArrow extends ArrowPopup implements DragSource, final Looper workerLooper = LauncherModel.getWorkerLooper(); new Handler(workerLooper).postAtFrontOfQueue(PopupPopulator.createUpdateRunnable( mLauncher, originalItemInfo, new Handler(Looper.getMainLooper()), - this, shortcutIds, mShortcuts, notificationKeys)); + this, mShortcuts, notificationKeys)); } private String getTitleForAccessibility() { diff --git a/src/com/android/launcher3/popup/PopupDataProvider.java b/src/com/android/launcher3/popup/PopupDataProvider.java index 4d5a9c6e93..320650397f 100644 --- a/src/com/android/launcher3/popup/PopupDataProvider.java +++ b/src/com/android/launcher3/popup/PopupDataProvider.java @@ -29,7 +29,6 @@ import com.android.launcher3.notification.NotificationKeyData; import com.android.launcher3.notification.NotificationListener; import com.android.launcher3.shortcuts.DeepShortcutManager; import com.android.launcher3.util.ComponentKey; -import com.android.launcher3.util.MultiHashMap; import com.android.launcher3.util.PackageUserKey; import com.android.launcher3.widget.WidgetListRowEntry; @@ -52,8 +51,8 @@ public class PopupDataProvider implements NotificationListener.NotificationsChan private final Launcher mLauncher; - /** Maps launcher activity components to their list of shortcut ids. */ - private MultiHashMap mDeepShortcutMap = new MultiHashMap<>(); + /** Maps launcher activity components to a count of how many shortcuts they have. */ + private HashMap mDeepShortcutMap = new HashMap<>(); /** Maps packages to their BadgeInfo's . */ private Map mPackageUserToBadgeInfos = new HashMap<>(); /** Maps packages to their Widgets */ @@ -146,22 +145,22 @@ public class PopupDataProvider implements NotificationListener.NotificationsChan } } - public void setDeepShortcutMap(MultiHashMap deepShortcutMapCopy) { + public void setDeepShortcutMap(HashMap deepShortcutMapCopy) { mDeepShortcutMap = deepShortcutMapCopy; if (LOGD) Log.d(TAG, "bindDeepShortcutMap: " + mDeepShortcutMap); } - public List getShortcutIdsForItem(ItemInfo info) { + public int getShortcutCountForItem(ItemInfo info) { if (!DeepShortcutManager.supportsShortcuts(info)) { - return Collections.EMPTY_LIST; + return 0; } ComponentName component = info.getTargetComponent(); if (component == null) { - return Collections.EMPTY_LIST; + return 0; } - List ids = mDeepShortcutMap.get(new ComponentKey(component, info.user)); - return ids == null ? Collections.EMPTY_LIST : ids; + Integer count = mDeepShortcutMap.get(new ComponentKey(component, info.user)); + return count == null ? 0 : count; } public BadgeInfo getBadgeInfoForItem(ItemInfo info) { diff --git a/src/com/android/launcher3/popup/PopupPopulator.java b/src/com/android/launcher3/popup/PopupPopulator.java index 61113b80fd..2c59202e9b 100644 --- a/src/com/android/launcher3/popup/PopupPopulator.java +++ b/src/com/android/launcher3/popup/PopupPopulator.java @@ -124,7 +124,7 @@ public class PopupPopulator { public static Runnable createUpdateRunnable(final Launcher launcher, final ItemInfo originalInfo, final Handler uiHandler, final PopupContainerWithArrow container, - final List shortcutIds, final List shortcutViews, + final List shortcutViews, final List notificationKeys) { final ComponentName activity = originalInfo.getTargetComponent(); final UserHandle user = originalInfo.user; @@ -141,7 +141,7 @@ public class PopupPopulator { } List shortcuts = DeepShortcutManager.getInstance(launcher) - .queryForShortcutsContainer(activity, shortcutIds, user); + .queryForShortcutsContainer(activity, user); String shortcutIdToDeDupe = notificationKeys.isEmpty() ? null : notificationKeys.get(0).shortcutId; shortcuts = PopupPopulator.sortAndFilterShortcuts(shortcuts, shortcutIdToDeDupe); diff --git a/src/com/android/launcher3/popup/RemoteActionShortcut.java b/src/com/android/launcher3/popup/RemoteActionShortcut.java index af0d3daa58..c76fb9651e 100644 --- a/src/com/android/launcher3/popup/RemoteActionShortcut.java +++ b/src/com/android/launcher3/popup/RemoteActionShortcut.java @@ -18,6 +18,7 @@ package com.android.launcher3.popup; import android.app.PendingIntent; import android.app.RemoteAction; +import android.content.Intent; import android.os.Handler; import android.os.Looper; import android.util.Log; @@ -48,14 +49,20 @@ public class RemoteActionShortcut extends SystemShortcut { AbstractFloatingView.closeAllOpenViews(launcher); try { - mAction.getActionIntent().send(0, + mAction.getActionIntent().send( + launcher, + 0, + new Intent().putExtra( + Intent.EXTRA_PACKAGE_NAME, + itemInfo.getTargetComponent().getPackageName()), (pendingIntent, intent, resultCode, resultData, resultExtras) -> { if (resultData != null && !resultData.isEmpty()) { Log.e(TAG, "Remote action returned result: " + mAction.getTitle() + " : " + resultData); Toast.makeText(launcher, resultData, Toast.LENGTH_SHORT).show(); } - }, new Handler(Looper.getMainLooper())); + }, + new Handler(Looper.getMainLooper())); } catch (PendingIntent.CanceledException e) { Log.e(TAG, "Remote action canceled: " + mAction.getTitle(), e); Toast.makeText(launcher, launcher.getString( diff --git a/quickstep/src/com/android/launcher3/uioverrides/plugins/PluginPreferencesFragment.java b/src/com/android/launcher3/settings/DeveloperOptionsFragment.java similarity index 53% rename from quickstep/src/com/android/launcher3/uioverrides/plugins/PluginPreferencesFragment.java rename to src/com/android/launcher3/settings/DeveloperOptionsFragment.java index 3da4f84274..a9242f94e0 100644 --- a/quickstep/src/com/android/launcher3/uioverrides/plugins/PluginPreferencesFragment.java +++ b/src/com/android/launcher3/settings/DeveloperOptionsFragment.java @@ -1,19 +1,24 @@ /* * Copyright (C) 2018 The Android Open Source Project * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software distributed under the - * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ +package com.android.launcher3.settings; -package com.android.launcher3.uioverrides.plugins; +import static com.android.launcher3.uioverrides.plugins.PluginManagerWrapper.PLUGIN_CHANGED; +import static com.android.launcher3.uioverrides.plugins.PluginManagerWrapper.pluginEnabledKey; +import android.annotation.TargetApi; import android.content.BroadcastReceiver; import android.content.ComponentName; import android.content.Context; @@ -23,66 +28,132 @@ import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; import android.net.Uri; +import android.os.Build; import android.os.Bundle; -import android.preference.PreferenceFragment; -import android.preference.PreferenceScreen; -import android.preference.SwitchPreference; import android.provider.Settings; import android.util.ArrayMap; import android.util.ArraySet; +import android.view.Menu; +import android.view.MenuInflater; +import android.view.MenuItem; import android.view.View; import com.android.launcher3.R; -import com.android.systemui.shared.plugins.PluginEnabler; -import com.android.systemui.shared.plugins.PluginManager; -import com.android.systemui.shared.plugins.PluginPrefs; +import com.android.launcher3.config.FeatureFlags; +import com.android.launcher3.config.FlagTogglerPrefUi; +import com.android.launcher3.uioverrides.plugins.PluginManagerWrapper; import java.util.List; import java.util.Set; -/** - * This class is copied from System UI Tuner, except using our PluginEnablerImpl. The reason we - * can't share a common base class in the shared lib is because the androidx preference dependency - * interferes with our recyclerview and fragment dependencies. - */ -public class PluginPreferencesFragment extends PreferenceFragment { - public static final String ACTION_PLUGIN_SETTINGS - = "com.android.systemui.action.PLUGIN_SETTINGS"; +import androidx.preference.Preference; +import androidx.preference.PreferenceCategory; +import androidx.preference.PreferenceDataStore; +import androidx.preference.PreferenceFragment; +import androidx.preference.PreferenceScreen; +import androidx.preference.PreferenceViewHolder; +import androidx.preference.SwitchPreference; +/** + * Dev-build only UI allowing developers to toggle flag settings and plugins. + * See {@link FeatureFlags}. + */ +@TargetApi(Build.VERSION_CODES.O) +public class DeveloperOptionsFragment extends PreferenceFragment { + + private static final String ACTION_PLUGIN_SETTINGS = "com.android.systemui.action.PLUGIN_SETTINGS"; private static final String PLUGIN_PERMISSION = "com.android.systemui.permission.PLUGIN"; - private PluginPrefs mPluginPrefs; - private PluginEnabler mPluginEnabler; + private final BroadcastReceiver mPluginReceiver = new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + loadPluginPrefs(); + } + }; + + private PreferenceScreen mPreferenceScreen; + + private PreferenceCategory mPluginsCategory; + private FlagTogglerPrefUi mFlagTogglerPrefUi; @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); + public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { IntentFilter filter = new IntentFilter(Intent.ACTION_PACKAGE_ADDED); filter.addAction(Intent.ACTION_PACKAGE_CHANGED); filter.addAction(Intent.ACTION_PACKAGE_REMOVED); filter.addDataScheme("package"); - getContext().registerReceiver(mReceiver, filter); - filter = new IntentFilter(Intent.ACTION_USER_UNLOCKED); - getContext().registerReceiver(mReceiver, filter); + getContext().registerReceiver(mPluginReceiver, filter); + getContext().registerReceiver(mPluginReceiver, + new IntentFilter(Intent.ACTION_USER_UNLOCKED)); - mPluginEnabler = PluginManagerWrapper.INSTANCE.get(getContext()).getPluginEnabler(); - loadPrefs(); + mPreferenceScreen = getPreferenceManager().createPreferenceScreen(getContext()); + setPreferenceScreen(mPreferenceScreen); + + initFlags(); + loadPluginPrefs(); } @Override public void onDestroy() { super.onDestroy(); - getContext().unregisterReceiver(mReceiver); + getContext().unregisterReceiver(mPluginReceiver); } - private void loadPrefs() { - PreferenceScreen screen = getPreferenceManager().createPreferenceScreen(getContext()); - screen.setOrderingAsAdded(false); + private PreferenceCategory newCategory(String title) { + PreferenceCategory category = new PreferenceCategory(getContext()); + category.setOrder(Preference.DEFAULT_ORDER); + category.setTitle(title); + mPreferenceScreen.addPreference(category); + return category; + } + + private void initFlags() { + if (!FeatureFlags.showFlagTogglerUi(getContext())) { + return; + } + + mFlagTogglerPrefUi = new FlagTogglerPrefUi(this); + mFlagTogglerPrefUi.applyTo(newCategory("Feature flags")); + } + + @Override + public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { + if (mFlagTogglerPrefUi != null) { + mFlagTogglerPrefUi.onCreateOptionsMenu(menu); + } + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + if (mFlagTogglerPrefUi != null) { + mFlagTogglerPrefUi.onOptionsItemSelected(item); + } + return super.onOptionsItemSelected(item); + } + + @Override + public void onStop() { + if (mFlagTogglerPrefUi != null) { + mFlagTogglerPrefUi.onStop(); + } + super.onStop(); + } + + private void loadPluginPrefs() { + if (mPluginsCategory != null) { + mPreferenceScreen.removePreference(mPluginsCategory); + } + if (!PluginManagerWrapper.hasPlugins(getActivity())) { + mPluginsCategory = null; + return; + } + mPluginsCategory = newCategory("Plugins"); + + PluginManagerWrapper manager = PluginManagerWrapper.INSTANCE.get(getContext()); Context prefContext = getContext(); - mPluginPrefs = new PluginPrefs(getContext()); PackageManager pm = getContext().getPackageManager(); - Set pluginActions = mPluginPrefs.getPluginList(); + Set pluginActions = manager.getPluginActions(); ArrayMap> plugins = new ArrayMap<>(); for (String action : pluginActions) { String name = toName(action); @@ -99,13 +170,13 @@ public class PluginPreferencesFragment extends PreferenceFragment { List apps = pm.getPackagesHoldingPermissions(new String[]{PLUGIN_PERMISSION}, PackageManager.MATCH_DISABLED_COMPONENTS | PackageManager.GET_SERVICES); + PreferenceDataStore enabled = manager.getPluginEnabler(); apps.forEach(app -> { if (!plugins.containsKey(app.packageName)) return; - SwitchPreference pref = new PluginPreference(prefContext, app, mPluginEnabler); + SwitchPreference pref = new PluginPreference(prefContext, app, enabled); pref.setSummary("Plugins: " + toString(plugins.get(app.packageName))); - screen.addPreference(pref); + mPluginsCategory.addPreference(pref); }); - setPreferenceScreen(screen); } private String toString(ArraySet plugins) { @@ -132,19 +203,13 @@ public class PluginPreferencesFragment extends PreferenceFragment { return b.toString(); } - private final BroadcastReceiver mReceiver = new BroadcastReceiver() { - @Override - public void onReceive(Context context, Intent intent) { - loadPrefs(); - } - }; - private static class PluginPreference extends SwitchPreference { private final boolean mHasSettings; private final PackageInfo mInfo; - private final PluginEnabler mPluginEnabler; + private final PreferenceDataStore mPluginEnabler; - public PluginPreference(Context prefContext, PackageInfo info, PluginEnabler pluginEnabler) { + public PluginPreference(Context prefContext, PackageInfo info, + PreferenceDataStore pluginEnabler) { super(prefContext); PackageManager pm = prefContext.getPackageManager(); mHasSettings = pm.resolveActivity(new Intent(ACTION_PLUGIN_SETTINGS) @@ -156,11 +221,16 @@ public class PluginPreferencesFragment extends PreferenceFragment { setWidgetLayoutResource(R.layout.switch_preference_with_settings); } + private boolean isEnabled(ComponentName cn) { + return mPluginEnabler.getBoolean(pluginEnabledKey(cn), true); + + } + private boolean isPluginEnabled() { for (int i = 0; i < mInfo.services.length; i++) { ComponentName componentName = new ComponentName(mInfo.packageName, mInfo.services[i].name); - if (!mPluginEnabler.isEnabled(componentName)) { + if (!isEnabled(componentName)) { return false; } } @@ -174,14 +244,14 @@ public class PluginPreferencesFragment extends PreferenceFragment { ComponentName componentName = new ComponentName(mInfo.packageName, mInfo.services[i].name); - if (mPluginEnabler.isEnabled(componentName) != isEnabled) { - mPluginEnabler.setEnabled(componentName, isEnabled); + if (isEnabled(componentName) != isEnabled) { + mPluginEnabler.putBoolean(pluginEnabledKey(componentName), isEnabled); shouldSendBroadcast = true; } } if (shouldSendBroadcast) { final String pkg = mInfo.packageName; - final Intent intent = new Intent(PluginManager.PLUGIN_CHANGED, + final Intent intent = new Intent(PLUGIN_CHANGED, pkg != null ? Uri.fromParts("package", pkg, null) : null); getContext().sendBroadcast(intent); } @@ -190,13 +260,13 @@ public class PluginPreferencesFragment extends PreferenceFragment { } @Override - protected void onBindView(View view) { - super.onBindView(view); - view.findViewById(R.id.settings).setVisibility(mHasSettings ? View.VISIBLE + public void onBindViewHolder(PreferenceViewHolder holder) { + super.onBindViewHolder(holder); + holder.findViewById(R.id.settings).setVisibility(mHasSettings ? View.VISIBLE : View.GONE); - view.findViewById(R.id.divider).setVisibility(mHasSettings ? View.VISIBLE + holder.findViewById(R.id.divider).setVisibility(mHasSettings ? View.VISIBLE : View.GONE); - view.findViewById(R.id.settings).setOnClickListener(v -> { + holder.findViewById(R.id.settings).setOnClickListener(v -> { ResolveInfo result = v.getContext().getPackageManager().resolveActivity( new Intent(ACTION_PLUGIN_SETTINGS).setPackage( mInfo.packageName), 0); @@ -206,7 +276,7 @@ public class PluginPreferencesFragment extends PreferenceFragment { result.activityInfo.name))); } }); - view.setOnLongClickListener(v -> { + holder.itemView.setOnLongClickListener(v -> { Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS); intent.setData(Uri.fromParts("package", mInfo.packageName, null)); getContext().startActivity(intent); diff --git a/src/com/android/launcher3/settings/SettingsActivity.java b/src/com/android/launcher3/settings/SettingsActivity.java index 66420d079e..7c158d9f73 100644 --- a/src/com/android/launcher3/settings/SettingsActivity.java +++ b/src/com/android/launcher3/settings/SettingsActivity.java @@ -24,17 +24,16 @@ import static com.android.launcher3.util.SecureSettingsObserver.newNotificationS import android.app.Activity; import android.app.DialogFragment; import android.app.Fragment; -import android.content.Intent; import android.os.Bundle; import android.provider.Settings; import android.text.TextUtils; -import android.util.Log; import com.android.launcher3.LauncherFiles; import com.android.launcher3.R; import com.android.launcher3.Utilities; import com.android.launcher3.config.FeatureFlags; import com.android.launcher3.graphics.IconShapeOverride; +import com.android.launcher3.uioverrides.plugins.PluginManagerWrapper; import com.android.launcher3.util.SecureSettingsObserver; import androidx.preference.ListPreference; @@ -52,6 +51,7 @@ import androidx.recyclerview.widget.RecyclerView; public class SettingsActivity extends Activity implements OnPreferenceStartFragmentCallback, OnPreferenceStartScreenCallback { + private static final String DEVELOPER_OPTIONS_KEY = "pref_developer_options"; private static final String FLAGS_PREFERENCE_KEY = "flag_toggler"; private static final String ICON_BADGING_PREFERENCE_KEY = "pref_icon_badging"; @@ -203,7 +203,12 @@ public class SettingsActivity extends Activity case FLAGS_PREFERENCE_KEY: // Only show flag toggler UI if this build variant implements that. - return FeatureFlags.showFlagTogglerUi(); + return FeatureFlags.showFlagTogglerUi(getContext()); + + case DEVELOPER_OPTIONS_KEY: + // Show if plugins are enabled or flag UI is enabled. + return FeatureFlags.showFlagTogglerUi(getContext()) || + PluginManagerWrapper.hasPlugins(getContext()); } return true; diff --git a/src/com/android/launcher3/shortcuts/DeepShortcutManager.java b/src/com/android/launcher3/shortcuts/DeepShortcutManager.java index 24e2e2f81f..e70aac68f6 100644 --- a/src/com/android/launcher3/shortcuts/DeepShortcutManager.java +++ b/src/com/android/launcher3/shortcuts/DeepShortcutManager.java @@ -94,10 +94,11 @@ public class DeepShortcutManager { * Gets all the manifest and dynamic shortcuts associated with the given package and user, * to be displayed in the shortcuts container on long press. */ + @TargetApi(25) public List queryForShortcutsContainer(ComponentName activity, - List ids, UserHandle user) { + UserHandle user) { return query(ShortcutQuery.FLAG_MATCH_MANIFEST | ShortcutQuery.FLAG_MATCH_DYNAMIC, - activity.getPackageName(), activity, ids, user); + activity.getPackageName(), activity, null, user); } /** diff --git a/src/com/android/launcher3/shortcuts/DeepShortcutTextView.java b/src/com/android/launcher3/shortcuts/DeepShortcutTextView.java index c809f27cdc..2daa2fe78e 100644 --- a/src/com/android/launcher3/shortcuts/DeepShortcutTextView.java +++ b/src/com/android/launcher3/shortcuts/DeepShortcutTextView.java @@ -18,8 +18,10 @@ package com.android.launcher3.shortcuts; import android.content.Context; import android.content.res.Resources; +import android.graphics.Canvas; import android.graphics.Rect; import android.graphics.drawable.Drawable; +import android.text.TextUtils; import android.util.AttributeSet; import android.view.MotionEvent; import android.widget.Toast; @@ -38,6 +40,10 @@ public class DeepShortcutTextView extends BubbleTextView { private Toast mInstructionToast; + private boolean mShowLoadingState; + private Drawable mLoadingStatePlaceholder; + private final Rect mLoadingStateBounds = new Rect(); + public DeepShortcutTextView(Context context) { this(context, null, 0); } @@ -53,6 +59,7 @@ public class DeepShortcutTextView extends BubbleTextView { mDragHandleWidth = resources.getDimensionPixelSize(R.dimen.popup_padding_end) + resources.getDimensionPixelSize(R.dimen.deep_shortcut_drag_handle_size) + resources.getDimensionPixelSize(R.dimen.deep_shortcut_drawable_padding) / 2; + showLoadingState(true); } @Override @@ -63,6 +70,25 @@ public class DeepShortcutTextView extends BubbleTextView { if (!Utilities.isRtl(getResources())) { mDragHandleBounds.offset(getMeasuredWidth() - mDragHandleBounds.width(), 0); } + + setLoadingBounds(); + } + + private void setLoadingBounds() { + if (mLoadingStatePlaceholder == null) { + return; + } + mLoadingStateBounds.set( + 0, + 0, + getMeasuredWidth() - mDragHandleWidth - getPaddingStart(), + mLoadingStatePlaceholder.getIntrinsicHeight()); + mLoadingStateBounds.offset( + Utilities.isRtl(getResources()) ? mDragHandleWidth : getPaddingStart(), + (int) ((getMeasuredHeight() - mLoadingStatePlaceholder.getIntrinsicHeight()) + / 2.0f) + ); + mLoadingStatePlaceholder.setBounds(mLoadingStateBounds); } @Override @@ -70,6 +96,15 @@ public class DeepShortcutTextView extends BubbleTextView { // The icon is drawn in a separate view. } + @Override + public void setText(CharSequence text, BufferType type) { + super.setText(text, type); + + if (!TextUtils.isEmpty(text)) { + showLoadingState(false); + } + } + @Override public boolean onTouchEvent(MotionEvent ev) { if (ev.getAction() == MotionEvent.ACTION_DOWN) { @@ -88,6 +123,34 @@ public class DeepShortcutTextView extends BubbleTextView { return super.performClick(); } + @Override + public void onDraw(Canvas canvas) { + if (!mShowLoadingState) { + super.onDraw(canvas); + return; + } + + mLoadingStatePlaceholder.draw(canvas); + } + + private void showLoadingState(boolean loading) { + if (loading == mShowLoadingState) { + return; + } + + mShowLoadingState = loading; + + if (loading) { + mLoadingStatePlaceholder = getContext().getDrawable( + R.drawable.deep_shortcuts_text_placeholder); + setLoadingBounds(); + } else { + mLoadingStatePlaceholder = null; + } + + invalidate(); + } + private void showToast() { if (mInstructionToast != null) { mInstructionToast.cancel(); diff --git a/src/com/android/launcher3/shortcuts/DeepShortcutView.java b/src/com/android/launcher3/shortcuts/DeepShortcutView.java index c856cdbe53..7b93ba2534 100644 --- a/src/com/android/launcher3/shortcuts/DeepShortcutView.java +++ b/src/com/android/launcher3/shortcuts/DeepShortcutView.java @@ -40,8 +40,6 @@ public class DeepShortcutView extends FrameLayout { private static final Point sTempPoint = new Point(); - private final Rect mPillRect; - private BubbleTextView mBubbleText; private View mIconView; private View mDivider; @@ -59,8 +57,6 @@ public class DeepShortcutView extends FrameLayout { public DeepShortcutView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); - - mPillRect = new Rect(); } @Override @@ -98,12 +94,6 @@ public class DeepShortcutView extends FrameLayout { return sTempPoint; } - @Override - protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { - super.onMeasure(widthMeasureSpec, heightMeasureSpec); - mPillRect.set(0, 0, getMeasuredWidth(), getMeasuredHeight()); - } - /** package private **/ public void applyShortcutInfo(ShortcutInfo info, ShortcutInfoCompat detail, PopupContainerWithArrow container) { diff --git a/src/com/android/launcher3/util/ConfigMonitor.java b/src/com/android/launcher3/util/ConfigMonitor.java index 5dd0d08d67..717acdccbe 100644 --- a/src/com/android/launcher3/util/ConfigMonitor.java +++ b/src/com/android/launcher3/util/ConfigMonitor.java @@ -29,9 +29,12 @@ import android.util.Log; import android.view.Display; import android.view.WindowManager; +import com.android.launcher3.MainThreadExecutor; +import com.android.launcher3.Utilities.Consumer; + /** * {@link BroadcastReceiver} which watches configuration changes and - * restarts the process in case changes which affect the device profile occur. + * notifies the callback in case changes which affect the device profile occur. */ public class ConfigMonitor extends BroadcastReceiver implements DisplayListener { @@ -48,7 +51,9 @@ public class ConfigMonitor extends BroadcastReceiver implements DisplayListener private final Point mRealSize; private final Point mSmallestSize, mLargestSize; - public ConfigMonitor(Context context) { + private Consumer mCallback; + + public ConfigMonitor(Context context, Consumer callback) { mContext = context; Configuration config = context.getResources().getConfiguration(); @@ -64,6 +69,12 @@ public class ConfigMonitor extends BroadcastReceiver implements DisplayListener mSmallestSize = new Point(); mLargestSize = new Point(); display.getCurrentSizeRange(mSmallestSize, mLargestSize); + + mCallback = callback; + + mContext.registerReceiver(this, new IntentFilter(Intent.ACTION_CONFIGURATION_CHANGED)); + mContext.getSystemService(DisplayManager.class) + .registerDisplayListener(this, new Handler(UiThreadHelper.getBackgroundLooper())); } @Override @@ -71,16 +82,10 @@ public class ConfigMonitor extends BroadcastReceiver implements DisplayListener Configuration config = context.getResources().getConfiguration(); if (mFontScale != config.fontScale || mDensity != config.densityDpi) { Log.d(TAG, "Configuration changed"); - killProcess(); + notifyChange(); } } - public void register() { - mContext.registerReceiver(this, new IntentFilter(Intent.ACTION_CONFIGURATION_CHANGED)); - mContext.getSystemService(DisplayManager.class) - .registerDisplayListener(this, new Handler(UiThreadHelper.getBackgroundLooper())); - } - @Override public void onDisplayAdded(int displayId) { } @@ -97,7 +102,7 @@ public class ConfigMonitor extends BroadcastReceiver implements DisplayListener if (!mRealSize.equals(mTmpPoint1) && !mRealSize.equals(mTmpPoint1.y, mTmpPoint1.x)) { Log.d(TAG, String.format("Display size changed from %s to %s", mRealSize, mTmpPoint1)); - killProcess(); + notifyChange(); return; } @@ -105,22 +110,28 @@ public class ConfigMonitor extends BroadcastReceiver implements DisplayListener if (!mSmallestSize.equals(mTmpPoint1) || !mLargestSize.equals(mTmpPoint2)) { Log.d(TAG, String.format("Available size changed from [%s, %s] to [%s, %s]", mSmallestSize, mLargestSize, mTmpPoint1, mTmpPoint2)); - killProcess(); + notifyChange(); } } - private void killProcess() { - Log.d(TAG, "restarting launcher"); - try { - mContext.unregisterReceiver(this); - mContext.getSystemService(DisplayManager.class).unregisterDisplayListener(this); - } catch (Exception e) { - // We are going to die anyway, ignore any error die to race condition in registering. + private synchronized void notifyChange() { + if (mCallback != null) { + Consumer callback = mCallback; + mCallback = null; + new MainThreadExecutor().execute(() -> callback.accept(mContext)); } - android.os.Process.killProcess(android.os.Process.myPid()); } private Display getDefaultDisplay(Context context) { return context.getSystemService(WindowManager.class).getDefaultDisplay(); } + + public void unregister() { + try { + mContext.unregisterReceiver(this); + mContext.getSystemService(DisplayManager.class).unregisterDisplayListener(this); + } catch (Exception e) { + Log.e(TAG, "Failed to unregister config monitor", e); + } + } } diff --git a/src/com/android/launcher3/util/SQLiteCacheHelper.java b/src/com/android/launcher3/util/SQLiteCacheHelper.java index 44c1762c34..3faf0709a9 100644 --- a/src/com/android/launcher3/util/SQLiteCacheHelper.java +++ b/src/com/android/launcher3/util/SQLiteCacheHelper.java @@ -87,6 +87,10 @@ public abstract class SQLiteCacheHelper { mOpenHelper.clearDB(mOpenHelper.getWritableDatabase()); } + public void close() { + mOpenHelper.close(); + } + protected abstract void onCreateTable(SQLiteDatabase db); /** diff --git a/src/com/android/launcher3/views/OptionsPopupView.java b/src/com/android/launcher3/views/OptionsPopupView.java index 3e58ea6739..c540b59c1c 100644 --- a/src/com/android/launcher3/views/OptionsPopupView.java +++ b/src/com/android/launcher3/views/OptionsPopupView.java @@ -136,7 +136,7 @@ public class OptionsPopupView extends ArrowPopup } @VisibleForTesting - public static OptionsPopupView getOptionsPopup(Launcher launcher) { + public static ArrowPopup getOptionsPopup(Launcher launcher) { return launcher.findViewById(R.id.deep_shortcuts_container); } diff --git a/src_plugins/com/android/systemui/plugins/FirstScreenWidget.java b/src_plugins/com/android/systemui/plugins/FirstScreenWidget.java new file mode 100644 index 0000000000..8d7dd4bc08 --- /dev/null +++ b/src_plugins/com/android/systemui/plugins/FirstScreenWidget.java @@ -0,0 +1,15 @@ +package com.android.systemui.plugins; + +import android.view.ViewGroup; +import com.android.systemui.plugins.annotations.ProvidesInterface; + +/** + * Implement this interface to wrap the widget on the first home screen, e.g. to add new content. + */ +@ProvidesInterface(action = FirstScreenWidget.ACTION, version = FirstScreenWidget.VERSION) +public interface FirstScreenWidget extends Plugin { + String ACTION = "com.android.systemui.action.PLUGIN_FIRST_SCREEN_WIDGET"; + int VERSION = 1; + + void onWidgetUpdated(ViewGroup widgetView); +} diff --git a/src_ui_overrides/com/android/launcher3/uioverrides/plugins/PluginManagerWrapper.java b/src_ui_overrides/com/android/launcher3/uioverrides/plugins/PluginManagerWrapper.java index 31dbb347ca..e1a35c963d 100644 --- a/src_ui_overrides/com/android/launcher3/uioverrides/plugins/PluginManagerWrapper.java +++ b/src_ui_overrides/com/android/launcher3/uioverrides/plugins/PluginManagerWrapper.java @@ -14,17 +14,26 @@ package com.android.launcher3.uioverrides.plugins; +import android.content.ComponentName; import android.content.Context; import com.android.launcher3.util.MainThreadInitializedObject; import com.android.systemui.plugins.Plugin; import com.android.systemui.plugins.PluginListener; +import java.util.Collections; +import java.util.Set; + +import androidx.preference.PreferenceDataStore; + public class PluginManagerWrapper { public static final MainThreadInitializedObject INSTANCE = new MainThreadInitializedObject<>(PluginManagerWrapper::new); + private static final String PREFIX_PLUGIN_ENABLED = "PLUGIN_ENABLED_"; + public static final String PLUGIN_CHANGED = "com.android.systemui.action.PLUGIN_CHANGED"; + private PluginManagerWrapper(Context c) { } @@ -35,6 +44,21 @@ public class PluginManagerWrapper { boolean allowMultiple) { } - public void removePluginListener(PluginListener listener) { + public void removePluginListener(PluginListener listener) { } + + public Set getPluginActions() { + return Collections.emptySet(); + } + + public PreferenceDataStore getPluginEnabler() { + return new PreferenceDataStore() { }; + } + + public static String pluginEnabledKey(ComponentName cn) { + return PREFIX_PLUGIN_ENABLED + cn.flattenToString(); + } + + public static boolean hasPlugins(Context context) { + return false; } } diff --git a/tests/Android.mk b/tests/Android.mk index d808873d11..a787537542 100644 --- a/tests/Android.mk +++ b/tests/Android.mk @@ -21,7 +21,8 @@ LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_STATIC_JAVA_LIBRARIES := \ androidx.annotation_annotation \ - androidx-test \ + androidx.test.runner \ + androidx.test.rules \ androidx.test.uiautomator_uiautomator \ libSharedSystemUI @@ -42,7 +43,8 @@ include $(CLEAR_VARS) LOCAL_MODULE_TAGS := tests LOCAL_STATIC_JAVA_LIBRARIES := \ - androidx-test \ + androidx.test.runner \ + androidx.test.rules \ androidx.test.uiautomator_uiautomator \ mockito-target-minus-junit4 diff --git a/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java b/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java index c878699c50..532d3e8b00 100644 --- a/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java +++ b/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java @@ -56,6 +56,7 @@ import org.junit.Rule; import org.junit.rules.TestRule; import org.junit.runners.model.Statement; +import java.io.IOException; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @@ -168,6 +169,16 @@ public abstract class AbstractLauncherUiTest { } } + protected void clearLauncherData() throws IOException { + if (TestHelpers.isInLauncherProcess()) { + LauncherSettings.Settings.call(mTargetContext.getContentResolver(), + LauncherSettings.Settings.METHOD_CREATE_EMPTY_DB); + resetLoaderState(); + } else { + mDevice.executeShellCommand("pm clear " + mDevice.getLauncherPackageName()); + } + } + /** * Scrolls the {@param container} until it finds an object matching {@param condition}. * @return the matching object. @@ -261,6 +272,10 @@ public abstract class AbstractLauncherUiTest { launcher -> launcher.getStateManager().getState() == state); } + protected void waitForResumed(String message) { + waitForLauncherCondition(message, launcher -> launcher.hasBeenResumed()); + } + // Cannot be used in TaplTests after injecting any gesture using Tapl because this can hide // flakiness. protected void waitForLauncherCondition(String message, Function condition) { diff --git a/tests/src/com/android/launcher3/ui/TestViewHelpers.java b/tests/src/com/android/launcher3/ui/TestViewHelpers.java index 524438642e..6fa28f1c91 100644 --- a/tests/src/com/android/launcher3/ui/TestViewHelpers.java +++ b/tests/src/com/android/launcher3/ui/TestViewHelpers.java @@ -28,6 +28,8 @@ import android.os.Process; import android.os.SystemClock; import android.util.Log; import android.view.MotionEvent; +import android.view.View; +import android.view.ViewGroup; import androidx.test.uiautomator.By; import androidx.test.uiautomator.BySelector; @@ -42,6 +44,7 @@ import com.android.launcher3.testcomponent.AppWidgetNoConfig; import com.android.launcher3.testcomponent.AppWidgetWithConfig; import java.util.concurrent.Callable; +import java.util.function.Function; public class TestViewHelpers { private static final String TAG = "TestViewHelpers"; @@ -183,4 +186,12 @@ public class TestViewHelpers { AbstractLauncherUiTest.DEFAULT_UI_TIMEOUT).click(); return findViewById(R.id.widgets_list_view); } + + public static View findChildView(ViewGroup parent, Function condition) { + for (int i = 0; i < parent.getChildCount(); ++i) { + final View child = parent.getChildAt(i); + if (condition.apply(child)) return child; + } + return null; + } }