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

Commit f35c97cd authored by Danesh M's avatar Danesh M Committed by Steve Kondik
Browse files

Quiet Hours Haptic Feedback (1/2)

Part 2 : http://review.cyanogenmod.com/#change,9429

Allow haptic feedback to be controlled via quiet hours

Change-Id: Ic168185e09246fa104a98e77413a6e929bf4e930
parent 48409b75
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -2632,6 +2632,12 @@ public final class Settings {
         */
        public static final String QUIET_HOURS_MUTE = "quiet_hours_mute";

        /**
         * Whether to disable haptic feedback during quiet hours.
         * @hide
         */
        public static final String QUIET_HOURS_HAPTIC = "quiet_hours_haptic";

        /**
         * Whether to remove the vibration from outgoing notifications during quiet hours.
         * @hide
+29 −1
Original line number Diff line number Diff line
@@ -30,8 +30,10 @@ import android.os.IBinder;
import android.os.Binder;
import android.os.SystemClock;
import android.os.WorkSource;
import android.provider.Settings;
import android.util.Slog;

import java.util.Calendar;
import java.util.LinkedList;
import java.util.ListIterator;

@@ -112,6 +114,29 @@ public class VibratorService extends IVibratorService.Stub {
        context.registerReceiver(mIntentReceiver, filter);
    }

    private boolean inQuietHours() {
        boolean mQuietHoursEnabled = Settings.System.getInt(mContext.getContentResolver(),
                Settings.System.QUIET_HOURS_ENABLED, 0) != 0;
        int mQuietHoursStart = Settings.System.getInt(mContext.getContentResolver(),
                Settings.System.QUIET_HOURS_START, 0);
        int mQuietHoursEnd = Settings.System.getInt(mContext.getContentResolver(),
                Settings.System.QUIET_HOURS_END, 0);
        boolean mQuietHoursHaptic = Settings.System.getInt(mContext.getContentResolver(),
                Settings.System.QUIET_HOURS_HAPTIC, 0) != 0;
        if (mQuietHoursEnabled && mQuietHoursHaptic && (mQuietHoursStart != mQuietHoursEnd)) {
            // Get the date in "quiet hours" format.
            Calendar calendar = Calendar.getInstance();
            int minutes = calendar.get(Calendar.HOUR_OF_DAY) * 60 + calendar.get(Calendar.MINUTE);
            if (mQuietHoursEnd < mQuietHoursStart) {
                // Starts at night, ends in the morning.
                return (minutes > mQuietHoursStart) || (minutes < mQuietHoursEnd);
            } else {
                return (minutes > mQuietHoursStart) && (minutes < mQuietHoursEnd);
            }
        }
        return false;
    }

    public void vibrate(long milliseconds, IBinder token) {
        if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.VIBRATE)
                != PackageManager.PERMISSION_GRANTED) {
@@ -122,7 +147,7 @@ public class VibratorService extends IVibratorService.Stub {
        // timeout of 0 or negative. This will ensure that a vibration has
        // either a timeout of > 0 or a non-null pattern.
        if (milliseconds <= 0 || (mCurrentVibration != null
                && mCurrentVibration.hasLongerTimeout(milliseconds))) {
                && mCurrentVibration.hasLongerTimeout(milliseconds)) || inQuietHours()) {
            // Ignore this vibration since the current vibration will play for
            // longer than milliseconds.
            return;
@@ -151,6 +176,9 @@ public class VibratorService extends IVibratorService.Stub {
                != PackageManager.PERMISSION_GRANTED) {
            throw new SecurityException("Requires VIBRATE permission");
        }
        if (inQuietHours()) {
            return;
        }
        int uid = Binder.getCallingUid();
        // so wakelock calls will succeed
        long identity = Binder.clearCallingIdentity();