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

Commit cdbb4e41 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Add help/error msg for ProgressViewModel"

parents eb74256e 822c5bac
Loading
Loading
Loading
Loading
+52 −0
Original line number Diff line number Diff line
/*
 * 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.biometrics2.ui.model;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

/**
 * Enrolling status message (help or error)
 */
public final class EnrollmentStatusMessage {

    private final int mMsgId;
    @NonNull private final CharSequence mStr;

    public EnrollmentStatusMessage(int msgId, @Nullable CharSequence str) {
        mMsgId = msgId;
        mStr = str != null ? str : "";
    }

    public int getMsgId() {
        return mMsgId;
    }

    @Override
    public String toString() {
        return getClass().getSimpleName() + "@" + Integer.toHexString(hashCode())
                + "{id:" + mMsgId + ", str:" + mStr + "}";
    }

    /**
     * Gets status string
     */
    @NonNull
    public CharSequence getStr() {
        return mStr;
    }
}
+25 −11
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ import com.android.settings.R;
import com.android.settings.biometrics.fingerprint.FingerprintUpdater;
import com.android.settings.biometrics.fingerprint.MessageDisplayController;
import com.android.settings.biometrics2.ui.model.EnrollmentProgress;
import com.android.settings.biometrics2.ui.model.EnrollmentStatusMessage;

/**
 * Progress ViewModel handles the state around biometric enrollment. It manages the state of
@@ -51,6 +52,10 @@ public class FingerprintEnrollProgressViewModel extends AndroidViewModel {

    private final MutableLiveData<EnrollmentProgress> mProgressLiveData = new MutableLiveData<>(
            new EnrollmentProgress(INITIAL_STEPS, INITIAL_REMAINING));
    private final MutableLiveData<EnrollmentStatusMessage> mHelpMessageLiveData =
            new MutableLiveData<>();
    private final MutableLiveData<EnrollmentStatusMessage> mErrorMessageLiveData =
            new MutableLiveData<>();

    private byte[] mToken = null;
    private int mUserId = UserHandle.myUserId();
@@ -75,12 +80,12 @@ public class FingerprintEnrollProgressViewModel extends AndroidViewModel {

        @Override
        public void onEnrollmentHelp(int helpMsgId, CharSequence helpString) {
            // TODO add LiveData for help message during implementing b/260957933
            mHelpMessageLiveData.postValue(new EnrollmentStatusMessage(helpMsgId, helpString));
        }

        @Override
        public void onEnrollmentError(int errMsgId, CharSequence errString) {
            // TODO add LiveData for error message during implementing b/260957933
            mErrorMessageLiveData.postValue(new EnrollmentStatusMessage(errMsgId, errString));
        }
    };

@@ -99,7 +104,8 @@ public class FingerprintEnrollProgressViewModel extends AndroidViewModel {
                                res.getInteger(R.integer.enrollment_progress_minimum_time_display),
                                res.getBoolean(R.bool.enrollment_progress_priority_over_help),
                                res.getBoolean(R.bool.enrollment_prioritize_acquire_messages),
                        res.getInteger(R.integer.enrollment_collect_time)) : null;
                                res.getInteger(R.integer.enrollment_collect_time))
                        : null;
    }

    public void setToken(byte[] token) {
@@ -121,6 +127,14 @@ public class FingerprintEnrollProgressViewModel extends AndroidViewModel {
        return mProgressLiveData;
    }

    public LiveData<EnrollmentStatusMessage> getHelpMessageLiveData() {
        return mHelpMessageLiveData;
    }

    public LiveData<EnrollmentStatusMessage> getErrorMessageLiveData() {
        return mErrorMessageLiveData;
    }

    /**
     * Starts enrollment and return latest isEnrolling() result
     */