| /* | |
| * Copyright (C) 2026 The Android Open Source Project | |
| * | |
| * Licensed under the Apache License, Version 2.0 (the "License"); | |
| * you may not use this file except in compliance with the License. | |
| * You may obtain a copy of the License at | |
| * | |
| * http://www.apache.org/licenses/LICENSE-2.0 | |
| * | |
| * Unless required by applicable law or agreed to in writing, software | |
| * distributed under the License is distributed on an "AS IS" BASIS, | |
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| * See the License for the specific language governing permissions and | |
| * limitations under the License. | |
| */ | |
| package com.android.settings.binarytransparency | |
| import android.content.Context | |
| import android.os.Bundle | |
| import androidx.preference.Preference | |
| import androidx.preference.PreferenceCategory | |
| import com.android.settings.R | |
| import com.android.settings.binarytransparency.DeviceIdentifierFragment.DeviceIdentifier | |
| import com.android.settings.core.BasePreferenceController | |
| import java.util.Locale | |
| class DeviceIdentifierPreferenceController(context: Context, key: String) : | |
| BasePreferenceController(context, key) { | |
| private var deviceIdentifiers: Bundle? = null | |
| private val context: Context = context | |
| override fun getAvailabilityStatus(): Int = AVAILABLE | |
| fun setDeviceIdentifiersBundle(deviceIdentifiers: Bundle?) { | |
| this.deviceIdentifiers = deviceIdentifiers | |
| } | |
| override fun updateState(preference: Preference) { | |
| val preferenceCategory = preference as PreferenceCategory | |
| for (deviceIdentifier in DeviceIdentifier.values()) { | |
| val entryKey = deviceIdentifier.representation | |
| val entryTitle = context.getString(deviceIdentifier.titleResId) | |
| val entrySummary = | |
| deviceIdentifiers | |
| ?.getString(entryKey) | |
| ?.takeUnless { it.isBlank() } | |
| ?.replaceFirstChar { it.titlecase(Locale.getDefault()) } | |
| ?: context.getString(R.string.abt_device_no_information_available) | |
| val existingPref = preferenceCategory.findPreference<Preference>(entryKey) | |
| if (existingPref != null) { | |
| existingPref.summary = | |
| if (entryKey == "imei") { | |
| AccessibilityUtils.getAccessibleImeiSummary(context, entrySummary) | |
| } else { | |
| entrySummary | |
| } | |
| } else { | |
| preferenceCategory.addPreference( | |
| Preference(context).apply { | |
| key = entryKey | |
| title = entryTitle | |
| summary = | |
| if (entryKey == "imei") { | |
| AccessibilityUtils.getAccessibleImeiSummary(context, entrySummary) | |
| } else { | |
| entrySummary | |
| } | |
| isSelectable = false | |
| } | |
| ) | |
| } | |
| } | |
| super.updateState(preference) | |
| } | |
| } |