FileDocCategorySizeDatePackage
VibratorServicePermissionTest.javaAPI DocAndroid 5.1 API3092Thu Mar 12 22:22:44 GMT 2015com.android.framework.permission.tests

VibratorServicePermissionTest

public class VibratorServicePermissionTest extends TestCase
Verify that Hardware apis cannot be called without required permissions.

Fields Summary
private android.os.IVibratorService
mVibratorService
Constructors Summary
Methods Summary
protected voidsetUp()

        mVibratorService = IVibratorService.Stub.asInterface(
                ServiceManager.getService("vibrator"));
    
public voidtestCancelVibrate()
Test that calling {@link android.os.IVibratorService#cancelVibrate()} requires permissions.

Tests permission: {@link android.Manifest.permission#VIBRATE}

throws
RemoteException

        try {
            mVibratorService.cancelVibrate(new Binder());
            fail("cancelVibrate did not throw SecurityException as expected");
        } catch (SecurityException e) {
            // expected
        }
    
public voidtestVibrate()
Test that calling {@link android.os.IVibratorService#vibrate(long)} requires permissions.

Tests permission: {@link android.Manifest.permission#VIBRATE}

throws
RemoteException

        try {
            mVibratorService.vibrate(Process.myUid(), null, 2000, AudioManager.STREAM_ALARM,
                    new Binder());
            fail("vibrate did not throw SecurityException as expected");
        } catch (SecurityException e) {
            // expected
        }
    
public voidtestVibratePattern()
Test that calling {@link android.os.IVibratorService#vibratePattern(long[], int, android.os.IBinder)} requires permissions.

Tests permission: {@link android.Manifest.permission#VIBRATE}

throws
RemoteException

        try {
            mVibratorService.vibratePattern(Process.myUid(), null, new long[] {0}, 0,
                    AudioManager.STREAM_ALARM, new Binder());
            fail("vibratePattern did not throw SecurityException as expected");
        } catch (SecurityException e) {
            // expected
        }