Navigation Menu

Skip to content

Commit

Permalink
Using SystemVibrator in the cases other than Ringer.java
Browse files Browse the repository at this point in the history
In ICS, Phone app was creating separate Vibrator instances in
Ringer.java and CallNotifier.java, while in Jellybean they started
relying on one single Vibrator Service.
See also Id928ffef9a87e2563198240e91184cf59ecebbb1.

It means vibrate()/cancel() calls from two files interfere with each
other. When "Emergency tone" is set to "Vibrate" in Sound Setting
(which is only available with CDMA devices), this causes unexpected
trouble; the "Emergency tone" vibration is canceled immediately by
Ringer's Vibrator#cancel() call. onPhoneStateChanged() is indirectly
calling the method.

This change stops using the Vibrator Service in the emergency vibration
case, so that two Vibrator objects won't interfere with each other.

TESTED (use CDMA phone):
- Set "Emergency tone" to "Vibrate", and make a phone call to "911"
-> The device should vibrate for hundreds of mills (even without a
   fix, it may vibrate for an instant, so need to check how long)

Bug: 6794250
Change-Id: I69e6c3d99b14b3c50c57ff5d59ca42f4ea18024f
  • Loading branch information
Daisuke Miyakawa committed Jul 12, 2012
1 parent 04642a3 commit 12c60e4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
6 changes: 4 additions & 2 deletions src/com/android/phone/CallNotifier.java
Expand Up @@ -39,6 +39,7 @@
import android.os.Message;
import android.os.RemoteException;
import android.os.SystemProperties;
import android.os.SystemVibrator;
import android.os.Vibrator;
import android.provider.CallLog.Calls;
import android.provider.Settings;
Expand Down Expand Up @@ -1932,7 +1933,9 @@ private class EmergencyTonePlayerVibrator {
new long[] { EMG_VIBRATE_LENGTH, EMG_VIBRATE_PAUSE };

private ToneGenerator mToneGenerator;
private Vibrator mEmgVibrator;
// We don't rely on getSystemService(Context.VIBRATOR_SERVICE) to make sure this vibrator
// object will be isolated from others.
private Vibrator mEmgVibrator = new SystemVibrator();
private int mInCallVolume;

/**
Expand Down Expand Up @@ -1963,7 +1966,6 @@ private void start() {
}
} else if (mIsEmergencyToneOn == EMERGENCY_TONE_VIBRATE) {
log("EmergencyTonePlayerVibrator.start(): emergency vibrate...");
mEmgVibrator = (Vibrator)mApplication.getSystemService(Context.VIBRATOR_SERVICE);
if (mEmgVibrator != null) {
mEmgVibrator.vibrate(mVibratePattern, 0);
mCurrentEmergencyToneState = EMERGENCY_TONE_VIBRATE;
Expand Down
9 changes: 6 additions & 3 deletions src/com/android/phone/HapticFeedback.java
Expand Up @@ -16,13 +16,14 @@

package com.android.phone;

import android.content.Context;
import android.content.ContentResolver;
import android.content.Context;
import android.content.res.Resources;
import android.os.SystemVibrator;
import android.os.Vibrator;
import android.util.Log;
import android.provider.Settings;
import android.provider.Settings.System;
import android.util.Log;

/**
* Handles the haptic feedback: a light buzz happening when the user
Expand Down Expand Up @@ -89,7 +90,9 @@ public class HapticFeedback {
public void init(Context context, boolean enabled) {
mEnabled = enabled;
if (enabled) {
mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
// We don't rely on getSystemService(Context.VIBRATOR_SERVICE) to make sure this
// vibrator object will be isolated from others.
mVibrator = new SystemVibrator();
if (!loadHapticSystemPattern(context.getResources())) {
mHapticPattern = new long[] {0, DURATION, 2 * DURATION, 3 * DURATION};
}
Expand Down
5 changes: 4 additions & 1 deletion src/com/android/phone/Ringer.java
Expand Up @@ -29,6 +29,7 @@
import android.os.ServiceManager;
import android.os.SystemClock;
import android.os.SystemProperties;
import android.os.SystemVibrator;
import android.os.Vibrator;
import android.provider.Settings;
import android.util.Log;
Expand Down Expand Up @@ -84,7 +85,9 @@ public class Ringer {
private Ringer(Context context) {
mContext = context;
mPowerManager = IPowerManager.Stub.asInterface(ServiceManager.getService(Context.POWER_SERVICE));
mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
// We don't rely on getSystemService(Context.VIBRATOR_SERVICE) to make sure this
// vibrator object will be isolated from others.
mVibrator = new SystemVibrator();
}

/**
Expand Down

0 comments on commit 12c60e4

Please sign in to comment.