diff options
Diffstat (limited to 'core/java/android')
| -rw-r--r-- | core/java/android/app/AppOpsManager.java | 48 | ||||
| -rw-r--r-- | core/java/android/hardware/input/InputManager.java | 28 | ||||
| -rw-r--r-- | core/java/android/os/IVibratorService.aidl | 4 | ||||
| -rw-r--r-- | core/java/android/os/NullVibrator.java | 20 | ||||
| -rw-r--r-- | core/java/android/os/SystemVibrator.java | 25 | ||||
| -rw-r--r-- | core/java/android/os/Vibrator.java | 74 |
6 files changed, 140 insertions, 59 deletions
diff --git a/core/java/android/app/AppOpsManager.java b/core/java/android/app/AppOpsManager.java index 079cf7a..b616c1e 100644 --- a/core/java/android/app/AppOpsManager.java +++ b/core/java/android/app/AppOpsManager.java @@ -780,6 +780,25 @@ public class AppOpsManager { } } + /** + * Set a non-persisted restriction on an audio operation at a stream-level. + * Restrictions are temporary additional constraints imposed on top of the persisted rules + * defined by {@link #setMode}. + * + * @param code The operation to restrict. + * @param stream The {@link android.media.AudioManager} stream type. + * @param mode The restriction mode (MODE_IGNORED,MODE_ERRORED) or MODE_ALLOWED to unrestrict. + * @param exceptionPackages Optional list of packages to exclude from the restriction. + * @hide + */ + public void setRestriction(int code, int stream, int mode, String[] exceptionPackages) { + try { + final int uid = Binder.getCallingUid(); + mService.setAudioRestriction(code, stream, uid, mode, exceptionPackages); + } catch (RemoteException e) { + } + } + /** @hide */ public void resetAllModes() { try { @@ -1009,6 +1028,35 @@ public class AppOpsManager { } /** + * Like {@link #checkOp} but at a stream-level for audio operations. + * @hide + */ + public int checkAudioOp(int op, int stream, int uid, String packageName) { + try { + final int mode = mService.checkAudioOperation(op, stream, uid, packageName); + if (mode == MODE_ERRORED) { + throw new SecurityException(buildSecurityExceptionMsg(op, uid, packageName)); + } + return mode; + } catch (RemoteException e) { + } + return MODE_IGNORED; + } + + /** + * Like {@link #checkAudioOp} but instead of throwing a {@link SecurityException} it + * returns {@link #MODE_ERRORED}. + * @hide + */ + public int checkAudioOpNoThrow(int op, int stream, int uid, String packageName) { + try { + return mService.checkAudioOperation(op, stream, uid, packageName); + } catch (RemoteException e) { + } + return MODE_IGNORED; + } + + /** * Make note of an application performing an operation. Note that you must pass * in both the uid and name of the application to be checked; this function will verify * that these two match, and if not, return {@link #MODE_IGNORED}. If this call diff --git a/core/java/android/hardware/input/InputManager.java b/core/java/android/hardware/input/InputManager.java index e3a3830..0c0dfe9 100644 --- a/core/java/android/hardware/input/InputManager.java +++ b/core/java/android/hardware/input/InputManager.java @@ -853,13 +853,21 @@ public final class InputManager { return true; } + /** + * @hide + */ @Override - public void vibrate(long milliseconds) { + public void vibrate(int owningUid, String owningPackage, long milliseconds, + int streamHint) { vibrate(new long[] { 0, milliseconds}, -1); } + /** + * @hide + */ @Override - public void vibrate(long[] pattern, int repeat) { + public void vibrate(int owningUid, String owningPackage, long[] pattern, int repeat, + int streamHint) { if (repeat >= pattern.length) { throw new ArrayIndexOutOfBoundsException(); } @@ -870,22 +878,6 @@ public final class InputManager { } } - /** - * @hide - */ - @Override - public void vibrate(int owningUid, String owningPackage, long milliseconds) { - vibrate(milliseconds); - } - - /** - * @hide - */ - @Override - public void vibrate(int owningUid, String owningPackage, long[] pattern, int repeat) { - vibrate(pattern, repeat); - } - @Override public void cancel() { try { diff --git a/core/java/android/os/IVibratorService.aidl b/core/java/android/os/IVibratorService.aidl index 456ffb1..4854bc0 100644 --- a/core/java/android/os/IVibratorService.aidl +++ b/core/java/android/os/IVibratorService.aidl @@ -20,8 +20,8 @@ package android.os; interface IVibratorService { boolean hasVibrator(); - void vibrate(int uid, String packageName, long milliseconds, IBinder token); - void vibratePattern(int uid, String packageName, in long[] pattern, int repeat, IBinder token); + void vibrate(int uid, String packageName, long milliseconds, int streamHint, IBinder token); + void vibratePattern(int uid, String packageName, in long[] pattern, int repeat, int streamHint, IBinder token); void cancelVibrate(IBinder token); } diff --git a/core/java/android/os/NullVibrator.java b/core/java/android/os/NullVibrator.java index af90bdb..536da32 100644 --- a/core/java/android/os/NullVibrator.java +++ b/core/java/android/os/NullVibrator.java @@ -36,22 +36,11 @@ public class NullVibrator extends Vibrator { return false; } - @Override - public void vibrate(long milliseconds) { - } - - @Override - public void vibrate(long[] pattern, int repeat) { - if (repeat >= pattern.length) { - throw new ArrayIndexOutOfBoundsException(); - } - } - /** * @hide */ @Override - public void vibrate(int owningUid, String owningPackage, long milliseconds) { + public void vibrate(int owningUid, String owningPackage, long milliseconds, int streamHint) { vibrate(milliseconds); } @@ -59,8 +48,11 @@ public class NullVibrator extends Vibrator { * @hide */ @Override - public void vibrate(int owningUid, String owningPackage, long[] pattern, int repeat) { - vibrate(pattern, repeat); + public void vibrate(int owningUid, String owningPackage, long[] pattern, int repeat, + int streamHint) { + if (repeat >= pattern.length) { + throw new ArrayIndexOutOfBoundsException(); + } } @Override diff --git a/core/java/android/os/SystemVibrator.java b/core/java/android/os/SystemVibrator.java index 700f80d..13bc4f6 100644 --- a/core/java/android/os/SystemVibrator.java +++ b/core/java/android/os/SystemVibrator.java @@ -16,7 +16,6 @@ package android.os; -import android.app.ActivityThread; import android.content.Context; import android.util.Log; @@ -28,18 +27,16 @@ import android.util.Log; public class SystemVibrator extends Vibrator { private static final String TAG = "Vibrator"; - private final String mPackageName; private final IVibratorService mService; private final Binder mToken = new Binder(); public SystemVibrator() { - mPackageName = ActivityThread.currentPackageName(); mService = IVibratorService.Stub.asInterface( ServiceManager.getService("vibrator")); } public SystemVibrator(Context context) { - mPackageName = context.getOpPackageName(); + super(context); mService = IVibratorService.Stub.asInterface( ServiceManager.getService("vibrator")); } @@ -57,27 +54,17 @@ public class SystemVibrator extends Vibrator { return false; } - @Override - public void vibrate(long milliseconds) { - vibrate(Process.myUid(), mPackageName, milliseconds); - } - - @Override - public void vibrate(long[] pattern, int repeat) { - vibrate(Process.myUid(), mPackageName, pattern, repeat); - } - /** * @hide */ @Override - public void vibrate(int owningUid, String owningPackage, long milliseconds) { + public void vibrate(int owningUid, String owningPackage, long milliseconds, int streamHint) { if (mService == null) { Log.w(TAG, "Failed to vibrate; no vibrator service."); return; } try { - mService.vibrate(owningUid, owningPackage, milliseconds, mToken); + mService.vibrate(owningUid, owningPackage, milliseconds, streamHint, mToken); } catch (RemoteException e) { Log.w(TAG, "Failed to vibrate.", e); } @@ -87,7 +74,8 @@ public class SystemVibrator extends Vibrator { * @hide */ @Override - public void vibrate(int owningUid, String owningPackage, long[] pattern, int repeat) { + public void vibrate(int owningUid, String owningPackage, long[] pattern, int repeat, + int streamHint) { if (mService == null) { Log.w(TAG, "Failed to vibrate; no vibrator service."); return; @@ -97,7 +85,8 @@ public class SystemVibrator extends Vibrator { // anyway if (repeat < pattern.length) { try { - mService.vibratePattern(owningUid, owningPackage, pattern, repeat, mToken); + mService.vibratePattern(owningUid, owningPackage, pattern, repeat, streamHint, + mToken); } catch (RemoteException e) { Log.w(TAG, "Failed to vibrate.", e); } diff --git a/core/java/android/os/Vibrator.java b/core/java/android/os/Vibrator.java index 5d55143..53034d8 100644 --- a/core/java/android/os/Vibrator.java +++ b/core/java/android/os/Vibrator.java @@ -16,7 +16,9 @@ package android.os; +import android.app.ActivityThread; import android.content.Context; +import android.media.AudioManager; /** * Class that operates the vibrator on the device. @@ -28,10 +30,21 @@ import android.content.Context; * {@link Context#getSystemService} with {@link Context#VIBRATOR_SERVICE} as the argument. */ public abstract class Vibrator { + + private final String mPackageName; + /** * @hide to prevent subclassing from outside of the framework */ public Vibrator() { + mPackageName = ActivityThread.currentPackageName(); + } + + /** + * @hide to prevent subclassing from outside of the framework + */ + protected Vibrator(Context context) { + mPackageName = context.getOpPackageName(); } /** @@ -40,7 +53,7 @@ public abstract class Vibrator { * @return True if the hardware has a vibrator, else false. */ public abstract boolean hasVibrator(); - + /** * Vibrate constantly for the specified period of time. * <p>This method requires the caller to hold the permission @@ -48,7 +61,23 @@ public abstract class Vibrator { * * @param milliseconds The number of milliseconds to vibrate. */ - public abstract void vibrate(long milliseconds); + public void vibrate(long milliseconds) { + vibrate(milliseconds, AudioManager.USE_DEFAULT_STREAM_TYPE); + } + + /** + * Vibrate constantly for the specified period of time. + * <p>This method requires the caller to hold the permission + * {@link android.Manifest.permission#VIBRATE}. + * + * @param milliseconds The number of milliseconds to vibrate. + * @param streamHint An {@link AudioManager} stream type corresponding to the vibration type. + * For example, specify {@link AudioManager.STREAM_ALARM} for alarm vibrations or + * {@link AudioManager.STREAM_RING} for vibrations associated with incoming calls. + */ + public void vibrate(long milliseconds, int streamHint) { + vibrate(Process.myUid(), mPackageName, milliseconds, streamHint); + } /** * Vibrate with a given pattern. @@ -70,21 +99,52 @@ public abstract class Vibrator { * @param repeat the index into pattern at which to repeat, or -1 if * you don't want to repeat. */ - public abstract void vibrate(long[] pattern, int repeat); + public void vibrate(long[] pattern, int repeat) { + vibrate(pattern, repeat, AudioManager.USE_DEFAULT_STREAM_TYPE); + } + + /** + * Vibrate with a given pattern. + * + * <p> + * Pass in an array of ints that are the durations for which to turn on or off + * the vibrator in milliseconds. The first value indicates the number of milliseconds + * to wait before turning the vibrator on. The next value indicates the number of milliseconds + * for which to keep the vibrator on before turning it off. Subsequent values alternate + * between durations in milliseconds to turn the vibrator off or to turn the vibrator on. + * </p><p> + * To cause the pattern to repeat, pass the index into the pattern array at which + * to start the repeat, or -1 to disable repeating. + * </p> + * <p>This method requires the caller to hold the permission + * {@link android.Manifest.permission#VIBRATE}. + * + * @param pattern an array of longs of times for which to turn the vibrator on or off. + * @param repeat the index into pattern at which to repeat, or -1 if + * you don't want to repeat. + * @param streamHint An {@link AudioManager} stream type corresponding to the vibration type. + * For example, specify {@link AudioManager.STREAM_ALARM} for alarm vibrations or + * {@link AudioManager.STREAM_RING} for vibrations associated with incoming calls. + */ + public void vibrate(long[] pattern, int repeat, int streamHint) { + vibrate(Process.myUid(), mPackageName, pattern, repeat, streamHint); + } /** * @hide - * Like {@link #vibrate(long)}, but allowing the caller to specify that + * Like {@link #vibrate(long, int)}, but allowing the caller to specify that * the vibration is owned by someone else. */ - public abstract void vibrate(int owningUid, String owningPackage, long milliseconds); + public abstract void vibrate(int owningUid, String owningPackage, + long milliseconds, int streamHint); /** * @hide - * Like {@link #vibrate(long[], int)}, but allowing the caller to specify that + * Like {@link #vibrate(long[], int, int)}, but allowing the caller to specify that * the vibration is owned by someone else. */ - public abstract void vibrate(int owningUid, String owningPackage, long[] pattern, int repeat); + public abstract void vibrate(int owningUid, String owningPackage, + long[] pattern, int repeat, int streamHint); /** * Turn the vibrator off. |
