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

Commit 04a17a7a authored by Jeff Davidson's avatar Jeff Davidson
Browse files

Enable live refresh of USB Debugging notification setting.

Change-Id: Iad521e0f9737c9c0bfa69b5ed18f7af5f7704814
parent f08c19fb
Loading
Loading
Loading
Loading
+29 −2
Original line number Diff line number Diff line
@@ -138,6 +138,7 @@ public class NotificationManagerService extends INotificationManager.Stub
    private boolean mGreenLightOn = false;

    // for adb connected notifications
    private boolean mUsbConnected = false;
    private boolean mAdbNotificationShown = false;
    private Notification mAdbNotification;

@@ -405,10 +406,10 @@ public class NotificationManagerService extends INotificationManager.Stub
                }
            } else if (action.equals(Usb.ACTION_USB_STATE)) {
                Bundle extras = intent.getExtras();
                boolean usbConnected = extras.getBoolean(Usb.USB_CONNECTED);
                mUsbConnected = extras.getBoolean(Usb.USB_CONNECTED);
                boolean adbEnabled = (Usb.USB_FUNCTION_ENABLED.equals(
                                    extras.getString(Usb.USB_FUNCTION_ADB)));
                updateAdbNotification(usbConnected && adbEnabled);
                updateAdbNotification(mUsbConnected && adbEnabled);
            } else if (action.equals(Usb.ACTION_USB_DISCONNECTED)) {
                updateAdbNotification(false);
            } else if (action.equals(Intent.ACTION_PACKAGE_REMOVED)
@@ -549,6 +550,29 @@ public class NotificationManagerService extends INotificationManager.Stub
        }
    }

    class AdbNotifyObserver extends ContentObserver {
        AdbNotifyObserver(Handler handler) {
            super(handler);
        }

        void observe() {
            ContentResolver resolver = mContext.getContentResolver();
            resolver.registerContentObserver(Settings.Secure.getUriFor(
                    Settings.Secure.ADB_ENABLED), false, this);
            resolver.registerContentObserver(Settings.Secure.getUriFor(
                    Settings.Secure.ADB_NOTIFY), false, this);
        }

        @Override public void onChange(boolean selfChange) {
            ContentResolver resolver = mContext.getContentResolver();
            boolean adbEnabled = Settings.Secure.getInt(resolver,
                    Settings.Secure.ADB_ENABLED, 0) != 0;
            boolean notifyEnabled = Settings.Secure.getInt(resolver,
                    Settings.Secure.ADB_NOTIFY, 1) != 0;
            updateAdbNotification(adbEnabled && notifyEnabled && mUsbConnected);
        }
    }

    NotificationManagerService(Context context, StatusBarManagerService statusBar,
            LightsService lights)
    {
@@ -604,6 +628,9 @@ public class NotificationManagerService extends INotificationManager.Stub

        SettingsObserver observer = new SettingsObserver(mHandler);
        observer.observe();

        AdbNotifyObserver notifyObserver = new AdbNotifyObserver(mHandler);
        notifyObserver.observe();
    }

    void systemReady() {