Skip to content

Commit

Permalink
Move VIBRATOR_INTENSITY to vibrator service
Browse files Browse the repository at this point in the history
This allows us to track user changes and restore preferences.

CYNGNOS-1166

Change-Id: I9383a7bc109aacb9de1c4ad660b678893935c872
  • Loading branch information
Danesh committed Mar 11, 2016
1 parent b7996b1 commit 1292e86
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions services/core/java/com/android/server/VibratorService.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import android.content.pm.PackageManager;
import android.database.ContentObserver;
import android.hardware.input.InputManager;
import android.net.Uri;
import android.os.BatteryStats;
import android.os.Handler;
import android.os.IVibratorService;
Expand Down Expand Up @@ -55,6 +56,9 @@
import java.util.LinkedList;
import java.util.ListIterator;

import cyanogenmod.hardware.CMHardwareManager;
import cyanogenmod.providers.CMSettings;

public class VibratorService extends IVibratorService.Stub
implements InputManager.InputDeviceListener {
private static final String TAG = "VibratorService";
Expand Down Expand Up @@ -86,6 +90,10 @@ public class VibratorService extends IVibratorService.Stub
private int mCurVibUid = -1;
private boolean mLowPowerMode;
private SettingsObserver mSettingObserver;
private CMHardwareManager mHardware;
private int mMinVibratorIntensity;
private int mMaxVibratorIntensity;
private int mVibratorIntensity;

native static boolean vibratorExists();
native static void vibratorOn(long milliseconds);
Expand Down Expand Up @@ -241,9 +249,20 @@ public void onLowPowerModeChanged(boolean enabled) {
@Override
public void onReceive(Context context, Intent intent) {
updateInputDeviceVibrators();
updateVibratorIntensity();
}
}, new IntentFilter(Intent.ACTION_USER_SWITCHED), null, mH);

mHardware = CMHardwareManager.getInstance(mContext);
if (mHardware.isSupported(CMHardwareManager.FEATURE_VIBRATOR)) {
mContext.getContentResolver().registerContentObserver(
CMSettings.Secure.getUriFor(CMSettings.Secure.VIBRATOR_INTENSITY),
true, mSettingObserver, UserHandle.USER_ALL);
mMinVibratorIntensity = mHardware.getVibratorMinIntensity();
mMaxVibratorIntensity = mHardware.getVibratorMaxIntensity();
updateVibratorIntensity();
}

updateInputDeviceVibrators();
}

Expand All @@ -253,11 +272,22 @@ public SettingsObserver(Handler handler) {
}

@Override
public void onChange(boolean SelfChange) {
updateInputDeviceVibrators();
public void onChange(boolean selfChange, Uri uri) {
if (uri.equals(CMSettings.Secure.getUriFor(CMSettings.Secure.VIBRATOR_INTENSITY))) {
updateVibratorIntensity();
} else {
updateInputDeviceVibrators();
}
}
}

private void updateVibratorIntensity() {
mVibratorIntensity = CMSettings.Secure.getIntForUser(mContext.getContentResolver(),
CMSettings.Secure.VIBRATOR_INTENSITY, mHardware.getVibratorDefaultIntensity(),
UserHandle.USER_CURRENT);
mHardware.setVibratorIntensity(mVibratorIntensity);
}

@Override // Binder call
public boolean hasVibrator() {
return doVibratorExists();
Expand Down

0 comments on commit 1292e86

Please sign in to comment.