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

Commit ba2afc5b authored by Dmitry Dementyev's avatar Dmitry Dementyev Committed by Android (Google) Code Review
Browse files

Merge "Implement startRemoteLockscreenValidation."

parents b867c1e9 d9444537
Loading
Loading
Loading
Loading
+20 −0
Original line number Diff line number Diff line
/*
 * 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 android.app;

/** {@hide} */
parcelable RemoteLockscreenValidationResult;
+150 −0
Original line number Diff line number Diff line
/*
 * 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 android.app;

import android.annotation.DurationMillisLong;
import android.annotation.IntDef;
import android.annotation.NonNull;
import android.os.Parcel;
import android.os.Parcelable;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
/**
 * Result of lock screen credentials verification.
 *
 * @hide
 */
public final class RemoteLockscreenValidationResult implements Parcelable {

    /**
     * The guess was correct
     */
    public static final int RESULT_GUESS_VALID = 1;

    /**
     * Remote device provided incorrect credentials.
     */
    public static final int RESULT_GUESS_INVALID = 2;

    /**
     * The operation was canceled because the API is locked out due to too many attempts. It
     * usually happens after 5 failed attempts and API may be called again after a short
     * delay specified by {@code getTimeoutMillis}.
     */
    public static final int RESULT_LOCKOUT = 3;

    /**
     * There were too many invalid guesses.
     */
    public static final int RESULT_NO_REMAINING_ATTEMPTS = 4;

    @IntDef({RESULT_GUESS_VALID,
            RESULT_GUESS_INVALID,
            RESULT_LOCKOUT,
            RESULT_NO_REMAINING_ATTEMPTS})
    @Retention(RetentionPolicy.SOURCE)
    @interface ResultCode {}

    private int mResultCode;
    private long mTimeoutMillis;

    public static final @NonNull Parcelable.Creator<RemoteLockscreenValidationResult> CREATOR =
            new Parcelable.Creator<RemoteLockscreenValidationResult>() {
        @Override
        public RemoteLockscreenValidationResult createFromParcel(Parcel source) {
            return new RemoteLockscreenValidationResult(source);
        }

        @Override
        public RemoteLockscreenValidationResult[] newArray(int size) {
            return new RemoteLockscreenValidationResult[size];
        }
    };

    /**
     * Builder for {@code RemoteLockscreenValidationResult}
     */
    public static final class Builder {
        private RemoteLockscreenValidationResult mInstance = new RemoteLockscreenValidationResult();

        /**
         * Sets the result code.
         */
        public @NonNull Builder setResultCode(@ResultCode int resultCode) {
            mInstance.mResultCode = resultCode;
            return this;
        }

        /**
         * Sets timeout for {@code RESULT_LOCKOUT}.
         * Default value is {@code 0}.
         */
        public @NonNull Builder setTimeoutMillis(@DurationMillisLong long timeoutMillis) {
            mInstance.mTimeoutMillis = timeoutMillis;
            return this;
        }

        /**
         * Creates {@code RemoteLockscreenValidationResult}.
         *
         * @throws IllegalStateException if result code was not set.
         */
        public @NonNull RemoteLockscreenValidationResult build() {
            if (mInstance.mResultCode == 0) {
                throw new IllegalStateException("Result code must be set");
            }
            return mInstance;
        }
    }

    /**
     * Gets the result code.
     */
    public @ResultCode int getResultCode() {
        return mResultCode;
    }

    /**
     * Delay before next attempt to verify credentials.
     *
     * Default value is {@code 0}.
     */
    public @DurationMillisLong long getTimeoutMillis() {
        return mTimeoutMillis;
    }


    @Override
    public void writeToParcel(@NonNull Parcel out, int flags) {
        out.writeInt(mResultCode);
        out.writeLong(mTimeoutMillis);
    }

    private RemoteLockscreenValidationResult() {
    }

    private RemoteLockscreenValidationResult(Parcel in) {
        mResultCode = in.readInt();
        mTimeoutMillis = in.readLong();
    }

    @Override
    public int describeContents() {
        return 0;
    }
}
+20 −0
Original line number Diff line number Diff line
/*
 * 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 android.app;

/** {@hide} */
parcelable StartLockscreenValidationRequest;
+146 −0
Original line number Diff line number Diff line
/*
 * 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 android.app;

import android.annotation.NonNull;
import android.app.KeyguardManager.LockTypes;
import android.os.Parcel;
import android.os.Parcelable;

import java.util.Objects;

/**
 * Provides information necessary to perform remote lock screen credentials check.
 *
 * @hide
 */
public final class StartLockscreenValidationRequest implements Parcelable {

    @LockTypes
    private int mLockscreenUiType;

    private byte[] mSourcePublicKey;

    private int mRemainingAttempts;

    public static final @NonNull Parcelable.Creator<StartLockscreenValidationRequest> CREATOR = new
            Parcelable.Creator<StartLockscreenValidationRequest>() {
        @Override
        public StartLockscreenValidationRequest createFromParcel(Parcel source) {
            return new StartLockscreenValidationRequest(source);
        }

        @Override
        public StartLockscreenValidationRequest[] newArray(int size) {
            return new StartLockscreenValidationRequest[size];
        }
    };


    /**
     * Builder for {@code StartLockscreenValidationRequest}
     */
    public static final class Builder {
        private StartLockscreenValidationRequest mInstance = new StartLockscreenValidationRequest();

        /**
         * Sets UI type.
         * Default value is {@code LockTypes.PASSWORD}
         *
         * @param lockscreenUiType The UI format
         * @return This builder.
         */
        public @NonNull Builder setLockscreenUiType(@LockTypes int lockscreenUiType) {
            mInstance.mLockscreenUiType = lockscreenUiType;
            return this;
        }

        /**
         * Sets public key using secure box encoding
         * @return This builder.
         */
        public @NonNull Builder setSourcePublicKey(@NonNull byte[] publicKey) {
            mInstance.mSourcePublicKey = publicKey;
            return this;
        }

        /**
         * Sets the number of remaining credentials check
         * Default value is {@code 0}
         *
         * @return This builder.
         */
        public @NonNull Builder setRemainingAttempts(int remainingAttempts) {
            mInstance.mRemainingAttempts = remainingAttempts;
            return this;
        }

        /**
         * Creates {@code StartLockscreenValidationRequest}
         *
         * @throws NullPointerException if required fields are not set.
         */
        public @NonNull StartLockscreenValidationRequest build() {
            Objects.requireNonNull(mInstance.mSourcePublicKey);
            return mInstance;
        }
    }

    /**
     * Specifies lock screen credential type.
     */
    public @LockTypes int getLockscreenUiType() {
        return mLockscreenUiType;
    }

    /**
     * Public key used to send encrypted credentials.
     */
    public @NonNull byte[] getSourcePublicKey() {
        return mSourcePublicKey;
    }

    /**
     * Number of remaining attempts to verify credentials.
     *
     * <p>After correct guess counter is reset to {@code 5}.
     */
    public int getRemainingAttempts() {
        return mRemainingAttempts;
    }

    @Override
    public void writeToParcel(@NonNull Parcel out, int flags) {
        out.writeInt(mLockscreenUiType);
        out.writeByteArray(mSourcePublicKey);
        out.writeInt(mRemainingAttempts);
    }

    private StartLockscreenValidationRequest() {
    }

    private StartLockscreenValidationRequest(Parcel in) {
        mLockscreenUiType = in.readInt();
        mSourcePublicKey = in.createByteArray();
        mRemainingAttempts = in.readInt();
    }

    @Override
    public int describeContents() {
        return 0;
    }
}
+10 −14
Original line number Diff line number Diff line
@@ -58,6 +58,8 @@ import android.app.KeyguardManager;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.RemoteLockscreenValidationResult;
import android.app.StartLockscreenValidationRequest;
import android.app.admin.DevicePolicyManager;
import android.app.admin.DevicePolicyManagerInternal;
import android.app.admin.DeviceStateCache;
@@ -118,7 +120,6 @@ import android.text.TextUtils;
import android.util.ArrayMap;
import android.util.ArraySet;
import android.util.EventLog;
import android.util.FeatureFlagUtils;
import android.util.LongSparseArray;
import android.util.Slog;
import android.util.SparseArray;
@@ -2553,23 +2554,18 @@ public class LockSettingsService extends ILockSettings.Stub {
    /**
     * Starts a session to verify lock screen credentials provided by a remote device.
     */
    public void startRemoteLockscreenValidation() {
        if (!FeatureFlagUtils.isEnabled(mContext,
                FeatureFlagUtils.SETTINGS_ENABLE_LOCKSCREEN_TRANSFER_API)) {
            throw new UnsupportedOperationException("Under development");
        }
        mRecoverableKeyStoreManager.startRemoteLockscreenValidation();
    @NonNull
    public StartLockscreenValidationRequest startRemoteLockscreenValidation() {
        return mRecoverableKeyStoreManager.startRemoteLockscreenValidation(this);
    }

    /**
     * Verifies credentials guess from a remote device.
     * Verifies encrypted credentials guess from a remote device.
     */
    public void validateRemoteLockscreen(@NonNull byte[] encryptedCredential) {
        if (!FeatureFlagUtils.isEnabled(mContext,
                FeatureFlagUtils.SETTINGS_ENABLE_LOCKSCREEN_TRANSFER_API)) {
            throw new UnsupportedOperationException("Under development");
        }
        mRecoverableKeyStoreManager.validateRemoteLockscreen(encryptedCredential);
    @NonNull
    public RemoteLockscreenValidationResult
            validateRemoteLockScreen2(@NonNull byte[] encryptedCredential) {
        return mRecoverableKeyStoreManager.validateRemoteLockscreen(encryptedCredential, this);
    }

    // Reading these settings needs the contacts permission
Loading