Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e3a180a4 authored by Lais Andrade's avatar Lais Andrade
Browse files

Add all vibration requests to service dumpsys

Make sure we cover all vibration requests in the service dumpsys to help
debugging missing vibrations. If we log all requests received then we
can help identify the cause for it's rejection or isolate the
investigation area to the client code.

Fix: 360330409
Test: adb shell dumpsys vibrator_manager
Flag: EXEMPT small bug fix
Change-Id: I85d2392cbb6aa0147c6cee55f4414082964d6722
parent ca6734ab
Loading
Loading
Loading
Loading
+37 −4
Original line number Diff line number Diff line
@@ -487,25 +487,37 @@ public class VibratorManagerService extends IVibratorManagerService.Stub {
    HalVibration performHapticFeedbackInternal(
            int uid, int deviceId, String opPkg, int constant, String reason,
            IBinder token, int flags, int privFlags) {

        // Make sure we report the constant id in the requested haptic feedback reason.
        reason = "performHapticFeedback(constant=" + constant + "): " + reason;

        HapticFeedbackVibrationProvider hapticVibrationProvider = getHapticVibrationProvider();
        if (hapticVibrationProvider == null) {
            Slog.e(TAG, "performHapticFeedback; haptic vibration provider not ready.");
            logAndRecordPerformHapticFeedbackAttempt(uid, deviceId, opPkg, reason,
                    Vibration.Status.IGNORED_ERROR_SCHEDULING);
            return null;
        }

        if (hapticVibrationProvider.isRestrictedHapticFeedback(constant)
                && !hasPermission(android.Manifest.permission.VIBRATE_SYSTEM_CONSTANTS)) {
            Slog.w(TAG, "performHapticFeedback; no permission for system constant " + constant);
            logAndRecordPerformHapticFeedbackAttempt(uid, deviceId, opPkg, reason,
                    Vibration.Status.IGNORED_MISSING_PERMISSION);
            return null;
        }

        VibrationEffect effect = hapticVibrationProvider.getVibrationForHapticFeedback(constant);
        if (effect == null) {
            Slog.w(TAG, "performHapticFeedback; vibration absent for constant " + constant);
            logAndRecordPerformHapticFeedbackAttempt(uid, deviceId, opPkg, reason,
                    Vibration.Status.IGNORED_UNSUPPORTED);
            return null;
        }

        CombinedVibration vib = CombinedVibration.createParallel(effect);
        VibrationAttributes attrs = hapticVibrationProvider.getVibrationAttributesForHapticFeedback(
                constant, flags, privFlags);
        reason = "performHapticFeedback(constant=" + constant + "): " + reason;
        VibratorFrameworkStatsLogger.logPerformHapticsFeedbackIfKeyboard(uid, constant);
        return vibrateWithoutPermissionCheck(uid, deviceId, opPkg, vib, attrs, reason, token);
    }
@@ -563,22 +575,27 @@ public class VibratorManagerService extends IVibratorManagerService.Stub {
    private HalVibration vibrateInternal(int uid, int deviceId, String opPkg,
            @NonNull CombinedVibration effect, @NonNull VibrationAttributes attrs,
            String reason, IBinder token) {
        Vibration.CallerInfo callerInfo =
                new Vibration.CallerInfo(attrs, uid, deviceId, opPkg, reason);
        if (token == null) {
            Slog.e(TAG, "token must not be null");
            logAndRecordVibrationAttempt(effect, callerInfo, Vibration.Status.IGNORED_ERROR_TOKEN);
            return null;
        }
        if (effect.hasVendorEffects()
                && !hasPermission(android.Manifest.permission.VIBRATE_VENDOR_EFFECTS)) {
            Slog.w(TAG, "vibrate; no permission for vendor effects");
            Slog.e(TAG, "vibrate; no permission for vendor effects");
            logAndRecordVibrationAttempt(effect, callerInfo,
                    Vibration.Status.IGNORED_MISSING_PERMISSION);
            return null;
        }
        enforceUpdateAppOpsStatsPermission(uid);
        if (!isEffectValid(effect)) {
            logAndRecordVibrationAttempt(effect, callerInfo, Vibration.Status.IGNORED_UNSUPPORTED);
            return null;
        }
        // Create Vibration.Stats as close to the received request as possible, for tracking.
        HalVibration vib = new HalVibration(token, effect,
                new Vibration.CallerInfo(attrs, uid, deviceId, opPkg, reason));
        HalVibration vib = new HalVibration(token, effect, callerInfo);
        fillVibrationFallbacks(vib, effect);

        if (attrs.isFlagSet(VibrationAttributes.FLAG_INVALIDATE_SETTINGS_CACHE)) {
@@ -973,6 +990,22 @@ public class VibratorManagerService extends IVibratorManagerService.Stub {
        return new Vibration.EndInfo(Vibration.Status.FORWARDED_TO_INPUT_DEVICES);
    }

    private void logAndRecordPerformHapticFeedbackAttempt(int uid, int deviceId, String opPkg,
            String reason, Vibration.Status status) {
        Vibration.CallerInfo callerInfo = new Vibration.CallerInfo(
                VibrationAttributes.createForUsage(VibrationAttributes.USAGE_UNKNOWN),
                uid, deviceId, opPkg, reason);
        logAndRecordVibrationAttempt(/* effect= */ null, callerInfo, status);
    }

    private void logAndRecordVibrationAttempt(@Nullable CombinedVibration effect,
            Vibration.CallerInfo callerInfo, Vibration.Status status) {
        logAndRecordVibration(
                new Vibration.DebugInfo(status, new VibrationStats(),
                        effect, /* originalEffect= */ null, VibrationScaler.SCALE_NONE,
                        VibrationScaler.ADAPTIVE_SCALE_NONE, callerInfo));
    }

    private void logAndRecordVibration(Vibration.DebugInfo info) {
        info.logMetrics(mFrameworkStatsLogger);
        logVibrationStatus(info.mCallerInfo.uid, info.mCallerInfo.attrs, info.mStatus);