Async load eid in SimEidPreferenceController am: d3cc9b20e4
Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Settings/+/25498123 Change-Id: I32a34923fdf9943a51bce3571977a328e33b3a97 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -114,7 +114,7 @@
|
|||||||
settings:controller="com.android.settings.deviceinfo.HardwareInfoPreferenceController"/>
|
settings:controller="com.android.settings.deviceinfo.HardwareInfoPreferenceController"/>
|
||||||
|
|
||||||
<!-- EID -->
|
<!-- EID -->
|
||||||
<com.android.settings.network.telephony.TelephonyPreferenceDialog
|
<com.android.settingslib.CustomDialogPreferenceCompat
|
||||||
android:key="eid_info"
|
android:key="eid_info"
|
||||||
android:order="31"
|
android:order="31"
|
||||||
android:title="@string/status_eid"
|
android:title="@string/status_eid"
|
||||||
|
@@ -21,16 +21,24 @@ import android.util.Log
|
|||||||
import android.view.WindowManager
|
import android.view.WindowManager
|
||||||
import android.widget.ImageView
|
import android.widget.ImageView
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
|
import androidx.lifecycle.Lifecycle
|
||||||
|
import androidx.lifecycle.LifecycleOwner
|
||||||
|
import androidx.lifecycle.lifecycleScope
|
||||||
|
import androidx.lifecycle.repeatOnLifecycle
|
||||||
import androidx.preference.Preference
|
import androidx.preference.Preference
|
||||||
import androidx.preference.PreferenceScreen
|
import androidx.preference.PreferenceScreen
|
||||||
import com.android.settings.R
|
import com.android.settings.R
|
||||||
import com.android.settings.core.BasePreferenceController
|
import com.android.settings.core.BasePreferenceController
|
||||||
import com.android.settings.deviceinfo.PhoneNumberUtil
|
import com.android.settings.deviceinfo.PhoneNumberUtil
|
||||||
import com.android.settings.network.SubscriptionUtil
|
import com.android.settings.network.SubscriptionUtil
|
||||||
import com.android.settings.network.telephony.TelephonyPreferenceDialog
|
import com.android.settingslib.CustomDialogPreferenceCompat
|
||||||
import com.android.settingslib.Utils
|
import com.android.settingslib.Utils
|
||||||
import com.android.settingslib.qrcode.QrCodeGenerator
|
import com.android.settingslib.qrcode.QrCodeGenerator
|
||||||
import com.android.settingslib.spaprivileged.framework.common.userManager
|
import com.android.settingslib.spaprivileged.framework.common.userManager
|
||||||
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is to show a preference regarding EID of SIM card.
|
* This is to show a preference regarding EID of SIM card.
|
||||||
@@ -41,7 +49,8 @@ class SimEidPreferenceController(context: Context, preferenceKey: String) :
|
|||||||
BasePreferenceController(context, preferenceKey) {
|
BasePreferenceController(context, preferenceKey) {
|
||||||
private var slotSimStatus: SlotSimStatus? = null
|
private var slotSimStatus: SlotSimStatus? = null
|
||||||
private var eidStatus: EidStatus? = null
|
private var eidStatus: EidStatus? = null
|
||||||
private lateinit var preference: TelephonyPreferenceDialog
|
private lateinit var preference: CustomDialogPreferenceCompat
|
||||||
|
private var coroutineScope: CoroutineScope? = null
|
||||||
private lateinit var eid: String
|
private lateinit var eid: String
|
||||||
|
|
||||||
fun init(slotSimStatus: SlotSimStatus?, eidStatus: EidStatus?) {
|
fun init(slotSimStatus: SlotSimStatus?, eidStatus: EidStatus?) {
|
||||||
@@ -49,21 +58,51 @@ class SimEidPreferenceController(context: Context, preferenceKey: String) :
|
|||||||
this.eidStatus = eidStatus
|
this.eidStatus = eidStatus
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getAvailabilityStatus(): Int {
|
/**
|
||||||
if (!SubscriptionUtil.isSimHardwareVisible(mContext)) return UNSUPPORTED_ON_DEVICE
|
* Returns available here, but UI availability is retrieved asynchronously later.
|
||||||
eid = eidStatus?.eid ?: ""
|
*
|
||||||
val isAvailable = mContext.userManager.isAdminUser &&
|
* Check [updateNonIndexableKeys] for search availability.
|
||||||
!Utils.isWifiOnly(mContext) &&
|
*/
|
||||||
eid.isNotEmpty()
|
override fun getAvailabilityStatus() = AVAILABLE
|
||||||
return if (isAvailable) AVAILABLE else CONDITIONALLY_UNAVAILABLE
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun displayPreference(screen: PreferenceScreen) {
|
override fun displayPreference(screen: PreferenceScreen) {
|
||||||
super.displayPreference(screen)
|
super.displayPreference(screen)
|
||||||
preference = screen.findPreference(preferenceKey)!!
|
preference = screen.findPreference(preferenceKey)!!
|
||||||
val title = getTitle()
|
}
|
||||||
preference.title = title
|
|
||||||
preference.dialogTitle = title
|
override fun onViewCreated(viewLifecycleOwner: LifecycleOwner) {
|
||||||
|
coroutineScope = viewLifecycleOwner.lifecycleScope
|
||||||
|
coroutineScope?.launch {
|
||||||
|
viewLifecycleOwner.repeatOnLifecycle(Lifecycle.State.STARTED) {
|
||||||
|
update()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private suspend fun update() {
|
||||||
|
val isAvailable = withContext(Dispatchers.Default) {
|
||||||
|
getIsAvailableAndUpdateEid()
|
||||||
|
}
|
||||||
|
preference.isVisible = isAvailable
|
||||||
|
if (isAvailable) {
|
||||||
|
val title = withContext(Dispatchers.Default) {
|
||||||
|
getTitle()
|
||||||
|
}
|
||||||
|
preference.title = title
|
||||||
|
preference.dialogTitle = title
|
||||||
|
updateDialog()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getIsAvailableAndUpdateEid(): Boolean {
|
||||||
|
if (!SubscriptionUtil.isSimHardwareVisible(mContext) ||
|
||||||
|
!mContext.userManager.isAdminUser ||
|
||||||
|
Utils.isWifiOnly(mContext)
|
||||||
|
) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
eid = eidStatus?.eid ?: ""
|
||||||
|
return eid.isNotEmpty()
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Constructs title string. */
|
/** Constructs title string. */
|
||||||
@@ -82,13 +121,7 @@ class SimEidPreferenceController(context: Context, preferenceKey: String) :
|
|||||||
return mContext.getString(R.string.status_eid)
|
return mContext.getString(R.string.status_eid)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun updateState(preference: Preference?) {
|
private suspend fun updateDialog() {
|
||||||
super.updateState(preference)
|
|
||||||
|
|
||||||
updateDialog()
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun updateDialog() {
|
|
||||||
val dialog = preference.dialog ?: return
|
val dialog = preference.dialog ?: return
|
||||||
dialog.window?.setFlags(
|
dialog.window?.setFlags(
|
||||||
WindowManager.LayoutParams.FLAG_SECURE,
|
WindowManager.LayoutParams.FLAG_SECURE,
|
||||||
@@ -106,11 +139,17 @@ class SimEidPreferenceController(context: Context, preferenceKey: String) :
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun handlePreferenceTreeClick(preference: Preference): Boolean {
|
override fun handlePreferenceTreeClick(preference: Preference): Boolean {
|
||||||
if (preference.key == preferenceKey) {
|
if (preference.key != preferenceKey) return false
|
||||||
this.preference.setOnShowListener { updateDialog() }
|
this.preference.setOnShowListener {
|
||||||
return true
|
coroutineScope?.launch { updateDialog() }
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun updateNonIndexableKeys(keys: MutableList<String>) {
|
||||||
|
if (!getIsAvailableAndUpdateEid()) {
|
||||||
|
keys.add(preferenceKey)
|
||||||
}
|
}
|
||||||
return super.handlePreferenceTreeClick(preference)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
@@ -122,11 +161,13 @@ class SimEidPreferenceController(context: Context, preferenceKey: String) :
|
|||||||
* @param eid is the EID string
|
* @param eid is the EID string
|
||||||
* @return a Bitmap of QR code
|
* @return a Bitmap of QR code
|
||||||
*/
|
*/
|
||||||
private fun getEidQrCode(eid: String): Bitmap? = try {
|
private suspend fun getEidQrCode(eid: String): Bitmap? = withContext(Dispatchers.Default) {
|
||||||
QrCodeGenerator.encodeQrCode(eid, QR_CODE_SIZE)
|
try {
|
||||||
} catch (exception: Exception) {
|
QrCodeGenerator.encodeQrCode(contents = eid, size = QR_CODE_SIZE)
|
||||||
Log.w(TAG, "Error when creating QR code width $QR_CODE_SIZE", exception)
|
} catch (exception: Exception) {
|
||||||
null
|
Log.w(TAG, "Error when creating QR code width $QR_CODE_SIZE", exception)
|
||||||
|
null
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,44 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2022 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.network.telephony;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.util.AttributeSet;
|
|
||||||
import com.android.settingslib.CustomDialogPreferenceCompat;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This is DialogPreference for supporting connectivity features.
|
|
||||||
*/
|
|
||||||
public class TelephonyPreferenceDialog extends CustomDialogPreferenceCompat {
|
|
||||||
|
|
||||||
public TelephonyPreferenceDialog(Context context, AttributeSet attrs, int defStyleAttr,
|
|
||||||
int defStyleRes) {
|
|
||||||
super(context, attrs, defStyleAttr, defStyleRes);
|
|
||||||
}
|
|
||||||
|
|
||||||
public TelephonyPreferenceDialog(Context context, AttributeSet attrs, int defStyleAttr) {
|
|
||||||
super(context, attrs, defStyleAttr);
|
|
||||||
}
|
|
||||||
|
|
||||||
public TelephonyPreferenceDialog(Context context, AttributeSet attrs) {
|
|
||||||
super(context, attrs);
|
|
||||||
}
|
|
||||||
|
|
||||||
public TelephonyPreferenceDialog(Context context) {
|
|
||||||
super(context);
|
|
||||||
}
|
|
||||||
}
|
|
Reference in New Issue
Block a user