Merge "[BiometricsV2] Refactor model code to kotlin"
This commit is contained in:
committed by
Android (Google) Code Review
commit
12deec820f
@@ -1,197 +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.biometrics2.ui.model;
|
||||
|
||||
import static com.android.settings.biometrics.BiometricEnrollBase.EXTRA_KEY_CHALLENGE;
|
||||
import static com.android.settings.password.ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN;
|
||||
import static com.android.settings.password.ChooseLockSettingsHelper.EXTRA_KEY_GK_PW_HANDLE;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.UserHandle;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
|
||||
import java.time.Clock;
|
||||
|
||||
/**
|
||||
* Secret credential data including
|
||||
* 1. userId
|
||||
* 2. challenge
|
||||
* 3. token
|
||||
* 4. gkPwHandle
|
||||
*/
|
||||
public final class CredentialModel {
|
||||
|
||||
/**
|
||||
* Default value for an invalid challenge
|
||||
*/
|
||||
@VisibleForTesting
|
||||
public static final long INVALID_CHALLENGE = -1L;
|
||||
|
||||
/**
|
||||
* Default value if GkPwHandle is invalid.
|
||||
*/
|
||||
@VisibleForTesting
|
||||
public static final long INVALID_GK_PW_HANDLE = 0L;
|
||||
|
||||
private final Clock mClock;
|
||||
|
||||
private final long mInitMillis;
|
||||
|
||||
private final int mUserId;
|
||||
|
||||
private long mChallenge;
|
||||
@Nullable
|
||||
private Long mUpdateChallengeMillis = null;
|
||||
|
||||
@Nullable
|
||||
private byte[] mToken;
|
||||
@Nullable
|
||||
private Long mUpdateTokenMillis = null;
|
||||
|
||||
private long mGkPwHandle;
|
||||
@Nullable
|
||||
private Long mClearGkPwHandleMillis = null;
|
||||
|
||||
public CredentialModel(@Nullable Bundle bundle, @NonNull Clock clock) {
|
||||
if (bundle == null) {
|
||||
bundle = new Bundle();
|
||||
}
|
||||
mUserId = bundle.getInt(Intent.EXTRA_USER_ID, UserHandle.myUserId());
|
||||
mChallenge = bundle.getLong(EXTRA_KEY_CHALLENGE, INVALID_CHALLENGE);
|
||||
mToken = bundle.getByteArray(EXTRA_KEY_CHALLENGE_TOKEN);
|
||||
mGkPwHandle = bundle.getLong(EXTRA_KEY_GK_PW_HANDLE, INVALID_GK_PW_HANDLE);
|
||||
mClock = clock;
|
||||
mInitMillis = mClock.millis();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a bundle which can be used to recreate CredentialModel
|
||||
*/
|
||||
@NonNull
|
||||
public Bundle getBundle() {
|
||||
final Bundle bundle = new Bundle();
|
||||
bundle.putInt(Intent.EXTRA_USER_ID, mUserId);
|
||||
bundle.putLong(EXTRA_KEY_CHALLENGE, mChallenge);
|
||||
bundle.putByteArray(EXTRA_KEY_CHALLENGE_TOKEN, mToken);
|
||||
bundle.putLong(EXTRA_KEY_GK_PW_HANDLE, mGkPwHandle);
|
||||
return bundle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get userId for this credential
|
||||
*/
|
||||
public int getUserId() {
|
||||
return mUserId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check user id is valid or not
|
||||
*/
|
||||
public boolean isValidUserId() {
|
||||
return mUserId != UserHandle.USER_NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get challenge
|
||||
*/
|
||||
public long getChallenge() {
|
||||
return mChallenge;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set challenge
|
||||
*/
|
||||
public void setChallenge(long value) {
|
||||
mUpdateChallengeMillis = mClock.millis();
|
||||
mChallenge = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check challenge is valid or not
|
||||
*/
|
||||
public boolean isValidChallenge() {
|
||||
return mChallenge != INVALID_CHALLENGE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get challenge token
|
||||
*/
|
||||
@Nullable
|
||||
public byte[] getToken() {
|
||||
return mToken;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set challenge token
|
||||
*/
|
||||
public void setToken(@Nullable byte[] value) {
|
||||
mUpdateTokenMillis = mClock.millis();
|
||||
mToken = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check challengeToken is valid or not
|
||||
*/
|
||||
public boolean isValidToken() {
|
||||
return mToken != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get gatekeeper password handle
|
||||
*/
|
||||
public long getGkPwHandle() {
|
||||
return mGkPwHandle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear gatekeeper password handle data
|
||||
*/
|
||||
public void clearGkPwHandle() {
|
||||
mClearGkPwHandleMillis = mClock.millis();
|
||||
mGkPwHandle = INVALID_GK_PW_HANDLE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check gkPwHandle is valid or not
|
||||
*/
|
||||
public boolean isValidGkPwHandle() {
|
||||
return mGkPwHandle != INVALID_GK_PW_HANDLE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation of the object
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
final int gkPwHandleLen = ("" + mGkPwHandle).length();
|
||||
final int tokenLen = mToken == null ? 0 : mToken.length;
|
||||
final int challengeLen = ("" + mChallenge).length();
|
||||
return getClass().getSimpleName() + ":{initMillis:" + mInitMillis
|
||||
+ ", userId:" + mUserId
|
||||
+ ", challenge:{len:" + challengeLen
|
||||
+ ", updateMillis:" + mUpdateChallengeMillis + "}"
|
||||
+ ", token:{len:" + tokenLen + ", isValid:" + isValidToken()
|
||||
+ ", updateMillis:" + mUpdateTokenMillis + "}"
|
||||
+ ", gkPwHandle:{len:" + gkPwHandleLen + ", isValid:" + isValidGkPwHandle()
|
||||
+ ", clearMillis:" + mClearGkPwHandleMillis + "}"
|
||||
+ " }";
|
||||
}
|
||||
}
|
||||
122
src/com/android/settings/biometrics2/ui/model/CredentialModel.kt
Normal file
122
src/com/android/settings/biometrics2/ui/model/CredentialModel.kt
Normal file
@@ -0,0 +1,122 @@
|
||||
/*
|
||||
* Copyright (C) 2023 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 android.content.Intent.EXTRA_USER_ID
|
||||
import android.os.Bundle
|
||||
import android.os.UserHandle
|
||||
import androidx.annotation.VisibleForTesting
|
||||
import com.android.settings.biometrics.BiometricEnrollBase.EXTRA_KEY_CHALLENGE
|
||||
import com.android.settings.password.ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN
|
||||
import com.android.settings.password.ChooseLockSettingsHelper.EXTRA_KEY_GK_PW_HANDLE
|
||||
import java.time.Clock
|
||||
|
||||
/**
|
||||
* Secret credential data including
|
||||
* 1. userId
|
||||
* 2. challenge
|
||||
* 3. token
|
||||
* 4. gkPwHandle
|
||||
*/
|
||||
class CredentialModel(bundle: Bundle?, private val clock: Clock) {
|
||||
|
||||
private val mInitMillis = clock.millis()
|
||||
|
||||
/** userId for this credential */
|
||||
val userId: Int = (bundle ?: Bundle()).getInt(EXTRA_USER_ID, UserHandle.myUserId())
|
||||
|
||||
private var clearGkPwHandleMillis: Long? = null
|
||||
|
||||
/** Gatekeeper password handle */
|
||||
var gkPwHandle: Long = (bundle ?: Bundle()).getLong(EXTRA_KEY_GK_PW_HANDLE, INVALID_GK_PW_HANDLE)
|
||||
private set
|
||||
|
||||
val isValidGkPwHandle: Boolean
|
||||
get() = gkPwHandle != INVALID_GK_PW_HANDLE
|
||||
|
||||
/** Clear gatekeeper password handle data */
|
||||
fun clearGkPwHandle() {
|
||||
clearGkPwHandleMillis = clock.millis()
|
||||
gkPwHandle = INVALID_GK_PW_HANDLE
|
||||
}
|
||||
|
||||
/** Check user id is valid or not */
|
||||
val isValidUserId: Boolean
|
||||
get() = userId != UserHandle.USER_NULL
|
||||
|
||||
private var updateChallengeMillis: Long? = null
|
||||
|
||||
var challenge: Long = (bundle ?: Bundle()).getLong(EXTRA_KEY_CHALLENGE, INVALID_CHALLENGE)
|
||||
set(value) {
|
||||
updateChallengeMillis = clock.millis()
|
||||
field = value
|
||||
}
|
||||
|
||||
val isValidChallenge: Boolean
|
||||
get() = challenge != INVALID_CHALLENGE
|
||||
|
||||
private var updateTokenMillis: Long? = null
|
||||
|
||||
/** Challenge token */
|
||||
var token: ByteArray? = (bundle ?: Bundle()).getByteArray(EXTRA_KEY_CHALLENGE_TOKEN)
|
||||
set(value) {
|
||||
updateTokenMillis = clock.millis()
|
||||
field = value
|
||||
}
|
||||
|
||||
val isValidToken: Boolean
|
||||
get() = token != null
|
||||
|
||||
val bundle: Bundle
|
||||
/**
|
||||
* Get a bundle which can be used to recreate CredentialModel
|
||||
*/
|
||||
get() {
|
||||
val bundle = Bundle()
|
||||
bundle.putInt(EXTRA_USER_ID, userId)
|
||||
bundle.putLong(EXTRA_KEY_CHALLENGE, challenge)
|
||||
bundle.putByteArray(EXTRA_KEY_CHALLENGE_TOKEN, token)
|
||||
bundle.putLong(EXTRA_KEY_GK_PW_HANDLE, gkPwHandle)
|
||||
return bundle
|
||||
}
|
||||
|
||||
|
||||
/** Returns a string representation of the object */
|
||||
override fun toString(): String {
|
||||
val gkPwHandleLen = "$gkPwHandle".length
|
||||
val tokenLen = token?.size ?: 0
|
||||
val challengeLen = "$challenge".length
|
||||
return (javaClass.simpleName + ":{initMillis:$mInitMillis"
|
||||
+ ", userId:$userId"
|
||||
+ ", challenge:{len:$challengeLen"
|
||||
+ ", updateMillis:$updateChallengeMillis}"
|
||||
+ ", token:{len:$tokenLen, isValid:$isValidToken"
|
||||
+ ", updateMillis:$updateTokenMillis}"
|
||||
+ ", gkPwHandle:{len:$gkPwHandleLen, isValid:$isValidGkPwHandle"
|
||||
+ ", clearMillis:$clearGkPwHandleMillis}"
|
||||
+ " }")
|
||||
}
|
||||
|
||||
companion object {
|
||||
/** Default value for an invalid challenge */
|
||||
@VisibleForTesting
|
||||
const val INVALID_CHALLENGE = -1L
|
||||
|
||||
/** Default value if GkPwHandle is invalid */
|
||||
@VisibleForTesting
|
||||
const val INVALID_GK_PW_HANDLE = 0L
|
||||
}
|
||||
}
|
||||
@@ -1,52 +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.biometrics2.ui.model;
|
||||
|
||||
/**
|
||||
* Biometric Enrollment progress
|
||||
*/
|
||||
public final class EnrollmentProgress {
|
||||
|
||||
public static final int INITIAL_STEPS = -1;
|
||||
public static final int INITIAL_REMAINING = 0;
|
||||
|
||||
private final int mSteps;
|
||||
private final int mRemaining;
|
||||
|
||||
public EnrollmentProgress(int steps, int remaining) {
|
||||
mSteps = steps;
|
||||
mRemaining = remaining;
|
||||
}
|
||||
|
||||
public int getSteps() {
|
||||
return mSteps;
|
||||
}
|
||||
|
||||
public int getRemaining() {
|
||||
return mRemaining;
|
||||
}
|
||||
|
||||
public boolean isInitialStep() {
|
||||
return mSteps == INITIAL_STEPS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getClass().getSimpleName() + "@" + Integer.toHexString(hashCode())
|
||||
+ "{steps:" + mSteps + ", remaining:" + mRemaining + "}";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright (C) 2023 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
|
||||
|
||||
/** Biometric Enrollment progress */
|
||||
class EnrollmentProgress(val steps: Int, val remaining: Int) {
|
||||
|
||||
val isInitialStep: Boolean
|
||||
get() = steps == INITIAL_STEPS
|
||||
|
||||
override fun toString(): String {
|
||||
return ("${javaClass.simpleName}@${Integer.toHexString(hashCode())}"
|
||||
+ "{steps:$steps, remaining:$remaining}")
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val INITIAL_STEPS = -1
|
||||
const val INITIAL_REMAINING = 0
|
||||
}
|
||||
}
|
||||
@@ -1,110 +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.biometrics2.ui.model;
|
||||
|
||||
import static com.google.android.setupcompat.util.WizardManagerHelper.EXTRA_IS_SUW_SUGGESTED_ACTION_FLOW;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.android.settings.SetupWizardUtils;
|
||||
import com.android.settings.biometrics.BiometricEnrollActivity;
|
||||
|
||||
import com.google.android.setupcompat.util.WizardManagerHelper;
|
||||
|
||||
/**
|
||||
* Biometric enrollment generic intent data, which includes
|
||||
* 1. isSuw
|
||||
* 2. isAfterSuwOrSuwSuggestedAction
|
||||
* 3. theme
|
||||
* 4. isFromSettingsSummery
|
||||
* 5. isSkipIntro
|
||||
* 6. isSkipFindSensor
|
||||
* 7. a helper method, getSetupWizardExtras
|
||||
*/
|
||||
public final class EnrollmentRequest {
|
||||
|
||||
public static final String EXTRA_SKIP_FIND_SENSOR = "skip_find_sensor";
|
||||
|
||||
private final boolean mIsSuw;
|
||||
private final boolean mIsAfterSuwOrSuwSuggestedAction;
|
||||
private final boolean mIsSkipIntro;
|
||||
private final boolean mIsSkipFindSensor;
|
||||
private final int mTheme;
|
||||
private final Bundle mSuwExtras;
|
||||
|
||||
public EnrollmentRequest(@NonNull Intent intent, @NonNull Context context,
|
||||
boolean isSetupActivity) {
|
||||
// Only allow mIsSuw to be enabled through SetupActivity for security reason
|
||||
mIsSuw = isSetupActivity && WizardManagerHelper.isAnySetupWizard(intent);
|
||||
mIsAfterSuwOrSuwSuggestedAction = isSetupActivity
|
||||
&& (WizardManagerHelper.isDeferredSetupWizard(intent)
|
||||
|| WizardManagerHelper.isPortalSetupWizard(intent)
|
||||
|| intent.getBooleanExtra(EXTRA_IS_SUW_SUGGESTED_ACTION_FLOW, false));
|
||||
mSuwExtras = getSuwExtras(mIsSuw, intent);
|
||||
mIsSkipIntro = intent.getBooleanExtra(BiometricEnrollActivity.EXTRA_SKIP_INTRO, false);
|
||||
mIsSkipFindSensor = intent.getBooleanExtra(EXTRA_SKIP_FIND_SENSOR, false);
|
||||
mTheme = SetupWizardUtils.getTheme(context, intent);
|
||||
}
|
||||
|
||||
public boolean isSuw() {
|
||||
return mIsSuw;
|
||||
}
|
||||
|
||||
public boolean isAfterSuwOrSuwSuggestedAction() {
|
||||
return mIsAfterSuwOrSuwSuggestedAction;
|
||||
}
|
||||
|
||||
public boolean isSkipIntro() {
|
||||
return mIsSkipIntro;
|
||||
}
|
||||
|
||||
public boolean isSkipFindSensor() {
|
||||
return mIsSkipFindSensor;
|
||||
}
|
||||
|
||||
public int getTheme() {
|
||||
return mTheme;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public Bundle getSuwExtras() {
|
||||
return new Bundle(mSuwExtras);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation of the object
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return getClass().getSimpleName() + ":{isSuw:" + mIsSuw
|
||||
+ ", isAfterSuwOrSuwSuggestedAction:" + mIsAfterSuwOrSuwSuggestedAction
|
||||
+ "}";
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private static Bundle getSuwExtras(boolean isSuw, @NonNull Intent intent) {
|
||||
final Intent toIntent = new Intent();
|
||||
if (isSuw) {
|
||||
SetupWizardUtils.copySetupExtras(intent, toIntent);
|
||||
}
|
||||
return toIntent.getExtras() != null ? toIntent.getExtras() : new Bundle();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* Copyright (C) 2023 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 android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import com.android.settings.SetupWizardUtils
|
||||
import com.android.settings.biometrics.BiometricEnrollActivity.EXTRA_SKIP_INTRO
|
||||
import com.google.android.setupcompat.util.WizardManagerHelper
|
||||
import com.google.android.setupcompat.util.WizardManagerHelper.EXTRA_IS_SUW_SUGGESTED_ACTION_FLOW
|
||||
|
||||
/**
|
||||
* Biometric enrollment generic intent data, which includes
|
||||
* 1. isSuw
|
||||
* 2. isAfterSuwOrSuwSuggestedAction
|
||||
* 3. theme
|
||||
* 4. isFromSettingsSummery
|
||||
* 5. isSkipIntro
|
||||
* 6. isSkipFindSensor
|
||||
* 7. a helper method, getSetupWizardExtras
|
||||
*/
|
||||
class EnrollmentRequest(
|
||||
intent: Intent,
|
||||
context: Context,
|
||||
isSetupActivity: Boolean
|
||||
) {
|
||||
val isSuw: Boolean = isSetupActivity && WizardManagerHelper.isAnySetupWizard(intent)
|
||||
|
||||
val isAfterSuwOrSuwSuggestedAction = (isSetupActivity
|
||||
&& (WizardManagerHelper.isDeferredSetupWizard(intent)
|
||||
|| WizardManagerHelper.isPortalSetupWizard(intent)
|
||||
|| intent.getBooleanExtra(EXTRA_IS_SUW_SUGGESTED_ACTION_FLOW, false)))
|
||||
|
||||
private val _suwExtras = getSuwExtras(isSuw, intent)
|
||||
|
||||
val isSkipIntro = intent.getBooleanExtra(EXTRA_SKIP_INTRO, false)
|
||||
|
||||
val isSkipFindSensor = intent.getBooleanExtra(EXTRA_SKIP_FIND_SENSOR, false)
|
||||
|
||||
val theme = SetupWizardUtils.getTheme(context, intent)
|
||||
|
||||
val suwExtras: Bundle
|
||||
get() = Bundle(_suwExtras)
|
||||
|
||||
/**
|
||||
* Returns a string representation of the object
|
||||
*/
|
||||
override fun toString(): String {
|
||||
return (javaClass.simpleName + ":{isSuw:" + isSuw
|
||||
+ ", isAfterSuwOrSuwSuggestedAction:" + isAfterSuwOrSuwSuggestedAction
|
||||
+ "}")
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val EXTRA_SKIP_FIND_SENSOR = "skip_find_sensor"
|
||||
private fun getSuwExtras(isSuw: Boolean, intent: Intent): Bundle {
|
||||
val toIntent = Intent()
|
||||
if (isSuw) {
|
||||
SetupWizardUtils.copySetupExtras(intent, toIntent)
|
||||
}
|
||||
return toIntent.extras ?: Bundle()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,52 +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.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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright (C) 2023 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
|
||||
|
||||
/** Enrolling status message (help or error) */
|
||||
class EnrollmentStatusMessage(val msgId: Int, string: CharSequence?) {
|
||||
|
||||
/** Status string */
|
||||
val str: CharSequence = string ?: ""
|
||||
|
||||
override fun toString(): String {
|
||||
return "${javaClass.simpleName}@${Integer.toHexString(hashCode())}{id:$msgId, str:$str}"
|
||||
}
|
||||
}
|
||||
@@ -1,88 +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.biometrics2.ui.model;
|
||||
|
||||
import android.annotation.IntDef;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
/**
|
||||
* Fingerprint onboarding introduction page data, it contains following information which needs
|
||||
* to be passed from view model to view.
|
||||
* 1. mEnrollableStatus: User is allowed to enroll a new fingerprint or not.
|
||||
* 2. mHasScrollToBottom: User has scrolled to the bottom of this page or not.
|
||||
*/
|
||||
public final class FingerprintEnrollIntroStatus {
|
||||
|
||||
/**
|
||||
* Unconfirmed case, it means that this value is invalid, and view shall bypass this value.
|
||||
*/
|
||||
public static final int FINGERPRINT_ENROLLABLE_UNKNOWN = -1;
|
||||
|
||||
/**
|
||||
* User is allowed to enrolled a new fingerprint.
|
||||
*/
|
||||
public static final int FINGERPRINT_ENROLLABLE_OK = 0;
|
||||
|
||||
/**
|
||||
* User is not allowed to enrolled a new fingerprint because the number of enrolled fingerprint
|
||||
* has reached maximum.
|
||||
*/
|
||||
public static final int FINGERPRINT_ENROLLABLE_ERROR_REACH_MAX = 1;
|
||||
|
||||
@IntDef(prefix = {"FINGERPRINT_ENROLLABLE_"}, value = {
|
||||
FINGERPRINT_ENROLLABLE_UNKNOWN,
|
||||
FINGERPRINT_ENROLLABLE_OK,
|
||||
FINGERPRINT_ENROLLABLE_ERROR_REACH_MAX
|
||||
})
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
public @interface FingerprintEnrollableStatus {
|
||||
}
|
||||
|
||||
private final boolean mHasScrollToBottom;
|
||||
|
||||
@FingerprintEnrollableStatus
|
||||
private final int mEnrollableStatus;
|
||||
|
||||
public FingerprintEnrollIntroStatus(boolean hasScrollToBottom, int enrollableStatus) {
|
||||
mEnrollableStatus = enrollableStatus;
|
||||
mHasScrollToBottom = hasScrollToBottom;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get enrollable status. It means that user is allowed to enroll a new fingerprint or not.
|
||||
*/
|
||||
@FingerprintEnrollableStatus
|
||||
public int getEnrollableStatus() {
|
||||
return mEnrollableStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get info for this onboarding introduction page has scrolled to bottom or not
|
||||
*/
|
||||
public boolean hasScrollToBottom() {
|
||||
return mHasScrollToBottom;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getClass().getSimpleName() + "@" + Integer.toHexString(hashCode())
|
||||
+ "{scrollToBottom:" + mHasScrollToBottom
|
||||
+ ", enrollableStatus:" + mEnrollableStatus + "}";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (C) 2023 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
|
||||
|
||||
|
||||
enum class FingerprintEnrollable {
|
||||
// Unconfirmed case, this value is invalid, and view shall bypass this value
|
||||
FINGERPRINT_ENROLLABLE_UNKNOWN,
|
||||
// User is allowed to enrolled a new fingerprint
|
||||
FINGERPRINT_ENROLLABLE_OK,
|
||||
// User is not allowed to enroll because the number has reached maximum
|
||||
FINGERPRINT_ENROLLABLE_ERROR_REACH_MAX
|
||||
}
|
||||
|
||||
/**
|
||||
* Fingerprint onboarding introduction page data, it contains following information which needs
|
||||
* to be passed from view model to view.
|
||||
* 1. mEnrollableStatus: User is allowed to enroll a new fingerprint or not.
|
||||
* 2. mHasScrollToBottom: User has scrolled to the bottom of this page or not.
|
||||
*/
|
||||
class FingerprintEnrollIntroStatus(
|
||||
private val mHasScrollToBottom: Boolean,
|
||||
/** Enrollable status. It means that user is allowed to enroll a new fingerprint or not. */
|
||||
val enrollableStatus: FingerprintEnrollable
|
||||
) {
|
||||
/** Get info for this onboarding introduction page has scrolled to bottom or not */
|
||||
fun hasScrollToBottom(): Boolean {
|
||||
return mHasScrollToBottom
|
||||
}
|
||||
|
||||
override fun toString(): String {
|
||||
return ("${javaClass.simpleName}@${Integer.toHexString(hashCode())}"
|
||||
+ "{scrollToBottom:$mHasScrollToBottom"
|
||||
+ ", enrollableStatus:$enrollableStatus}")
|
||||
}
|
||||
}
|
||||
@@ -18,9 +18,7 @@ package com.android.settings.biometrics2.ui.view;
|
||||
|
||||
import static android.app.admin.DevicePolicyResources.Strings.Settings.FINGERPRINT_UNLOCK_DISABLED;
|
||||
|
||||
import static com.android.settings.biometrics2.ui.model.FingerprintEnrollIntroStatus.FINGERPRINT_ENROLLABLE_ERROR_REACH_MAX;
|
||||
import static com.android.settings.biometrics2.ui.model.FingerprintEnrollIntroStatus.FINGERPRINT_ENROLLABLE_OK;
|
||||
import static com.android.settings.biometrics2.ui.model.FingerprintEnrollIntroStatus.FINGERPRINT_ENROLLABLE_UNKNOWN;
|
||||
import static com.android.settings.biometrics2.ui.model.FingerprintEnrollable.FINGERPRINT_ENROLLABLE_ERROR_REACH_MAX;
|
||||
|
||||
import static com.google.android.setupdesign.util.DynamicColorPalette.ColorType.ACCENT;
|
||||
|
||||
|
||||
@@ -16,9 +16,9 @@
|
||||
|
||||
package com.android.settings.biometrics2.ui.viewmodel;
|
||||
|
||||
import static com.android.settings.biometrics2.ui.model.FingerprintEnrollIntroStatus.FINGERPRINT_ENROLLABLE_ERROR_REACH_MAX;
|
||||
import static com.android.settings.biometrics2.ui.model.FingerprintEnrollIntroStatus.FINGERPRINT_ENROLLABLE_OK;
|
||||
import static com.android.settings.biometrics2.ui.model.FingerprintEnrollIntroStatus.FINGERPRINT_ENROLLABLE_UNKNOWN;
|
||||
import static com.android.settings.biometrics2.ui.model.FingerprintEnrollable.FINGERPRINT_ENROLLABLE_ERROR_REACH_MAX;
|
||||
import static com.android.settings.biometrics2.ui.model.FingerprintEnrollable.FINGERPRINT_ENROLLABLE_OK;
|
||||
import static com.android.settings.biometrics2.ui.model.FingerprintEnrollable.FINGERPRINT_ENROLLABLE_UNKNOWN;
|
||||
|
||||
import android.annotation.IntDef;
|
||||
import android.app.Application;
|
||||
@@ -33,6 +33,7 @@ import androidx.lifecycle.MutableLiveData;
|
||||
import com.android.settings.biometrics2.data.repository.FingerprintRepository;
|
||||
import com.android.settings.biometrics2.ui.model.EnrollmentRequest;
|
||||
import com.android.settings.biometrics2.ui.model.FingerprintEnrollIntroStatus;
|
||||
import com.android.settings.biometrics2.ui.model.FingerprintEnrollable;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
@@ -44,7 +45,8 @@ public class FingerprintEnrollIntroViewModel extends AndroidViewModel {
|
||||
|
||||
private static final String TAG = "FingerprintEnrollIntroViewModel";
|
||||
private static final boolean HAS_SCROLLED_TO_BOTTOM_DEFAULT = false;
|
||||
private static final int ENROLLABLE_STATUS_DEFAULT = FINGERPRINT_ENROLLABLE_UNKNOWN;
|
||||
private static final FingerprintEnrollable ENROLLABLE_STATUS_DEFAULT =
|
||||
FINGERPRINT_ENROLLABLE_UNKNOWN;
|
||||
|
||||
/**
|
||||
* User clicks 'Done' button on this page
|
||||
@@ -73,7 +75,7 @@ public class FingerprintEnrollIntroViewModel extends AndroidViewModel {
|
||||
|
||||
private final MutableLiveData<Boolean> mHasScrolledToBottomLiveData =
|
||||
new MutableLiveData<>(HAS_SCROLLED_TO_BOTTOM_DEFAULT);
|
||||
private final MutableLiveData<Integer> mEnrollableStatusLiveData =
|
||||
private final MutableLiveData<FingerprintEnrollable> mEnrollableStatusLiveData =
|
||||
new MutableLiveData<>(ENROLLABLE_STATUS_DEFAULT);
|
||||
private final MediatorLiveData<FingerprintEnrollIntroStatus> mPageStatusLiveData =
|
||||
new MediatorLiveData<>();
|
||||
@@ -101,7 +103,8 @@ public class FingerprintEnrollIntroViewModel extends AndroidViewModel {
|
||||
mPageStatusLiveData.addSource(
|
||||
mHasScrolledToBottomLiveData,
|
||||
hasScrolledToBottom -> {
|
||||
final Integer enrollableValue = mEnrollableStatusLiveData.getValue();
|
||||
final FingerprintEnrollable enrollableValue =
|
||||
mEnrollableStatusLiveData.getValue();
|
||||
final FingerprintEnrollIntroStatus status = new FingerprintEnrollIntroStatus(
|
||||
hasScrolledToBottom,
|
||||
enrollableValue != null ? enrollableValue : ENROLLABLE_STATUS_DEFAULT);
|
||||
@@ -181,7 +184,7 @@ public class FingerprintEnrollIntroViewModel extends AndroidViewModel {
|
||||
* User clicks next button
|
||||
*/
|
||||
public void onNextButtonClick() {
|
||||
final Integer status = mEnrollableStatusLiveData.getValue();
|
||||
final FingerprintEnrollable status = mEnrollableStatusLiveData.getValue();
|
||||
switch (status != null ? status : ENROLLABLE_STATUS_DEFAULT) {
|
||||
case FINGERPRINT_ENROLLABLE_ERROR_REACH_MAX:
|
||||
mActionLiveData.postValue(FINGERPRINT_ENROLL_INTRO_ACTION_DONE_AND_FINISH);
|
||||
|
||||
Reference in New Issue
Block a user