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

Commit 2240c959 authored by Roman Birg's avatar Roman Birg
Browse files

DeskClock: restore vibrations after screen is turned off



android.server.VibratorService forcefully clears out all vibrations
after the screen is turned off. If an alarm is going off, we do not want
the power button to only stop vibrations.

Change-Id: Ic7bc556d7cf5529b23b482c34e986853ad4ba4f2
Signed-off-by: default avatarRoman Birg <roman@cyngn.com>
parent baa746c3
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -38,7 +38,7 @@ import java.io.IOException;
 * Manages playing ringtone and vibrating the device.
 */
public class AlarmKlaxon {
    private static final long[] sVibratePattern = new long[] { 500, 500 };
    /* package */ static final long[] sVibratePattern = new long[] { 500, 500 };

    // Volume suggested by media team for in-call alarms.
    private static final float IN_CALL_VOLUME = 0.125f;
+25 −0
Original line number Diff line number Diff line
@@ -18,10 +18,13 @@ package com.android.deskclock.alarms;
import android.app.Profile;
import android.app.ProfileManager;
import android.app.Service;
import android.content.BroadcastReceiver;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.IBinder;
import android.os.Vibrator;
import android.provider.Settings;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
@@ -96,6 +99,22 @@ public class AlarmService extends Service {
        }
    };

    /**
     * Workaround for com.android.server.VibratorService shutting down all
     * vibrations when the screen is turned off.
     */
    private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            if (mCurrentAlarm != null) {
                if (mCurrentAlarm.mVibrate) {
                    Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
                    vibrator.vibrate(AlarmKlaxon.sVibratePattern, 0);
                }
            }
        }
    };

    private void changeToProfile(final Context context, final AlarmInstance instance) {
        // The alarm is defined to change the active profile?
        if (instance.mProfile.equals(ProfileManager.NO_PROFILE)) {
@@ -169,6 +188,11 @@ public class AlarmService extends Service {
    public void onCreate() {
        super.onCreate();
        mTelephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);

        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction(Intent.ACTION_SCREEN_OFF);
        intentFilter.addAction(Intent.ACTION_SCREEN_ON);
        registerReceiver(mBroadcastReceiver, intentFilter);
    }

    @Override
@@ -207,6 +231,7 @@ public class AlarmService extends Service {
    public void onDestroy() {
        Log.v("AlarmService.onDestroy() called");
        super.onDestroy();
        unregisterReceiver(mBroadcastReceiver);
        stopCurrentAlarm();
    }