Merge "Add vibrator capabilities to service dumpsys" into sc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
2aebc3e739
@@ -581,6 +581,7 @@ java_library {
|
|||||||
"android.hardware.vibrator-V1.1-java",
|
"android.hardware.vibrator-V1.1-java",
|
||||||
"android.hardware.vibrator-V1.2-java",
|
"android.hardware.vibrator-V1.2-java",
|
||||||
"android.hardware.vibrator-V1.3-java",
|
"android.hardware.vibrator-V1.3-java",
|
||||||
|
"android.hardware.vibrator-V2-java",
|
||||||
"android.security.apc-java",
|
"android.security.apc-java",
|
||||||
"android.security.authorization-java",
|
"android.security.authorization-java",
|
||||||
"android.security.usermanager-java",
|
"android.security.usermanager-java",
|
||||||
|
|||||||
@@ -502,6 +502,20 @@ public abstract class VibrationEffect implements Parcelable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @hide */
|
||||||
|
public static String effectStrengthToString(int effectStrength) {
|
||||||
|
switch (effectStrength) {
|
||||||
|
case EFFECT_STRENGTH_LIGHT:
|
||||||
|
return "LIGHT";
|
||||||
|
case EFFECT_STRENGTH_MEDIUM:
|
||||||
|
return "MEDIUM";
|
||||||
|
case EFFECT_STRENGTH_STRONG:
|
||||||
|
return "STRONG";
|
||||||
|
default:
|
||||||
|
return Integer.toString(effectStrength);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** @hide */
|
/** @hide */
|
||||||
@TestApi
|
@TestApi
|
||||||
public static class OneShot extends VibrationEffect implements Parcelable {
|
public static class OneShot extends VibrationEffect implements Parcelable {
|
||||||
@@ -936,8 +950,8 @@ public abstract class VibrationEffect implements Parcelable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "Prebaked{mEffectId=" + mEffectId
|
return "Prebaked{mEffectId=" + effectIdToString(mEffectId)
|
||||||
+ ", mEffectStrength=" + mEffectStrength
|
+ ", mEffectStrength=" + effectStrengthToString(mEffectStrength)
|
||||||
+ ", mFallback=" + mFallback
|
+ ", mFallback=" + mFallback
|
||||||
+ ", mFallbackEffect=" + mFallbackEffect
|
+ ", mFallbackEffect=" + mFallbackEffect
|
||||||
+ "}";
|
+ "}";
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ package android.os;
|
|||||||
|
|
||||||
import android.annotation.NonNull;
|
import android.annotation.NonNull;
|
||||||
import android.annotation.Nullable;
|
import android.annotation.Nullable;
|
||||||
|
import android.hardware.vibrator.IVibrator;
|
||||||
import android.util.SparseBooleanArray;
|
import android.util.SparseBooleanArray;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -33,20 +34,7 @@ import java.util.Objects;
|
|||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
public final class VibratorInfo implements Parcelable {
|
public final class VibratorInfo implements Parcelable {
|
||||||
|
private static final String TAG = "VibratorInfo";
|
||||||
/**
|
|
||||||
* Capability to set amplitude values to vibrations.
|
|
||||||
* @hide
|
|
||||||
*/
|
|
||||||
// Internally this maps to the HAL constant IVibrator::CAP_AMPLITUDE_CONTROL
|
|
||||||
public static final int CAPABILITY_AMPLITUDE_CONTROL = 4;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Capability to compose primitives into a single effect.
|
|
||||||
* @hide
|
|
||||||
*/
|
|
||||||
// Internally this maps to the HAL constant IVibrator::CAP_COMPOSE_EFFECTS
|
|
||||||
public static final int CAPABILITY_COMPOSE_EFFECTS = 32;
|
|
||||||
|
|
||||||
private final int mId;
|
private final int mId;
|
||||||
private final long mCapabilities;
|
private final long mCapabilities;
|
||||||
@@ -108,7 +96,7 @@ public final class VibratorInfo implements Parcelable {
|
|||||||
return "VibratorInfo{"
|
return "VibratorInfo{"
|
||||||
+ "mId=" + mId
|
+ "mId=" + mId
|
||||||
+ ", mCapabilities=" + Arrays.toString(getCapabilitiesNames())
|
+ ", mCapabilities=" + Arrays.toString(getCapabilitiesNames())
|
||||||
+ ", mCapabilities flags=" + mCapabilities
|
+ ", mCapabilities flags=" + Long.toBinaryString(mCapabilities)
|
||||||
+ ", mSupportedEffects=" + Arrays.toString(getSupportedEffectsNames())
|
+ ", mSupportedEffects=" + Arrays.toString(getSupportedEffectsNames())
|
||||||
+ ", mSupportedPrimitives=" + Arrays.toString(getSupportedPrimitivesNames())
|
+ ", mSupportedPrimitives=" + Arrays.toString(getSupportedPrimitivesNames())
|
||||||
+ '}';
|
+ '}';
|
||||||
@@ -125,7 +113,7 @@ public final class VibratorInfo implements Parcelable {
|
|||||||
* @return True if the hardware can control the amplitude of the vibrations, otherwise false.
|
* @return True if the hardware can control the amplitude of the vibrations, otherwise false.
|
||||||
*/
|
*/
|
||||||
public boolean hasAmplitudeControl() {
|
public boolean hasAmplitudeControl() {
|
||||||
return hasCapability(CAPABILITY_AMPLITUDE_CONTROL);
|
return hasCapability(IVibrator.CAP_AMPLITUDE_CONTROL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -153,7 +141,7 @@ public final class VibratorInfo implements Parcelable {
|
|||||||
* @return Whether the primitive is supported.
|
* @return Whether the primitive is supported.
|
||||||
*/
|
*/
|
||||||
public boolean isPrimitiveSupported(@VibrationEffect.Composition.Primitive int primitiveId) {
|
public boolean isPrimitiveSupported(@VibrationEffect.Composition.Primitive int primitiveId) {
|
||||||
return hasCapability(CAPABILITY_COMPOSE_EFFECTS) && mSupportedPrimitives != null
|
return hasCapability(IVibrator.CAP_COMPOSE_EFFECTS) && mSupportedPrimitives != null
|
||||||
&& mSupportedPrimitives.get(primitiveId, false);
|
&& mSupportedPrimitives.get(primitiveId, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -170,11 +158,26 @@ public final class VibratorInfo implements Parcelable {
|
|||||||
|
|
||||||
private String[] getCapabilitiesNames() {
|
private String[] getCapabilitiesNames() {
|
||||||
List<String> names = new ArrayList<>();
|
List<String> names = new ArrayList<>();
|
||||||
if (hasCapability(CAPABILITY_AMPLITUDE_CONTROL)) {
|
if (hasCapability(IVibrator.CAP_ON_CALLBACK)) {
|
||||||
|
names.add("ON_CALLBACK");
|
||||||
|
}
|
||||||
|
if (hasCapability(IVibrator.CAP_PERFORM_CALLBACK)) {
|
||||||
|
names.add("PERFORM_CALLBACK");
|
||||||
|
}
|
||||||
|
if (hasCapability(IVibrator.CAP_COMPOSE_EFFECTS)) {
|
||||||
|
names.add("COMPOSE_EFFECTS");
|
||||||
|
}
|
||||||
|
if (hasCapability(IVibrator.CAP_ALWAYS_ON_CONTROL)) {
|
||||||
|
names.add("ALWAYS_ON_CONTROL");
|
||||||
|
}
|
||||||
|
if (hasCapability(IVibrator.CAP_AMPLITUDE_CONTROL)) {
|
||||||
names.add("AMPLITUDE_CONTROL");
|
names.add("AMPLITUDE_CONTROL");
|
||||||
}
|
}
|
||||||
if (hasCapability(CAPABILITY_COMPOSE_EFFECTS)) {
|
if (hasCapability(IVibrator.CAP_EXTERNAL_CONTROL)) {
|
||||||
names.add("COMPOSE_EFFECTS");
|
names.add("EXTERNAL_CONTROL");
|
||||||
|
}
|
||||||
|
if (hasCapability(IVibrator.CAP_EXTERNAL_AMPLITUDE_CONTROL)) {
|
||||||
|
names.add("EXTERNAL_AMPLITUDE_CONTROL");
|
||||||
}
|
}
|
||||||
return names.toArray(new String[names.size()]);
|
return names.toArray(new String[names.size()]);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import static junit.framework.Assert.assertEquals;
|
|||||||
import static junit.framework.Assert.assertFalse;
|
import static junit.framework.Assert.assertFalse;
|
||||||
import static junit.framework.Assert.assertTrue;
|
import static junit.framework.Assert.assertTrue;
|
||||||
|
|
||||||
|
import android.hardware.vibrator.IVibrator;
|
||||||
import android.platform.test.annotations.Presubmit;
|
import android.platform.test.annotations.Presubmit;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@@ -33,16 +34,16 @@ public class VibratorInfoTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testHasAmplitudeControl() {
|
public void testHasAmplitudeControl() {
|
||||||
assertFalse(createInfo(/* capabilities= */ 0).hasAmplitudeControl());
|
assertFalse(createInfo(/* capabilities= */ 0).hasAmplitudeControl());
|
||||||
assertTrue(createInfo(VibratorInfo.CAPABILITY_COMPOSE_EFFECTS
|
assertTrue(createInfo(IVibrator.CAP_COMPOSE_EFFECTS
|
||||||
| VibratorInfo.CAPABILITY_AMPLITUDE_CONTROL).hasAmplitudeControl());
|
| IVibrator.CAP_AMPLITUDE_CONTROL).hasAmplitudeControl());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testHasCapabilities() {
|
public void testHasCapabilities() {
|
||||||
assertTrue(createInfo(VibratorInfo.CAPABILITY_COMPOSE_EFFECTS)
|
assertTrue(createInfo(IVibrator.CAP_COMPOSE_EFFECTS)
|
||||||
.hasCapability(VibratorInfo.CAPABILITY_COMPOSE_EFFECTS));
|
.hasCapability(IVibrator.CAP_COMPOSE_EFFECTS));
|
||||||
assertFalse(createInfo(VibratorInfo.CAPABILITY_COMPOSE_EFFECTS)
|
assertFalse(createInfo(IVibrator.CAP_COMPOSE_EFFECTS)
|
||||||
.hasCapability(VibratorInfo.CAPABILITY_AMPLITUDE_CONTROL));
|
.hasCapability(IVibrator.CAP_AMPLITUDE_CONTROL));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -59,7 +60,7 @@ public class VibratorInfoTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsPrimitiveSupported() {
|
public void testIsPrimitiveSupported() {
|
||||||
VibratorInfo info = new VibratorInfo(/* id= */ 0, VibratorInfo.CAPABILITY_COMPOSE_EFFECTS,
|
VibratorInfo info = new VibratorInfo(/* id= */ 0, IVibrator.CAP_COMPOSE_EFFECTS,
|
||||||
null, new int[]{VibrationEffect.Composition.PRIMITIVE_CLICK});
|
null, new int[]{VibrationEffect.Composition.PRIMITIVE_CLICK});
|
||||||
assertTrue(info.isPrimitiveSupported(VibrationEffect.Composition.PRIMITIVE_CLICK));
|
assertTrue(info.isPrimitiveSupported(VibrationEffect.Composition.PRIMITIVE_CLICK));
|
||||||
assertFalse(info.isPrimitiveSupported(VibrationEffect.Composition.PRIMITIVE_TICK));
|
assertFalse(info.isPrimitiveSupported(VibrationEffect.Composition.PRIMITIVE_TICK));
|
||||||
@@ -73,30 +74,30 @@ public class VibratorInfoTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testEquals() {
|
public void testEquals() {
|
||||||
VibratorInfo empty = new VibratorInfo(1, 0, null, null);
|
VibratorInfo empty = new VibratorInfo(1, 0, null, null);
|
||||||
VibratorInfo complete = new VibratorInfo(1, VibratorInfo.CAPABILITY_AMPLITUDE_CONTROL,
|
VibratorInfo complete = new VibratorInfo(1, IVibrator.CAP_AMPLITUDE_CONTROL,
|
||||||
new int[]{VibrationEffect.EFFECT_CLICK},
|
new int[]{VibrationEffect.EFFECT_CLICK},
|
||||||
new int[]{VibrationEffect.Composition.PRIMITIVE_CLICK});
|
new int[]{VibrationEffect.Composition.PRIMITIVE_CLICK});
|
||||||
|
|
||||||
assertEquals(complete, complete);
|
assertEquals(complete, complete);
|
||||||
assertEquals(complete, new VibratorInfo(1, VibratorInfo.CAPABILITY_AMPLITUDE_CONTROL,
|
assertEquals(complete, new VibratorInfo(1, IVibrator.CAP_AMPLITUDE_CONTROL,
|
||||||
new int[]{VibrationEffect.EFFECT_CLICK},
|
new int[]{VibrationEffect.EFFECT_CLICK},
|
||||||
new int[]{VibrationEffect.Composition.PRIMITIVE_CLICK}));
|
new int[]{VibrationEffect.Composition.PRIMITIVE_CLICK}));
|
||||||
|
|
||||||
assertFalse(empty.equals(new VibratorInfo(1, 0, new int[]{}, new int[]{})));
|
assertFalse(empty.equals(new VibratorInfo(1, 0, new int[]{}, new int[]{})));
|
||||||
assertFalse(complete.equals(new VibratorInfo(1, VibratorInfo.CAPABILITY_COMPOSE_EFFECTS,
|
assertFalse(complete.equals(new VibratorInfo(1, IVibrator.CAP_COMPOSE_EFFECTS,
|
||||||
new int[]{VibrationEffect.EFFECT_CLICK},
|
new int[]{VibrationEffect.EFFECT_CLICK},
|
||||||
new int[]{VibrationEffect.Composition.PRIMITIVE_CLICK})));
|
new int[]{VibrationEffect.Composition.PRIMITIVE_CLICK})));
|
||||||
assertFalse(complete.equals(new VibratorInfo(1, VibratorInfo.CAPABILITY_AMPLITUDE_CONTROL,
|
assertFalse(complete.equals(new VibratorInfo(1, IVibrator.CAP_AMPLITUDE_CONTROL,
|
||||||
new int[]{}, new int[]{})));
|
new int[]{}, new int[]{})));
|
||||||
assertFalse(complete.equals(new VibratorInfo(1, VibratorInfo.CAPABILITY_AMPLITUDE_CONTROL,
|
assertFalse(complete.equals(new VibratorInfo(1, IVibrator.CAP_AMPLITUDE_CONTROL,
|
||||||
null, new int[]{VibrationEffect.Composition.PRIMITIVE_CLICK})));
|
null, new int[]{VibrationEffect.Composition.PRIMITIVE_CLICK})));
|
||||||
assertFalse(complete.equals(new VibratorInfo(1, VibratorInfo.CAPABILITY_AMPLITUDE_CONTROL,
|
assertFalse(complete.equals(new VibratorInfo(1, IVibrator.CAP_AMPLITUDE_CONTROL,
|
||||||
new int[]{VibrationEffect.EFFECT_CLICK}, null)));
|
new int[]{VibrationEffect.EFFECT_CLICK}, null)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSerialization() {
|
public void testSerialization() {
|
||||||
VibratorInfo original = new VibratorInfo(1, VibratorInfo.CAPABILITY_COMPOSE_EFFECTS,
|
VibratorInfo original = new VibratorInfo(1, IVibrator.CAP_COMPOSE_EFFECTS,
|
||||||
new int[]{VibrationEffect.EFFECT_CLICK}, null);
|
new int[]{VibrationEffect.EFFECT_CLICK}, null);
|
||||||
|
|
||||||
Parcel parcel = Parcel.obtain();
|
Parcel parcel = Parcel.obtain();
|
||||||
|
|||||||
@@ -120,7 +120,9 @@ final class Vibration {
|
|||||||
if (newEffect.equals(mEffect)) {
|
if (newEffect.equals(mEffect)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
mOriginalEffect = mEffect;
|
if (mOriginalEffect == null) {
|
||||||
|
mOriginalEffect = mEffect;
|
||||||
|
}
|
||||||
mEffect = newEffect;
|
mEffect = newEffect;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -344,10 +344,11 @@ public class VibratorManagerService extends IVibratorManagerService.Stub {
|
|||||||
if (!isEffectValid(effect)) {
|
if (!isEffectValid(effect)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
effect = fixupVibrationEffect(effect);
|
|
||||||
attrs = fixupVibrationAttributes(attrs);
|
attrs = fixupVibrationAttributes(attrs);
|
||||||
Vibration vib = new Vibration(token, mNextVibrationId.getAndIncrement(), effect, attrs,
|
Vibration vib = new Vibration(token, mNextVibrationId.getAndIncrement(), effect, attrs,
|
||||||
uid, opPkg, reason);
|
uid, opPkg, reason);
|
||||||
|
// Update with fixed up effect to keep the original effect in Vibration for debugging.
|
||||||
|
vib.updateEffect(fixupVibrationEffect(effect));
|
||||||
|
|
||||||
synchronized (mLock) {
|
synchronized (mLock) {
|
||||||
Vibration.Status ignoreStatus = shouldIgnoreVibrationLocked(vib);
|
Vibration.Status ignoreStatus = shouldIgnoreVibrationLocked(vib);
|
||||||
@@ -1138,6 +1139,9 @@ public class VibratorManagerService extends IVibratorManagerService.Stub {
|
|||||||
void dumpText(PrintWriter pw) {
|
void dumpText(PrintWriter pw) {
|
||||||
pw.println("Vibrator Manager Service:");
|
pw.println("Vibrator Manager Service:");
|
||||||
synchronized (mLock) {
|
synchronized (mLock) {
|
||||||
|
pw.println(" mVibrationSettings:");
|
||||||
|
pw.println(" " + mVibrationSettings);
|
||||||
|
pw.println();
|
||||||
pw.println(" mVibratorControllers:");
|
pw.println(" mVibratorControllers:");
|
||||||
for (int i = 0; i < mVibrators.size(); i++) {
|
for (int i = 0; i < mVibrators.size(); i++) {
|
||||||
pw.println(" " + mVibrators.valueAt(i));
|
pw.println(" " + mVibrators.valueAt(i));
|
||||||
@@ -1146,14 +1150,15 @@ public class VibratorManagerService extends IVibratorManagerService.Stub {
|
|||||||
pw.println(" mCurrentVibration:");
|
pw.println(" mCurrentVibration:");
|
||||||
pw.println(" " + (mCurrentVibration == null
|
pw.println(" " + (mCurrentVibration == null
|
||||||
? null : mCurrentVibration.getVibration().getDebugInfo()));
|
? null : mCurrentVibration.getVibration().getDebugInfo()));
|
||||||
|
pw.println();
|
||||||
pw.println(" mNextVibration:");
|
pw.println(" mNextVibration:");
|
||||||
pw.println(" " + (mNextVibration == null
|
pw.println(" " + (mNextVibration == null
|
||||||
? null : mNextVibration.getVibration().getDebugInfo()));
|
? null : mNextVibration.getVibration().getDebugInfo()));
|
||||||
|
pw.println();
|
||||||
pw.println(" mCurrentExternalVibration:");
|
pw.println(" mCurrentExternalVibration:");
|
||||||
pw.println(" " + (mCurrentExternalVibration == null
|
pw.println(" " + (mCurrentExternalVibration == null
|
||||||
? null : mCurrentExternalVibration.getDebugInfo()));
|
? null : mCurrentExternalVibration.getDebugInfo()));
|
||||||
pw.println();
|
pw.println();
|
||||||
pw.println(" mVibrationSettings=" + mVibrationSettings);
|
|
||||||
for (int i = 0; i < mPreviousVibrations.size(); i++) {
|
for (int i = 0; i < mPreviousVibrations.size(); i++) {
|
||||||
pw.println();
|
pw.println();
|
||||||
pw.print(" Previous vibrations for usage ");
|
pw.print(" Previous vibrations for usage ");
|
||||||
|
|||||||
Reference in New Issue
Block a user