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

Commit e04da33a authored by Song Chun Fan's avatar Song Chun Fan
Browse files

[ADI][5/N] Use synchronous interface for report* methods

We still want to be able to throw an exception to the client if the
reporting has failed (e.g., if the session has already been finished).
Therefore, changing these methods to be synchronous.

FLAG: android.content.pm.verification_service

BUG: 360129657

Test: atest CtsPackageManagerTestCases:VerifierServiceTest

Reverted changes: /q/submissionid:30469933-revert_verification_service_main

Merged-In: I2f69ec8dbda56357c82745ef60c60fac96fc2c8e
Change-Id: I2f69ec8dbda56357c82745ef60c60fac96fc2c8e
parent b38bf933
Loading
Loading
Loading
Loading
+0 −34
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 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.content.pm.verify.pkg;

import android.content.pm.verify.pkg.VerificationStatus;
import android.os.PersistableBundle;

/**
 * Oneway interface that allows the verifier to send response or verification results back to
 * the system.
 * @hide
 */
oneway interface IVerificationSessionCallback {
    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.VERIFICATION_AGENT)")
    void reportVerificationIncomplete(int verificationId, int reason);
    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.VERIFICATION_AGENT)")
    void reportVerificationComplete(int verificationId, in VerificationStatus status);
    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.VERIFICATION_AGENT)")
    void reportVerificationCompleteWithExtensionResponse(int verificationId, in VerificationStatus status, in PersistableBundle response);
}
+10 −1
Original line number Diff line number Diff line
@@ -16,8 +16,11 @@

package android.content.pm.verify.pkg;

import android.content.pm.verify.pkg.VerificationStatus;
import android.os.PersistableBundle;

/**
 * Non-oneway interface that allows the verifier to retrieve information from the system.
 * Non-oneway interface that allows the verifier to communicate with the system.
 * @hide
 */
interface IVerificationSessionInterface {
@@ -27,4 +30,10 @@ interface IVerificationSessionInterface {
    long extendTimeRemaining(int verificationId, long additionalMs);
    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.VERIFICATION_AGENT)")
    boolean setVerificationPolicy(int verificationId, int policy);
    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.VERIFICATION_AGENT)")
    void reportVerificationIncomplete(int verificationId, int reason);
    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.VERIFICATION_AGENT)")
    void reportVerificationComplete(int verificationId, in VerificationStatus status);
    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.VERIFICATION_AGENT)")
    void reportVerificationCompleteWithExtensionResponse(int verificationId, in VerificationStatus status, in PersistableBundle response);
}
 No newline at end of file
+4 −10
Original line number Diff line number Diff line
@@ -79,8 +79,6 @@ public final class VerificationSession implements Parcelable {
    private final PersistableBundle mExtensionParams;
    @NonNull
    private final IVerificationSessionInterface mSession;
    @NonNull
    private final IVerificationSessionCallback mCallback;
    /**
     * The current policy that is active for the session. It might not be
     * the same as the original policy that was initially assigned for this verification session,
@@ -100,8 +98,7 @@ public final class VerificationSession implements Parcelable {
            @NonNull List<SharedLibraryInfo> declaredLibraries,
            @NonNull PersistableBundle extensionParams,
            @PackageInstaller.VerificationPolicy int defaultPolicy,
            @NonNull IVerificationSessionInterface session,
            @NonNull IVerificationSessionCallback callback) {
            @NonNull IVerificationSessionInterface session) {
        mId = id;
        mInstallSessionId = installSessionId;
        mPackageName = packageName;
@@ -111,7 +108,6 @@ public final class VerificationSession implements Parcelable {
        mExtensionParams = extensionParams;
        mVerificationPolicy = defaultPolicy;
        mSession = session;
        mCallback = callback;
    }

    /**
@@ -236,7 +232,7 @@ public final class VerificationSession implements Parcelable {
    @RequiresPermission(android.Manifest.permission.VERIFICATION_AGENT)
    public void reportVerificationIncomplete(@VerificationIncompleteReason int reason) {
        try {
            mCallback.reportVerificationIncomplete(mId, reason);
            mSession.reportVerificationIncomplete(mId, reason);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
@@ -250,7 +246,7 @@ public final class VerificationSession implements Parcelable {
    @RequiresPermission(android.Manifest.permission.VERIFICATION_AGENT)
    public void reportVerificationComplete(@NonNull VerificationStatus status) {
        try {
            mCallback.reportVerificationComplete(mId, status);
            mSession.reportVerificationComplete(mId, status);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
@@ -265,7 +261,7 @@ public final class VerificationSession implements Parcelable {
    public void reportVerificationComplete(@NonNull VerificationStatus status,
            @NonNull PersistableBundle response) {
        try {
            mCallback.reportVerificationCompleteWithExtensionResponse(mId, status, response);
            mSession.reportVerificationCompleteWithExtensionResponse(mId, status, response);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
@@ -281,7 +277,6 @@ public final class VerificationSession implements Parcelable {
        mExtensionParams = in.readPersistableBundle(getClass().getClassLoader());
        mVerificationPolicy = in.readInt();
        mSession = IVerificationSessionInterface.Stub.asInterface(in.readStrongBinder());
        mCallback = IVerificationSessionCallback.Stub.asInterface(in.readStrongBinder());
    }

    @Override
@@ -300,7 +295,6 @@ public final class VerificationSession implements Parcelable {
        dest.writePersistableBundle(mExtensionParams);
        dest.writeInt(mVerificationPolicy);
        dest.writeStrongBinder(mSession.asBinder());
        dest.writeStrongBinder(mCallback.asBinder());
    }

    @NonNull
+4 −10
Original line number Diff line number Diff line
@@ -32,7 +32,6 @@ import static org.mockito.Mockito.when;
import android.content.pm.SharedLibraryInfo;
import android.content.pm.SigningInfo;
import android.content.pm.VersionedPackage;
import android.content.pm.verify.pkg.IVerificationSessionCallback;
import android.content.pm.verify.pkg.IVerificationSessionInterface;
import android.content.pm.verify.pkg.VerificationSession;
import android.content.pm.verify.pkg.VerificationStatus;
@@ -83,8 +82,6 @@ public class VerificationSessionTest {
    private final PersistableBundle mTestExtensionParams = new PersistableBundle();
    @Mock
    private IVerificationSessionInterface mTestSessionInterface;
    @Mock
    private IVerificationSessionCallback mTestCallback;
    private VerificationSession mTestSession;

    @Before
@@ -95,7 +92,7 @@ public class VerificationSessionTest {
        mTestExtensionParams.putString(TEST_KEY, TEST_VALUE);
        mTestSession = new VerificationSession(TEST_ID, TEST_INSTALL_SESSION_ID,
                TEST_PACKAGE_NAME, TEST_PACKAGE_URI, TEST_SIGNING_INFO, mTestDeclaredLibraries,
                mTestExtensionParams, TEST_POLICY, mTestSessionInterface, mTestCallback);
                mTestExtensionParams, TEST_POLICY, mTestSessionInterface);
    }

    @Test
@@ -137,25 +134,22 @@ public class VerificationSessionTest {
        assertThat(mTestSession.extendTimeRemaining(TEST_EXTEND_TIME)).isEqualTo(TEST_EXTEND_TIME);
        verify(mTestSessionInterface, times(1)).extendTimeRemaining(
                eq(TEST_ID), eq(TEST_EXTEND_TIME));
    }

    @Test
    public void testCallback() throws Exception {
        PersistableBundle response = new PersistableBundle();
        response.putString("test key", "test value");
        final VerificationStatus status =
                new VerificationStatus.Builder().setVerified(true).build();
        mTestSession.reportVerificationComplete(status);
        verify(mTestCallback, times(1)).reportVerificationComplete(
        verify(mTestSessionInterface, times(1)).reportVerificationComplete(
                eq(TEST_ID), eq(status));
        mTestSession.reportVerificationComplete(status, response);
        verify(mTestCallback, times(1))
        verify(mTestSessionInterface, times(1))
                .reportVerificationCompleteWithExtensionResponse(
                        eq(TEST_ID), eq(status), eq(response));

        final int reason = VerificationSession.VERIFICATION_INCOMPLETE_UNKNOWN;
        mTestSession.reportVerificationIncomplete(reason);
        verify(mTestCallback, times(1)).reportVerificationIncomplete(
        verify(mTestSessionInterface, times(1)).reportVerificationIncomplete(
                eq(TEST_ID), eq(reason));
    }

+3 −1
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import static org.mockito.Mockito.when;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.SigningInfo;
import android.content.pm.verify.pkg.IVerificationSessionInterface;
import android.content.pm.verify.pkg.IVerifierService;
import android.content.pm.verify.pkg.VerificationSession;
import android.content.pm.verify.pkg.VerifierService;
@@ -63,7 +64,8 @@ public class VerifierServiceTest {
        mService = Mockito.mock(VerifierService.class, Answers.CALLS_REAL_METHODS);
        mSession = new VerificationSession(TEST_ID, TEST_INSTALL_SESSION_ID,
                TEST_PACKAGE_NAME, TEST_PACKAGE_URI, TEST_SIGNING_INFO,
                new ArrayList<>(), new PersistableBundle(), TEST_POLICY, null, null);
                new ArrayList<>(), new PersistableBundle(), TEST_POLICY, Mockito.mock(
                IVerificationSessionInterface.class));
    }

    @Test
Loading