diff options
author | Ricardo Cerqueira <cyanogenmod@cerqueira.org> | 2013-11-04 02:17:27 +0000 |
---|---|---|
committer | Steve Kondik <steve@cyngn.com> | 2015-10-25 21:49:36 -0700 |
commit | 47e1d1f59e1f35a9eacc99ecc7e638d7eeb860e8 (patch) | |
tree | f53c6bc545bc67cb013f0401707aaede07a022a4 /services/usb | |
parent | cce429f5139cb423979d22e6c0ac969115538e61 (diff) | |
download | frameworks_base-47e1d1f59e1f35a9eacc99ecc7e638d7eeb860e8.zip frameworks_base-47e1d1f59e1f35a9eacc99ecc7e638d7eeb860e8.tar.gz frameworks_base-47e1d1f59e1f35a9eacc99ecc7e638d7eeb860e8.tar.bz2 |
Framework: Forward port ADB over network (Part 2 of 2)
Includes:
- ADB Over Network, integration of the adb-host mode (already present)
The feature can be used/tested without the Settings part:
setprop service.adb.tcp.port 5555
Note: This ADB setting is not persistent (for security purpose) and
require init.rc implementation event like this : http://bit.ly/AdbTcpIP
Author: Tanguy Pruvot
Id: I5c61a53948349c785356cb5aae165110d75e3074
Author: sssemil <suleymanovemil8@gmail.com>
Show notification on adb over network too
Screenshots - http://goo.gl/TgsRI6
Id: I9ddc0aa9a4f330a06ab5d97a8645d1b31bb6f299
Change-Id: I101216c5b8ddff5040d9eeaf35afefc5cd98bbf3
Diffstat (limited to 'services/usb')
-rw-r--r-- | services/usb/java/com/android/server/usb/UsbDeviceManager.java | 105 |
1 files changed, 64 insertions, 41 deletions
diff --git a/services/usb/java/com/android/server/usb/UsbDeviceManager.java b/services/usb/java/com/android/server/usb/UsbDeviceManager.java index 2beb669..7a2f1a3 100644 --- a/services/usb/java/com/android/server/usb/UsbDeviceManager.java +++ b/services/usb/java/com/android/server/usb/UsbDeviceManager.java @@ -305,7 +305,7 @@ public class UsbDeviceManager { private boolean mCurrentFunctionsApplied; private UsbAccessory mCurrentAccessory; private int mUsbNotificationId; - private boolean mAdbNotificationShown; + private int mAdbNotificationId; private int mCurrentUser = UserHandle.USER_NULL; public UsbHandler(Looper looper) { @@ -330,14 +330,20 @@ public class UsbDeviceManager { mContentResolver.registerContentObserver( Settings.Global.getUriFor(Settings.Global.ADB_ENABLED), false, new AdbSettingsObserver()); + + ContentObserver adbNotificationObserver = new ContentObserver(null) { + @Override + public void onChange(boolean selfChange) { + updateAdbNotification(); + } + }; + + mContentResolver.registerContentObserver( + Settings.Secure.getUriFor(Settings.Secure.ADB_PORT), + false, adbNotificationObserver); mContentResolver.registerContentObserver( Settings.Secure.getUriFor(Settings.Secure.ADB_NOTIFY), - false, new ContentObserver(null) { - public void onChange(boolean selfChange) { - updateAdbNotification(); - } - } - ); + false, adbNotificationObserver); // Watch for USB configuration changes mUEventObserver.startObserving(USB_STATE_MATCH); @@ -775,44 +781,61 @@ public class UsbDeviceManager { private void updateAdbNotification() { if (mNotificationManager == null) return; - final int id = com.android.internal.R.string.adb_active_notification_title; + final int id; + boolean usbAdbActive = mAdbEnabled && mConnected; + boolean netAdbActive = mAdbEnabled && + Settings.Secure.getInt(mContentResolver, Settings.Secure.ADB_PORT, -1) > 0; boolean hideNotification = "0".equals(SystemProperties.get("persist.adb.notify")) || Settings.Secure.getInt(mContext.getContentResolver(), Settings.Secure.ADB_NOTIFY, 1) == 0; - if (mAdbEnabled && mConnected && !mAdbNotificationShown && !hideNotification) { - Resources r = mContext.getResources(); - CharSequence title = r.getText(id); - CharSequence message = r.getText( - com.android.internal.R.string.adb_active_notification_message); - - Intent intent = Intent.makeRestartActivityTask( - new ComponentName("com.android.settings", - "com.android.settings.DevelopmentSettings")); - PendingIntent pi = PendingIntent.getActivityAsUser(mContext, 0, - intent, 0, null, UserHandle.CURRENT); - - Notification notification = new Notification.Builder(mContext) - .setSmallIcon(com.android.internal.R.drawable.stat_sys_adb) - .setWhen(0) - .setOngoing(true) - .setTicker(title) - .setDefaults(0) // please be quiet - .setPriority(Notification.PRIORITY_LOW) - .setColor(mContext.getColor( - com.android.internal.R.color.system_notification_accent_color)) - .setContentTitle(title) - .setContentText(message) - .setContentIntent(pi) - .setVisibility(Notification.VISIBILITY_PUBLIC) - .build(); - - mAdbNotificationShown = true; - mNotificationManager.notifyAsUser(null, id, notification, - UserHandle.ALL); - } else if (mAdbNotificationShown) { - mAdbNotificationShown = false; - mNotificationManager.cancelAsUser(null, id, UserHandle.ALL); + if (hideNotification) { + id = 0; + } else if (usbAdbActive && netAdbActive) { + id = com.android.internal.R.string.adb_both_active_notification_title; + } else if (usbAdbActive) { + id = com.android.internal.R.string.adb_active_notification_title; + } else if (netAdbActive) { + id = com.android.internal.R.string.adb_net_active_notification_title; + } else { + id = 0; + } + + if (id != mAdbNotificationId) { + if (mAdbNotificationId != 0) { + mNotificationManager.cancelAsUser(null, mAdbNotificationId, UserHandle.ALL); + } + if (id != 0) { + Resources r = mContext.getResources(); + CharSequence title = r.getText(id); + CharSequence message = r.getText( + com.android.internal.R.string.adb_active_generic_notification_message); + + Intent intent = Intent.makeRestartActivityTask( + new ComponentName("com.android.settings", + "com.android.settings.DevelopmentSettings")); + PendingIntent pi = PendingIntent.getActivityAsUser(mContext, 0, + intent, 0, null, UserHandle.CURRENT); + + Notification notification = new Notification.Builder(mContext) + .setSmallIcon(com.android.internal.R.drawable.stat_sys_adb) + .setWhen(0) + .setOngoing(true) + .setTicker(title) + .setDefaults(0) // please be quiet + .setPriority(Notification.PRIORITY_LOW) + .setColor(mContext.getColor( + com.android.internal.R.color.system_notification_accent_color)) + .setContentTitle(title) + .setContentText(message) + .setContentIntent(pi) + .setVisibility(Notification.VISIBILITY_PUBLIC) + .build(); + + mNotificationManager.notifyAsUser(null, id, notification, + UserHandle.ALL); + } + mAdbNotificationId = id; } } |