From e24cb63b811e2885a69e7df794e9972cdf5a57b9 Mon Sep 17 00:00:00 2001 From: Hyunyoung Song Date: Mon, 11 Sep 2017 11:18:03 -0700 Subject: WallpaperManagerCompat should target correct platform Also replace Utilities.isAtLeastO() to static final constant. Bug: 65544683 Change-Id: I39fbea66939d72c31702748716c4e65b4f9bee6a --- src/com/android/launcher3/IconCache.java | 2 +- src/com/android/launcher3/Launcher.java | 4 ++-- src/com/android/launcher3/LauncherAppWidgetHostView.java | 2 +- src/com/android/launcher3/SessionCommitReceiver.java | 4 ++-- src/com/android/launcher3/SettingsActivity.java | 2 +- src/com/android/launcher3/Utilities.java | 12 +++++++----- .../android/launcher3/compat/AppWidgetManagerCompat.java | 2 +- src/com/android/launcher3/compat/LauncherAppsCompat.java | 2 +- .../android/launcher3/compat/WallpaperManagerCompat.java | 4 ++-- .../launcher3/compat/WallpaperManagerCompatVOMR1.java | 3 ++- src/com/android/launcher3/dragndrop/DragView.java | 2 +- .../android/launcher3/dragndrop/PinItemDragListener.java | 2 +- src/com/android/launcher3/graphics/DrawableFactory.java | 2 +- src/com/android/launcher3/graphics/IconNormalizer.java | 4 ++-- .../android/launcher3/graphics/IconShapeOverride.java | 4 ++-- src/com/android/launcher3/graphics/LauncherIcons.java | 16 ++++++++-------- src/com/android/launcher3/graphics/ShadowDrawable.java | 2 +- src/com/android/launcher3/model/PackageUpdatedTask.java | 4 ++-- .../android/launcher3/util/ManagedProfileHeuristic.java | 2 +- src/com/android/launcher3/util/SystemUiController.java | 2 +- .../android/launcher3/ui/widget/RequestPinItemTest.java | 2 +- 21 files changed, 41 insertions(+), 38 deletions(-) diff --git a/src/com/android/launcher3/IconCache.java b/src/com/android/launcher3/IconCache.java index 6f86954dc..573e8a256 100644 --- a/src/com/android/launcher3/IconCache.java +++ b/src/com/android/launcher3/IconCache.java @@ -123,7 +123,7 @@ public class IconCache { } private Drawable getFullResDefaultActivityIcon() { - return getFullResIcon(Resources.getSystem(), Utilities.isAtLeastO() ? + return getFullResIcon(Resources.getSystem(), Utilities.ATLEAST_OREO ? android.R.drawable.sym_def_app_icon : android.R.mipmap.sym_def_app_icon); } diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java index 60d2e81f3..61d12dd3f 100644 --- a/src/com/android/launcher3/Launcher.java +++ b/src/com/android/launcher3/Launcher.java @@ -1132,7 +1132,7 @@ public class Launcher extends BaseActivity // On O and above we there is always some setting present settings (add icon to // home screen or icon badging). On earlier APIs we will have the allow rotation // setting, on devices with a locked orientation, - return Utilities.isAtLeastO() || !getResources().getBoolean(R.bool.allow_rotation); + return Utilities.ATLEAST_OREO || !getResources().getBoolean(R.bool.allow_rotation); } } @@ -1414,7 +1414,7 @@ public class Launcher extends BaseActivity CellLayout layout = getCellLayout(container, screenId); ShortcutInfo info = null; - if (Utilities.isAtLeastO()) { + if (Utilities.ATLEAST_OREO) { info = LauncherAppsCompatVO.createShortcutInfoFromPinItemRequest( this, LauncherAppsCompatVO.getPinItemRequest(data), 0); } diff --git a/src/com/android/launcher3/LauncherAppWidgetHostView.java b/src/com/android/launcher3/LauncherAppWidgetHostView.java index c7b778252..b65b74ea0 100644 --- a/src/com/android/launcher3/LauncherAppWidgetHostView.java +++ b/src/com/android/launcher3/LauncherAppWidgetHostView.java @@ -92,7 +92,7 @@ public class LauncherAppWidgetHostView extends AppWidgetHostView setAccessibilityDelegate(Launcher.getLauncher(context).getAccessibilityDelegate()); setBackgroundResource(R.drawable.widget_internal_focus_bg); - if (Utilities.isAtLeastO()) { + if (Utilities.ATLEAST_OREO) { setExecutor(Utilities.THREAD_POOL_EXECUTOR); } } diff --git a/src/com/android/launcher3/SessionCommitReceiver.java b/src/com/android/launcher3/SessionCommitReceiver.java index 8caba75cd..edb7ff533 100644 --- a/src/com/android/launcher3/SessionCommitReceiver.java +++ b/src/com/android/launcher3/SessionCommitReceiver.java @@ -59,7 +59,7 @@ public class SessionCommitReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { - if (!isEnabled(context) || !Utilities.isAtLeastO()) { + if (!isEnabled(context) || !Utilities.ATLEAST_OREO) { // User has decided to not add icons on homescreen. return; } @@ -92,7 +92,7 @@ public class SessionCommitReceiver extends BroadcastReceiver { } public static void applyDefaultUserPrefs(final Context context) { - if (!Utilities.isAtLeastO()) { + if (!Utilities.ATLEAST_OREO) { return; } SharedPreferences prefs = Utilities.getPrefs(context); diff --git a/src/com/android/launcher3/SettingsActivity.java b/src/com/android/launcher3/SettingsActivity.java index 5bdc1f5bd..d40ac8f97 100644 --- a/src/com/android/launcher3/SettingsActivity.java +++ b/src/com/android/launcher3/SettingsActivity.java @@ -94,7 +94,7 @@ public class SettingsActivity extends Activity { ButtonPreference iconBadgingPref = (ButtonPreference) findPreference(ICON_BADGING_PREFERENCE_KEY); - if (!Utilities.isAtLeastO()) { + if (!Utilities.ATLEAST_OREO) { getPreferenceScreen().removePreference( findPreference(SessionCommitReceiver.ADD_ICON_PREFERENCE_KEY)); getPreferenceScreen().removePreference(iconBadgingPref); diff --git a/src/com/android/launcher3/Utilities.java b/src/com/android/launcher3/Utilities.java index 3aa2db000..b6876f670 100644 --- a/src/com/android/launcher3/Utilities.java +++ b/src/com/android/launcher3/Utilities.java @@ -83,15 +83,17 @@ public final class Utilities { private static final Matrix sMatrix = new Matrix(); private static final Matrix sInverseMatrix = new Matrix(); - public static boolean isAtLeastO() { - return Build.VERSION.SDK_INT >= Build.VERSION_CODES.O; - } + public static final boolean ATLEAST_OREO_MR1 = + Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1; + + public static final boolean ATLEAST_OREO = + Build.VERSION.SDK_INT >= Build.VERSION_CODES.O; public static final boolean ATLEAST_NOUGAT_MR1 = - Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1; + Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1; public static final boolean ATLEAST_NOUGAT = - Build.VERSION.SDK_INT >= Build.VERSION_CODES.N; + Build.VERSION.SDK_INT >= Build.VERSION_CODES.N; public static final boolean ATLEAST_MARSHMALLOW = Build.VERSION.SDK_INT >= Build.VERSION_CODES.M; diff --git a/src/com/android/launcher3/compat/AppWidgetManagerCompat.java b/src/com/android/launcher3/compat/AppWidgetManagerCompat.java index 4e00eae9d..a77a87f2c 100644 --- a/src/com/android/launcher3/compat/AppWidgetManagerCompat.java +++ b/src/com/android/launcher3/compat/AppWidgetManagerCompat.java @@ -40,7 +40,7 @@ public abstract class AppWidgetManagerCompat { public static AppWidgetManagerCompat getInstance(Context context) { synchronized (sInstanceLock) { if (sInstance == null) { - if (Utilities.isAtLeastO()) { + if (Utilities.ATLEAST_OREO) { sInstance = new AppWidgetManagerCompatVO(context.getApplicationContext()); } else { sInstance = new AppWidgetManagerCompatVL(context.getApplicationContext()); diff --git a/src/com/android/launcher3/compat/LauncherAppsCompat.java b/src/com/android/launcher3/compat/LauncherAppsCompat.java index 75a2a5d18..2cac536f6 100644 --- a/src/com/android/launcher3/compat/LauncherAppsCompat.java +++ b/src/com/android/launcher3/compat/LauncherAppsCompat.java @@ -53,7 +53,7 @@ public abstract class LauncherAppsCompat { public static LauncherAppsCompat getInstance(Context context) { synchronized (sInstanceLock) { if (sInstance == null) { - if (Utilities.isAtLeastO()) { + if (Utilities.ATLEAST_OREO) { sInstance = new LauncherAppsCompatVO(context.getApplicationContext()); } else { sInstance = new LauncherAppsCompatVL(context.getApplicationContext()); diff --git a/src/com/android/launcher3/compat/WallpaperManagerCompat.java b/src/com/android/launcher3/compat/WallpaperManagerCompat.java index cbcabdf9b..00258c7da 100644 --- a/src/com/android/launcher3/compat/WallpaperManagerCompat.java +++ b/src/com/android/launcher3/compat/WallpaperManagerCompat.java @@ -31,10 +31,10 @@ public abstract class WallpaperManagerCompat { if (sInstance == null) { context = context.getApplicationContext(); - if (Utilities.isAtLeastO()) { + if (Utilities.ATLEAST_OREO) { try { sInstance = new WallpaperManagerCompatVOMR1(context); - } catch (Exception e) { + } catch (Throwable e) { // The wallpaper APIs do not yet exist } } diff --git a/src/com/android/launcher3/compat/WallpaperManagerCompatVOMR1.java b/src/com/android/launcher3/compat/WallpaperManagerCompatVOMR1.java index 28b780a38..524f266fc 100644 --- a/src/com/android/launcher3/compat/WallpaperManagerCompatVOMR1.java +++ b/src/com/android/launcher3/compat/WallpaperManagerCompatVOMR1.java @@ -35,8 +35,9 @@ public class WallpaperManagerCompatVOMR1 extends WallpaperManagerCompat { private final WallpaperManager mWm; private Method mWCColorHintsMethod; - WallpaperManagerCompatVOMR1(Context context) throws Exception { + WallpaperManagerCompatVOMR1(Context context) throws Throwable { mWm = context.getSystemService(WallpaperManager.class); + String className = WallpaperColors.class.getName(); try { mWCColorHintsMethod = WallpaperColors.class.getDeclaredMethod("getColorHints"); } catch (Exception exc) { diff --git a/src/com/android/launcher3/dragndrop/DragView.java b/src/com/android/launcher3/dragndrop/DragView.java index e81e2a386..33d4fa628 100644 --- a/src/com/android/launcher3/dragndrop/DragView.java +++ b/src/com/android/launcher3/dragndrop/DragView.java @@ -193,7 +193,7 @@ public class DragView extends View { */ @TargetApi(Build.VERSION_CODES.O) public void setItemInfo(final ItemInfo info) { - if (!(FeatureFlags.LAUNCHER3_SPRING_ICONS && Utilities.isAtLeastO())) { + if (!(FeatureFlags.LAUNCHER3_SPRING_ICONS && Utilities.ATLEAST_OREO)) { return; } if (info.itemType != LauncherSettings.Favorites.ITEM_TYPE_APPLICATION && diff --git a/src/com/android/launcher3/dragndrop/PinItemDragListener.java b/src/com/android/launcher3/dragndrop/PinItemDragListener.java index c8d3890ba..b9d97ac5a 100644 --- a/src/com/android/launcher3/dragndrop/PinItemDragListener.java +++ b/src/com/android/launcher3/dragndrop/PinItemDragListener.java @@ -128,7 +128,7 @@ public class PinItemDragListener extends BaseItemDragListener implements Parcela } public static boolean handleDragRequest(Launcher launcher, Intent intent) { - if (!Utilities.isAtLeastO()) { + if (!Utilities.ATLEAST_OREO) { return false; } if (intent == null || !Intent.ACTION_MAIN.equals(intent.getAction())) { diff --git a/src/com/android/launcher3/graphics/DrawableFactory.java b/src/com/android/launcher3/graphics/DrawableFactory.java index 45344c020..371479b36 100644 --- a/src/com/android/launcher3/graphics/DrawableFactory.java +++ b/src/com/android/launcher3/graphics/DrawableFactory.java @@ -80,7 +80,7 @@ public class DrawableFactory { protected Path getPreloadProgressPath(Context context) { - if (Utilities.isAtLeastO()) { + if (Utilities.ATLEAST_OREO) { try { // Try to load the path from Mask Icon Drawable icon = context.getDrawable(R.drawable.adaptive_icon_drawable_wrapper); diff --git a/src/com/android/launcher3/graphics/IconNormalizer.java b/src/com/android/launcher3/graphics/IconNormalizer.java index 8ed62bcdc..28fc42368 100644 --- a/src/com/android/launcher3/graphics/IconNormalizer.java +++ b/src/com/android/launcher3/graphics/IconNormalizer.java @@ -231,7 +231,7 @@ public class IconNormalizer { */ public synchronized float getScale(@NonNull Drawable d, @Nullable RectF outBounds, @Nullable Path path, @Nullable boolean[] outMaskShape) { - if (Utilities.isAtLeastO() && d instanceof AdaptiveIconDrawable && + if (Utilities.ATLEAST_OREO && d instanceof AdaptiveIconDrawable && mAdaptiveIconScale != SCALE_NOT_INITIALIZED) { if (outBounds != null) { outBounds.set(mAdaptiveIconBounds); @@ -347,7 +347,7 @@ public class IconNormalizer { 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; - if (Utilities.isAtLeastO() && d instanceof AdaptiveIconDrawable && + if (Utilities.ATLEAST_OREO && d instanceof AdaptiveIconDrawable && mAdaptiveIconScale == SCALE_NOT_INITIALIZED) { mAdaptiveIconScale = scale; mAdaptiveIconBounds.set(mBounds); diff --git a/src/com/android/launcher3/graphics/IconShapeOverride.java b/src/com/android/launcher3/graphics/IconShapeOverride.java index 654fa98bc..223243b7a 100644 --- a/src/com/android/launcher3/graphics/IconShapeOverride.java +++ b/src/com/android/launcher3/graphics/IconShapeOverride.java @@ -59,7 +59,7 @@ public class IconShapeOverride { private static final int RESTART_REQUEST_CODE = 42; // the answer to everything public static boolean isSupported(Context context) { - if (!Utilities.isAtLeastO()) { + if (!Utilities.ATLEAST_OREO) { return false; } // Only supported when developer settings is enabled @@ -82,7 +82,7 @@ public class IconShapeOverride { } public static void apply(Context context) { - if (!Utilities.isAtLeastO()) { + if (!Utilities.ATLEAST_OREO) { return; } String path = getAppliedValue(context); diff --git a/src/com/android/launcher3/graphics/LauncherIcons.java b/src/com/android/launcher3/graphics/LauncherIcons.java index 7c80c3098..d55baf0f8 100644 --- a/src/com/android/launcher3/graphics/LauncherIcons.java +++ b/src/com/android/launcher3/graphics/LauncherIcons.java @@ -104,7 +104,7 @@ public class LauncherIcons { float scale = 1f; if (!FeatureFlags.LAUNCHER3_DISABLE_ICON_NORMALIZATION) { normalizer = IconNormalizer.getInstance(context); - if (Utilities.isAtLeastO() && iconAppTargetSdk >= Build.VERSION_CODES.O) { + if (Utilities.ATLEAST_OREO && iconAppTargetSdk >= Build.VERSION_CODES.O) { boolean[] outShape = new boolean[1]; AdaptiveIconDrawable dr = (AdaptiveIconDrawable) context.getDrawable(R.drawable.adaptive_icon_drawable_wrapper).mutate(); @@ -123,7 +123,7 @@ public class LauncherIcons { } } Bitmap bitmap = createIconBitmap(icon, context, scale); - if (FeatureFlags.ADAPTIVE_ICON_SHADOW && Utilities.isAtLeastO() && + if (FeatureFlags.ADAPTIVE_ICON_SHADOW && Utilities.ATLEAST_OREO && icon instanceof AdaptiveIconDrawable) { bitmap = ShadowGenerator.getInstance(context).recreateIcon(bitmap); } @@ -158,13 +158,13 @@ public class LauncherIcons { float scale = 1f; if (!FeatureFlags.LAUNCHER3_DISABLE_ICON_NORMALIZATION) { normalizer = IconNormalizer.getInstance(context); - if (Utilities.isAtLeastO() && iconAppTargetSdk >= Build.VERSION_CODES.O) { + if (Utilities.ATLEAST_OREO && iconAppTargetSdk >= Build.VERSION_CODES.O) { boolean[] outShape = new boolean[1]; AdaptiveIconDrawable dr = (AdaptiveIconDrawable) context.getDrawable(R.drawable.adaptive_icon_drawable_wrapper).mutate(); dr.setBounds(0, 0, 1, 1); scale = normalizer.getScale(icon, iconBounds, dr.getIconMask(), outShape); - if (Utilities.isAtLeastO() && FeatureFlags.LEGACY_ICON_TREATMENT && + if (Utilities.ATLEAST_OREO && FeatureFlags.LEGACY_ICON_TREATMENT && !outShape[0]) { Drawable wrappedIcon = wrapToAdaptiveIconDrawable(context, icon, scale); if (wrappedIcon != icon) { @@ -213,12 +213,12 @@ public class LauncherIcons { */ public static Bitmap createIconBitmap(Drawable icon, Context context) { float scale = 1f; - if (FeatureFlags.ADAPTIVE_ICON_SHADOW && Utilities.isAtLeastO() && + if (FeatureFlags.ADAPTIVE_ICON_SHADOW && Utilities.ATLEAST_OREO && icon instanceof AdaptiveIconDrawable) { scale = ShadowGenerator.getScaleForBounds(new RectF(0, 0, 0, 0)); } Bitmap bitmap = createIconBitmap(icon, context, scale); - if (FeatureFlags.ADAPTIVE_ICON_SHADOW && Utilities.isAtLeastO() && + if (FeatureFlags.ADAPTIVE_ICON_SHADOW && Utilities.ATLEAST_OREO && icon instanceof AdaptiveIconDrawable) { bitmap = ShadowGenerator.getInstance(context).recreateIcon(bitmap); } @@ -271,7 +271,7 @@ public class LauncherIcons { final int top = (textureHeight-height) / 2; sOldBounds.set(icon.getBounds()); - if (Utilities.isAtLeastO() && icon instanceof AdaptiveIconDrawable) { + if (Utilities.ATLEAST_OREO && icon instanceof AdaptiveIconDrawable) { int offset = Math.max((int)(ShadowGenerator.BLUR_FACTOR * iconBitmapSize), Math.min(left, top)); int size = Math.max(width, height); @@ -296,7 +296,7 @@ public class LauncherIcons { * create AdaptiveIconDrawable. */ static Drawable wrapToAdaptiveIconDrawable(Context context, Drawable drawable, float scale) { - if (!(FeatureFlags.LEGACY_ICON_TREATMENT && Utilities.isAtLeastO())) { + if (!(FeatureFlags.LEGACY_ICON_TREATMENT && Utilities.ATLEAST_OREO)) { return drawable; } diff --git a/src/com/android/launcher3/graphics/ShadowDrawable.java b/src/com/android/launcher3/graphics/ShadowDrawable.java index ffcedb26a..b40bf7828 100644 --- a/src/com/android/launcher3/graphics/ShadowDrawable.java +++ b/src/com/android/launcher3/graphics/ShadowDrawable.java @@ -146,7 +146,7 @@ public class ShadowDrawable extends Drawable { d.draw(canvas); } - if (Utilities.isAtLeastO()) { + if (Utilities.ATLEAST_OREO) { bitmap = bitmap.copy(Bitmap.Config.HARDWARE, false); } mState.mLastDrawnBitmap = bitmap; diff --git a/src/com/android/launcher3/model/PackageUpdatedTask.java b/src/com/android/launcher3/model/PackageUpdatedTask.java index 13962a259..fa77619ea 100644 --- a/src/com/android/launcher3/model/PackageUpdatedTask.java +++ b/src/com/android/launcher3/model/PackageUpdatedTask.java @@ -101,7 +101,7 @@ public class PackageUpdatedTask extends BaseModelUpdateTask { appsList.addPackage(context, packages[i], mUser); // Automatically add homescreen icon for work profile apps for below O device. - if (!Utilities.isAtLeastO() && !Process.myUserHandle().equals(mUser)) { + if (!Utilities.ATLEAST_OREO && !Process.myUserHandle().equals(mUser)) { SessionCommitReceiver.queueAppIconAddition(context, packages[i], mUser); } } @@ -342,7 +342,7 @@ public class PackageUpdatedTask extends BaseModelUpdateTask { callbacks.notifyWidgetProvidersChanged(); } }); - } else if (Utilities.isAtLeastO() && mOp == OP_ADD) { + } else if (Utilities.ATLEAST_OREO && mOp == OP_ADD) { // Load widgets for the new package. for (int i = 0; i < N; i++) { dataModel.widgetsModel.update(app, new PackageUserKey(packages[i], mUser)); diff --git a/src/com/android/launcher3/util/ManagedProfileHeuristic.java b/src/com/android/launcher3/util/ManagedProfileHeuristic.java index 091dd84bc..009aee775 100644 --- a/src/com/android/launcher3/util/ManagedProfileHeuristic.java +++ b/src/com/android/launcher3/util/ManagedProfileHeuristic.java @@ -67,7 +67,7 @@ public class ManagedProfileHeuristic { return; } - if (Utilities.isAtLeastO() && !SessionCommitReceiver.isEnabled(context)) { + if (Utilities.ATLEAST_OREO && !SessionCommitReceiver.isEnabled(context)) { // Just mark the folder id preference to avoid new folder creation later. ufi.prefs.edit().putLong(ufi.folderIdKey, ItemInfo.NO_ID).apply(); return; diff --git a/src/com/android/launcher3/util/SystemUiController.java b/src/com/android/launcher3/util/SystemUiController.java index d7a2625e9..edbf05a7c 100644 --- a/src/com/android/launcher3/util/SystemUiController.java +++ b/src/com/android/launcher3/util/SystemUiController.java @@ -59,7 +59,7 @@ public class SystemUiController { // Apply the state flags in priority order int newFlags = oldFlags; for (int stateFlag : mStates) { - if (Utilities.isAtLeastO()) { + if (Utilities.ATLEAST_OREO) { if ((stateFlag & FLAG_LIGHT_NAV) != 0) { newFlags |= View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR; } else if ((stateFlag & FLAG_DARK_NAV) != 0) { diff --git a/tests/src/com/android/launcher3/ui/widget/RequestPinItemTest.java b/tests/src/com/android/launcher3/ui/widget/RequestPinItemTest.java index 4b9d83f8a..bd213157e 100644 --- a/tests/src/com/android/launcher3/ui/widget/RequestPinItemTest.java +++ b/tests/src/com/android/launcher3/ui/widget/RequestPinItemTest.java @@ -141,7 +141,7 @@ public class RequestPinItemTest extends AbstractLauncherUiTest { private void runTest(String activityMethod, boolean isWidget, ItemOperator itemMatcher, Intent... commandIntents) throws Throwable { - if (!Utilities.isAtLeastO()) { + if (!Utilities.ATLEAST_OREO) { return; } lockRotation(true); -- cgit v1.2.3