[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

Change-Id: I1f91277cb4db669e5bf3a59faf72b38c21737e4d
diff --git a/core/java/android/content/pm/verify/pkg/IVerificationSessionCallback.aidl b/core/java/android/content/pm/verify/pkg/IVerificationSessionCallback.aidl
deleted file mode 100644
index 38a7956..0000000
--- a/core/java/android/content/pm/verify/pkg/IVerificationSessionCallback.aidl
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * 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);
-}
diff --git a/core/java/android/content/pm/verify/pkg/IVerificationSessionInterface.aidl b/core/java/android/content/pm/verify/pkg/IVerificationSessionInterface.aidl
index 036c1e6..66caf2d 100644
--- a/core/java/android/content/pm/verify/pkg/IVerificationSessionInterface.aidl
+++ b/core/java/android/content/pm/verify/pkg/IVerificationSessionInterface.aidl
@@ -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 @@
     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
diff --git a/core/java/android/content/pm/verify/pkg/VerificationSession.java b/core/java/android/content/pm/verify/pkg/VerificationSession.java
index f393be8..4ade211 100644
--- a/core/java/android/content/pm/verify/pkg/VerificationSession.java
+++ b/core/java/android/content/pm/verify/pkg/VerificationSession.java
@@ -79,8 +79,6 @@
     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 @@
             @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 @@
         mExtensionParams = extensionParams;
         mVerificationPolicy = defaultPolicy;
         mSession = session;
-        mCallback = callback;
     }
 
     /**
@@ -236,7 +232,7 @@
     @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 @@
     @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 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 @@
         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 @@
         dest.writePersistableBundle(mExtensionParams);
         dest.writeInt(mVerificationPolicy);
         dest.writeStrongBinder(mSession.asBinder());
-        dest.writeStrongBinder(mCallback.asBinder());
     }
 
     @NonNull
diff --git a/core/tests/coretests/src/android/content/pm/verify/VerificationSessionTest.java b/core/tests/coretests/src/android/content/pm/verify/VerificationSessionTest.java
index 80255c5..90ae306 100644
--- a/core/tests/coretests/src/android/content/pm/verify/VerificationSessionTest.java
+++ b/core/tests/coretests/src/android/content/pm/verify/VerificationSessionTest.java
@@ -33,7 +33,6 @@
 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;
@@ -84,8 +83,6 @@
     private final PersistableBundle mTestExtensionParams = new PersistableBundle();
     @Mock
     private IVerificationSessionInterface mTestSessionInterface;
-    @Mock
-    private IVerificationSessionCallback mTestCallback;
     private VerificationSession mTestSession;
 
     @Before
@@ -96,7 +93,7 @@
         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
@@ -138,25 +135,22 @@
         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));
     }
 
diff --git a/core/tests/coretests/src/android/content/pm/verify/VerifierServiceTest.java b/core/tests/coretests/src/android/content/pm/verify/VerifierServiceTest.java
index 7807c8a..56fc66a 100644
--- a/core/tests/coretests/src/android/content/pm/verify/VerifierServiceTest.java
+++ b/core/tests/coretests/src/android/content/pm/verify/VerifierServiceTest.java
@@ -27,6 +27,7 @@
 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 @@
         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
diff --git a/services/core/java/com/android/server/pm/verify/pkg/VerifierController.java b/services/core/java/com/android/server/pm/verify/pkg/VerifierController.java
index b7cc7cce..0dd1f4c 100644
--- a/services/core/java/com/android/server/pm/verify/pkg/VerifierController.java
+++ b/services/core/java/com/android/server/pm/verify/pkg/VerifierController.java
@@ -35,7 +35,6 @@
 import android.content.pm.ResolveInfo;
 import android.content.pm.SharedLibraryInfo;
 import android.content.pm.SigningInfo;
-import android.content.pm.verify.pkg.IVerificationSessionCallback;
 import android.content.pm.verify.pkg.IVerificationSessionInterface;
 import android.content.pm.verify.pkg.IVerifierService;
 import android.content.pm.verify.pkg.VerificationSession;
@@ -45,7 +44,6 @@
 import android.os.Handler;
 import android.os.PersistableBundle;
 import android.os.Process;
-import android.os.RemoteException;
 import android.os.UserHandle;
 import android.provider.DeviceConfig;
 import android.util.Pair;
@@ -307,8 +305,7 @@
                 /* id= */ verificationId,
                 /* installSessionId= */ installationSessionId,
                 packageName, stagedPackageUri, signingInfo, declaredLibraries, extensionParams,
-                verificationPolicy, new VerificationSessionInterface(callback),
-                new VerificationSessionCallback(callback));
+                verificationPolicy, new VerificationSessionInterface(callback));
         AndroidFuture<Void> unusedFuture = mRemoteService.post(service -> {
             if (!retry) {
                 if (DEBUG) {
@@ -468,17 +465,9 @@
             }
             return mCallback.setVerificationPolicy(policy);
         }
-    }
-
-    private class VerificationSessionCallback extends IVerificationSessionCallback.Stub {
-        private final PackageInstallerSession.VerifierCallback mCallback;
-
-        VerificationSessionCallback(PackageInstallerSession.VerifierCallback callback) {
-            mCallback = callback;
-        }
 
         @Override
-        public void reportVerificationIncomplete(int id, int reason) throws RemoteException {
+        public void reportVerificationIncomplete(int id, int reason) {
             checkCallerPermission();
             final VerificationStatusTracker tracker;
             synchronized (mVerificationStatus) {
@@ -494,16 +483,14 @@
         }
 
         @Override
-        public void reportVerificationComplete(int id, VerificationStatus verificationStatus)
-                throws RemoteException {
+        public void reportVerificationComplete(int id, VerificationStatus verificationStatus) {
             reportVerificationCompleteWithExtensionResponse(id, verificationStatus,
                     /* extensionResponse= */ null);
         }
 
         @Override
         public void reportVerificationCompleteWithExtensionResponse(int id,
-                VerificationStatus verificationStatus, PersistableBundle extensionResponse)
-                throws RemoteException {
+                VerificationStatus verificationStatus, PersistableBundle extensionResponse) {
             checkCallerPermission();
             final VerificationStatusTracker tracker;
             synchronized (mVerificationStatus) {