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

Commit b7480f67 authored by Bonian Chen's avatar Bonian Chen Committed by Android (Google) Code Review
Browse files

Merge "[Settings] Add QR code for EID and enable text copy"

parents 7d0f2b7e 6a383db7
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@

<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
    <LinearLayout
@@ -168,6 +169,11 @@
            android:layout_height="wrap_content"
            android:textIsSelectable="true"
            android:text="@string/device_info_not_available"/>
        <ImageView
            android:id="@+id/esim_id_qrcode"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            tools:ignore="ContentDescription" />

        <TextView
            style="@style/device_info_dialog_label"
+32 −5
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.annotation.Nullable;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.ServiceConnection;
@@ -72,7 +73,8 @@ import java.util.concurrent.atomic.AtomicReference;
/**
 * Controller for Sim Status information within the About Phone Settings page.
 */
public class SimStatusDialogController implements LifecycleObserver {
public class SimStatusDialogController implements LifecycleObserver,
        DialogInterface.OnShowListener {

    private final static String TAG = "SimStatusDialogCtrl";

@@ -107,6 +109,8 @@ public class SimStatusDialogController implements LifecycleObserver {
    @VisibleForTesting
    final static int EID_INFO_VALUE_ID = R.id.esim_id_value;
    @VisibleForTesting
    final static int EID_INFO_QRCODE_ID = R.id.esim_id_qrcode;
    @VisibleForTesting
    final static int IMS_REGISTRATION_STATE_LABEL_ID = R.id.ims_reg_state_label;
    @VisibleForTesting
    final static int IMS_REGISTRATION_STATE_VALUE_ID = R.id.ims_reg_state_value;
@@ -158,6 +162,7 @@ public class SimStatusDialogController implements LifecycleObserver {

    private boolean mShowLatestAreaInfo;
    private boolean mIsRegisteredListener = false;
    private AtomicReference<String> mEid = null;

    private final BroadcastReceiver mAreaInfoReceiver = new BroadcastReceiver() {
        @Override
@@ -263,6 +268,19 @@ public class SimStatusDialogController implements LifecycleObserver {
        updateImsRegistrationState();
    }

    /**
     * Callback when dialog end of show().
     */
    public void onShow(DialogInterface dialog) {
        if (mEid != null) {
            String eidText = mEid.get();
            if (eidText != null) {
                // Present QR code after the completion of layout
                mDialog.setQrCode(EID_INFO_QRCODE_ID, eidText);
            }
        }
    }

    /**
     * Deinitialization works
     */
@@ -618,8 +636,8 @@ public class SimStatusDialogController implements LifecycleObserver {
    @VisibleForTesting
    protected void requestForUpdateEid() {
        ThreadUtils.postOnBackgroundThread(() -> {
            final AtomicReference<String> eid = getEid(mSlotIndex);
            ThreadUtils.postOnMainThread(() -> updateEid(eid));
            mEid = getEid(mSlotIndex);
            ThreadUtils.postOnMainThread(() -> updateEid(mEid));
        });
    }

@@ -663,11 +681,20 @@ public class SimStatusDialogController implements LifecycleObserver {

    @VisibleForTesting
    protected void updateEid(AtomicReference<String> eid) {
        boolean removeQrCode = true;
        if (eid == null) {
            mDialog.removeSettingFromScreen(EID_INFO_LABEL_ID);
            mDialog.removeSettingFromScreen(EID_INFO_VALUE_ID);
        } else if (eid.get() != null) {
            mDialog.setText(EID_INFO_VALUE_ID, eid.get());
            mDialog.removeSettingFromScreen(EID_INFO_QRCODE_ID);
        } else {
            String eidText = eid.get();
            if (eidText != null) {
                mDialog.setText(EID_INFO_VALUE_ID, eidText);
                removeQrCode = (eidText == "");
            }
        }
        if (removeQrCode) {
            mDialog.removeSettingFromScreen(EID_INFO_QRCODE_ID);
        }
    }

+25 −0
Original line number Diff line number Diff line
@@ -19,11 +19,14 @@ package com.android.settings.deviceinfo.simstatus;
import android.app.Dialog;
import android.app.settings.SettingsEnums;
import android.os.Bundle;
import android.graphics.Bitmap;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;
import android.util.Log;

import androidx.appcompat.app.AlertDialog;
import androidx.fragment.app.Fragment;
@@ -32,6 +35,7 @@ import androidx.fragment.app.FragmentManager;
import com.android.settings.R;
import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
import com.android.settings.deviceinfo.PhoneNumberUtil;
import com.android.settingslib.qrcode.QrCodeGenerator;

import java.util.Arrays;
import java.util.stream.IntStream;
@@ -80,6 +84,7 @@ public class SimStatusDialogFragment extends InstrumentedDialogFragment {
        Dialog dlg = builder.setView(mRootView).create();
        dlg.getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE,
                WindowManager.LayoutParams.FLAG_SECURE);
        dlg.setOnShowListener(mController);

        return dlg;
    }
@@ -107,6 +112,10 @@ public class SimStatusDialogFragment extends InstrumentedDialogFragment {
            .sorted().toArray();

    public void setText(int viewId, CharSequence text) {
        setText(viewId, text, true);
    }

    public void setText(int viewId, CharSequence text, boolean enableCopy) {
        final TextView textView = mRootView.findViewById(viewId);
        if (textView == null) {
            return;
@@ -117,5 +126,21 @@ public class SimStatusDialogFragment extends InstrumentedDialogFragment {
            text = PhoneNumberUtil.expandByTts(text);
        }
        textView.setText(text);
        textView.setTextIsSelectable(enableCopy);
    }

    public void setQrCode(int viewId, String qrcodeText) {
        ImageView qrCodeView = (ImageView) mRootView.findViewById(viewId);

        Bitmap qrCodeBitmap = null;
        try {
            qrCodeBitmap = QrCodeGenerator.encodeQrCode(qrcodeText, qrCodeView.getWidth());
        } catch (Exception exception) {
            Log.w(TAG, "Error when presenting QR code in + " + qrCodeView, exception);
        }
        if (qrCodeBitmap == null) {
            return;
        }
        qrCodeView.setImageBitmap(qrCodeBitmap);
    }
}