From d0c2359a492a08e5f614ea2117fd13b1771b1306 Mon Sep 17 00:00:00 2001 From: Fengjiang Li Date: Thu, 20 Apr 2023 16:42:25 -0700 Subject: [PATCH] Check build version before using predicitve back API Test: build and run app Fix: 278798546 Change-Id: I4a7b226b1d710cc84ef40b59a33f50a84aca84bb --- .../com/android/launcher3/uioverrides/QuickstepLauncher.java | 3 +++ src/com/android/launcher3/Launcher.java | 3 ++- src/com/android/launcher3/views/AbstractSlideInView.java | 4 ++-- src/com/android/launcher3/widget/picker/WidgetsFullSheet.java | 4 ++-- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/quickstep/src/com/android/launcher3/uioverrides/QuickstepLauncher.java b/quickstep/src/com/android/launcher3/uioverrides/QuickstepLauncher.java index b2b062344e..9dcbb9abcd 100644 --- a/quickstep/src/com/android/launcher3/uioverrides/QuickstepLauncher.java +++ b/quickstep/src/com/android/launcher3/uioverrides/QuickstepLauncher.java @@ -74,6 +74,7 @@ import android.hardware.SensorManager; import android.hardware.devicestate.DeviceStateManager; import android.hardware.display.DisplayManager; import android.media.permission.SafeCloseable; +import android.os.Build; import android.os.Bundle; import android.os.CancellationSignal; import android.os.IBinder; @@ -91,6 +92,7 @@ import android.window.SplashScreen; import androidx.annotation.BinderThread; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import androidx.annotation.RequiresApi; import com.android.app.viewcapture.SettingsAwareViewCapture; import com.android.launcher3.AbstractFloatingView; @@ -764,6 +766,7 @@ public class QuickstepLauncher extends Launcher { mActiveOnBackAnimationCallback.onBackStarted(backEvent); } + @RequiresApi(Build.VERSION_CODES.UPSIDE_DOWN_CAKE) @Override public void onBackInvoked() { // Recreate mActiveOnBackAnimationCallback if necessary to avoid NPE diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java index 59f56ff1b5..560cf40260 100644 --- a/src/com/android/launcher3/Launcher.java +++ b/src/com/android/launcher3/Launcher.java @@ -119,6 +119,7 @@ import android.window.OnBackAnimationCallback; import androidx.annotation.CallSuper; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import androidx.annotation.RequiresApi; import androidx.annotation.StringRes; import androidx.annotation.VisibleForTesting; @@ -572,7 +573,7 @@ public class Launcher extends StatefulActivity * Note that state handler will always be handling the back press event if the previous 3 don't. */ @NonNull - @TargetApi(Build.VERSION_CODES.UPSIDE_DOWN_CAKE) + @RequiresApi(Build.VERSION_CODES.UPSIDE_DOWN_CAKE) protected OnBackAnimationCallback getOnBackAnimationCallback() { // #1 auto cancel action mode handler if (isInAutoCancelActionMode()) { diff --git a/src/com/android/launcher3/views/AbstractSlideInView.java b/src/com/android/launcher3/views/AbstractSlideInView.java index 57305827ef..99616f15b9 100644 --- a/src/com/android/launcher3/views/AbstractSlideInView.java +++ b/src/com/android/launcher3/views/AbstractSlideInView.java @@ -28,7 +28,6 @@ import android.animation.Animator; import android.animation.AnimatorListenerAdapter; import android.animation.ObjectAnimator; import android.animation.PropertyValuesHolder; -import android.annotation.TargetApi; import android.content.Context; import android.graphics.Canvas; import android.graphics.Outline; @@ -46,6 +45,7 @@ import android.window.BackEvent; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.annotation.Px; +import androidx.annotation.RequiresApi; import com.android.launcher3.AbstractFloatingView; import com.android.launcher3.Utilities; @@ -195,7 +195,7 @@ public abstract class AbstractSlideInView } @Override - @TargetApi(Build.VERSION_CODES.UPSIDE_DOWN_CAKE) + @RequiresApi(Build.VERSION_CODES.UPSIDE_DOWN_CAKE) public void onBackProgressed(BackEvent backEvent) { final float progress = backEvent.getProgress(); float deceleratedProgress = diff --git a/src/com/android/launcher3/widget/picker/WidgetsFullSheet.java b/src/com/android/launcher3/widget/picker/WidgetsFullSheet.java index 49f3fe9f84..d565dc9ce4 100644 --- a/src/com/android/launcher3/widget/picker/WidgetsFullSheet.java +++ b/src/com/android/launcher3/widget/picker/WidgetsFullSheet.java @@ -25,7 +25,6 @@ import static com.android.launcher3.testing.shared.TestProtocol.NORMAL_STATE_ORD import android.animation.Animator; import android.animation.AnimatorListenerAdapter; import android.animation.PropertyValuesHolder; -import android.annotation.TargetApi; import android.content.Context; import android.content.pm.LauncherApps; import android.content.res.Configuration; @@ -52,6 +51,7 @@ import android.window.BackEvent; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.annotation.Px; +import androidx.annotation.RequiresApi; import androidx.annotation.VisibleForTesting; import androidx.recyclerview.widget.DefaultItemAnimator; import androidx.recyclerview.widget.RecyclerView; @@ -286,7 +286,7 @@ public class WidgetsFullSheet extends BaseWidgetSheet } @Override - @TargetApi(Build.VERSION_CODES.UPSIDE_DOWN_CAKE) + @RequiresApi(Build.VERSION_CODES.UPSIDE_DOWN_CAKE) public void onBackProgressed(@NonNull BackEvent backEvent) { super.onBackProgressed(backEvent); mFastScroller.setVisibility(backEvent.getProgress() > 0 ? View.INVISIBLE : View.VISIBLE);