Merge "Adding test for injectKeyEvent" into sc-dev
diff --git a/car-lib/src/android/car/hardware/power/CarPowerPolicy.java b/car-lib/src/android/car/hardware/power/CarPowerPolicy.java
index 99fb245..bbc37eb 100644
--- a/car-lib/src/android/car/hardware/power/CarPowerPolicy.java
+++ b/car-lib/src/android/car/hardware/power/CarPowerPolicy.java
@@ -16,9 +16,12 @@
package android.car.hardware.power;
+import static com.android.car.internal.ExcludeFromCodeCoverageGeneratedReport.BOILERPLATE_CODE;
+
import android.annotation.NonNull;
import android.os.Parcelable;
+import com.android.car.internal.ExcludeFromCodeCoverageGeneratedReport;
import com.android.internal.util.DataClass;
/**
@@ -186,6 +189,7 @@
sourceFile = "packages/services/Car/car-lib/src/android/car/hardware/power/CarPowerPolicy.java",
inputSignatures = "private final @android.annotation.NonNull java.lang.String mPolicyId\nprivate final @android.annotation.NonNull int[] mEnabledComponents\nprivate final @android.annotation.NonNull int[] mDisabledComponents\nclass CarPowerPolicy extends java.lang.Object implements [android.os.Parcelable]\n@com.android.internal.util.DataClass(genHiddenConstructor=true)")
@Deprecated
+ @ExcludeFromCodeCoverageGeneratedReport(reason = BOILERPLATE_CODE)
private void __metadata() {}
diff --git a/car-lib/src/android/car/hardware/power/CarPowerPolicyFilter.java b/car-lib/src/android/car/hardware/power/CarPowerPolicyFilter.java
index 29b8ad6..2fce4b1 100644
--- a/car-lib/src/android/car/hardware/power/CarPowerPolicyFilter.java
+++ b/car-lib/src/android/car/hardware/power/CarPowerPolicyFilter.java
@@ -16,9 +16,12 @@
package android.car.hardware.power;
+import static com.android.car.internal.ExcludeFromCodeCoverageGeneratedReport.BOILERPLATE_CODE;
+
import android.annotation.NonNull;
import android.os.Parcelable;
+import com.android.car.internal.ExcludeFromCodeCoverageGeneratedReport;
import com.android.internal.util.DataClass;
/**
@@ -165,6 +168,7 @@
sourceFile = "packages/services/Car/car-lib/src/android/car/hardware/power/CarPowerPolicyFilter.java",
inputSignatures = "private @android.annotation.NonNull int[] mComponents\nclass CarPowerPolicyFilter extends java.lang.Object implements [android.os.Parcelable]\n@com.android.internal.util.DataClass(genBuilder=true)")
@Deprecated
+ @ExcludeFromCodeCoverageGeneratedReport(reason = BOILERPLATE_CODE)
private void __metadata() {}
diff --git a/tests/carservice_test/src/com/android/car/CarEvsManagerTest.java b/tests/carservice_test/src/com/android/car/CarEvsManagerTest.java
index 8aeea95..cb15747 100644
--- a/tests/carservice_test/src/com/android/car/CarEvsManagerTest.java
+++ b/tests/carservice_test/src/com/android/car/CarEvsManagerTest.java
@@ -96,7 +96,9 @@
@After
public void tearDown() throws Exception {
- mEvsManager.stopVideoStream();
+ if (mEvsManager != null) {
+ mEvsManager.stopVideoStream();
+ }
}
@Test
diff --git a/tests/carservice_test/src/com/android/car/garagemode/GarageModeServiceTest.java b/tests/carservice_test/src/com/android/car/garagemode/GarageModeServiceTest.java
index c1b45d3..cd9adfb 100644
--- a/tests/carservice_test/src/com/android/car/garagemode/GarageModeServiceTest.java
+++ b/tests/carservice_test/src/com/android/car/garagemode/GarageModeServiceTest.java
@@ -60,6 +60,15 @@
}
@Test
+ public void testInitAndRelease() {
+ mService.init();
+ mService.release();
+
+ verify(mMockController).init();
+ verify(mMockController).release();
+ }
+
+ @Test
public void testDump_shouldSucceed() {
when(mMockController.isGarageModeActive()).thenReturn(true);
@@ -68,4 +77,33 @@
List<String> strings = mCaptorString.getAllValues();
assertThat(strings.get(0)).isEqualTo("GarageModeInProgress true");
}
+
+ @Test
+ public void testIsGarageModeActive_true() {
+ when(mMockController.isGarageModeActive()).thenReturn(true);
+
+ assertThat(mService.isGarageModeActive()).isTrue();
+ }
+
+ @Test
+ public void testIsGarageModeActive_false() {
+ when(mMockController.isGarageModeActive()).thenReturn(false);
+
+ assertThat(mService.isGarageModeActive()).isFalse();
+ }
+
+ @Test
+ public void testForceStartGarageMode() {
+ mService.forceStartGarageMode();
+
+ verify(mMockController).initiateGarageMode(null);
+ }
+
+ @Test
+ public void testStopAndResetGarageMode() {
+ mService.stopAndResetGarageMode();
+
+ verify(mMockController).resetGarageMode();
+ }
+
}
diff --git a/tests/carservice_unit_test/src/com/android/car/power/CarPowerManagementServiceUnitTest.java b/tests/carservice_unit_test/src/com/android/car/power/CarPowerManagementServiceUnitTest.java
index 6384d69..1ad6b7e 100644
--- a/tests/carservice_unit_test/src/com/android/car/power/CarPowerManagementServiceUnitTest.java
+++ b/tests/carservice_unit_test/src/com/android/car/power/CarPowerManagementServiceUnitTest.java
@@ -560,6 +560,29 @@
assertThat(listenerAudio.getCurrentPowerPolicy()).isNull();
}
+ /**
+ * This test case increases the code coverage to cover methods
+ * {@code describeContents()} and {@code newArray()}. They are public APIs
+ * can not be marked out as BOILERPLATE_CODE.
+ */
+ @Test
+ public void testParcelableCreation() throws Exception {
+ grantPowerPolicyPermission();
+
+ CarPowerPolicy policy = mService.getCurrentPowerPolicy();
+ assertThat(policy.describeContents()).isEqualTo(0);
+
+ CarPowerPolicy[] policies = CarPowerPolicy.CREATOR.newArray(1);
+ assertThat(policies.length).isEqualTo(1);
+
+ CarPowerPolicyFilter filterAudio = new CarPowerPolicyFilter.Builder()
+ .setComponents(PowerComponent.AUDIO).build();
+ assertThat(filterAudio.describeContents()).isEqualTo(0);
+
+ CarPowerPolicyFilter[] filters = CarPowerPolicyFilter.CREATOR.newArray(1);
+ assertThat(filters.length).isEqualTo(1);
+ }
+
private void suspendAndResume() throws Exception {
Log.d(TAG, "suspend()");
mPowerHal.setCurrentPowerState(new PowerState(VehicleApPowerStateReq.SHUTDOWN_PREPARE,