diff options
| -rwxr-xr-x | core/res/res/values/config.xml | 3 | ||||
| -rwxr-xr-x | core/res/res/values/symbols.xml | 1 | ||||
| -rw-r--r-- | services/core/java/com/android/server/VibratorService.java | 82 |
3 files changed, 84 insertions, 2 deletions
diff --git a/core/res/res/values/config.xml b/core/res/res/values/config.xml index 4bc2205..451813c 100755 --- a/core/res/res/values/config.xml +++ b/core/res/res/values/config.xml @@ -2258,4 +2258,7 @@ <!-- Flag indicating device support for EAP SIM, AKA, AKA' --> <bool name="config_eap_sim_based_auth_supported">true</bool> + + <!-- How long history of previous vibrations should be kept for the dumpsys. --> + <integer name="config_previousVibrationsDumpLimit">20</integer> </resources> diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml index ebbbc4c..01ecba8 100755 --- a/core/res/res/values/symbols.xml +++ b/core/res/res/values/symbols.xml @@ -1708,6 +1708,7 @@ <java-symbol type="integer" name="config_notificationsBatteryLowARGB" /> <java-symbol type="integer" name="config_notificationsBatteryMediumARGB" /> <java-symbol type="integer" name="config_notificationServiceArchiveSize" /> + <java-symbol type="integer" name="config_previousVibrationsDumpLimit" /> <java-symbol type="integer" name="config_radioScanningTimeout" /> <java-symbol type="integer" name="config_screenBrightnessSettingMinimum" /> <java-symbol type="integer" name="config_screenBrightnessSettingMaximum" /> diff --git a/services/core/java/com/android/server/VibratorService.java b/services/core/java/com/android/server/VibratorService.java index 20f6f1c..30f4dce 100644 --- a/services/core/java/com/android/server/VibratorService.java +++ b/services/core/java/com/android/server/VibratorService.java @@ -47,7 +47,10 @@ import android.media.AudioAttributes; import com.android.internal.app.IAppOpsService; import com.android.internal.app.IBatteryStats; +import java.io.FileDescriptor; +import java.io.PrintWriter; import java.util.ArrayList; +import java.util.Arrays; import java.util.Iterator; import java.util.LinkedList; import java.util.ListIterator; @@ -58,6 +61,8 @@ public class VibratorService extends IVibratorService.Stub private static final boolean DEBUG = false; private final LinkedList<Vibration> mVibrations; + private final LinkedList<VibrationInfo> mPreviousVibrations; + private final int mPreviousVibrationsLimit; private Vibration mCurrentVibration; private final WorkSource mTmpWorkSource = new WorkSource(); private final Handler mH = new Handler(); @@ -146,6 +151,47 @@ public class VibratorService extends IVibratorService.Stub } } + private static class VibrationInfo { + long timeout; + long startTime; + long[] pattern; + int repeat; + int usageHint; + int uid; + String opPkg; + + public VibrationInfo(long timeout, long startTime, long[] pattern, int repeat, + int usageHint, int uid, String opPkg) { + this.timeout = timeout; + this.startTime = startTime; + this.pattern = pattern; + this.repeat = repeat; + this.usageHint = usageHint; + this.uid = uid; + this.opPkg = opPkg; + } + + @Override + public String toString() { + return new StringBuilder() + .append("timeout: ") + .append(timeout) + .append(", startTime: ") + .append(startTime) + .append(", pattern: ") + .append(Arrays.toString(pattern)) + .append(", repeat: ") + .append(repeat) + .append(", usageHint: ") + .append(usageHint) + .append(", uid: ") + .append(uid) + .append(", opPkg: ") + .append(opPkg) + .toString(); + } + } + VibratorService(Context context) { // Reset the hardware to a default state, in case this is a runtime // restart instead of a fresh boot. @@ -161,7 +207,11 @@ public class VibratorService extends IVibratorService.Stub mBatteryStatsService = IBatteryStats.Stub.asInterface(ServiceManager.getService( BatteryStats.SERVICE_NAME)); - mVibrations = new LinkedList<Vibration>(); + mPreviousVibrationsLimit = mContext.getResources().getInteger( + com.android.internal.R.integer.config_previousVibrationsDumpLimit); + + mVibrations = new LinkedList<>(); + mPreviousVibrations = new LinkedList<>(); IntentFilter filter = new IntentFilter(); filter.addAction(Intent.ACTION_SCREEN_OFF); @@ -252,6 +302,7 @@ public class VibratorService extends IVibratorService.Stub removeVibrationLocked(token); doCancelVibrateLocked(); mCurrentVibration = vib; + addToPreviousVibrationsLocked(vib); startVibrationLocked(vib); } } finally { @@ -315,6 +366,7 @@ public class VibratorService extends IVibratorService.Stub mCurrentVibration = vib; startVibrationLocked(vib); } + addToPreviousVibrationsLocked(vib); } } finally { @@ -322,6 +374,14 @@ public class VibratorService extends IVibratorService.Stub } } + private void addToPreviousVibrationsLocked(Vibration vib) { + if (mPreviousVibrations.size() > mPreviousVibrationsLimit) { + mPreviousVibrations.removeFirst(); + } + mPreviousVibrations.addLast(new VibratorService.VibrationInfo(vib.mTimeout, vib.mStartTime, + vib.mPattern, vib.mRepeat, vib.mUsageHint, vib.mUid, vib.mOpPkg)); + } + @Override // Binder call public void cancelVibrate(IBinder token) { mContext.enforceCallingOrSelfPermission( @@ -649,7 +709,6 @@ public class VibratorService extends IVibratorService.Stub if (!mDone) { // If this vibration finished naturally, start the next // vibration. - mVibrations.remove(mVibration); unlinkVibration(mVibration); startNextVibrationLocked(); } @@ -685,4 +744,23 @@ public class VibratorService extends IVibratorService.Stub } } }; + + @Override + protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) { + if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) + != PackageManager.PERMISSION_GRANTED) { + + pw.println("Permission Denial: can't dump vibrator service from from pid=" + + Binder.getCallingPid() + + ", uid=" + Binder.getCallingUid()); + return; + } + pw.println("Previous vibrations:"); + synchronized (mVibrations) { + for (VibrationInfo info : mPreviousVibrations) { + pw.print(" "); + pw.println(info.toString()); + } + } + } } |
