From 55a0aebe7f1426a08dbe234ee65657b07846b430 Mon Sep 17 00:00:00 2001 From: Lais Andrade Date: Fri, 11 Dec 2020 19:45:42 +0000 Subject: Introduce SystemVibratorManager Add default system implementation of vibrator manager service that uses IVibratorManagerService to access the device vibrators. Change implementation of SystemVibrator to use VibratorManagerService and delete local service VibratorService. Introduce missing public APIs for VibratorManager and Vibrator.getId. Bug: 167946816 Test: VibratorManagerServiceTest, VibratorTest, VibrationEffectTest Change-Id: I55cdeb72c7ca39ccf0c7b2fda60b16de1031801e --- .../VibratorManagerServicePermissionTest.java | 84 ++++++++++++++++++++++ .../tests/VibratorServicePermissionTest.java | 80 --------------------- 2 files changed, 84 insertions(+), 80 deletions(-) create mode 100644 tests/permission/src/com/android/framework/permission/tests/VibratorManagerServicePermissionTest.java delete mode 100644 tests/permission/src/com/android/framework/permission/tests/VibratorServicePermissionTest.java (limited to 'tests/permission/src') diff --git a/tests/permission/src/com/android/framework/permission/tests/VibratorManagerServicePermissionTest.java b/tests/permission/src/com/android/framework/permission/tests/VibratorManagerServicePermissionTest.java new file mode 100644 index 000000000000..0f920b36cffd --- /dev/null +++ b/tests/permission/src/com/android/framework/permission/tests/VibratorManagerServicePermissionTest.java @@ -0,0 +1,84 @@ +/* + * Copyright (C) 2009 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.framework.permission.tests; + +import android.content.Context; +import android.os.Binder; +import android.os.CombinedVibrationEffect; +import android.os.IBinder; +import android.os.IVibratorManagerService; +import android.os.Process; +import android.os.RemoteException; +import android.os.ServiceManager; +import android.os.VibrationAttributes; +import android.os.VibrationEffect; +import android.test.suitebuilder.annotation.SmallTest; + +import junit.framework.TestCase; + + +/** + * Verify that Hardware apis cannot be called without required permissions. + */ +@SmallTest +public class VibratorManagerServicePermissionTest extends TestCase { + + private IVibratorManagerService mVibratorService; + + @Override + protected void setUp() throws Exception { + mVibratorService = IVibratorManagerService.Stub.asInterface( + ServiceManager.getService(Context.VIBRATOR_MANAGER_SERVICE)); + } + + /** + * Test that calling {@link android.os.IVibratorManagerService#vibrate(int, String, + * CombinedVibrationEffect, VibrationAttributes, String, IBinder)} requires permissions. + *

Tests permission: + * {@link android.Manifest.permission#VIBRATE} + */ + public void testVibrate() throws RemoteException { + try { + CombinedVibrationEffect effect = + CombinedVibrationEffect.createSynced( + VibrationEffect.createOneShot(100, VibrationEffect.DEFAULT_AMPLITUDE)); + VibrationAttributes attrs = new VibrationAttributes.Builder() + .setUsage(VibrationAttributes.USAGE_ALARM) + .build(); + mVibratorService.vibrate(Process.myUid(), null, effect, attrs, + "testVibrate", new Binder()); + fail("vibrate did not throw SecurityException as expected"); + } catch (SecurityException e) { + // expected + } + } + + /** + * Test that calling {@link android.os.IVibratorManagerService#cancelVibrate(IBinder)} requires + * permissions. + *

Tests permission: + * {@link android.Manifest.permission#VIBRATE} + */ + public void testCancelVibrate() throws RemoteException { + try { + mVibratorService.cancelVibrate(new Binder()); + fail("cancelVibrate did not throw SecurityException as expected"); + } catch (SecurityException e) { + // expected + } + } +} diff --git a/tests/permission/src/com/android/framework/permission/tests/VibratorServicePermissionTest.java b/tests/permission/src/com/android/framework/permission/tests/VibratorServicePermissionTest.java deleted file mode 100644 index d1d6a26790fd..000000000000 --- a/tests/permission/src/com/android/framework/permission/tests/VibratorServicePermissionTest.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright (C) 2009 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.framework.permission.tests; - -import android.os.Binder; -import android.os.IVibratorService; -import android.os.Process; -import android.os.RemoteException; -import android.os.ServiceManager; -import android.os.VibrationAttributes; -import android.os.VibrationEffect; -import android.test.suitebuilder.annotation.SmallTest; - -import junit.framework.TestCase; - - -/** - * Verify that Hardware apis cannot be called without required permissions. - */ -@SmallTest -public class VibratorServicePermissionTest extends TestCase { - - private IVibratorService mVibratorService; - - @Override - protected void setUp() throws Exception { - mVibratorService = IVibratorService.Stub.asInterface( - ServiceManager.getService("vibrator")); - } - - /** - * Test that calling {@link android.os.IVibratorService#vibrate(long)} requires permissions. - *

Tests permission: - * {@link android.Manifest.permission#VIBRATE} - * @throws RemoteException - */ - public void testVibrate() throws RemoteException { - try { - final VibrationEffect effect = - VibrationEffect.createOneShot(100, VibrationEffect.DEFAULT_AMPLITUDE); - final VibrationAttributes attrs = new VibrationAttributes.Builder() - .setUsage(VibrationAttributes.USAGE_ALARM) - .build(); - mVibratorService.vibrate(Process.myUid(), null, effect, attrs, - "testVibrate", new Binder()); - fail("vibrate did not throw SecurityException as expected"); - } catch (SecurityException e) { - // expected - } - } - - /** - * Test that calling {@link android.os.IVibratorService#cancelVibrate()} requires permissions. - *

Tests permission: - * {@link android.Manifest.permission#VIBRATE} - * @throws RemoteException - */ - public void testCancelVibrate() throws RemoteException { - try { - mVibratorService.cancelVibrate(new Binder()); - fail("cancelVibrate did not throw SecurityException as expected"); - } catch (SecurityException e) { - // expected - } - } -} -- cgit v1.2.3-59-g8ed1b