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

Commit a98ec263 authored by Gianmarco Reverberi's avatar Gianmarco Reverberi Committed by Steve Kondik
Browse files

SystemUI: fix notification on charger

Change-Id: I92382d556f6224f46beb211bfa0c4a22f2179683
parent 82f05fbb
Loading
Loading
Loading
Loading
+11 −16
Original line number Diff line number Diff line
@@ -24,12 +24,15 @@ import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.database.ContentObserver;
import android.media.Ringtone;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.BatteryManager;
import android.os.Handler;
import android.os.PowerManager;
import android.os.SystemClock;
import android.os.UserHandle;
import android.os.Vibrator;
import android.provider.Settings;
import android.util.Log;
import android.util.Slog;
@@ -249,27 +252,19 @@ public class PowerUI extends SystemUI {
        final String soundPath =
                Settings.Global.getString(cr, Settings.Global.POWER_NOTIFICATIONS_RINGTONE);

        NotificationManager notificationManager =
                (NotificationManager)mContext.getSystemService(Context.NOTIFICATION_SERVICE);
        if (notificationManager == null) {
            return;
        }

        Notification powerNotify=new Notification();
        powerNotify.defaults = Notification.DEFAULT_ALL;
        if (soundPath != null) {
            powerNotify.sound = Uri.parse(soundPath);
            if (powerNotify.sound != null) {
                // DEFAULT_SOUND overrides so flip off
                powerNotify.defaults &= ~Notification.DEFAULT_SOUND;
            Ringtone powerRingtone = RingtoneManager.getRingtone(mContext, Uri.parse(soundPath));
            if (powerRingtone != null) {
                powerRingtone.play();
            }
        }
        if (Settings.Global.getInt(cr,
                Settings.Global.POWER_NOTIFICATIONS_VIBRATE, 0) == 0) {
            powerNotify.defaults &= ~Notification.DEFAULT_VIBRATE;
                Settings.Global.POWER_NOTIFICATIONS_VIBRATE, 0) == 1) {
            Vibrator vibrator = (Vibrator) mContext.getSystemService(Context.VIBRATOR_SERVICE);
            if (vibrator != null) {
                vibrator.vibrate(250);
            }
        }

        notificationManager.notify(0, powerNotify);
    }

    public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {