muinmohd / android-notifier

Automatically exported from code.google.com/p/android-notifier
0 stars 0 forks source link

USB Notification Support #162

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
I'd like to see USB added as a notification option.

Original issue reported on code.google.com by lehph...@gmail.com on 22 Sep 2010 at 12:09

GoogleCodeExporter commented 8 years ago
I wonder what it would take to get this one going.
I checked out the source code and it looks like USB is completely 
unimplemented...  are you thinking of using the adb for this? or are you 
thinking of having the desktop application monitor the USB device somehow by 
using the native OS?  I'd like to see if I can help with this.

Original comment by nizn...@gmail.com on 27 Sep 2010 at 9:16

GoogleCodeExporter commented 8 years ago
As far as I know, Android does not provide an API for USB communication, adb 
port forwarding could work.

> I'd like to see if I can help with this.
Your help would be much appreciated :)

Original comment by lehph...@gmail.com on 27 Sep 2010 at 9:23

GoogleCodeExporter commented 8 years ago
Hi,

So I just wrote some test code that uses adb port forwarding to pass messages 
between a quick-n-dirty python script on the computer and a very simple android 
activity that simply listens on a certain port - this is workable two way 
communication.

As a proof of concept, this works 'as advertised'.  

What is the mindset about communication?  My approach was to open a server 
socket on the phone and then connect to it from my computer, send a few 
messages -- which get echoed back using the same connection.

I think this doesn't agree with the android-notifier concept... I believe that 
what we need is for the server to run on the computer (inside the desktop 
application) and the phone to connect to it every time there's a notification 
(no need to maintain an open connection); is this how that's done?  Or is it 
two-way (for SMS reply support for example), where the side notifying is the 
creating the client connection... this will require two server's one on the 
phone, and one on the computer.

Please provide some pointers.

Original comment by nizn...@gmail.com on 27 Sep 2010 at 11:19

GoogleCodeExporter commented 8 years ago
I'm afraid your proof of concept is backwards - what you want is to have the PC 
listen and the Android phone start the connection - can you get that to work?

Original comment by rdamazio@gmail.com on 27 Sep 2010 at 11:48

GoogleCodeExporter commented 8 years ago
By the way, if we are to use the adb for communication, we will need the users 
to have the android sdk installed.  If we do, why complicate our lives with 
sockets if we can just use logcat to monitor the device?  In this way, we can 
have the desktop application "listen for" android log messages with our special 
tag that will be of a specific format, that can be parsed for a notification...

Original comment by nizn...@gmail.com on 27 Sep 2010 at 11:49

GoogleCodeExporter commented 8 years ago
No we don't need them to have the Android SDK installed - the idea was to 
isolate the communication bits of adb into a library that we can link against. 
See http://code.google.com/p/adblib/ (no code though, adb's source is horrible, 
I ended up not finishing the lib).

Original comment by rdamazio@gmail.com on 27 Sep 2010 at 11:59

GoogleCodeExporter commented 8 years ago
Yeah - there doesn't seem to be a way to do "backwards" port forwarding - from 
the phone to the computer; like there is from adb on the computer, to the 
phone; without the SDK, we will need to listen to 'raw' USB bits and filter 
things out.  My aforementioned proposal of using logcat could be an easy way of 
using the existing pipeline to send notifications - but that challenge remains. 
 I'll look into it.

Original comment by nizn...@gmail.com on 28 Sep 2010 at 12:09

GoogleCodeExporter commented 8 years ago
Why not have the android app open a server socket and have the desktop app 
connect to it? We can send messages in both ways anyway, we just need to make 
the desktop app look for devices periodically through adb. And I think we can 
bundle only what is necessary for adb to work, not everything in the SDK.

Original comment by lehph...@gmail.com on 28 Sep 2010 at 1:10

GoogleCodeExporter commented 8 years ago
Provided I don't know enough about bundling adb, I don't see a reason why this 
wouldn't work.
There can only be 2 use cases: one when the desktop app starts first, and one 
when it starts after the android app.

If it starts first, it could, like you said - periodically look for servers at 
a pre-determined port.
If it starts last, the server (on the phone) is there, so there's no problem.

Because we're using port-forwarding, it is also feasible for more than one 
instance of the desktop application to connect to a single phone - even on 
different machines.  But I don't want to get into that to much.

Yeah, so this takes me back to the original question here: 
http://code.google.com/p/android-notifier/issues/detail?id=162#c3

Bottom line: I can give you code to start a server and handle connections for 
you to start with the service the android app starts; this code will also be 
able to provide that connection as a notification "target" (if I'm using the 
right terminology here) so it can be sent notifications like anything else.

I just need to make sure I have robust error handling (e.g. when the 
connection's lost, etc).
Can you provide some entry points to the code for me to start my server socket 
thread in the service and for me to implement (if necessary) the 
UsbNotificationMethod?

Original comment by nizn...@gmail.com on 28 Sep 2010 at 2:26

GoogleCodeExporter commented 8 years ago
afaik keeping the connection open will drain more battery than you want as 
you'll need to hold a wakelock.
Of course this is not a direct issue if you're plugged to usb, except you'd 
need to detect whether you're plugged to usb.

Original comment by rdamazio@gmail.com on 28 Sep 2010 at 2:31

GoogleCodeExporter commented 8 years ago
That makes complete sense... so I'll need to use some android API, something 
for detecting that the USB is connected or maybe even just the BatteryManager 
to know when I'm connected.

Then, the USB server will know to kill itself when disconnected or start itself 
upon receiving that intent.

Original comment by nizn...@gmail.com on 28 Sep 2010 at 2:53

GoogleCodeExporter commented 8 years ago
I don't know about bundling adb either, it'll need some research.

> Can you provide some entry points to the code
Basically, you have to implement the 
com.google.code.notifier.desktop.NotificationReceiver interface in the 
multiplatform client to add usb support. I'd suggest you to use Netty to handle 
network communication, you can take a look at TcpNotificationReceiver for an 
example of a complete implementation of NotificationReceiver.

Original comment by lehph...@gmail.com on 28 Sep 2010 at 3:30

GoogleCodeExporter commented 8 years ago
The license of the Windows USB driver doesn't allow redistribution, we have to 
ask the user to install it before enabling usb notifications...

Original comment by lehph...@gmail.com on 11 Oct 2010 at 1:52

GoogleCodeExporter commented 8 years ago
Is there any seperate repository from any of you guys working on USB support?

I don't know if I can help out that much, but this feature is very interesting.

Original comment by bjorn.to...@gmail.com on 14 Oct 2010 at 6:33

GoogleCodeExporter commented 8 years ago
No, I don't have anything yet... school and work got kind of busy lately.

Original comment by nizn...@gmail.com on 14 Oct 2010 at 6:43

GoogleCodeExporter commented 8 years ago
http://code.google.com/p/adblib/ - I created this one but never got around to 
posting any code. The adb source was more complicated than I thought (too messy 
IMHO).

Original comment by rdamazio@gmail.com on 14 Oct 2010 at 6:51

GoogleCodeExporter commented 8 years ago
I've started implementation of 
com.notifier.desktop.notification.usb.UsbNotificationReceiver using adb to do 
port forwarding, it's in SVN repo.

Original comment by lehph...@gmail.com on 14 Oct 2010 at 8:45

GoogleCodeExporter commented 8 years ago
Please add a wiki page detailing how it'll work.

Original comment by rdamazio@gmail.com on 14 Oct 2010 at 10:12

GoogleCodeExporter commented 8 years ago
I've committed the code to the android app to get usb support going, the idea 
is to use adb to forward connections as previously discussed in this issue.

The desktop app is running adb forward tcp:10602 localabstract:androidnotifier 
to forward connections on port 10602 to a LocalServerSocket on the device.

Since the only way to know if the device is connected to usb is through the 
BATTERY_CHANGED intent, I added a new extra to the notification intent to let 
the NotificationService know if it should start a socketserver. I can't get it 
to run the server only once though and notifications are not going to the right 
UsbNotificationMethod instance, help?

Original comment by lehph...@gmail.com on 15 Oct 2010 at 3:39

GoogleCodeExporter commented 8 years ago
Ok, finished usb support in both desktop and android apps. Right now, 
UsbNotificationMethod will keep a thread running all the time even if the phone 
is not plugged to usb, the thread just waits for incoming connections so it's 
not a battery killer but we can/should? implement a BatteryReceiver that 
starts/stops this thread if the phone is plugged/unplugged.

I'll make the Android SDK path configurable through the preferences window of 
the desktop app, then it'll be ready for testing.

@rdamazio Do I need to do something to provide test builds of the apk file?

Original comment by lehph...@gmail.com on 15 Oct 2010 at 3:26

GoogleCodeExporter commented 8 years ago
Cool :)

You can just build them normally (choose to export the project from eclipse, 
sign with your own key), it'll work (people will just need to uninstall the 
official version before trying yours because of the different key).

Original comment by rdamazio@gmail.com on 15 Oct 2010 at 5:56

GoogleCodeExporter commented 8 years ago
Android app: http://dl.dropbox.com/u/1401233/AndroidNotifier.apk

I'm linking to the pure java desktop program, no exe or sh scripts, to make it 
easier for me to post fixes.

lib: http://dl.dropbox.com/u/1401233/android-notifier-desktop-lib.zip
jar: http://dl.dropbox.com/u/1401233/android-notifier-desktop.jar

Copy android-notifier-desktop.jar to some directory and unzip 
android-notifier-desktop-lib.zip into the same directory. Now rename one of the 
swt-*.jar files to swt.jar only, you have to rename the file that matches your 
OS, for example, swt-win32-x86_64-3.7M1.jar is for Windows 64-bit, 
swt-gtk-linux-x86-3.7M1.jar is for Linux 32-bit and 
swt-cocoa-macosx-x86_64-3.7M1.jar is for MacOSX 64-bit.

Now you can run it with java -jar android-notifier-desktop.jar from command 
line, not all features will be working correctly and preferences may be reset, 
but USB support will work fine.

For USB notifications to work, you have to download the Android SDK for your 
system from this page: http://developer.android.com/sdk/index.html and unzip it 
somewhere, the directory created after unzipping is SDK_HOME. The command 
"SDK_HOME/tools/adb devices" must list your device correctly, something like 
this:

List of devices attached
HT012P801245    device

To do this, you have to enable USB Debugging in Settings -> Applications -> 
Development in your device and setup your OS to recognize your phone with the 
following instructions:

Windows users must install the USB driver for their phone available in this 
page: http://developer.android.com/sdk/win-usb.html or in respective 
manufacturer page.

Linux users must follow the instructions in this page: 
http://developer.android.com/guide/developing/device.html#setting-up but the 
comment of jerichod in 
http://www.google.com/support/forum/p/android/thread?tid=08945730bbd7b22b&hl=en 
is much more detailed and helpful.

MacOSX users don't have to do anything according to Google documentation.

Now that "SDK_HOME/tools/adb devices" works for you, start the desktop app, 
enable USB in preferences and select SDK_HOME in the dialog that appears, 
something like the following will be printed in your log file:

2010-10-16 14:08:35,459 DEBUG [UsbPortForwarder] - Found [1] new device(s)
2010-10-16 14:08:35,460 DEBUG [UsbPortForwarder] - Forwarding port [10602] for 
device [HT012PXXXXXX]
2010-10-16 14:08:35,493 DEBUG [UsbPortForwarder] - Forwarded successfully, 
starting client

Go to the android app select Notification Methods and enable USB, disable Wifi 
and bluetooth to make sure notifications are arriving only over USB.

That's it, easy right?

Original comment by lehph...@gmail.com on 16 Oct 2010 at 5:14

GoogleCodeExporter commented 8 years ago
Tried the above, however getting an error when running the java notifier

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/cl
i/CommandLineParser
Caused by: java.lang.ClassNotFoundException: org.apache.commons.cli.CommandLineP
arser
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClassInternal(Unknown Source)
Could not find the main class: com.notifier.desktop.Main. Program will exit.

Original comment by Brandon....@gmail.com on 23 Oct 2010 at 12:14

GoogleCodeExporter commented 8 years ago
@Brandon.Martine00 Your directory layout must be:

+ some directory
  - android-notifier-desktop.jar
  + lib
    - swt.jar
    - commons-cli-1.2.jar

You have to run "java -jar android-notifier-desktop.jar" inside "some 
directory".

Original comment by lehph...@gmail.com on 23 Oct 2010 at 1:10

GoogleCodeExporter commented 8 years ago
Could you provide the source code for the desktop application with USB support?
Thanks!

Original comment by miguelpe...@gmail.com on 25 Oct 2010 at 1:45

GoogleCodeExporter commented 8 years ago
lehph,
  That helped in getting it started.  Thank you, but I'm having problems as notifications aren't popping up.  I have Growl installed and I tried System Default, but not getting any messages when attempting to test sending myself a SMS.  I've left my Devices set to 'Receive notifications from any device' and I tried to pair with test and it doesn't see anything when attempting to pair.  Any help?

Thank you,

2010-10-25 12:01:26,114 INFO [ApplicationImpl] - Starting SWT
2010-10-25 12:01:26,208 INFO [ApplicationImpl] - Showing tray icon
2010-10-25 12:01:26,302 INFO [ApplicationImpl] - Starting [service server]
2010-10-25 12:01:26,302 DEBUG [ServiceServerImpl] - Starting service server on p
ort [10700]
2010-10-25 12:01:26,302 DEBUG [InetAddresses] - Looking for local address
2010-10-25 12:01:26,317 INFO [ApplicationImpl] - Starting [Growl] broadcaster
2010-10-25 12:01:26,317 DEBUG [InetAddresses] - Local address found
2010-10-25 12:01:26,520 INFO [ApplicationImpl] - Starting [USB] receiver
2010-10-25 12:01:26,536 INFO [ApplicationImpl] - Adding to startup
2010-10-25 12:01:26,708 INFO [GrowlNotificationBroadcaster] - Registered with GN
TP server sucessfully
2010-10-25 12:02:05,899 DEBUG [UsbPortForwarder] - Found [1] new device(s)
2010-10-25 12:02:05,899 DEBUG [UsbPortForwarder] - Forwarding port [10602] for d
evice [HT09PRXXXXXX]
2010-10-25 12:02:05,930 DEBUG [UsbPortForwarder] - Forwarded successfully, start
ing client

Original comment by Brandon....@gmail.com on 25 Oct 2010 at 6:09

GoogleCodeExporter commented 8 years ago
Does it work over wifi? Do you have the log of the android app? You can get it 
using the alogcat app from market. Try to send some test notifications and then 
send the log to yourself via email.

Original comment by lehph...@gmail.com on 25 Oct 2010 at 6:24

GoogleCodeExporter commented 8 years ago
Not sure why, but installing alogcat worked!  Really excited for this because I 
can use my 6 multi-monitor workstation for everything at work and now dock my 
phone to it!

Thank you so much!

Original comment by Brandon....@gmail.com on 25 Oct 2010 at 6:40

GoogleCodeExporter commented 8 years ago
It must be some error that happens randomly on the android side, please attach 
the android log in a new issue when it happens.

Original comment by lehph...@gmail.com on 25 Oct 2010 at 7:05

GoogleCodeExporter commented 8 years ago
So it took me some trial/error to get as far as I have. FYI for HTC Eris, you 
need HTC's USB driver (I got it from installing HTC sync), the Android one 
didn't work on its own. So the adb devices is working now, but when I start up 
the notifier I get:
2010-11-05 16:48:03,030 DEBUG [UsbPortClient] - Could not connect to device 
[HT012HXXXXXX] over usb, will try again in [3] seconds
over and over and over again. I'm at work now, so wifi and BlueTooth aren't an 
option (hence why I'm interested in USB!). When I get a chance at home, I'll 
try the same via wifi to see if it's notifier or not. Any additional help would 
be lovely, thanks!

Original comment by Marie.F....@gmail.com on 5 Nov 2010 at 8:51

GoogleCodeExporter commented 8 years ago
@miguelpellon Sorry, I didn't see your comment, the source code is available in 
the Source tab, direct link: 
http://code.google.com/p/android-notifier/source/browse/trunk/#trunk/MultiDroidN
otifier

@Marie.F.Russo Make sure you've enabled USB support in the android app. If it's 
enabled and still doesn't work, please attach the android log in this issue 
using the alogcat app from android market.

Original comment by lehph...@gmail.com on 5 Nov 2010 at 9:41

GoogleCodeExporter commented 8 years ago
Just realized I wasn't running the android app last time I tried. I turned that 
on, but realized I hadn't installed the updated version given here. After all 
that, it works! However, without the SMS reply capability, I can't use this app 
just yet. Thanks for all of your help!

Original comment by Marie.F....@gmail.com on 8 Nov 2010 at 3:05

GoogleCodeExporter commented 8 years ago
Taking over lehphyro's issues.

Original comment by rdamazio@gmail.com on 11 Jan 2011 at 4:31

GoogleCodeExporter commented 8 years ago
I'm not sure about windows, but on linux and mac, adb has moved to 
platform-tools/

desktop side is still looking for it in tools/

Original comment by halkeye on 6 Feb 2011 at 4:05

GoogleCodeExporter commented 8 years ago
What happened to this? The Dropbox links do not work and MultiDroidNotifier 
0.5.1 doesn't have a USB option in preferences.

I am willing to try to lend some help here, but I need some starting point.

Original comment by thiago.a...@gmail.com on 14 Nov 2012 at 7:14