Merge "Add core volume group call to set preferred device for strategy" into main
diff --git a/car-lib/src/android/car/hardware/power/CarPowerPolicy.java b/car-lib/src/android/car/hardware/power/CarPowerPolicy.java
index b343184..66ee488 100644
--- a/car-lib/src/android/car/hardware/power/CarPowerPolicy.java
+++ b/car-lib/src/android/car/hardware/power/CarPowerPolicy.java
@@ -16,6 +16,8 @@
 
 package android.car.hardware.power;
 
+import static android.car.hardware.power.PowerComponentUtil.powerComponentsToString;
+
 import static com.android.car.internal.ExcludeFromCodeCoverageGeneratedReport.BOILERPLATE_CODE;
 
 import android.annotation.NonNull;
@@ -24,6 +26,7 @@
 import com.android.car.internal.ExcludeFromCodeCoverageGeneratedReport;
 import com.android.car.internal.util.AnnotationValidations;
 import com.android.car.internal.util.DataClass;
+import com.android.car.internal.util.Lists;
 
 /**
  * Car power policy definition.
@@ -33,19 +36,19 @@
     /**
      * ID of power policy.
      */
-    private final @NonNull String mPolicyId;
+    private @NonNull String mPolicyId = "";
 
     /**
      * List of enabled components. Components are one of
      * {@code android.frameworks.automotive.powerpolicy.PowerComponent}.
      */
-    private final @NonNull int[] mEnabledComponents;
+    private @NonNull int[] mEnabledComponents = new int[]{};
 
     /**
      * List of disabled components. Components are one of
      * {@code android.frameworks.automotive.powerpolicy.PowerComponent}.
      */
-    private final @NonNull int[] mDisabledComponents;
+    private @NonNull int[] mDisabledComponents = new int[]{};
 
     /**
      * Returns {@code true} if the given component is enabled in the power policy. Otherwise,
@@ -60,6 +63,14 @@
         return false;
     }
 
+    @Override
+    @ExcludeFromCodeCoverageGeneratedReport(reason = BOILERPLATE_CODE)
+    public String toString() {
+        return String.format("%s(enabledComponents: %s, disabledComponents: %s)", mPolicyId,
+                powerComponentsToString(Lists.asImmutableList(mEnabledComponents)),
+                powerComponentsToString(Lists.asImmutableList(mDisabledComponents)));
+    }
+
 
 
     // Code below generated by codegen v1.0.23.
diff --git a/car-lib/src/android/car/hardware/power/PowerComponentUtil.java b/car-lib/src/android/car/hardware/power/PowerComponentUtil.java
index c1ee70d..734c437 100644
--- a/car-lib/src/android/car/hardware/power/PowerComponentUtil.java
+++ b/car-lib/src/android/car/hardware/power/PowerComponentUtil.java
@@ -244,4 +244,23 @@
         }
         return powerComponents;
     }
+
+    /**
+     * Convert list of {@link PowerComponent} to string containing a list of the components,
+     * each separated by a comma and a space. (Example: "AUDIO, WIFI")
+     */
+    @NonNull
+    public static String powerComponentsToString(Iterable<Integer> components) {
+        StringBuilder builder = new StringBuilder();
+        Iterator<Integer> componentsIterator = components.iterator();
+        // Do first element separately to not start the list with a comma
+        if (componentsIterator.hasNext()) {
+            builder.append(powerComponentToString(componentsIterator.next()));
+        }
+        while (componentsIterator.hasNext()) {
+            builder.append(
+                    String.format(", %s", powerComponentToString(componentsIterator.next())));
+        }
+        return builder.toString();
+    }
 }
diff --git a/car-lib/src/android/car/remoteaccess/CarRemoteAccessManager.java b/car-lib/src/android/car/remoteaccess/CarRemoteAccessManager.java
index 8638167..e0c687f 100644
--- a/car-lib/src/android/car/remoteaccess/CarRemoteAccessManager.java
+++ b/car-lib/src/android/car/remoteaccess/CarRemoteAccessManager.java
@@ -50,7 +50,7 @@
  * System is not running.
  *
  * <p>The remote task client registers to {@link CarRemoteAccessManager} to listen to remote access
- * events. At {@link RemoteTaskClientCallback#onClientRegistered} it is required to share
+ * events. At {@link RemoteTaskClientCallback#onRegistrationUpdated} it is required to share
  * {@code serviceId}, {@code deviceId} and {@code clientId} with the cloud service which will use
  * the IDs to wake the vehicle. At {@link RemoteTaskClientCallback#onRemoteTaskRequested}, it starts
  * executing the given task. It is supposed to call {@link #reportRemoteTaskDone(String)} when it
@@ -77,7 +77,7 @@
  * <p>For serverless setup, there is a pre-configured set of serverless remote task clients. They
  * register to {@link CarRemoteAccessManager} to listen to remote access events.
  * {@link RemoteTaskClientCallback#onServerlessClientRegistered} will be called instead of
- * {@link RemoteTaskClientCallback#onClientRegistered} and there is no cloud service involved.
+ * {@link RemoteTaskClientCallback#onRegistrationUpdated} and there is no cloud service involved.
  * {@link RemoteTaskClientCallback#onRemoteTaskRequested} will be invoked when the task is to be
  * executed. It is supposed to call {@link #reportRemoteTaskDone(String)} when it
  * finishes the given task. Once the task completion is reported or the timeout expires, Android
@@ -285,7 +285,7 @@
          * <p>For a serverless remote task client, the {@link onServerlessClientRegistered} will be
          * called instead of this.
          *
-         * @param info {@link RemoteTaskClientRegistrationIfno} which contains wake-up service ID,
+         * @param info {@link RemoteTaskClientRegistrationInfo} which contains wake-up service ID,
          *             vehicle ID, processor ID and client ID.
          */
         void onRegistrationUpdated(@NonNull RemoteTaskClientRegistrationInfo info);
diff --git a/service/src/com/android/car/power/CarPowerManagementService.java b/service/src/com/android/car/power/CarPowerManagementService.java
index 982399e..5ae0b39 100644
--- a/service/src/com/android/car/power/CarPowerManagementService.java
+++ b/service/src/com/android/car/power/CarPowerManagementService.java
@@ -19,6 +19,8 @@
 import static android.car.feature.Flags.carPowerPolicyRefactoring;
 import static android.car.hardware.power.CarPowerManager.STATE_PRE_SHUTDOWN_PREPARE;
 import static android.car.hardware.power.CarPowerManager.STATE_SHUTDOWN_PREPARE;
+import static android.car.hardware.power.PowerComponentUtil.FIRST_POWER_COMPONENT;
+import static android.car.hardware.power.PowerComponentUtil.LAST_POWER_COMPONENT;
 import static android.net.ConnectivityManager.TETHERING_WIFI;
 
 import static com.android.car.internal.ExcludeFromCodeCoverageGeneratedReport.DUMP_INFO;
@@ -283,8 +285,6 @@
     // TODO(b/286303350): remove after policy refactor, since daemon will be source of truth
     @GuardedBy("mLock")
     private String mCurrentPowerPolicyId;
-    @GuardedBy("mLock")
-    private CarPowerPolicy mCurrentAccumulatedPowerPolicy;
     // TODO(b/286303350): remove after policy refactor, since daemon will control power policy
     @GuardedBy("mLock")
     private String mPendingPowerPolicyId;
@@ -295,6 +295,8 @@
     // TODO(b/286303350): remove after policy refactor, since daemon will control power policy
     @GuardedBy("mLock")
     private boolean mHasControlOverDaemon;
+    @GuardedBy("mLock")
+    private CarPowerPolicy mCurrentAccumulatedPowerPolicy = getInitialAccumulatedPowerPolicy();
     private AtomicBoolean mIsListenerWaitingCancelled = new AtomicBoolean(false);
     private final Semaphore mListenerCompletionSem = new Semaphore(/* permits= */ 0);
     @GuardedBy("mLock")
@@ -2041,6 +2043,18 @@
         }
     }
 
+    private static CarPowerPolicy getInitialAccumulatedPowerPolicy() {
+        String initialPolicyId = "";
+        int[] enabledComponents = new int[0];
+        int[] disabledComponents = new int[LAST_POWER_COMPONENT - FIRST_POWER_COMPONENT + 1];
+        int disabledIndex = 0;
+        for (int component = FIRST_POWER_COMPONENT; component <= LAST_POWER_COMPONENT;
+                component++) {
+            disabledComponents[disabledIndex++] = component;
+        }
+        return new CarPowerPolicy(initialPolicyId, enabledComponents, disabledComponents);
+    }
+
     private void initializeRegisteredPowerPolicies(
             android.frameworks.automotive.powerpolicy.CarPowerPolicy[] policies) {
         for (int i = 0; i < policies.length; i++) {
diff --git a/tests/carservice_unit_test/res/raw/car_hidden_apis.txt b/tests/carservice_unit_test/res/raw/car_hidden_apis.txt
index f0f8a97..0cb6fb7 100644
--- a/tests/carservice_unit_test/res/raw/car_hidden_apis.txt
+++ b/tests/carservice_unit_test/res/raw/car_hidden_apis.txt
@@ -438,6 +438,7 @@
 android.car.hardware.power CarPowerManager void scheduleNextWakeupTime(int seconds)
 android.car.hardware.power PowerComponentUtil List<String> powerComponentsToStrings(Iterable<Integer> components)
 android.car.hardware.power PowerComponentUtil String powerComponentToString(int component)
+android.car.hardware.power PowerComponentUtil String powerComponentsToString(Iterable<Integer> components)
 android.car.hardware.power PowerComponentUtil boolean hasComponents(CarPowerPolicy policy, CarPowerPolicyFilter filter)
 android.car.hardware.power PowerComponentUtil boolean isValidPowerComponent(int component)
 android.car.hardware.power PowerComponentUtil int COMPONENT_STATE_DISABLED