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

Commit d0eaa522 authored by Pedlar's avatar Pedlar
Browse files

Altered power lock to stay on, instead of only on during a period of time.

Modified the Wake Lock to run for 1000 miliseconds longer (1 second) instead of trying
to hold onto it. This will insure it is relased over a period of time.

Need Kmobs and some others to test this to make sure it really
does work and provide feedback on it if it dosen't
parent dd699a2c
Loading
Loading
Loading
Loading
+81 −58
Original line number Diff line number Diff line
@@ -937,9 +937,9 @@ class NotificationManagerService extends INotificationManager.Stub {
            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);
                return ((minutes > mQuietHoursStart) || (minutes < mQuietHoursEnd));
            } else {
                return (minutes > mQuietHoursStart) && (minutes < mQuietHoursEnd);
                return ((minutes > mQuietHoursStart) && (minutes < mQuietHoursEnd));
            }
        }
        return false;
@@ -1202,7 +1202,7 @@ class NotificationManagerService extends INotificationManager.Stub {
        }

        public void run() {
            powerWake.acquire(sleepTimer);
            powerWake.acquire((sleepTimer+1000));
            try {
                Thread.sleep(sleepTimer);
            } catch (InterruptedException e) {
@@ -1224,6 +1224,81 @@ class NotificationManagerService extends INotificationManager.Stub {
        threadExecutor = Executors.newSingleThreadExecutor();
    }

    private int getLedARGB(NotificationRecord sLight) {
        int rledARGB = sLight.notification.ledARGB;
        int mRandomColor = Settings.System.getInt(mContext.getContentResolver(),
                Settings.System.TRACKBALL_NOTIFICATION_RANDOM, 0);
        int mPulseAllColor = Settings.System.getInt(mContext.getContentResolver(),
                Settings.System.TRACKBALL_NOTIFICATION_PULSE_ORDER, 0);
        int mBlendColor = Settings.System.getInt(mContext.getContentResolver(),
                Settings.System.TRACKBALL_NOTIFICATION_BLEND_COLOR, 0);

        if ((sLight.notification.defaults & Notification.DEFAULT_LIGHTS) != 0) {
                rledARGB = mDefaultNotificationColor;
        }

        String[] mPackageInfo = findPackage(sLight.pkg);
        if (mPackageInfo != null) {
            if (!mPackageInfo[1].equals("none")) {
                if (mPackageInfo[1].equals("random")) {
                    Random generator = new Random();
                    int x = generator.nextInt(colorList.length - 1);
                    rledARGB = Color.parseColor(colorList[x]);
                } else {
                    rledARGB = Color.parseColor(mPackageInfo[1]);
                }
            }
        }

        if (mRandomColor == 1) {
            // Lets make this intresting...
            Random generator = new Random();
            int x = generator.nextInt(colorList.length - 1);
            rledARGB = Color.parseColor(colorList[x]);
        } else if (mPulseAllColor == 1) {
            if (lastColor >= colorList.length)
                lastColor = 1;

            rledARGB = Color.parseColor(colorList[lastColor - 1]);
            lastColor = lastColor + 1;
        } else if (mBlendColor == 1) { // Blend lights: Credit to eshabtai
                                       // for the application of this.
            rledARGB = 0;
            for (NotificationRecord light : mLights) {
                mPackageInfo = findPackage(light.pkg);
                if (mPackageInfo != null) {
                    if (mPackageInfo[1].equals("random")) {
                        Random generator = new Random();
                        int j = generator.nextInt(colorList.length - 1);
                        rledARGB |= Color.parseColor(colorList[j]);
                    } else {
                        rledARGB |= Color.parseColor(mPackageInfo[1]);
                    }
                } else if ((light.notification.defaults & Notification.DEFAULT_LIGHTS) != 0) {
                    rledARGB |= light.notification.ledARGB;
                }
            }
            if (rledARGB == 0) {
                rledARGB = mDefaultNotificationColor;
            }
        }

        // Adjust the LED for quiet hours
        if (inQuietHours() && mQuietHoursDim) {
            // Cut all of the channels by a factor of 16 to dim on capable
            // hardware.
            // Note that this should fail gracefully on other hardware.
            int argb = rledARGB;
            int red = (((argb & 0xFF0000) >>> 16) >>> 4);
            int green = (((argb & 0xFF00) >>> 8) >>> 4);
            int blue = ((argb & 0xFF) >>> 4);

            rledARGB = (0xFF000000 | (red << 16) | (green << 8) | blue);
        }

        return rledARGB;
    }

    // lock on mNotificationList
    private void updateLightsLocked() {
        int mPulseScreen = Settings.System.getInt(mContext.getContentResolver(),
@@ -1283,6 +1358,8 @@ class NotificationManagerService extends INotificationManager.Stub {
        if (mLedNotification == null || (mScreenOn && (mPulseScreen == 0)) || mInCall) {
            mNotificationLight.turnOff();
            isTimer = false;
            if(powerWake != null && powerWake.isHeld())
                powerWake.release();
        } else {
            if (mSuccession == 1) {
                int n = mLights.size();
@@ -1301,11 +1378,10 @@ class NotificationManagerService extends INotificationManager.Stub {
                    mLastLight = thisLight;
                }
            }
            int ledARGB = mLedNotification.notification.ledARGB;
            int ledARGB = getLedARGB(mLedNotification);
            int ledOnMS = mLedNotification.notification.ledOnMS;
            int ledOffMS = mLedNotification.notification.ledOffMS;
            if ((mLedNotification.notification.defaults & Notification.DEFAULT_LIGHTS) != 0) {
                ledARGB = mDefaultNotificationColor;
                ledOnMS = mDefaultNotificationLedOn;
                ledOffMS = mDefaultNotificationLedOff;
            }
@@ -1313,13 +1389,6 @@ class NotificationManagerService extends INotificationManager.Stub {
            String[] mPackageInfo = findPackage(mLedNotification.pkg);
            if (mPackageInfo != null) {
                if (!mPackageInfo[1].equals("none")) {
                    if (mPackageInfo[1].equals("random")) {
                        Random generator = new Random();
                        int x = generator.nextInt(colorList.length - 1);
                        ledARGB = Color.parseColor(colorList[x]);
                    } else {
                        ledARGB = Color.parseColor(mPackageInfo[1]);
                    }
                    if (mPackageInfo[2].equals(".5")) {
                        ledOffMS = 500;
                    } else {
@@ -1328,52 +1397,6 @@ class NotificationManagerService extends INotificationManager.Stub {
                }
            }

            if (mRandomColor == 1) {
                // Lets make this intresting...
                Random generator = new Random();
                int x = generator.nextInt(colorList.length - 1);
                ledARGB = Color.parseColor(colorList[x]);
            } else if (mPulseAllColor == 1) {
                if (lastColor >= colorList.length)
                    lastColor = 1;

                ledARGB = Color.parseColor(colorList[lastColor - 1]);
                lastColor = lastColor + 1;
            } else if (mBlendColor == 1) { // Blend lights: Credit to eshabtai
                                           // for the application of this.
                ledARGB = 0;
                for (NotificationRecord light : mLights) {
                    mPackageInfo = findPackage(light.pkg);
                    if (mPackageInfo != null) {
                        if (mPackageInfo[1].equals("random")) {
                            Random generator = new Random();
                            int j = generator.nextInt(colorList.length - 1);
                            ledARGB |= Color.parseColor(colorList[j]);
                        } else {
                            ledARGB |= Color.parseColor(mPackageInfo[1]);
                        }
                    } else if ((light.notification.defaults & Notification.DEFAULT_LIGHTS) != 0) {
                        ledARGB |= light.notification.ledARGB;
                    }
                }
                if (ledARGB == 0) {
                    ledARGB = mDefaultNotificationColor;
                }
            }

            // Adjust the LED for quiet hours
            if (inQuietHours() && mQuietHoursDim) {
                // Cut all of the channels by a factor of 16 to dim on capable
                // hardware.
                // Note that this should fail gracefully on other hardware.
                int argb = ledARGB;
                int red = (((argb & 0xFF0000) >>> 16) >>> 4);
                int green = (((argb & 0xFF00) >>> 8) >>> 4);
                int blue = ((argb & 0xFF) >>> 4);

                ledARGB = (0xFF000000 | (red << 16) | (green << 8) | blue);
            }

            if (mNotificationPulseEnabled) {
                // pulse repeatedly
                if ((mSuccession == 1) || (mRandomColor == 1) || (mPulseAllColor == 1)) {