Java Code Examples for android.os.VibrationEffect#Waveform

The following examples show how to use android.os.VibrationEffect#Waveform . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: InputManager.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/**
 * @hide
 */
@Override
public void vibrate(int uid, String opPkg,
        VibrationEffect effect, AudioAttributes attributes) {
    long[] pattern;
    int repeat;
    if (effect instanceof VibrationEffect.OneShot) {
        VibrationEffect.OneShot oneShot = (VibrationEffect.OneShot) effect;
        pattern = new long[] { 0, oneShot.getDuration() };
        repeat = -1;
    } else if (effect instanceof VibrationEffect.Waveform) {
        VibrationEffect.Waveform waveform = (VibrationEffect.Waveform) effect;
        pattern = waveform.getTimings();
        repeat = waveform.getRepeatIndex();
    } else {
        // TODO: Add support for prebaked effects
        Log.w(TAG, "Pre-baked effects aren't supported on input devices");
        return;
    }

    try {
        mIm.vibrate(mDeviceId, pattern, repeat, mToken);
    } catch (RemoteException ex) {
        throw ex.rethrowFromSystemServer();
    }
}
 
Example 2
Source File: VibratorService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@GuardedBy("mLock")
private void startVibrationInnerLocked(Vibration vib) {
    Trace.traceBegin(Trace.TRACE_TAG_VIBRATOR, "startVibrationInnerLocked");
    try {
        mCurrentVibration = vib;
        if (vib.effect instanceof VibrationEffect.OneShot) {
            Trace.asyncTraceBegin(Trace.TRACE_TAG_VIBRATOR, "vibration", 0);
            VibrationEffect.OneShot oneShot = (VibrationEffect.OneShot) vib.effect;
            doVibratorOn(oneShot.getDuration(), oneShot.getAmplitude(), vib.uid, vib.usageHint);
            mH.postDelayed(mVibrationEndRunnable, oneShot.getDuration());
        } else if (vib.effect instanceof VibrationEffect.Waveform) {
            // mThread better be null here. doCancelVibrate should always be
            // called before startNextVibrationLocked or startVibrationLocked.
            Trace.asyncTraceBegin(Trace.TRACE_TAG_VIBRATOR, "vibration", 0);
            VibrationEffect.Waveform waveform = (VibrationEffect.Waveform) vib.effect;
            mThread = new VibrateThread(waveform, vib.uid, vib.usageHint);
            mThread.start();
        } else if (vib.effect instanceof VibrationEffect.Prebaked) {
            Trace.asyncTraceBegin(Trace.TRACE_TAG_VIBRATOR, "vibration", 0);
            long timeout = doVibratorPrebakedEffectLocked(vib);
            if (timeout > 0) {
                mH.postDelayed(mVibrationEndRunnable, timeout);
            }
        } else {
            Slog.e(TAG, "Unknown vibration type, ignoring");
        }
    } finally {
        Trace.traceEnd(Trace.TRACE_TAG_VIBRATOR);
    }
}
 
Example 3
Source File: VibratorService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private void linkVibration(Vibration vib) {
    // Only link against waveforms since they potentially don't have a finish if
    // they're repeating. Let other effects just play out until they're done.
    if (vib.effect instanceof VibrationEffect.Waveform) {
        try {
            vib.token.linkToDeath(vib, 0);
        } catch (RemoteException e) {
            return;
        }
    }
}
 
Example 4
Source File: VibratorService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
VibrateThread(VibrationEffect.Waveform waveform, int uid, int usageHint) {
    mWaveform = waveform;
    mUid = uid;
    mUsageHint = usageHint;
    mTmpWorkSource.set(uid);
    mWakeLock.setWorkSource(mTmpWorkSource);
}
 
Example 5
Source File: VibratorService.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
/**
 * Scale the vibration effect by the intensity as appropriate based its intent.
 */
private void applyVibrationIntensityScalingLocked(Vibration vib, int intensity) {
    if (vib.effect instanceof VibrationEffect.Prebaked) {
        // Prebaked effects are always just a direct translation from intensity to
        // EffectStrength.
        VibrationEffect.Prebaked prebaked = (VibrationEffect.Prebaked)vib.effect;
        prebaked.setEffectStrength(intensityToEffectStrength(intensity));
        return;
    }

    final int defaultIntensity;
    if (vib.isNotification() || vib.isRingtone()) {
        defaultIntensity = mVibrator.getDefaultNotificationVibrationIntensity();
    } else if (vib.isHapticFeedback()) {
        defaultIntensity = mVibrator.getDefaultHapticFeedbackIntensity();
    } else {
        // If we don't know what kind of vibration we're playing then just skip scaling for
        // now.
        return;
    }

    final ScaleLevel scale = mScaleLevels.get(intensity - defaultIntensity);
    if (scale == null) {
        // We should have scaling levels for all cases, so not being able to scale because of a
        // missing level is unexpected.
        Slog.e(TAG, "No configured scaling level!"
                + " (current=" + intensity + ", default= " + defaultIntensity + ")");
        return;
    }

    VibrationEffect scaledEffect = null;
    if (vib.effect instanceof VibrationEffect.OneShot) {
        VibrationEffect.OneShot oneShot = (VibrationEffect.OneShot) vib.effect;
        oneShot = oneShot.resolve(mDefaultVibrationAmplitude);
        scaledEffect = oneShot.scale(scale.gamma, scale.maxAmplitude);
    } else if (vib.effect instanceof VibrationEffect.Waveform) {
        VibrationEffect.Waveform waveform = (VibrationEffect.Waveform) vib.effect;
        waveform = waveform.resolve(mDefaultVibrationAmplitude);
        scaledEffect = waveform.scale(scale.gamma, scale.maxAmplitude);
    } else {
        Slog.w(TAG, "Unable to apply intensity scaling, unknown VibrationEffect type");
    }

    if (scaledEffect != null) {
        vib.originalEffect = vib.effect;
        vib.effect = scaledEffect;
    }
}
 
Example 6
Source File: VibratorService.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
private void unlinkVibration(Vibration vib) {
    if (vib.effect instanceof VibrationEffect.Waveform) {
        vib.token.unlinkToDeath(vib, 0);
    }
}