Loading core/java/android/os/SystemVibrator.java +23 −6 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ package android.os; import android.annotation.CallbackExecutor; import android.annotation.IntDef; import android.annotation.NonNull; import android.annotation.Nullable; import android.compat.annotation.UnsupportedAppUsage; Loading @@ -27,6 +28,8 @@ import android.util.Log; import com.android.internal.annotations.GuardedBy; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.util.Objects; import java.util.concurrent.Executor; Loading @@ -38,6 +41,14 @@ import java.util.concurrent.Executor; public class SystemVibrator extends Vibrator { private static final String TAG = "Vibrator"; private static final int VIBRATOR_PRESENT_UNKNOWN = 0; private static final int VIBRATOR_PRESENT_YES = 1; private static final int VIBRATOR_PRESENT_NO = 2; @Retention(RetentionPolicy.SOURCE) @IntDef({VIBRATOR_PRESENT_UNKNOWN, VIBRATOR_PRESENT_YES, VIBRATOR_PRESENT_NO}) private @interface VibratorPresent {} private final IVibratorService mService; private final IVibratorManagerService mManagerService; private final Object mLock = new Object(); Loading @@ -45,6 +56,9 @@ public class SystemVibrator extends Vibrator { private final Context mContext; @GuardedBy("mLock") private VibratorInfo mVibratorInfo; @GuardedBy("mLock") @VibratorPresent private int mVibratorPresent; @GuardedBy("mDelegates") private final ArrayMap<OnVibratorStateChangedListener, Loading @@ -69,16 +83,19 @@ public class SystemVibrator extends Vibrator { @Override public boolean hasVibrator() { if (mService == null) { Log.w(TAG, "Failed to vibrate; no vibrator service."); return false; } try { return mService.hasVibrator(); } catch (RemoteException e) { synchronized (mLock) { if (mVibratorPresent == VIBRATOR_PRESENT_UNKNOWN && mService != null) { mVibratorPresent = mService.hasVibrator() ? VIBRATOR_PRESENT_YES : VIBRATOR_PRESENT_NO; } return mVibratorPresent == VIBRATOR_PRESENT_YES; } } catch (RemoteException e) { Log.w(TAG, "Failed to query vibrator presence", e); return false; } } /** * Check whether the vibrator is vibrating. Loading Loading
core/java/android/os/SystemVibrator.java +23 −6 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ package android.os; import android.annotation.CallbackExecutor; import android.annotation.IntDef; import android.annotation.NonNull; import android.annotation.Nullable; import android.compat.annotation.UnsupportedAppUsage; Loading @@ -27,6 +28,8 @@ import android.util.Log; import com.android.internal.annotations.GuardedBy; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.util.Objects; import java.util.concurrent.Executor; Loading @@ -38,6 +41,14 @@ import java.util.concurrent.Executor; public class SystemVibrator extends Vibrator { private static final String TAG = "Vibrator"; private static final int VIBRATOR_PRESENT_UNKNOWN = 0; private static final int VIBRATOR_PRESENT_YES = 1; private static final int VIBRATOR_PRESENT_NO = 2; @Retention(RetentionPolicy.SOURCE) @IntDef({VIBRATOR_PRESENT_UNKNOWN, VIBRATOR_PRESENT_YES, VIBRATOR_PRESENT_NO}) private @interface VibratorPresent {} private final IVibratorService mService; private final IVibratorManagerService mManagerService; private final Object mLock = new Object(); Loading @@ -45,6 +56,9 @@ public class SystemVibrator extends Vibrator { private final Context mContext; @GuardedBy("mLock") private VibratorInfo mVibratorInfo; @GuardedBy("mLock") @VibratorPresent private int mVibratorPresent; @GuardedBy("mDelegates") private final ArrayMap<OnVibratorStateChangedListener, Loading @@ -69,16 +83,19 @@ public class SystemVibrator extends Vibrator { @Override public boolean hasVibrator() { if (mService == null) { Log.w(TAG, "Failed to vibrate; no vibrator service."); return false; } try { return mService.hasVibrator(); } catch (RemoteException e) { synchronized (mLock) { if (mVibratorPresent == VIBRATOR_PRESENT_UNKNOWN && mService != null) { mVibratorPresent = mService.hasVibrator() ? VIBRATOR_PRESENT_YES : VIBRATOR_PRESENT_NO; } return mVibratorPresent == VIBRATOR_PRESENT_YES; } } catch (RemoteException e) { Log.w(TAG, "Failed to query vibrator presence", e); return false; } } /** * Check whether the vibrator is vibrating. Loading