Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8ca4e81d authored by Darryl L Johnson's avatar Darryl L Johnson
Browse files

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
parent e33b2810
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -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());
    }

+1 −0
Original line number Diff line number Diff line
@@ -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"
+3 −1
Original line number Diff line number Diff line
@@ -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