diff options
| author | 2015-03-19 01:11:55 +0800 | |
|---|---|---|
| committer | 2015-03-18 19:01:36 +0000 | |
| commit | d3b371755df509cabbc5b4451df83309be5439b0 (patch) | |
| tree | 70d3cd4df91e053459d63cdbc1d1a41c1a25f45b | |
| parent | 28e6aeca3aad075ef4fd7aab08cd1ad1ff9eb555 (diff) | |
Fix no vibration during shutdown.
In ShutdownThread:rebootOrShutdown, the vibrator is created
by "new SystemVibrator()" which will use default constructor
of Vibrator.
And because system server is not bound application,
ActivityThread.currentPackageName will be null.
Then the member mPackageName of Vibrator is null.
When doing vibration:
VibratorService.startVibrationLocked
-> mAppOpsService.startOperation
-> getOpsLocked (null package will get null op)
-> return MODE_ERRORED
-> no vibration
https://code.google.com/p/android/issues/detail?id=160830
Pass null context in SystemServer.performPendingShutdown
because vibrator service is not ready, and from the call
sequence, there is no available context to use.
Change-Id: I3e0175ba6dc2e1a92787873eda4461fba6e89783
| -rw-r--r-- | services/core/java/com/android/server/power/ShutdownThread.java | 9 | ||||
| -rw-r--r-- | services/java/com/android/server/SystemServer.java | 2 |
2 files changed, 6 insertions, 5 deletions
diff --git a/services/core/java/com/android/server/power/ShutdownThread.java b/services/core/java/com/android/server/power/ShutdownThread.java index da1138771e39..f61a0c81d09d 100644 --- a/services/core/java/com/android/server/power/ShutdownThread.java +++ b/services/core/java/com/android/server/power/ShutdownThread.java @@ -384,7 +384,7 @@ public final class ShutdownThread extends Thread { } } - rebootOrShutdown(mReboot, mRebootReason); + rebootOrShutdown(mContext, mReboot, mRebootReason); } private void shutdownRadios(int timeout) { @@ -501,17 +501,18 @@ public final class ShutdownThread extends Thread { * Do not call this directly. Use {@link #reboot(Context, String, boolean)} * or {@link #shutdown(Context, boolean)} instead. * + * @param context Context used to vibrate or null without vibration * @param reboot true to reboot or false to shutdown * @param reason reason for reboot */ - public static void rebootOrShutdown(boolean reboot, String reason) { + public static void rebootOrShutdown(final Context context, boolean reboot, String reason) { if (reboot) { Log.i(TAG, "Rebooting, reason: " + reason); PowerManagerService.lowLevelReboot(reason); Log.e(TAG, "Reboot failed, will attempt shutdown instead"); - } else if (SHUTDOWN_VIBRATE_MS > 0) { + } else if (SHUTDOWN_VIBRATE_MS > 0 && context != null) { // vibrate before shutting down - Vibrator vibrator = new SystemVibrator(); + Vibrator vibrator = new SystemVibrator(context); try { vibrator.vibrate(SHUTDOWN_VIBRATE_MS, VIBRATION_ATTRIBUTES); } catch (Exception e) { diff --git a/services/java/com/android/server/SystemServer.java b/services/java/com/android/server/SystemServer.java index 78711477511f..fa12d5f51eb4 100644 --- a/services/java/com/android/server/SystemServer.java +++ b/services/java/com/android/server/SystemServer.java @@ -288,7 +288,7 @@ public final class SystemServer { reason = null; } - ShutdownThread.rebootOrShutdown(reboot, reason); + ShutdownThread.rebootOrShutdown(null, reboot, reason); } } |