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

Commit 0ba049d7 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Create parcelable VibratorInfo to expose HAL profile"

parents 71293a7c 61ddb947
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -18,10 +18,12 @@ package android.os;

import android.os.CombinedVibrationEffect;
import android.os.VibrationAttributes;
import android.os.VibratorInfo;

/** {@hide} */
interface IVibratorManagerService {
    int[] getVibratorIds();
    VibratorInfo getVibratorInfo(int vibratorId);
    boolean setAlwaysOnEffect(int uid, String opPkg, int alwaysOnId,
            in CombinedVibrationEffect effect, in VibrationAttributes attributes);
    void vibrate(int uid, String opPkg, in CombinedVibrationEffect effect,
+2 −2
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package android.os;

import android.os.VibrationEffect;
import android.os.VibrationAttributes;
import android.os.VibratorInfo;
import android.os.IVibratorStateListener;

/** {@hide} */
@@ -25,11 +26,10 @@ interface IVibratorService
{
    boolean hasVibrator();
    boolean isVibrating();
    VibratorInfo getVibratorInfo();
    boolean registerVibratorStateListener(in IVibratorStateListener listener);
    boolean unregisterVibratorStateListener(in IVibratorStateListener listener);
    boolean hasAmplitudeControl();
    int[] areEffectsSupported(in int[] effectIds);
    boolean[] arePrimitivesSupported(in int[] primitiveIds);
    void vibrate(int uid, String opPkg, in VibrationEffect effect,
            in VibrationAttributes attributes, String reason, IBinder token);
    void cancelVibrate(IBinder token);
+35 −10
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package android.os;

import android.annotation.CallbackExecutor;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.compat.annotation.UnsupportedAppUsage;
import android.content.Context;
import android.media.AudioAttributes;
@@ -39,8 +40,11 @@ public class SystemVibrator extends Vibrator {

    private final IVibratorService mService;
    private final IVibratorManagerService mManagerService;
    private final Object mLock = new Object();
    private final Binder mToken = new Binder();
    private final Context mContext;
    @GuardedBy("mLock")
    private VibratorInfo mVibratorInfo;

    @GuardedBy("mDelegates")
    private final ArrayMap<OnVibratorStateChangedListener,
@@ -242,23 +246,26 @@ public class SystemVibrator extends Vibrator {

    @Override
    public int[] areEffectsSupported(@VibrationEffect.EffectType int... effectIds) {
        try {
            return mService.areEffectsSupported(effectIds);
        } catch (RemoteException e) {
            Log.w(TAG, "Failed to query effect support");
            throw e.rethrowAsRuntimeException();
        VibratorInfo vibratorInfo = getVibratorInfo();
        int[] supported = new int[effectIds.length];
        for (int i = 0; i < effectIds.length; i++) {
            supported[i] = vibratorInfo == null
                    ? Vibrator.VIBRATION_EFFECT_SUPPORT_UNKNOWN
                    : vibratorInfo.isEffectSupported(effectIds[i]);
        }
        return supported;
    }

    @Override
    public boolean[] arePrimitivesSupported(
            @NonNull @VibrationEffect.Composition.Primitive int... primitiveIds) {
        try {
            return mService.arePrimitivesSupported(primitiveIds);
        } catch (RemoteException e) {
            Log.w(TAG, "Failed to query effect support");
            throw e.rethrowAsRuntimeException();
        VibratorInfo vibratorInfo = getVibratorInfo();
        boolean[] supported = new boolean[primitiveIds.length];
        for (int i = 0; i < primitiveIds.length; i++) {
            supported[i] = vibratorInfo == null
                    ? false : vibratorInfo.isPrimitiveSupported(primitiveIds[i]);
        }
        return supported;
    }

    @Override
@@ -272,4 +279,22 @@ public class SystemVibrator extends Vibrator {
            Log.w(TAG, "Failed to cancel vibration.", e);
        }
    }

    @Nullable
    private VibratorInfo getVibratorInfo() {
        try {
            synchronized (mLock) {
                if (mVibratorInfo != null) {
                    return mVibratorInfo;
                }
                if (mService == null) {
                    return null;
                }
                return mVibratorInfo = mService.getVibratorInfo();
            }
        } catch (RemoteException e) {
            Log.w(TAG, "Failed to query vibrator info");
            throw e.rethrowFromSystemServer();
        }
    }
}
+22 −2
Original line number Diff line number Diff line
@@ -476,6 +476,28 @@ public abstract class VibrationEffect implements Parcelable {
        return a * fx;
    }

    /** @hide */
    public static String effectIdToString(int effectId) {
        switch (effectId) {
            case EFFECT_CLICK:
                return "CLICK";
            case EFFECT_TICK:
                return "TICK";
            case EFFECT_HEAVY_CLICK:
                return "HEAVY_CLICK";
            case EFFECT_DOUBLE_CLICK:
                return "DOUBLE_CLICK";
            case EFFECT_POP:
                return "POP";
            case EFFECT_THUD:
                return "THUD";
            case EFFECT_TEXTURE_TICK:
                return "TEXTURE_TICK";
            default:
                return Integer.toString(effectId);
        }
    }

    /** @hide */
    @TestApi
    public static class OneShot extends VibrationEffect implements Parcelable {
@@ -1201,10 +1223,8 @@ public abstract class VibrationEffect implements Parcelable {
                    return "PRIMITIVE_QUICK_FALL";
                case PRIMITIVE_TICK:
                    return "PRIMITIVE_TICK";

                default:
                    return Integer.toString(id);

            }
        }

+19 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2020 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 android.os;

parcelable VibratorInfo;
Loading