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

Commit 61f606e7 authored by Danny Baumann's avatar Danny Baumann Committed by Steve Kondik
Browse files

Clean up and improve RGB LED code.

- Improve battery usage by using AlarmManager instead of keeping a
  wakelock when cycling through colors
- Rename stupidly named LED configuration settings key
- Use intent based communication with CMParts instead of writing random
  files
- Streamline code
- Optimize settings DB accesses
- Share random color list with CMParts
- Implement improvements done in CMParts change
  I6fb4d2ef8ddce5aaed83ef6b21f87868620f5c16

Change-Id: Iaf2a930ecf6393980e5648c89aa8c04ec7c0d337
parent c79cb8d1
Loading
Loading
Loading
Loading
+19 −18
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package android.app;
import java.io.FileOutputStream;

import android.content.Context;
import android.content.Intent;
import android.os.Binder;
import android.os.RemoteException;
import android.os.Handler;
@@ -63,6 +64,15 @@ public class NotificationManager
    private static boolean DEBUG = false;
    private static boolean localLOGV = DEBUG || android.util.Config.LOGV;

    /** @hide */
    public static final String ACTION_NOTIFY = "android.app.NotificationManager.ACTION_NOTIFY";
    /** @hide */
    public static final String EXTRA_PACKAGE = "android.app.NotificationManager.EXTRA_PACKAGE";
    /** @hide */
    public static final String EXTRA_USES_LIGHT = "android.app.NotificationManager.EXTRA_USES_LIGHT";
    /** @hide */
    public static final String EXTRA_IS_ONGOING = "android.app.NotificationManager.EXTRA_IS_ONGOING";

    private static INotificationManager sService;

    /** @hide */
@@ -94,21 +104,6 @@ public class NotificationManager
        notify(null, id, notification);
    }

    private void updatePackageList() {
        try {
            if (mContext.getPackageName().equals("com.cyanogenmod.cmparts")) {
                return;
            }
            //File file = new File(appContext.getFilesDir(), "trackball_lights");
            FileOutputStream fos = mContext.openFileOutput("trackball_lights", Context.MODE_WORLD_READABLE);
            String blank = "yes";
            fos.write(blank.getBytes());
            fos.close();
        } catch(Exception e) {
            Log.d("WriteApps", "Error: " + e.toString());
        }
    }

    /**
     * Persistent notification on the status bar,
     *
@@ -124,9 +119,15 @@ public class NotificationManager
        int[] idOut = new int[1];
        INotificationManager service = getService();
        String pkg = mContext.getPackageName();
        if ((notification.flags & Notification.FLAG_SHOW_LIGHTS) != 0) {
            updatePackageList();
        }

        boolean usesLight = (notification.flags & Notification.FLAG_SHOW_LIGHTS) != 0;
        boolean isOngoing = (notification.flags & Notification.FLAG_ONGOING_EVENT) != 0;
        Intent notifyIntent = new Intent(ACTION_NOTIFY);
        notifyIntent.putExtra(EXTRA_PACKAGE, pkg);
        notifyIntent.putExtra(EXTRA_USES_LIGHT, usesLight);
        notifyIntent.putExtra(EXTRA_IS_ONGOING, isOngoing);
        mContext.sendBroadcast(notifyIntent);

        if (localLOGV) Log.v(TAG, pkg + ": notify(" + id + ", " + notification + ")");
        try {
            service.enqueueNotificationWithTag(pkg, tag, id, notification, idOut);
+3 −14
Original line number Diff line number Diff line
@@ -2558,22 +2558,11 @@ public final class Settings {
         public static final String TRACKBALL_NOTIFICATION_BLEND_COLOR = "trackball_blend_color";

        /**
         * Trackball Notification Colors. The value is String  pkg=color|pkg=color
         * Trackball Notification Colors. The value is a String, containing a list of packages:
         * pkg=color=blink=mode=category|pkg=color=blink=mode=category|...
         * @hide
         */
        public static final String NOTIFICATION_PACKAGE_COLORS = "|";

        /**
         * Trackball Notification List. The value is String  pkg|pkg
         * @hide
         */
        public static final String NOTIFICATION_PACKAGE_LIST = "|";

        /**
         * Trackball Notification Colors Debugging. The value is boolean (1 or 0)
         * @hide
         */
        public static final String NOTIFICATION_PACKAGE_COLORS_GET_PACK = "0";
        public static final String NOTIFICATION_PACKAGE_COLORS = "notification_custom_led_colors";

        /**
         * Whether to unlock the menu key.  The value is boolean (1 or 0).
+15 −0
Original line number Diff line number Diff line
@@ -124,4 +124,19 @@
        <item>bootloader</item>
    </string-array>

    <!-- Defines the set of colors used for selecting a random
          notification color. -->
    <string-array name="notification_led_random_color_set" translatable="false">
        <item>green</item>
        <item>white</item>
        <item>red</item>
        <item>blue</item>
        <item>yellow</item>
        <item>cyan</item>
        <item>#800080</item>
        <item>#ffc0cb</item>
        <item>#ffa500</item>
        <item>#add8e6</item>
    </string-array>

</resources>
+237 −225

File changed.

Preview size limit exceeded, changes collapsed.