CTS coverage for package name in AmbientContextDetectionServiceStatus.Builder

Test: run cts test
Bug: 220030261
Change-Id: I4f2015f216048604e3a18dc6498d92a482d70d5f
(cherry picked from commit 2fb9af109b963221e932436c19010ab0b6dcaab5)
diff --git a/tests/ambientcontext/src/android/ambientcontext/cts/CtsAmbientContextDetectionService.java b/tests/ambientcontext/src/android/ambientcontext/cts/CtsAmbientContextDetectionService.java
index e880d2f..c2ae00e 100644
--- a/tests/ambientcontext/src/android/ambientcontext/cts/CtsAmbientContextDetectionService.java
+++ b/tests/ambientcontext/src/android/ambientcontext/cts/CtsAmbientContextDetectionService.java
@@ -30,6 +30,7 @@
 
 public class CtsAmbientContextDetectionService extends AmbientContextDetectionService {
     private static final String TAG = "CtsTestAmbientContextEventProviderService";
+    private static final String FAKE_APP_PACKAGE = "foo.bar.baz";
 
     private static Consumer<AmbientContextDetectionResult> sResultConsumer;
     private static Consumer<AmbientContextDetectionServiceStatus> sQueryConsumer;
@@ -63,13 +64,15 @@
 
     public static void respondSuccess(AmbientContextEvent event) {
         if (sResultConsumer != null) {
-            AmbientContextDetectionResult result = new AmbientContextDetectionResult.Builder()
-                    .addEvent(event).build();
+            AmbientContextDetectionResult result = new AmbientContextDetectionResult
+                    .Builder(FAKE_APP_PACKAGE)
+                    .addEvent(event)
+                    .build();
             sResultConsumer.accept(result);
         }
         if (sQueryConsumer != null) {
             AmbientContextDetectionServiceStatus serviceStatus =
-                    new AmbientContextDetectionServiceStatus.Builder()
+                    new AmbientContextDetectionServiceStatus.Builder(FAKE_APP_PACKAGE)
                             .setStatusCode(AmbientContextManager.STATUS_SUCCESS)
                             .build();
             sQueryConsumer.accept(serviceStatus);
@@ -80,7 +83,7 @@
     public static void respondFailure(int status) {
         if (sQueryConsumer != null) {
             AmbientContextDetectionServiceStatus serviceStatus =
-                    new AmbientContextDetectionServiceStatus.Builder()
+                    new AmbientContextDetectionServiceStatus.Builder(FAKE_APP_PACKAGE)
                             .setStatusCode(status)
                             .build();
             sQueryConsumer.accept(serviceStatus);
diff --git a/tests/ambientcontext/src/android/ambientcontext/cts/CtsAmbientContextDetectionServiceDeviceTest.java b/tests/ambientcontext/src/android/ambientcontext/cts/CtsAmbientContextDetectionServiceDeviceTest.java
index d648282..2aa89fa 100644
--- a/tests/ambientcontext/src/android/ambientcontext/cts/CtsAmbientContextDetectionServiceDeviceTest.java
+++ b/tests/ambientcontext/src/android/ambientcontext/cts/CtsAmbientContextDetectionServiceDeviceTest.java
@@ -52,6 +52,7 @@
 
     private static final String NAMESPACE_ambient_context = "ambient_context";
     private static final String KEY_SERVICE_ENABLED = "service_enabled";
+    private static final String FAKE_APP_PACKAGE = "foo.bar.baz";
     private static final String FAKE_SERVICE_PACKAGE =
             CtsAmbientContextDetectionService.class.getPackage().getName();
     private static final String USER_ID = "0";
@@ -100,6 +101,7 @@
 
         // From manager, verify callback was called
         assertThat(getLastStatusCode()).isEqualTo(AmbientContextManager.STATUS_SUCCESS);
+        assertThat(getLastAppPackageName()).isEqualTo(FAKE_APP_PACKAGE);
     }
 
     @Test
@@ -119,6 +121,7 @@
         // From manager, verify that the callback was called with STATUS_SERVICE_UNAVAILABLE
         assertThat(getLastStatusCode()).isEqualTo(
                 AmbientContextManager.STATUS_SERVICE_UNAVAILABLE);
+        assertThat(getLastAppPackageName()).isEqualTo(FAKE_APP_PACKAGE);
     }
 
     @Test
@@ -133,6 +136,7 @@
 
         // From manager, verify callback was called
         assertThat(getLastStatusCode()).isEqualTo(AmbientContextManager.STATUS_ACCESS_DENIED);
+        assertThat(getLastAppPackageName()).isEqualTo(FAKE_APP_PACKAGE);
     }
 
     private int getLastStatusCode() {
@@ -140,6 +144,11 @@
                 "cmd ambient_context get-last-status-code"));
     }
 
+    private String getLastAppPackageName() {
+        return runShellCommand(
+                "cmd ambient_context get-last-package-name");
+    }
+
     private void bindToTestService() {
         // On Manager, bind to test service
         assertThat(getAmbientContextDetectionServiceComponent()).isNotEqualTo(FAKE_SERVICE_PACKAGE);
@@ -159,7 +168,7 @@
      */
     private void callStartDetection() {
         runShellCommand("cmd ambient_context start-detection %s %s",
-                USER_ID, FAKE_SERVICE_PACKAGE);
+                USER_ID, FAKE_APP_PACKAGE);
         CtsAmbientContextDetectionService.onReceivedResponse();
     }
 
@@ -171,7 +180,7 @@
      */
     private void callQueryServiceStatus() {
         runShellCommand("cmd ambient_context query-service-status %s %s",
-                USER_ID, FAKE_SERVICE_PACKAGE);
+                USER_ID, FAKE_APP_PACKAGE);
         CtsAmbientContextDetectionService.onReceivedResponse();
     }