The open source OpenXR runtime

t/android_common: Fix lint errors for !! usages

The lint doesn't recommend us to use someVariable!!,
and we can use built-in Kotlin's requireNotNull and with
scope function to use variables without errors.

Signed-off-by: utzcoz <utzcoz@outlook.com>
Part-of: <https://gitlab.freedesktop.org/monado/monado/-/merge_requests/2382>

authored by

utzcoz and committed by
korejan
4f3c9bb2 ab48d417

+32 -26
+20 -16
src/xrt/targets/android_common/src/main/java/org/freedesktop/monado/android_common/DisplayOverOtherAppsStatusFragment.kt
··· 43 43 44 44 private fun updateStatus(view: View?) { 45 45 displayOverOtherAppsEnabled = Settings.canDrawOverlays(requireContext()) 46 - val tv = view!!.findViewById<TextView>(R.id.textDisplayOverOtherAppsStatus) 47 - // Combining format with html style tag might have problem. See 48 - // https://developer.android.com/guide/topics/resources/string-resource.html#StylingWithHTML 49 - val msg = 50 - getString( 51 - R.string.msg_display_over_other_apps, 52 - if (displayOverOtherAppsEnabled) getString(R.string.enabled) 53 - else getString(R.string.disabled), 54 - ) 55 - tv.text = Html.fromHtml(msg, Html.FROM_HTML_MODE_LEGACY) 46 + with(requireNotNull(view)) { 47 + val tv = this.findViewById<TextView>(R.id.textDisplayOverOtherAppsStatus) 48 + // Combining format with html style tag might have problem. See 49 + // https://developer.android.com/guide/topics/resources/string-resource.html#StylingWithHTML 50 + val msg = 51 + getString( 52 + R.string.msg_display_over_other_apps, 53 + if (displayOverOtherAppsEnabled) getString(R.string.enabled) 54 + else getString(R.string.disabled), 55 + ) 56 + tv.text = Html.fromHtml(msg, Html.FROM_HTML_MODE_LEGACY) 57 + } 56 58 } 57 59 58 60 private fun launchDisplayOverOtherAppsSettings() { 59 61 // Since Android 11, framework ignores the uri and takes user to the top-level settings. 60 62 // See https://developer.android.com/about/versions/11/privacy/permissions#system-alert 61 63 // for detail. 62 - val intent = 63 - Intent( 64 - Settings.ACTION_MANAGE_OVERLAY_PERMISSION, 65 - Uri.parse("package:" + context!!.packageName), 66 - ) 67 - startActivityForResult(intent, REQUEST_CODE_DISPLAY_OVER_OTHER_APPS) 64 + with(requireNotNull(context)) { 65 + val intent = 66 + Intent( 67 + Settings.ACTION_MANAGE_OVERLAY_PERMISSION, 68 + Uri.parse("package:" + this.packageName), 69 + ) 70 + startActivityForResult(intent, REQUEST_CODE_DISPLAY_OVER_OTHER_APPS) 71 + } 68 72 } 69 73 70 74 override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
+12 -10
src/xrt/targets/android_common/src/main/java/org/freedesktop/monado/android_common/RestartRuntimeDialogFragment.kt
··· 22 22 class RestartRuntimeDialogFragment : DialogFragment() { 23 23 24 24 override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { 25 - val message = arguments!!.getString(ARGS_KEY_MESSAGE) 26 - val builder = AlertDialog.Builder(requireActivity()) 27 - builder.setMessage(message).setCancelable(false).setPositiveButton(R.string.restart) { 28 - _: DialogInterface?, 29 - _: Int -> 30 - delayRestart(DELAY_RESTART_DURATION) 31 - // ! @todo elegant way to stop service? A bounded service might be restarted by 32 - // framework automatically. 33 - Process.killProcess(Process.myPid()) 25 + with(requireNotNull(arguments)) { 26 + val message = this.getString(ARGS_KEY_MESSAGE) 27 + val builder = AlertDialog.Builder(requireActivity()) 28 + builder.setMessage(message).setCancelable(false).setPositiveButton(R.string.restart) { 29 + _: DialogInterface?, 30 + _: Int -> 31 + delayRestart(DELAY_RESTART_DURATION) 32 + // ! @todo elegant way to stop service? A bounded service might be restarted by 33 + // framework automatically. 34 + Process.killProcess(Process.myPid()) 35 + } 36 + return builder.create() 34 37 } 35 - return builder.create() 36 38 } 37 39 38 40 private fun delayRestart(delayMillis: Long) {