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

Commit da3d2a82 authored by Sam Mortimer's avatar Sam Mortimer Committed by Steve Kondik
Browse files

[1/2] Forward port power connect/disconnect notification support

Original commit info:

    [1/2] Power connect/disconnect notification support

    part 1/2: frameworks/base PowerUI and Settings
    http://review.cyanogenmod.org/#/c/35241/

    part 2/2: packages/apps/Settings Sound settings
    http://review.cyanogenmod.org/#/c/35242/



    V-Old_Change-Id: I36a6b9f924d2cd52191a8e83a744745b37c5b068

OldChange-Id: Ib865e1c296cb8e1d957b2a48616c88ceaba5c008

Change-Id: I5db20ef23bdb644e2af06e8dcbc8fbd0cf7ce321
Signed-off-by: default avatarSTELIX <ssspinni@gmail.com>
parent ad84082e
Loading
Loading
Loading
Loading
+18 −0
Original line number Original line Diff line number Diff line
@@ -7076,6 +7076,24 @@ public final class Settings {
         */
         */
        public static final String LOW_POWER_MODE_TRIGGER_LEVEL = "low_power_trigger_level";
        public static final String LOW_POWER_MODE_TRIGGER_LEVEL = "low_power_trigger_level";


        /**
         * Whether to sound when charger power is connected/disconnected
         * @hide
         */
        public static final String POWER_NOTIFICATIONS_ENABLED = "power_notifications_enabled";

        /**
         * Whether to vibrate when charger power is connected/disconnected
         * @hide
         */
        public static final String POWER_NOTIFICATIONS_VIBRATE = "power_notifications_vibrate";

        /**
         * URI for power notification sounds
         * @hide
         */
        public static final String POWER_NOTIFICATIONS_RINGTONE = "power_notifications_ringtone";

         /**
         /**
         * If 1, the activity manager will aggressively finish activities and
         * If 1, the activity manager will aggressively finish activities and
         * processes as soon as they are no longer needed.  If 0, the normal
         * processes as soon as they are no longer needed.  If 0, the normal
+4 −0
Original line number Original line Diff line number Diff line
@@ -77,6 +77,10 @@
    <string name="def_trusted_sound" translatable="false">/system/media/audio/ui/Trusted.ogg</string>
    <string name="def_trusted_sound" translatable="false">/system/media/audio/ui/Trusted.ogg</string>
    <string name="def_wireless_charging_started_sound" translatable="false">/system/media/audio/ui/WirelessChargingStarted.ogg</string>
    <string name="def_wireless_charging_started_sound" translatable="false">/system/media/audio/ui/WirelessChargingStarted.ogg</string>


    <bool name="def_power_notifications_enabled">false</bool>
    <bool name="def_power_notifications_vibrate">false</bool>
    <string name="def_power_notifications_ringtone" translatable="false">content://settings/system/notification_sound</string>

    <bool name="def_lockscreen_disabled">false</bool>
    <bool name="def_lockscreen_disabled">false</bool>
    <bool name="def_device_provisioned">false</bool>
    <bool name="def_device_provisioned">false</bool>
    <integer name="def_dock_audio_media_enabled">1</integer>
    <integer name="def_dock_audio_media_enabled">1</integer>
+6 −0
Original line number Original line Diff line number Diff line
@@ -1516,6 +1516,12 @@ public class DatabaseHelper extends SQLiteOpenHelper {
                            + " VALUES(?,?);");
                            + " VALUES(?,?);");
                    loadStringSetting(stmt, Settings.Global.WIRELESS_CHARGING_STARTED_SOUND,
                    loadStringSetting(stmt, Settings.Global.WIRELESS_CHARGING_STARTED_SOUND,
                            R.string.def_wireless_charging_started_sound);
                            R.string.def_wireless_charging_started_sound);
                    loadBooleanSetting(stmt, Settings.Global.POWER_NOTIFICATIONS_ENABLED,
                            R.bool.def_power_notifications_enabled);
                    loadBooleanSetting(stmt, Settings.Global.POWER_NOTIFICATIONS_VIBRATE,
                            R.bool.def_power_notifications_vibrate);
                    loadStringSetting(stmt, Settings.Global.POWER_NOTIFICATIONS_RINGTONE,
                            R.string.def_power_notifications_ringtone);
                    db.setTransactionSuccessful();
                    db.setTransactionSuccessful();
                } finally {
                } finally {
                    db.endTransaction();
                    db.endTransaction();
+52 −0
Original line number Original line Diff line number Diff line
@@ -16,12 +16,15 @@


package com.android.systemui.power;
package com.android.systemui.power;


import android.app.Notification;
import android.app.NotificationManager;
import android.content.BroadcastReceiver;
import android.content.BroadcastReceiver;
import android.content.ContentResolver;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Context;
import android.content.Intent;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.IntentFilter;
import android.database.ContentObserver;
import android.database.ContentObserver;
import android.net.Uri;
import android.os.BatteryManager;
import android.os.BatteryManager;
import android.os.Handler;
import android.os.Handler;
import android.os.PowerManager;
import android.os.PowerManager;
@@ -57,6 +60,9 @@ public class PowerUI extends SystemUI {


    private long mScreenOffTime = -1;
    private long mScreenOffTime = -1;


    // For filtering ACTION_POWER_DISCONNECTED on boot
    boolean mIgnoreFirstPowerEvent = true;

    public void start() {
    public void start() {
        mPowerManager = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
        mPowerManager = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
        mScreenOffTime = mPowerManager.isScreenOn() ? -1 : SystemClock.elapsedRealtime();
        mScreenOffTime = mPowerManager.isScreenOn() ? -1 : SystemClock.elapsedRealtime();
@@ -139,6 +145,8 @@ public class PowerUI extends SystemUI {
            filter.addAction(Intent.ACTION_SCREEN_ON);
            filter.addAction(Intent.ACTION_SCREEN_ON);
            filter.addAction(PowerManager.ACTION_POWER_SAVE_MODE_CHANGING);
            filter.addAction(PowerManager.ACTION_POWER_SAVE_MODE_CHANGING);
            filter.addAction(PowerManager.ACTION_POWER_SAVE_MODE_CHANGED);
            filter.addAction(PowerManager.ACTION_POWER_SAVE_MODE_CHANGED);
            filter.addAction(Intent.ACTION_POWER_CONNECTED);
            filter.addAction(Intent.ACTION_POWER_DISCONNECTED);
            mContext.registerReceiver(this, filter, null, mHandler);
            mContext.registerReceiver(this, filter, null, mHandler);
            updateSaverMode();
            updateSaverMode();
        }
        }
@@ -164,6 +172,10 @@ public class PowerUI extends SystemUI {
                final boolean plugged = mPlugType != 0;
                final boolean plugged = mPlugType != 0;
                final boolean oldPlugged = oldPlugType != 0;
                final boolean oldPlugged = oldPlugType != 0;


                if (mIgnoreFirstPowerEvent && plugged) {
                    mIgnoreFirstPowerEvent = false;
                }

                int oldBucket = findBatteryLevelBucket(oldBatteryLevel);
                int oldBucket = findBatteryLevelBucket(oldBatteryLevel);
                int bucket = findBatteryLevelBucket(mBatteryLevel);
                int bucket = findBatteryLevelBucket(mBatteryLevel);


@@ -211,12 +223,52 @@ public class PowerUI extends SystemUI {
                updateSaverMode();
                updateSaverMode();
            } else if (PowerManager.ACTION_POWER_SAVE_MODE_CHANGING.equals(action)) {
            } else if (PowerManager.ACTION_POWER_SAVE_MODE_CHANGING.equals(action)) {
                setSaverMode(intent.getBooleanExtra(PowerManager.EXTRA_POWER_SAVE_MODE, false));
                setSaverMode(intent.getBooleanExtra(PowerManager.EXTRA_POWER_SAVE_MODE, false));
            } else if (Intent.ACTION_POWER_CONNECTED.equals(action)
                    || Intent.ACTION_POWER_DISCONNECTED.equals(action)) {
                final ContentResolver cr = mContext.getContentResolver();

                if (mIgnoreFirstPowerEvent) {
                    mIgnoreFirstPowerEvent = false;
                } else {
                    if (Settings.Global.getInt(cr,
                            Settings.Global.POWER_NOTIFICATIONS_ENABLED, 0) == 1) {
                        playPowerNotificationSound();
                    }
                }
            } else {
            } else {
                Slog.w(TAG, "unknown intent: " + intent);
                Slog.w(TAG, "unknown intent: " + intent);
            }
            }
        }
        }
    };
    };


    void playPowerNotificationSound() {
        final ContentResolver cr = mContext.getContentResolver();
        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;
            }
        }
        if (Settings.Global.getInt(cr,
                Settings.Global.POWER_NOTIFICATIONS_VIBRATE, 0) == 0) {
            powerNotify.defaults &= ~Notification.DEFAULT_VIBRATE;
        }

        notificationManager.notify(0, powerNotify);
    }

    public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
    public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
        pw.print("mLowBatteryAlertCloseLevel=");
        pw.print("mLowBatteryAlertCloseLevel=");
        pw.println(mLowBatteryAlertCloseLevel);
        pw.println(mLowBatteryAlertCloseLevel);