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

Commit e9455289 authored by Danny Baumann's avatar Danny Baumann Committed by Altaf-Mahdi
Browse files

Add back phone notification LED settings backend (1/2)

Change-Id: I1f6834872ac8320e43a0c5d77b1dc8d3654fa99b
parent 680b9204
Loading
Loading
Loading
Loading
+32 −3
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.TaskStackBuilder;
import android.content.AsyncQueryHandler;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
@@ -29,6 +30,7 @@ import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.provider.Settings;
import android.os.UserHandle;
import android.provider.CallLog;
import android.provider.CallLog.Calls;
@@ -59,6 +61,10 @@ class MissedCallNotifier extends CallsManagerListenerBase {
    };
    private static final int MISSED_CALL_NOTIFICATION_ID = 1;

    // notification light default constants
    public static final int DEFAULT_COLOR = 0xFFFFFF; //White
    public static final int DEFAULT_TIME = 1000; // 1 second

    private final Context mContext;
    private final NotificationManager mNotificationManager;

@@ -166,7 +172,7 @@ class MissedCallNotifier extends CallsManagerListenerBase {
        }

        Notification notification = builder.build();
        configureLedOnNotification(notification);
        configureLedOnNotification(mContext, notification);

        Log.i(this, "Adding missed call notification for %s.", call);
        mNotificationManager.notifyAsUser(
@@ -259,10 +265,33 @@ class MissedCallNotifier extends CallsManagerListenerBase {

    /**
     * Configures a notification to emit the blinky notification light.
     *
     */
    private void configureLedOnNotification(Notification notification) {
    private static void configureLedOnNotification(Context context, Notification notification) {
        ContentResolver resolver = context.getContentResolver();

        boolean lightEnabled = Settings.System.getInt(resolver,
                Settings.System.NOTIFICATION_LIGHT_PULSE, 0) == 1;
        if (!lightEnabled) {
            return;
        }

        notification.flags |= Notification.FLAG_SHOW_LIGHTS;

        // Get Missed call values if they are to be used
        boolean customEnabled = Settings.System.getInt(resolver,
                Settings.System.NOTIFICATION_LIGHT_PULSE_CUSTOM_ENABLE, 0) == 1;
        if (!customEnabled) {
            notification.defaults |= Notification.DEFAULT_LIGHTS;
            return;
        }

        notification.ledARGB = Settings.System.getInt(resolver,
            Settings.System.NOTIFICATION_LIGHT_PULSE_CALL_COLOR, DEFAULT_COLOR);
        notification.ledOnMS = Settings.System.getInt(resolver,
            Settings.System.NOTIFICATION_LIGHT_PULSE_CALL_LED_ON, DEFAULT_TIME);
        notification.ledOffMS = Settings.System.getInt(resolver,
            Settings.System.NOTIFICATION_LIGHT_PULSE_CALL_LED_OFF, DEFAULT_TIME);
    }

    /**