Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6d8fb06a authored by zhibinliu's avatar zhibinliu
Browse files

[Catalyst] Migrate EID preference

Created a dedicated preference class to avoid creating duplicate Dialogs.
Created a dedicated dialog class

Bug: b/389127983
Flag: com.android.settings.flags.catalyst_my_device_info_pref_screen
Test: manual, atest MyDeviceInfoFragmentTest, atest MyDeviceInfoScreenTest, atest SimEidDialogFragmentTest, atest SimEidPreferenceTest
Change-Id: Id0d5eefcedbde38f3898959c3aaae9249f7a5254
parent 63f3ebd0
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -116,7 +116,7 @@
            settings:controller="com.android.settings.deviceinfo.HardwareInfoPreferenceController"/>

        <!-- EID -->
        <com.android.settingslib.CustomDialogPreferenceCompat
        <com.android.settings.deviceinfo.simstatus.SimEidInfoPreference
            android:key="eid_info"
            android:order="31"
            android:title="@string/status_eid"
+9 −6
Original line number Diff line number Diff line
@@ -156,10 +156,13 @@ public class MyDeviceInfoFragment extends DashboardFragment
            }
        }

        if (!Flags.catalystMyDeviceInfoPrefScreen()) {
            EidStatus eidStatus = new EidStatus(slotSimStatus, context, executor);
        SimEidPreferenceController simEid = new SimEidPreferenceController(context, KEY_EID_INFO);
            SimEidPreferenceController simEid = new SimEidPreferenceController(context,
                    KEY_EID_INFO);
            simEid.init(slotSimStatus, eidStatus);
            controllers.add(simEid);
        }

        if (executor != null) {
            executor.shutdown();
+2 −0
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import android.os.Build
import android.provider.Settings
import com.android.settings.R
import com.android.settings.deviceinfo.imei.ImeiPreference
import com.android.settings.deviceinfo.simstatus.SimEidPreference
import com.android.settings.flags.Flags
import com.android.settings.wifi.utils.activeModemCount
import com.android.settingslib.metadata.PreferenceCategory
@@ -61,6 +62,7 @@ class MyDeviceInfoScreen :
            "device_detail_category",
            R.string.my_device_info_device_details_category_title,
        ) += {
            +SimEidPreference(context) order 31
            val activeModemCount = context.activeModemCount
            for (i in 0 until activeModemCount) {
                +ImeiPreference(context, i, activeModemCount) order (i + 33)
+4 −1
Original line number Diff line number Diff line
@@ -22,6 +22,9 @@ import android.telephony.TelephonyManager;
import android.telephony.UiccCardInfo;
import android.telephony.euicc.EuiccManager;
import android.text.TextUtils;

import androidx.annotation.Nullable;

import java.util.Arrays;
import java.util.List;
import java.util.Objects;
@@ -55,7 +58,7 @@ public class EidStatus {
     * @param context Context
     * @param executor executor for offload to thread
     */
    public EidStatus(SlotSimStatus slotSimStatus, Context context, Executor executor) {
    public EidStatus(SlotSimStatus slotSimStatus, Context context, @Nullable Executor executor) {
        mSlotSimStatus = slotSimStatus;

        if (executor == null) {
+98 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2017 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.deviceinfo.simstatus

import android.R
import android.app.Dialog
import android.graphics.Bitmap
import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.WindowManager
import android.widget.ImageView
import android.widget.TextView
import androidx.appcompat.app.AlertDialog
import androidx.fragment.app.FragmentManager
import com.android.settings.core.instrumentation.InstrumentedDialogFragment
import com.android.settings.deviceinfo.PhoneNumberUtil
import com.android.settingslib.qrcode.QrCodeGenerator

class SimEidDialogFragment : InstrumentedDialogFragment() {
    private var mRootView: View? = null

    override fun getMetricsCategory(): Int {
        return 0
    }

    override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
        val bundle = requireArguments()
        val dialogTitle = bundle.getString(DIALOG_TITLE_BUNDLE_KEY)
        val eid = bundle.getString(SIM_EID_BUNDLE_KEY)!!
        val builder = AlertDialog.Builder(requireActivity())
            .setTitle(dialogTitle)
            .setPositiveButton(R.string.ok, null /* onClickListener */)
        mRootView = LayoutInflater.from(builder.context)
            .inflate(com.android.settings.R.layout.dialog_eid_status, null /* parent */)

        val dialog = builder.setView(mRootView).create()
        dialog.window!!.setFlags(
            WindowManager.LayoutParams.FLAG_SECURE,
            WindowManager.LayoutParams.FLAG_SECURE
        )
        dialog.setCanceledOnTouchOutside(false)
        val textView = mRootView!!.requireViewById<TextView>(com.android.settings.R.id.esim_id_value)
        textView.text = PhoneNumberUtil.expandByTts(eid)

        val qrCodeView = mRootView!!.requireViewById<ImageView>(com.android.settings.R.id.esim_id_qrcode)
        qrCodeView.setImageBitmap(getEidQrCode(eid))

        return dialog
    }

    companion object {
        private const val SIM_EID_BUNDLE_KEY = "arg_key_sim_eid"
        private const val DIALOG_TITLE_BUNDLE_KEY = "arg_key_dialog_title"

        private const val TAG = "SimEidDialogFragment"
        private const val QR_CODE_SIZE = 600

        fun show(manager: FragmentManager, title: String, eid: String) {
            if (manager.findFragmentByTag(TAG) == null) {
                val bundle = Bundle()
                bundle.putString(SIM_EID_BUNDLE_KEY, eid)
                bundle.putString(DIALOG_TITLE_BUNDLE_KEY, title)
                val dialog = SimEidDialogFragment()
                dialog.setArguments(bundle)
                dialog.show(manager, TAG)
            }
        }

        /**
         * Gets the QR code for EID
         * @param eid is the EID string
         * @return a Bitmap of QR code
         */
        private fun getEidQrCode(eid: String): Bitmap? {
            return try {
                QrCodeGenerator.encodeQrCode(contents = eid, size = QR_CODE_SIZE)
            } catch (exception: Exception) {
                Log.w(TAG, "Error when creating QR code width $QR_CODE_SIZE", exception)
                null
            }
        }
    }
}
Loading