From f3da6a2855ad2a64904fc5ea0de1547208650b0e Mon Sep 17 00:00:00 2001 From: Michael Wright Date: Fri, 15 Jan 2021 15:09:57 +0000 Subject: [PATCH 1/3] Clean up some deprecation warnings in SettingsLib Bug: 177652618 Test: Compiles Change-Id: I266d4a038d5f66e0c7e46f6f1a02bc3ee4d84c5b --- .../src/com/android/settingslib/fuelgauge/Estimate.kt | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/SettingsLib/src/com/android/settingslib/fuelgauge/Estimate.kt b/packages/SettingsLib/src/com/android/settingslib/fuelgauge/Estimate.kt index b2e75ea6867fc..cd22247d6142b 100644 --- a/packages/SettingsLib/src/com/android/settingslib/fuelgauge/Estimate.kt +++ b/packages/SettingsLib/src/com/android/settingslib/fuelgauge/Estimate.kt @@ -38,14 +38,13 @@ class Estimate( * @return An [Estimate] object with the latest battery estimates. */ @JvmStatic + @Suppress("DEPRECATION") fun getCachedEstimateIfAvailable(context: Context): Estimate? { // if time > 2 min return null or the estimate otherwise val resolver = context.contentResolver - val lastUpdateTime = Instant.ofEpochMilli( - Settings.Global.getLong( - resolver, Settings.Global.BATTERY_ESTIMATES_LAST_UPDATE_TIME, -1)) + val lastUpdateTime = getLastCacheUpdateTime(context) return if (Duration.between(lastUpdateTime, - Instant.now()).compareTo(Duration.ofMinutes(1)) > 0) { + Instant.now()) > Duration.ofMinutes(1)) { null } else Estimate( Settings.Global.getLong(resolver, @@ -65,6 +64,7 @@ class Estimate( * @param estimate the [Estimate] object to store */ @JvmStatic + @Suppress("DEPRECATION") fun storeCachedEstimate(context: Context, estimate: Estimate) { // store the estimate and update the timestamp val resolver = context.contentResolver @@ -82,6 +82,7 @@ class Estimate( * Returns when the estimate was last updated as an Instant */ @JvmStatic + @Suppress("DEPRECATION") fun getLastCacheUpdateTime(context: Context): Instant { return Instant.ofEpochMilli( Settings.Global.getLong( From dd319c4a2af85e35ce4915a31adf9580b740e1a7 Mon Sep 17 00:00:00 2001 From: Michael Wright Date: Fri, 15 Jan 2021 15:21:23 +0000 Subject: [PATCH 2/3] Clean up SysUI Kotlin warnings Bug: 177652618 Test: Compiles Change-Id: Ic2b318e40f93184ae4a09eb0984488603fbb9ece --- .../EasterEgg/src/com/android/egg/neko/NekoControlsService.kt | 4 ++-- packages/EasterEgg/src/com/android/egg/paint/ToolbarView.kt | 1 + .../EasterEgg/src/com/android/egg/quares/QuaresActivity.kt | 1 + 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/EasterEgg/src/com/android/egg/neko/NekoControlsService.kt b/packages/EasterEgg/src/com/android/egg/neko/NekoControlsService.kt index 56f599a3a2198..7efaf0b37de13 100644 --- a/packages/EasterEgg/src/com/android/egg/neko/NekoControlsService.kt +++ b/packages/EasterEgg/src/com/android/egg/neko/NekoControlsService.kt @@ -74,6 +74,7 @@ public class NekoControlsService : ControlsProviderService(), PrefState.PrefsLis private val controls = HashMap() private val publishers = ArrayList() private val rng = Random() + private val metricsLogger = MetricsLogger() private var lastToyIcon: Icon? = null @@ -184,7 +185,6 @@ public class NekoControlsService : ControlsProviderService(), PrefState.PrefsLis return getPendingIntent() } - override fun performControlAction( controlId: String, action: ControlAction, @@ -196,7 +196,7 @@ public class NekoControlsService : ControlsProviderService(), PrefState.PrefsLis controls[CONTROL_ID_FOOD] = makeFoodBowlControl(true) Log.v(TAG, "Bowl refilled. (Registering job.)") NekoService.registerJob(this, FOOD_SPAWN_CAT_DELAY_MINS) - MetricsLogger.histogram(this, "egg_neko_offered_food", 11) + metricsLogger.histogram("egg_neko_offered_food", 11) prefs.foodState = 11 } CONTROL_ID_TOY -> { diff --git a/packages/EasterEgg/src/com/android/egg/paint/ToolbarView.kt b/packages/EasterEgg/src/com/android/egg/paint/ToolbarView.kt index 460fa3a7241fb..20527afd9652f 100644 --- a/packages/EasterEgg/src/com/android/egg/paint/ToolbarView.kt +++ b/packages/EasterEgg/src/com/android/egg/paint/ToolbarView.kt @@ -47,6 +47,7 @@ class ToolbarView : FrameLayout { ) : super(context, attrs, defStyle) { } + @Suppress("DEPRECATION") override fun onApplyWindowInsets(insets: WindowInsets?): WindowInsets { var lp = layoutParams as FrameLayout.LayoutParams? if (lp != null && insets != null) { diff --git a/packages/EasterEgg/src/com/android/egg/quares/QuaresActivity.kt b/packages/EasterEgg/src/com/android/egg/quares/QuaresActivity.kt index ce439a9a663ca..578de01a0c30c 100644 --- a/packages/EasterEgg/src/com/android/egg/quares/QuaresActivity.kt +++ b/packages/EasterEgg/src/com/android/egg/quares/QuaresActivity.kt @@ -49,6 +49,7 @@ class QuaresActivity : Activity() { private lateinit var label: Button private lateinit var grid: GridLayout + @Suppress("DEPRECATION") override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) From 64dcb6e4b6a462d157caf4dae04f197f6565b81a Mon Sep 17 00:00:00 2001 From: Michael Wright Date: Fri, 15 Jan 2021 15:32:29 +0000 Subject: [PATCH 3/3] Fix some deprecation warnings in WM Shell. Also, it seems like the vibrate call was always broken by conflating effect IDs with durations. Fixed that, which should hopefully provide a better haptics experience. Move things to use more Kotlin idioms along the way as well. Bug: 177652618 Test: manual Change-Id: I057989eab8f6728953c2c4f0d7489a5aa0e9bf2d --- .../android/wm/shell/bubbles/BubbleOverflow.kt | 18 +++++++++--------- .../wm/shell/bubbles/RelativeTouchListener.kt | 3 ++- .../common/magnetictarget/MagnetizedObject.kt | 4 ++-- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleOverflow.kt b/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleOverflow.kt index 8ab2f6325d2ba..08ad96585b522 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleOverflow.kt +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleOverflow.kt @@ -86,7 +86,7 @@ class BubbleOverflow( bitmapSize = positioner.bubbleBitmapSize iconBitmapSize = (bitmapSize * 0.46f).toInt() val bubbleSize = positioner.bubbleSize - overflowBtn?.setLayoutParams(FrameLayout.LayoutParams(bubbleSize, bubbleSize)) + overflowBtn?.layoutParams = FrameLayout.LayoutParams(bubbleSize, bubbleSize) expandedView?.updateDimensions() } @@ -96,7 +96,7 @@ class BubbleOverflow( // Set overflow button accent color, dot color val typedValue = TypedValue() context.theme.resolveAttribute(android.R.attr.colorAccent, typedValue, true) - val colorAccent = res.getColor(typedValue.resourceId) + val colorAccent = res.getColor(typedValue.resourceId, null) overflowBtn?.drawable?.setTint(colorAccent) dotColor = colorAccent @@ -106,7 +106,7 @@ class BubbleOverflow( val nightMode = (res.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK == Configuration.UI_MODE_NIGHT_YES) val bg = ColorDrawable(res.getColor( - if (nightMode) R.color.bubbles_dark else R.color.bubbles_light)) + if (nightMode) R.color.bubbles_dark else R.color.bubbles_light, null)) val fg = InsetDrawable(overflowBtn?.drawable, bitmapSize - iconBitmapSize /* inset */) @@ -116,7 +116,7 @@ class BubbleOverflow( // Update dot path dotPath = PathParser.createPathFromPathData( res.getString(com.android.internal.R.string.config_icon_mask)) - val scale = iconFactory.normalizer.getScale(getIconView()!!.getDrawable(), + val scale = iconFactory.normalizer.getScale(iconView!!.drawable, null /* outBounds */, null /* path */, null /* outMaskShape */) val radius = BadgedImageView.DEFAULT_PATH_SIZE / 2f val matrix = Matrix() @@ -177,10 +177,10 @@ class BubbleOverflow( overflowBtn = inflater.inflate(R.layout.bubble_overflow_button, null /* root */, false /* attachToRoot */) as BadgedImageView overflowBtn?.initialize(positioner) - overflowBtn?.setContentDescription(context.resources.getString( - R.string.bubble_overflow_button_content_description)) + overflowBtn?.contentDescription = context.resources.getString( + R.string.bubble_overflow_button_content_description) val bubbleSize = positioner.bubbleSize - overflowBtn?.setLayoutParams(FrameLayout.LayoutParams(bubbleSize, bubbleSize)) + overflowBtn?.layoutParams = FrameLayout.LayoutParams(bubbleSize, bubbleSize) updateBtnTheme() } return overflowBtn @@ -191,10 +191,10 @@ class BubbleOverflow( } override fun getTaskId(): Int { - return if (expandedView != null) expandedView!!.getTaskId() else INVALID_TASK_ID + return if (expandedView != null) expandedView!!.taskId else INVALID_TASK_ID } companion object { - @JvmField val KEY = "Overflow" + const val KEY = "Overflow" } } \ No newline at end of file diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/RelativeTouchListener.kt b/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/RelativeTouchListener.kt index b34732901648f..a1b0dbe0a6dd9 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/RelativeTouchListener.kt +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/RelativeTouchListener.kt @@ -18,6 +18,7 @@ package com.android.wm.shell.bubbles import android.graphics.PointF import android.os.Handler +import android.os.Looper import android.view.MotionEvent import android.view.VelocityTracker import android.view.View @@ -90,7 +91,7 @@ abstract class RelativeTouchListener : View.OnTouchListener { private var touchSlop: Int = -1 private var movedEnough = false - private val handler = Handler() + private val handler = Handler(Looper.myLooper()!!) private var performedLongClick = false @Suppress("UNCHECKED_CAST") diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/common/magnetictarget/MagnetizedObject.kt b/libs/WindowManager/Shell/src/com/android/wm/shell/common/magnetictarget/MagnetizedObject.kt index b4d7387128932..9f6dd1f27b62a 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/common/magnetictarget/MagnetizedObject.kt +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/common/magnetictarget/MagnetizedObject.kt @@ -460,9 +460,9 @@ abstract class MagnetizedObject( /** Plays the given vibration effect if haptics are enabled. */ @SuppressLint("MissingPermission") - private fun vibrateIfEnabled(effect: Int) { + private fun vibrateIfEnabled(effectId: Int) { if (hapticsEnabled && systemHapticsEnabled) { - vibrator.vibrate(effect.toLong()) + vibrator.vibrate(VibrationEffect.createPredefined(effectId)) } }