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

Commit 8d53eaf8 authored by Ahmad Khalil's avatar Ahmad Khalil
Browse files

Enable runtime logging in vibrator

Adding the ability to enable/disable vibrator logging through adb shell commands.

Bug: 399368467
Flag: EXEMPT log only update
Test: adb shell setprop persist.log.tag.Vibrator_All DEBUG
Test: adb shell setprop persist.log.tag.Vibrator_All \"\"
Change-Id: I48b6e1fe653892c44c24fd988f725d609eb04bc5
parent 48f483b8
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -51,7 +51,9 @@ import java.util.NoSuchElementException;
final class VendorVibrationSession extends IVibrationSession.Stub
        implements VibrationSession, CancellationSignal.OnCancelListener, IBinder.DeathRecipient {
    private static final String TAG = "VendorVibrationSession";
    private static final boolean DEBUG = false;
    // To enable these logs, run:
    // 'adb shell setprop persist.log.tag.VendorVibrationSession DEBUG && adb reboot'
    private static final boolean DEBUG = VibratorDebugUtils.isDebuggable(TAG);

    /** Calls into VibratorManager functionality needed for playing an {@link ExternalVibration}. */
    interface VibratorManagerHooks {
+3 −1
Original line number Diff line number Diff line
@@ -36,7 +36,9 @@ import java.util.Objects;
/** Plays a {@link HalVibration} in dedicated thread. */
final class VibrationThread extends Thread {
    static final String TAG = "VibrationThread";
    static final boolean DEBUG = false;
    // To enable these logs, run:
    // 'adb shell setprop persist.log.tag.VibrationThread DEBUG && adb reboot'
    static final boolean DEBUG = VibratorDebugUtils.isDebuggable(TAG);

    /** Calls into VibratorManager functionality needed for playing a {@link HalVibration}. */
    interface VibratorManagerHooks {
+37 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2025 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.server.vibrator;

import android.util.Log;

class VibratorDebugUtils {

    /**
     * Checks if debugging is enabled for the specified tag or globally.
     *
     * <p>To enable debugging:<br>
     * {@code adb shell setprop persist.log.tag.Vibrator_All DEBUG}<br>
     * To disable debugging:<br>
     * {@code adb shell setprop persist.log.tag.Vibrator_All \"\" }
     *
     * @param tag The tag to check for debugging. Use the tag name from the calling class.
     * @return True if debugging is enabled for the tag or globally (Vibrator_All), false otherwise.
     */
    public static boolean isDebuggable(String tag) {
        return Log.isLoggable(tag, Log.DEBUG) || Log.isLoggable("Vibrator_All", Log.DEBUG);
    }
}
+3 −1
Original line number Diff line number Diff line
@@ -108,7 +108,9 @@ public class VibratorManagerService extends IVibratorManagerService.Stub {
    private static final String EXTERNAL_VIBRATOR_SERVICE = "external_vibrator_service";
    private static final String VIBRATOR_CONTROL_SERVICE =
            "android.frameworks.vibrator.IVibratorControlService/default";
    private static final boolean DEBUG = false;
    // To enable these logs, run:
    // 'adb shell setprop persist.log.tag.VibratorManagerService DEBUG && adb reboot'
    private static final boolean DEBUG = VibratorDebugUtils.isDebuggable(TAG);
    private static final VibrationAttributes DEFAULT_ATTRIBUTES =
            new VibrationAttributes.Builder().build();
    private static final int ATTRIBUTES_ALL_BYPASS_FLAGS =