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

Commit 88fffe82 authored by Song Chun Fan's avatar Song Chun Fan
Browse files

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

BUG: 374797861
Test: n/a
FLAG: android.content.pm.verification_service

This reverts commit f27be658.

Change-Id: I7c3828cbf64db9203aebaee047ca4363a13b971d
parent eeb314d0
Loading
Loading
Loading
Loading
+34 −0
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);
}
+1 −10
Original line number Diff line number Diff line
@@ -16,11 +16,8 @@

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 communicate with the system.
 * Non-oneway interface that allows the verifier to retrieve information from the system.
 * @hide
 */
interface IVerificationSessionInterface {
@@ -30,10 +27,4 @@ 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
+10 −4
Original line number Diff line number Diff line
@@ -79,6 +79,8 @@ 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,
@@ -98,7 +100,8 @@ public final class VerificationSession implements Parcelable {
            @NonNull List<SharedLibraryInfo> declaredLibraries,
            @NonNull PersistableBundle extensionParams,
            @PackageInstaller.VerificationPolicy int defaultPolicy,
            @NonNull IVerificationSessionInterface session) {
            @NonNull IVerificationSessionInterface session,
            @NonNull IVerificationSessionCallback callback) {
        mId = id;
        mInstallSessionId = installSessionId;
        mPackageName = packageName;
@@ -108,6 +111,7 @@ public final class VerificationSession implements Parcelable {
        mExtensionParams = extensionParams;
        mVerificationPolicy = defaultPolicy;
        mSession = session;
        mCallback = callback;
    }

    /**
@@ -232,7 +236,7 @@ public final class VerificationSession implements Parcelable {
    @RequiresPermission(android.Manifest.permission.VERIFICATION_AGENT)
    public void reportVerificationIncomplete(@VerificationIncompleteReason int reason) {
        try {
            mSession.reportVerificationIncomplete(mId, reason);
            mCallback.reportVerificationIncomplete(mId, reason);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
@@ -246,7 +250,7 @@ public final class VerificationSession implements Parcelable {
    @RequiresPermission(android.Manifest.permission.VERIFICATION_AGENT)
    public void reportVerificationComplete(@NonNull VerificationStatus status) {
        try {
            mSession.reportVerificationComplete(mId, status);
            mCallback.reportVerificationComplete(mId, status);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
@@ -261,7 +265,7 @@ public final class VerificationSession implements Parcelable {
    public void reportVerificationComplete(@NonNull VerificationStatus status,
            @NonNull PersistableBundle response) {
        try {
            mSession.reportVerificationCompleteWithExtensionResponse(mId, status, response);
            mCallback.reportVerificationCompleteWithExtensionResponse(mId, status, response);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
@@ -277,6 +281,7 @@ 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
@@ -295,6 +300,7 @@ public final class VerificationSession implements Parcelable {
        dest.writePersistableBundle(mExtensionParams);
        dest.writeInt(mVerificationPolicy);
        dest.writeStrongBinder(mSession.asBinder());
        dest.writeStrongBinder(mCallback.asBinder());
    }

    @NonNull
+10 −4
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ 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,6 +84,8 @@ public class VerificationSessionTest {
    private final PersistableBundle mTestExtensionParams = new PersistableBundle();
    @Mock
    private IVerificationSessionInterface mTestSessionInterface;
    @Mock
    private IVerificationSessionCallback mTestCallback;
    private VerificationSession mTestSession;

    @Before
@@ -93,7 +96,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);
                mTestExtensionParams, TEST_POLICY, mTestSessionInterface, mTestCallback);
    }

    @Test
@@ -135,22 +138,25 @@ 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(mTestSessionInterface, times(1)).reportVerificationComplete(
        verify(mTestCallback, times(1)).reportVerificationComplete(
                eq(TEST_ID), eq(status));
        mTestSession.reportVerificationComplete(status, response);
        verify(mTestSessionInterface, times(1))
        verify(mTestCallback, times(1))
                .reportVerificationCompleteWithExtensionResponse(
                        eq(TEST_ID), eq(status), eq(response));

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

+1 −3
Original line number Diff line number Diff line
@@ -27,7 +27,6 @@ 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;
@@ -64,8 +63,7 @@ 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, Mockito.mock(
                IVerificationSessionInterface.class));
                new ArrayList<>(), new PersistableBundle(), TEST_POLICY, null, null);
    }

    @Test
Loading