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

Commit 83c4b8fa authored by Song Chun Fan's avatar Song Chun Fan
Browse files

[ADI][11/N] address API review feedback

FLAG: android.content.pm.verification_service

BUG: 376282352
FIXES: 376282352
Test: n/a (just adding annotations and comments)

Merged-In: Ie34f9df3428f3b6f16bf60d64b4313e9cf45db8f
Change-Id: Ie34f9df3428f3b6f16bf60d64b4313e9cf45db8f
parent 951db3ae
Loading
Loading
Loading
Loading
+25 −5
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package android.content.pm.verify.pkg;

import android.annotation.CurrentTimeMillisLong;
import android.annotation.DurationMillisLong;
import android.annotation.FlaggedApi;
import android.annotation.IntDef;
import android.annotation.NonNull;
@@ -147,8 +149,8 @@ public final class VerificationSession implements Parcelable {

    /**
     * Returns a mapping of any shared libraries declared in the manifest
     * to the {@link SharedLibraryInfo.Type} that is declared. This will be an empty
     * map if no shared libraries are declared by the package.
     * to the {@link SharedLibraryInfo.Type} that is declared.
     * <p>This will be an empty map if no shared libraries are declared by the package.</p>
     */
    @NonNull
    public List<SharedLibraryInfo> getDeclaredLibraries() {
@@ -170,8 +172,11 @@ public final class VerificationSession implements Parcelable {
     * Get the value of Clock.elapsedRealtime() at which time this verification
     * will timeout as incomplete if no other verification response is provided.
     * @throws SecurityException if the caller is not the current verifier bound by the system.
     * @throws IllegalStateException if this is called after the session has finished, because
     * the {@link #reportVerificationComplete} or {@link #reportVerificationIncomplete} have
     * been called, or because the session has timed out.
     */
    public long getTimeoutTime() {
    public @CurrentTimeMillisLong long getTimeoutTime() {
        try {
            return mSession.getTimeoutTime(mId);
        } catch (RemoteException e) {
@@ -194,6 +199,10 @@ public final class VerificationSession implements Parcelable {
     * Override the verification policy for this session.
     * @return True if the override was successful, False otherwise.
     * @throws SecurityException if the caller is not the current verifier bound by the system.
     * @throws IllegalStateException if this is called after the session has finished, because
     * the {@link #reportVerificationComplete} or {@link #reportVerificationIncomplete} have
     * been called, or because the session has timed out, unless the new policy value is the same
     * as the existing one.
     */
    public boolean setVerificationPolicy(@PackageInstaller.VerificationPolicy int policy) {
        if (mVerificationPolicy == policy) {
@@ -215,12 +224,14 @@ public final class VerificationSession implements Parcelable {
    /**
     * Extend the timeout for this session by the provided additionalMs to
     * fetch relevant information over the network or wait for the network.
     * <p>
     * This may be called multiple times. If the request would bypass any max
     * duration by the system, the method will return a lower value than the
     * requested amount that indicates how much the time was extended.
     * </p>
     * @throws SecurityException if the caller is not the current verifier bound by the system.
     */
    public long extendTimeRemaining(long additionalMs) {
    public @DurationMillisLong long extendTimeRemaining(@DurationMillisLong long additionalMs) {
        try {
            return mSession.extendTimeRemaining(mId, additionalMs);
        } catch (RemoteException e) {
@@ -230,8 +241,11 @@ public final class VerificationSession implements Parcelable {

    /**
     * Report to the system that verification could not be completed along
     * with an approximate reason to pass on to the installer.]
     * with an approximate reason to pass on to the installer.
     * @throws SecurityException if the caller is not the current verifier bound by the system.
     * @throws IllegalStateException if this is called after the session has finished, because
     * this API or {@link #reportVerificationComplete} have already been called once, or because the
     * session has timed out.
     */
    public void reportVerificationIncomplete(@VerificationIncompleteReason int reason) {
        try {
@@ -246,6 +260,9 @@ public final class VerificationSession implements Parcelable {
     * install process may act on that status to either block in the case
     * of failure or continue to process the install in the case of success.
     * @throws SecurityException if the caller is not the current verifier bound by the system.
     * @throws IllegalStateException if this is called after the session has finished, because
     * this API or {@link #reportVerificationIncomplete} have already been called once, or because
     * the session has timed out.
     */
    public void reportVerificationComplete(@NonNull VerificationStatus status) {
        try {
@@ -260,6 +277,9 @@ public final class VerificationSession implements Parcelable {
     * a result to the extension params provided in the request, which will be passed to the
     * installer in the installation result.
     * @throws SecurityException if the caller is not the current verifier bound by the system.
     * @throws IllegalStateException if this is called after the session has finished, because
     * this API or {@link #reportVerificationIncomplete} have already been called once, or because
     * the session has timed out.
     */
    public void reportVerificationComplete(@NonNull VerificationStatus status,
            @NonNull PersistableBundle extensionResponse) {
+7 −2
Original line number Diff line number Diff line
@@ -36,9 +36,11 @@ import java.lang.annotation.RetentionPolicy;
@FlaggedApi(Flags.FLAG_VERIFICATION_SERVICE)
public final class  VerificationStatus implements Parcelable {
    /**
     * The ASL status has not been determined.  This happens in situations where the verification
     * The ASL status has not been determined.
     * <p>This happens in situations where the verification
     * service is not monitoring ASLs, and means the ASL data in the app is not necessarily bad but
     * can't be trusted.
     * </p>
     */
    public static final int VERIFIER_STATUS_ASL_UNDEFINED = 0;

@@ -48,8 +50,11 @@ public final class VerificationStatus implements Parcelable {
    public static final int VERIFIER_STATUS_ASL_GOOD = 1;

    /**
     * There is something bad in the app's ASL data; the user should be warned about this when shown
     * There is something bad in the app's ASL data.
     * <p>
     * The user should be warned about this when shown
     * the ASL data and/or appropriate decisions made about the use of this data by the platform.
     * </p>
     */
    public static final int VERIFIER_STATUS_ASL_BAD = 2;

+13 −10
Original line number Diff line number Diff line
@@ -56,8 +56,9 @@ public abstract class VerifierService extends Service {

    /**
     * Called when a package recently provided via {@link #onPackageNameAvailable}
     * is no longer expected to be installed. This is a hint that any pre-fetch or
     * cache created as a result of the previous call may be be cleared.
     * is no longer expected to be installed.
     * <p>This is a hint that any pre-fetch or
     * cache created as a result of the previous call may be be cleared.</p>
     * <p>This method will never be called after {@link #onVerificationRequired} is called for the
     * same package. Once a verification is officially requested by
     * {@link #onVerificationRequired}, it cannot be cancelled.
@@ -66,26 +67,28 @@ public abstract class VerifierService extends Service {
    public abstract void onVerificationCancelled(@NonNull String packageName);

    /**
     * Called when an application needs to be verified. Details about the
     * Called when an application needs to be verified.
     * <p>Details about the
     * verification and actions that can be taken on it will be encapsulated in
     * the provided {@link VerificationSession} parameter.
     * the provided {@link VerificationSession} parameter.</p>
     */
    public abstract void onVerificationRequired(@NonNull VerificationSession session);

    /**
     * Called when a verification needs to be retried. This can be encountered
     * Called when a verification needs to be retried.
     * <p>This can be encountered
     * when a prior verification was marked incomplete and the user has indicated
     * that they've resolved the issue, or when a timeout is reached, but the
     * the system is attempting to retry. Details about the
     * the system is attempting to retry.
     * </p>
     * <p>Details about the
     * verification and actions that can be taken on it will be encapsulated in
     * the provided {@link VerificationSession} parameter.
     * the provided {@link VerificationSession} parameter.</p>
     */
    public abstract void onVerificationRetry(@NonNull VerificationSession session);

    /**
     * Called in the case that an active verification has failed. Any APIs called
     * on the {@link VerificationSession} instance associated with this {@code verificationId} will
     * throw an {@link IllegalStateException}.
     * Called in the case that an active verification has failed because of the timeout.
     */
    public abstract void onVerificationTimeout(int verificationId);

+5 −3
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.server.pm.verify.pkg;

import android.annotation.CurrentTimeMillisLong;
import android.annotation.DurationMillisLong;
import android.annotation.NonNull;

import com.android.internal.annotations.VisibleForTesting;
@@ -38,7 +39,8 @@ public final class VerificationStatusTracker {
     * can be extended via {@link #extendTimeRemaining} to the maximum allowed.
     */
    @VisibleForTesting(visibility = VisibleForTesting.Visibility.PROTECTED)
    public VerificationStatusTracker(long defaultTimeoutMillis, long maxExtendedTimeoutMillis,
    public VerificationStatusTracker(@DurationMillisLong long defaultTimeoutMillis,
            @DurationMillisLong long maxExtendedTimeoutMillis,
            @NonNull VerifierController.Injector injector) {
        mStartTime = injector.getCurrentTimeMillis();
        mTimeoutTime = mStartTime + defaultTimeoutMillis;
@@ -59,7 +61,7 @@ public final class VerificationStatusTracker {
     * @return 0 if the timeout time has been reached, otherwise the remaining time in milliseconds
     * before the timeout is reached.
     */
    public @CurrentTimeMillisLong long getRemainingTime() {
    public @DurationMillisLong long getRemainingTime() {
        final long remainingTime = mTimeoutTime - mInjector.getCurrentTimeMillis();
        if (remainingTime < 0) {
            return 0;
@@ -73,7 +75,7 @@ public final class VerificationStatusTracker {
     * @return the amount of time in millis that the timeout has been extended, subject to the max
     * amount allowed.
     */
    public long extendTimeRemaining(@CurrentTimeMillisLong long additionalMs) {
    public @DurationMillisLong long extendTimeRemaining(@DurationMillisLong long additionalMs) {
        if (mTimeoutTime + additionalMs > mMaxTimeoutTime) {
            additionalMs = mMaxTimeoutTime - mTimeoutTime;
        }
+5 −2
Original line number Diff line number Diff line
@@ -22,6 +22,8 @@ import static android.provider.DeviceConfig.NAMESPACE_PACKAGE_MANAGER_SERVICE;

import static com.android.server.pm.PackageInstallerService.isValidPackageName;

import android.annotation.CurrentTimeMillisLong;
import android.annotation.DurationMillisLong;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.content.Context;
@@ -467,7 +469,7 @@ public class VerifierController {
        }

        @Override
        public long getTimeoutTime(int verificationId) {
        public @CurrentTimeMillisLong long getTimeoutTime(int verificationId) {
            assertCallerIsCurrentVerifier(getCallingUid());
            synchronized (mVerificationStatus) {
                final VerificationStatusTracker tracker = mVerificationStatus.get(verificationId);
@@ -480,7 +482,8 @@ public class VerifierController {
        }

        @Override
        public long extendTimeRemaining(int verificationId, long additionalMs) {
        public @DurationMillisLong long extendTimeRemaining(int verificationId,
                @DurationMillisLong long additionalMs) {
            assertCallerIsCurrentVerifier(getCallingUid());
            synchronized (mVerificationStatus) {
                final VerificationStatusTracker tracker = mVerificationStatus.get(verificationId);