From 45b07a2d7b6270f473dbec2976ddb6311046d697 Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Wed, 9 Aug 2023 12:07:37 -0700 Subject: [PATCH] Fix kotlin nullable errors in frameworks/base Fix kotlin nullable errors that were exposed by setting the retention of android.annotation.NonNull and android.annotation.Nullable to class retention. Bug: 294110802 Test: builds Change-Id: I0736e8abf503c80b92e3762bed908400ffedb335 --- .../EasterEgg/src/com/android/egg/quares/Quare.kt | 14 ++++++-------- .../src/com/android/egg/quares/QuaresActivity.kt | 6 +++--- .../settingslib/graph/ThemedBatteryDrawable.kt | 2 +- .../PeerDeviceSystemAttestationVerificationTest.kt | 2 +- .../SystemAttestationVerificationTest.kt | 2 +- tests/Input/src/com/android/test/input/AnrTest.kt | 2 +- .../input/UnresponsiveGestureMonitorActivity.kt | 2 +- .../silkfx/materials/BackgroundBlurActivity.kt | 12 ++++++------ 8 files changed, 20 insertions(+), 22 deletions(-) diff --git a/packages/EasterEgg/src/com/android/egg/quares/Quare.kt b/packages/EasterEgg/src/com/android/egg/quares/Quare.kt index eb77362a0be2c..f0cc2a1eac938 100644 --- a/packages/EasterEgg/src/com/android/egg/quares/Quare.kt +++ b/packages/EasterEgg/src/com/android/egg/quares/Quare.kt @@ -137,14 +137,12 @@ class Quare(val width: Int, val height: Int, val depth: Int) : Parcelable { return 0 } - override fun writeToParcel(p: Parcel?, flags: Int) { - p?.let { - p.writeInt(width) - p.writeInt(height) - p.writeInt(depth) - p.writeIntArray(data) - p.writeIntArray(user) - } + override fun writeToParcel(p: Parcel, flags: Int) { + p.writeInt(width) + p.writeInt(height) + p.writeInt(depth) + p.writeIntArray(data) + p.writeIntArray(user) } companion object CREATOR : Parcelable.Creator { diff --git a/packages/EasterEgg/src/com/android/egg/quares/QuaresActivity.kt b/packages/EasterEgg/src/com/android/egg/quares/QuaresActivity.kt index 578de01a0c30c..5fa61373a6869 100644 --- a/packages/EasterEgg/src/com/android/egg/quares/QuaresActivity.kt +++ b/packages/EasterEgg/src/com/android/egg/quares/QuaresActivity.kt @@ -60,8 +60,8 @@ class QuaresActivity : Activity() { setContentView(R.layout.activity_quares) - grid = findViewById(R.id.grid) - label = findViewById(R.id.label) + grid = requireViewById(R.id.grid) + label = requireViewById(R.id.label) if (savedInstanceState != null) { Log.v(TAG, "restoring puzzle from state") @@ -135,7 +135,7 @@ class QuaresActivity : Activity() { if (q.check()) { val dp = resources.displayMetrics.density - val label: Button = findViewById(R.id.label) + val label: Button = requireViewById(R.id.label) label.text = resName.replace(Regex("^.*/"), "") val drawable = icon?.loadDrawable(this)?.also { it.setBounds(0, 0, (32 * dp).toInt(), (32 * dp).toInt()) diff --git a/packages/SettingsLib/src/com/android/settingslib/graph/ThemedBatteryDrawable.kt b/packages/SettingsLib/src/com/android/settingslib/graph/ThemedBatteryDrawable.kt index faea5b2c3e715..61a45f79691b3 100644 --- a/packages/SettingsLib/src/com/android/settingslib/graph/ThemedBatteryDrawable.kt +++ b/packages/SettingsLib/src/com/android/settingslib/graph/ThemedBatteryDrawable.kt @@ -324,7 +324,7 @@ open class ThemedBatteryDrawable(private val context: Context, frameColor: Int) return batteryLevel } - override fun onBoundsChange(bounds: Rect?) { + override fun onBoundsChange(bounds: Rect) { super.onBoundsChange(bounds) updateSize() } diff --git a/tests/AttestationVerificationTest/src/android/security/attestationverification/PeerDeviceSystemAttestationVerificationTest.kt b/tests/AttestationVerificationTest/src/android/security/attestationverification/PeerDeviceSystemAttestationVerificationTest.kt index 32c2230e48804..ad95fbc36867c 100644 --- a/tests/AttestationVerificationTest/src/android/security/attestationverification/PeerDeviceSystemAttestationVerificationTest.kt +++ b/tests/AttestationVerificationTest/src/android/security/attestationverification/PeerDeviceSystemAttestationVerificationTest.kt @@ -39,7 +39,7 @@ class PeerDeviceSystemAttestationVerificationTest { @Before fun setup() { rule.getScenario().onActivity { - avm = it.getSystemService(AttestationVerificationManager::class.java) + avm = it.getSystemService(AttestationVerificationManager::class.java)!! activity = it } invalidAttestationByteArray = TEST_ATTESTATION_CERT_FILENAME.fromPEMFileToByteArray() diff --git a/tests/AttestationVerificationTest/src/android/security/attestationverification/SystemAttestationVerificationTest.kt b/tests/AttestationVerificationTest/src/android/security/attestationverification/SystemAttestationVerificationTest.kt index 169effaa45ca3..8f06b4a2ea0a6 100644 --- a/tests/AttestationVerificationTest/src/android/security/attestationverification/SystemAttestationVerificationTest.kt +++ b/tests/AttestationVerificationTest/src/android/security/attestationverification/SystemAttestationVerificationTest.kt @@ -43,7 +43,7 @@ class SystemAttestationVerificationTest { @Before fun setup() { rule.getScenario().onActivity { - avm = it.getSystemService(AttestationVerificationManager::class.java) + avm = it.getSystemService(AttestationVerificationManager::class.java)!! activity = it androidKeystore = KeyStore.getInstance(ANDROID_KEYSTORE).apply { load(null) } } diff --git a/tests/Input/src/com/android/test/input/AnrTest.kt b/tests/Input/src/com/android/test/input/AnrTest.kt index 8025406499d8f..1355fd245f289 100644 --- a/tests/Input/src/com/android/test/input/AnrTest.kt +++ b/tests/Input/src/com/android/test/input/AnrTest.kt @@ -134,7 +134,7 @@ class AnrTest { private fun getExitReasons(): List { lateinit var infos: List instrumentation.runOnMainSync { - val am = instrumentation.getContext().getSystemService(ActivityManager::class.java) + val am = instrumentation.getContext().getSystemService(ActivityManager::class.java)!! infos = am.getHistoricalProcessExitReasons(PACKAGE_NAME, ALL_PIDS, NO_MAX) } return infos diff --git a/tests/Input/src/com/android/test/input/UnresponsiveGestureMonitorActivity.kt b/tests/Input/src/com/android/test/input/UnresponsiveGestureMonitorActivity.kt index d83a4570fedc4..29d5c7754d85c 100644 --- a/tests/Input/src/com/android/test/input/UnresponsiveGestureMonitorActivity.kt +++ b/tests/Input/src/com/android/test/input/UnresponsiveGestureMonitorActivity.kt @@ -47,6 +47,6 @@ class UnresponsiveGestureMonitorActivity : Activity() { super.onCreate(savedInstanceState) mInputMonitor = InputManager.getInstance().monitorGestureInput(MONITOR_NAME, displayId) mInputEventReceiver = UnresponsiveReceiver( - mInputMonitor.getInputChannel(), Looper.myLooper()) + mInputMonitor.getInputChannel(), Looper.myLooper()!!) } } diff --git a/tests/SilkFX/src/com/android/test/silkfx/materials/BackgroundBlurActivity.kt b/tests/SilkFX/src/com/android/test/silkfx/materials/BackgroundBlurActivity.kt index 9d17d38d42985..4d38660e60294 100644 --- a/tests/SilkFX/src/com/android/test/silkfx/materials/BackgroundBlurActivity.kt +++ b/tests/SilkFX/src/com/android/test/silkfx/materials/BackgroundBlurActivity.kt @@ -132,7 +132,7 @@ class BackgroundBlurActivity : Activity(), SeekBar.OnSeekBarChangeListener { mBlurForceDisabled = disabled Settings.Global.putInt(getContentResolver(), Settings.Global.DISABLE_WINDOW_BLURS, if (mBlurForceDisabled) 1 else 0) - (findViewById(R.id.toggle_blur_enabled) as Button) + (requireViewById(R.id.toggle_blur_enabled) as Button) .setText(if (mBlurForceDisabled) "Enable blurs" else "Disable blurs") } @@ -142,13 +142,13 @@ class BackgroundBlurActivity : Activity(), SeekBar.OnSeekBarChangeListener { fun setBackgroundBlur(radius: Int) { mBackgroundBlurRadius = radius - (findViewById(R.id.background_blur_radius) as TextView).setText(radius.toString()) + (requireViewById(R.id.background_blur_radius) as TextView).setText(radius.toString()) window.setBackgroundBlurRadius(mBackgroundBlurRadius) } fun setBlurBehind(radius: Int) { mBlurBehindRadius = radius - (findViewById(R.id.blur_behind_radius) as TextView).setText(radius.toString()) + (requireViewById(R.id.blur_behind_radius) as TextView).setText(radius.toString()) window.getAttributes().setBlurBehindRadius(mBlurBehindRadius) window.setAttributes(window.getAttributes()) } @@ -159,7 +159,7 @@ class BackgroundBlurActivity : Activity(), SeekBar.OnSeekBarChangeListener { } else { mDimAmountNoBlur = amount } - (findViewById(R.id.dim_amount) as TextView).setText("%.2f".format(amount)) + (requireViewById(R.id.dim_amount) as TextView).setText("%.2f".format(amount)) window.getAttributes().dimAmount = amount window.setAttributes(window.getAttributes()) } @@ -168,7 +168,7 @@ class BackgroundBlurActivity : Activity(), SeekBar.OnSeekBarChangeListener { mBatterySavingModeOn = on Settings.Global.putInt(getContentResolver(), Settings.Global.LOW_POWER_MODE, if (on) 1 else 0) - (findViewById(R.id.toggle_battery_saving_mode) as Button).setText( + (requireViewById(R.id.toggle_battery_saving_mode) as Button).setText( if (on) "Exit low power mode" else "Enter low power mode") } @@ -182,7 +182,7 @@ class BackgroundBlurActivity : Activity(), SeekBar.OnSeekBarChangeListener { } else { mAlphaNoBlur = alpha } - (findViewById(R.id.background_alpha) as TextView).setText("%.2f".format(alpha)) + (requireViewById(R.id.background_alpha) as TextView).setText("%.2f".format(alpha)) mBackgroundDrawable.setAlpha((alpha * 255f).toInt()) getWindowManager().updateViewLayout(window.getDecorView(), window.getAttributes()) }