Fix DeviceStateManagerServiceTests and add to presubmit.
1. The addition of the CONTROL_DEVICE_STATE permission broke the test as the permission was not granted to the test APK. 2. Publishing of the binder service was previously wrapped with a SecurityException catch which failed gracefully in the test. This prevents registering the binder service in the test. Test: atest DeviceStateManagerServiceTests Bug: 159401801 Change-Id: Ifc24ba370a30a86121ca1fa531b8a396f7513b97
This commit is contained in:
@@ -16,8 +16,8 @@
|
||||
|
||||
package com.android.server.devicestate;
|
||||
|
||||
import static android.hardware.devicestate.DeviceStateManager.INVALID_DEVICE_STATE;
|
||||
import static android.Manifest.permission.CONTROL_DEVICE_STATE;
|
||||
import static android.hardware.devicestate.DeviceStateManager.INVALID_DEVICE_STATE;
|
||||
|
||||
import android.annotation.NonNull;
|
||||
import android.content.Context;
|
||||
@@ -96,11 +96,11 @@ public final class DeviceStateManagerService extends SystemService {
|
||||
DeviceStateManagerService(@NonNull Context context, @NonNull DeviceStatePolicy policy) {
|
||||
super(context);
|
||||
mDeviceStatePolicy = policy;
|
||||
mDeviceStatePolicy.getDeviceStateProvider().setListener(new DeviceStateProviderListener());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
mDeviceStatePolicy.getDeviceStateProvider().setListener(new DeviceStateProviderListener());
|
||||
publishBinderService(Context.DEVICE_STATE_SERVICE, new BinderService());
|
||||
}
|
||||
|
||||
|
||||
@@ -85,6 +85,7 @@
|
||||
<uses-permission android:name="android.permission.VIBRATE"/>
|
||||
<uses-permission android:name="android.permission.ACCESS_VIBRATOR_STATE"/>
|
||||
<uses-permission android:name="android.permission.VIBRATE_ALWAYS_ON"/>
|
||||
<uses-permission android:name="android.permission.CONTROL_DEVICE_STATE"/>
|
||||
|
||||
<!-- Uses API introduced in O (26) -->
|
||||
<uses-sdk android:minSdkVersion="1"
|
||||
|
||||
@@ -21,6 +21,8 @@ import static android.hardware.devicestate.DeviceStateManager.INVALID_DEVICE_STA
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertThrows;
|
||||
|
||||
import android.platform.test.annotations.Presubmit;
|
||||
|
||||
import androidx.test.InstrumentationRegistry;
|
||||
import androidx.test.runner.AndroidJUnit4;
|
||||
|
||||
@@ -33,6 +35,7 @@ import org.junit.runner.RunWith;
|
||||
* <p/>
|
||||
* Run with <code>atest DeviceStateManagerServiceTest</code>.
|
||||
*/
|
||||
@Presubmit
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public final class DeviceStateManagerServiceTest {
|
||||
private static final int DEFAULT_DEVICE_STATE = 0;
|
||||
@@ -48,7 +51,6 @@ public final class DeviceStateManagerServiceTest {
|
||||
mProvider = new TestDeviceStateProvider();
|
||||
mPolicy = new TestDeviceStatePolicy(mProvider);
|
||||
mService = new DeviceStateManagerService(InstrumentationRegistry.getContext(), mPolicy);
|
||||
mService.onStart();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user