Fix kotlin nullable errors in Settings

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: I6aa0516fa4f6443b6d4dff873baf3b08ff9189f0
This commit is contained in:
Colin Cross
2023-08-14 12:29:02 -07:00
parent beea9e488d
commit 87b870a090
12 changed files with 25 additions and 23 deletions

View File

@@ -46,7 +46,7 @@ class RegulatoryInfoDisplayActivity : Activity() {
getRegulatoryInfo()?.let { getRegulatoryInfo()?.let {
val view = layoutInflater.inflate(R.layout.regulatory_info, null) val view = layoutInflater.inflate(R.layout.regulatory_info, null)
val image = view.findViewById<ImageView>(R.id.regulatoryInfo) val image = view.requireViewById<ImageView>(R.id.regulatoryInfo)
image.setImageDrawable(it) image.setImageDrawable(it)
builder.setView(view) builder.setView(view)
builder.show() builder.show()

View File

@@ -106,8 +106,8 @@ class FingerprintSettingsRenameDialog : InstrumentedDialogFragment() {
val dialog = FingerprintSettingsRenameDialog() val dialog = FingerprintSettingsRenameDialog()
val onClick = val onClick =
DialogInterface.OnClickListener { _, _ -> DialogInterface.OnClickListener { _, _ ->
val dialogTextField = val dialogTextField = dialog.requireDialog()
dialog.requireDialog().findViewById(R.id.fingerprint_rename_field) as ImeAwareEditText .requireViewById(R.id.fingerprint_rename_field) as ImeAwareEditText
val newName = dialogTextField.text.toString() val newName = dialogTextField.text.toString()
if (!TextUtils.equals(newName, fp.name)) { if (!TextUtils.equals(newName, fp.name)) {
Log.d(TAG, "rename $fp.name to $newName for $dialog") Log.d(TAG, "rename $fp.name to $newName for $dialog")

View File

@@ -205,8 +205,8 @@ class FingerprintEnrollIntroFragment : Fragment() {
private fun getDescriptionDisabledByAdmin(context: Context): String? { private fun getDescriptionDisabledByAdmin(context: Context): String? {
val defaultStrId: Int = val defaultStrId: Int =
R.string.security_settings_fingerprint_enroll_introduction_message_unlock_disabled R.string.security_settings_fingerprint_enroll_introduction_message_unlock_disabled
val devicePolicyManager: DevicePolicyManager = requireActivity() val devicePolicyManager: DevicePolicyManager =
.getSystemService(DevicePolicyManager::class.java) checkNotNull(requireActivity().getSystemService(DevicePolicyManager::class.java))
return devicePolicyManager.resources.getString(FINGERPRINT_UNLOCK_DISABLED) { return devicePolicyManager.resources.getString(FINGERPRINT_UNLOCK_DISABLED) {
context.getString(defaultStrId) context.getString(defaultStrId)
@@ -234,7 +234,7 @@ class FingerprintEnrollIntroFragment : Fragment() {
else else
View.INVISIBLE View.INVISIBLE
view!!.findViewById<TextView>(R.id.error_text).let { view!!.requireViewById<TextView>(R.id.error_text).let {
when (status.enrollableStatus) { when (status.enrollableStatus) {
FINGERPRINT_ENROLLABLE_OK -> { FINGERPRINT_ENROLLABLE_OK -> {
it.text = null it.text = null

View File

@@ -95,10 +95,10 @@ class SimEidPreferenceController(context: Context, preferenceKey: String) :
WindowManager.LayoutParams.FLAG_SECURE WindowManager.LayoutParams.FLAG_SECURE
) )
dialog.setCanceledOnTouchOutside(false) dialog.setCanceledOnTouchOutside(false)
val textView = dialog.findViewById<TextView>(R.id.esim_id_value) val textView = dialog.requireViewById<TextView>(R.id.esim_id_value)
textView.text = PhoneNumberUtil.expandByTts(eid) textView.text = PhoneNumberUtil.expandByTts(eid)
val qrCodeView = dialog.findViewById<ImageView>(R.id.esim_id_qrcode) val qrCodeView = dialog.requireViewById<ImageView>(R.id.esim_id_qrcode)
qrCodeView.setImageBitmap(getEidQrCode(eid)) qrCodeView.setImageBitmap(getEidQrCode(eid))
// After "Tap to show", eid is displayed on preference. // After "Tap to show", eid is displayed on preference.

View File

@@ -81,7 +81,7 @@ class FullScreenIntentPermissionPreferenceController(
private fun isPermissionRequested(): Boolean { private fun isPermissionRequested(): Boolean {
val packageInfo = packageManager.getPackageInfo(packageName, GET_PERMISSIONS) val packageInfo = packageManager.getPackageInfo(packageName, GET_PERMISSIONS)
for (requestedPermission in packageInfo.requestedPermissions) { for (requestedPermission in packageInfo.requestedPermissions.orEmpty()) {
if (USE_FULL_SCREEN_INTENT.equals(requestedPermission)) { if (USE_FULL_SCREEN_INTENT.equals(requestedPermission)) {
return true return true
} }

View File

@@ -65,7 +65,7 @@ abstract class RemoteAuthEnrollBase(
abstract fun initializeSecondaryFooterButton(): FooterButton? abstract fun initializeSecondaryFooterButton(): FooterButton?
private fun initializeFooterbarMixin(view: View) { private fun initializeFooterbarMixin(view: View) {
val footerBarMixin = getGlifLayout(view).getMixin(FooterBarMixin::class.java) val footerBarMixin = checkNotNull(getGlifLayout(view)).getMixin(FooterBarMixin::class.java)
primaryFooterButton.also { footerBarMixin.primaryButton = it } primaryFooterButton.also { footerBarMixin.primaryButton = it }
secondaryFooterButton?.also { footerBarMixin.secondaryButton = it } secondaryFooterButton?.also { footerBarMixin.secondaryButton = it }
footerBarMixin.getButtonContainer().setBackgroundColor(getBackgroundColor()) footerBarMixin.getButtonContainer().setBackgroundColor(getBackgroundColor())

View File

@@ -38,13 +38,15 @@ import com.android.settings.R
import com.android.settingslib.widget.LottieColorUtils import com.android.settingslib.widget.LottieColorUtils
class IntroductionImageCarousel : ConstraintLayout { class IntroductionImageCarousel : ConstraintLayout {
private val carousel: ViewPager2 by lazy { findViewById<ViewPager2>(R.id.image_carousel) } private val carousel: ViewPager2 by lazy { requireViewById<ViewPager2>(R.id.image_carousel) }
private val progressIndicator: RecyclerView by lazy { private val progressIndicator: RecyclerView by lazy {
findViewById<RecyclerView>(R.id.carousel_progress_indicator) requireViewById<RecyclerView>(R.id.carousel_progress_indicator)
}
private val backArrow: ImageView by lazy {
requireViewById<ImageView>(R.id.carousel_back_arrow)
} }
private val backArrow: ImageView by lazy { findViewById<ImageView>(R.id.carousel_back_arrow) }
private val forwardArrow: ImageView by lazy { private val forwardArrow: ImageView by lazy {
findViewById<ImageView>(R.id.carousel_forward_arrow) requireViewById<ImageView>(R.id.carousel_forward_arrow)
} }
private val progressIndicatorAdapter = ProgressIndicatorAdapter() private val progressIndicatorAdapter = ProgressIndicatorAdapter()
// The index of the current animation we are on // The index of the current animation we are on

View File

@@ -71,7 +71,7 @@ class RemoteAuthEnrollIntroduction :
} }
private fun initializeRequireScrollMixin(view: View) { private fun initializeRequireScrollMixin(view: View) {
val layout = getGlifLayout(view) val layout = checkNotNull(getGlifLayout(view))
secondaryFooterButton?.visibility = View.INVISIBLE secondaryFooterButton?.visibility = View.INVISIBLE
val requireScrollMixin = layout.getMixin(RequireScrollMixin::class.java) val requireScrollMixin = layout.getMixin(RequireScrollMixin::class.java)
requireScrollMixin.requireScrollWithButton(requireContext(), primaryFooterButton, requireScrollMixin.requireScrollWithButton(requireContext(), primaryFooterButton,

View File

@@ -45,7 +45,7 @@ private class AppButtonsPresenter(private val packageInfoPresenter: PackageInfoP
@Composable @Composable
fun getActionButtons() = fun getActionButtons() =
packageInfoPresenter.flow.collectAsStateWithLifecycle(initialValue = null).value?.let { packageInfoPresenter.flow.collectAsStateWithLifecycle(initialValue = null).value?.let {
getActionButtons(it.applicationInfo) getActionButtons(checkNotNull(it.applicationInfo))
} ?: emptyList() } ?: emptyList()
@Composable @Composable

View File

@@ -118,7 +118,7 @@ object AppInfoSettingsProvider : SettingsPageProvider {
private fun AppInfoSettings(packageInfoPresenter: PackageInfoPresenter) { private fun AppInfoSettings(packageInfoPresenter: PackageInfoPresenter) {
LifecycleEffect(onStart = { packageInfoPresenter.reloadPackageInfo() }) LifecycleEffect(onStart = { packageInfoPresenter.reloadPackageInfo() })
val packageInfo = packageInfoPresenter.flow.collectAsStateWithLifecycle().value ?: return val packageInfo = packageInfoPresenter.flow.collectAsStateWithLifecycle().value ?: return
val app = packageInfo.applicationInfo val app = checkNotNull(packageInfo.applicationInfo)
RegularScaffold( RegularScaffold(
title = stringResource(R.string.application_info_label), title = stringResource(R.string.application_info_label),
actions = { actions = {

View File

@@ -41,7 +41,7 @@ private class CloneAppButtonsPresenter(private val packageInfoPresenter: Package
@Composable @Composable
fun getActionButtons() = fun getActionButtons() =
packageInfoPresenter.flow.collectAsStateWithLifecycle(initialValue = null).value?.let { packageInfoPresenter.flow.collectAsStateWithLifecycle(initialValue = null).value?.let {
getActionButtons(it.applicationInfo) getActionButtons(checkNotNull(it.applicationInfo))
} ?: emptyList() } ?: emptyList()
@Composable @Composable

View File

@@ -77,7 +77,7 @@ class PackageInfoPresenter(
DisposableBroadcastReceiverAsUser(intentFilter, userHandle) { intent -> DisposableBroadcastReceiverAsUser(intentFilter, userHandle) { intent ->
if (packageName == intent.data?.schemeSpecificPart) { if (packageName == intent.data?.schemeSpecificPart) {
val packageInfo = flow.value val packageInfo = flow.value
if (packageInfo != null && packageInfo.applicationInfo.isSystemApp) { if (packageInfo != null && packageInfo.applicationInfo?.isSystemApp == true) {
// System app still exists after uninstalling the updates, refresh the page. // System app still exists after uninstalling the updates, refresh the page.
reloadPackageInfo() reloadPackageInfo()
} else { } else {