Restore the default power policy after test

Device's components could be in power off state if the default power
policy is not restored after CarPowerManagerTest.

Bug: 193718474
Test: 1. atest CtsCarTestCases:CarPowerManagerTest
      2. check if Wifi is enabled in the setting UI
      3. use adb shell dumpsys car_service --services
      CarPowerManagementService to check current power policy id is
      system_power_policy_all_on
      4. run the test over Seahawk, emulator and cf
Change-Id: I9c55b64f0bba6b0d5ff87b709fc714ff9ffc704c
diff --git a/tests/tests/car/src/android/car/cts/CarPowerManagerTest.java b/tests/tests/car/src/android/car/cts/CarPowerManagerTest.java
index c16943c..4cb1019 100644
--- a/tests/tests/car/src/android/car/cts/CarPowerManagerTest.java
+++ b/tests/tests/car/src/android/car/cts/CarPowerManagerTest.java
@@ -48,6 +48,7 @@
     private static final int NO_WAIT = 0;
 
     private CarPowerManager mCarPowerManager;
+    private String mInitialPowerPolicyId;
     private final Executor mExecutor = mContext.getMainExecutor();
 
     @Override
@@ -55,6 +56,15 @@
     public void setUp() throws Exception {
         super.setUp();
         mCarPowerManager = (CarPowerManager) getCar().getCarManager(Car.POWER_SERVICE);
+        mInitialPowerPolicyId = mCarPowerManager.getCurrentPowerPolicy().getPolicyId();
+    }
+
+    @After
+    public void teardown() throws Exception {
+        CarPowerPolicy policy = mCarPowerManager.getCurrentPowerPolicy();
+        if (!mInitialPowerPolicyId.equals(policy.getPolicyId())) {
+            applyPowerPolicy(mInitialPowerPolicyId);
+        }
     }
 
     /**
@@ -98,6 +108,8 @@
         makeSureExecutorReady();
         assertWithMessage("Added location listener's current policy")
                 .that(listenerLocation.getCurrentPolicyId(NO_WAIT)).isNull();
+
+        applyPowerPolicy(mInitialPowerPolicyId);
     }
 
     private void makeSureExecutorReady() throws Exception {