How to control a serial device on Android? - android

I want to develop an application whitch control the serial device over usb, on Linux Android.
An Android OS is 3.1 that supports USB host.
Q1: Please let me know how to get which port the serial device is mounted .
I got likely USB device information when I got "Dump Device State" on Dalvik Debug Monitor.
And, I checked /dev/tty* on android device by using adb.
I don't know which one(/dev/tty??) the serial device is.
adb shell
$ ls /dev/tty*
/dev/tty
/dev/ttyFIQ0
/dev/ttyHS0
/dev/ttyHS2
/dev/ttyHS3
/dev/ttyHS4
/dev/ttyS0
/dev/ttyS1
/dev/ttyS2
/dev/ttyS3
Q2: Please let me know how to control the serial device on Android without root permission.
I have a application(exe) that can control the serial device on linux.
I tried to do on android , but I couldn't do for permission denied.
And, I tried redirect to the serial port(maybe)
$ ls > /dev/ttyS0
But I couldn't.
cannot create /dev/ttyS0: permission denied.
Please let me know anything how to control and access to the serial device.

There is a great review of this in the XDA forum thread:
How to talk to the Modem with AT commands.
That thread show you how to send AT commands (ATC) with a remote terminal (USB connected to you PC), but it has not yet solved the problem of how to use a local (phone) terminal to talk to the phone Modem.
BTW. You need a terminal application/program to do any talking to the modem (remember, its a 2-way communication). So that's why you need a rooted device, since the root kit usually come with Busybox (that includes a microcom terminal program). Otherwise you have to write your own program.

in next step, you can test tty* port by couple of command:
$ cat /dev/tty* /for receive the characters from tty
and
$ echo 'text string' > /dev/tty* /for send characters to tty
good luck!

Try on a rooted device?? In researching the same thing I've read that only a few 3.1 / 2.3.4 devices allow non-root access to the usb port.
This is what I get on my HTC Desire unrooted, 2.2:
$ ls /dev/tty*
ls /dev/tty*
/dev/tty
/dev/ttyHS0
/dev/ttyHSUSB0
/dev/ttyHSUSB1
/dev/ttyHSUSB2
/dev/ttyMSM0
My Asus Transformer, unrooted, 3.2:
$ ls /dev/tty*
ls /dev/tty*
/dev/tty
/dev/ttyHS1
/dev/ttyHS2
/dev/ttyS0
/dev/ttyS1
/dev/ttyS2
/dev/ttyS3
I get exactly the same list when docked with the Keyboard Dock installed (It as 2 x USB ports).
Hope it helps, please let me know I'd love to be able to do the same.

Related

Insufficient permissions for device in Android Studio Workspace running in openSUSE 13.2

I have a rooted Motorola Defy+ running a Cyanogenmod v11 custom ROM (nightly build) created by Quarx. Using Android Studio Workspace,(ASW) v.1.1.0, when I try and debug on this device, I get
????????????[null]
listed in the Choose Device window, with the Logcat window showing
insufficient permissions for device
I would really like to use this device and ROM for debugging purposes.
When I enter lsusb from the command line I get,
Bus 002 Device 002: ID 22b8:431d Motorola PCS
This is the correct device id for Motorola units. I have installed 51-android.rules and 71-android.rules in /etc/udev/rules.d/ with the correct Motorola ids in these files.
I've also tried Revoke USB debugging authority, from Developer Options on the device, with no luck.
I have not tried running ASW as root hoping that there might be another option; is there?
Update: I was able to get in and access ADB by
uvachem-gsmith2:/home/greg/Android/Sdk/platform-tools # ./adb
I then did a kill server, did an SU to root user and restarted the server. I then tried to connect to the device from Android Studio. Got a message on the device about accepting the RSA key from the PC, said "Yes" and then was able to deploy the app to the device. So back to my original question, Is there another way to access this device without logging in as root? It seems as if there is a permission issue on the phone file system that is preventing this...
Update #2 The core problem here was a permission thing. Even though running ADB as root will allow access to the rooted Android device, a better solution is to change permissions in the udev file for this device...resetting 664 to 666, (see answer below). This allows the PC to access the file system on the device.
I had this while using a Linux machine with a Nexus 4 running Android 5.1
The fix was to enable both 'debug over USB' and 'connect as MTP'. The opposite is true when using the same device and Android Studio and adb on OSX though - to allow Android Studio to recognise the handset, I need to disable 'connect as MTP'.
I found a simple answer that worked for me:
adb kill-server
sudo adb start-server
sudo adb devices
You will find your device then.
Reference: http://itsfoss.com/fix-error-insufficient-permissions-device/
It's simple.
Just change your USB mode to File Transfer mode then it works.
Android 8
MTP is no longer available. On my android 8 "Transfer Files" option did not work.
"Transfer photos PTP" Is worked, and Studio showed the device name.
Steps on your cell phone
Open the developer options
Enable USB debugging.
change USB connection to PTP
Steps on Linux
on console run sudo usermod -aG plugdev $LOGNAME
Android 9
With Android 9 use the option File Transfer.
Changing permissions in this line from /etc/udev/rules.d/51-android.rules,
#Motorola
SUBSYSTEM=="usb", ATTR{idVendor}=="22b8", MODE="0664", GROUP="plugdev"
to,
#Motorola
SUBSYSTEM=="usb", ATTR{idVendor}=="22b8", MODE="0666", GROUP="plugdev"
resolves this issue in a manner that DOES NOT require running adb as root.
IN my phone Symphony W75,
in option USB computer connection-> selecting Connect as Media device(MTP) has solved the problem.
Long to short,
I had the same problem with a Prestigio PMP5570C tablet,
all you have to do is to confirm on your tablet that you want to copy data to/from your computer (what i forgot), and add the 2 lines that #portsample wrote.
You can find the idVendor of your device typing
lsusb
in UBUNTU 12.04, then you get:
Bus 001 Device 011: ID 2207:0010,
where 2207 is your vendor id.
Summed up the question and answer...
I updated my device (Nvidia Shield) that was previously connecting fine, so I knew that the PC setup is correct already. The developer settings seem to have a new layout on Android 7.0.
It is under Settings > Preferences > Developer options > Networking > Select USB configuration
Here, I needed to select PTP and everything works fine again:
Enable USB debugging
Use USB to transer file
This procedure solves the problem for me:
- On the Android device, drag the top menu and select "USB for file transfer"
- Press "Run" again
Go to Developer Options -> Default USB Configurations and Change to PTP
Run these two commands in terminal
sudo adb kill-server
sudo adb start-server
Should Work!
I made a script for this error. For me it works fine in Fedora 28, but it should work in many Linux distributions.
Just create a file with the content of the selfexpanied script. I called it usbDebbugingAndroidStudio.sh
Give him execution permission with: chmod +x usbDebbugingAndroidStudio.sh
And run it: sudo ./usbDebbugingAndroidStudio.sh
After that check the list displayed by the command lsusb and introduce the Id of
your device.
For example:
My output was: Bus 006 Device 002: ID 05c6:9091 Qualcomm, Inc.
So I type 05c6 and press enter.
The script:
#!/usr/bin/env bash
#This script configure Android Debug Bridge permissions to solve the following
#error: com.android.ddmlib.AdbCommandRejectedException: insufficient permissions for device
#This error is produced when you try to install an APK from Android Studio in your device.
#You can check the vendorId here:
#https://developer.android.com/studio/run/device#setting-up
#If your device's brand isn't listed check the info displayed by the command lsusb
lsusb
#My output was:
#Bus 006 Device 002: ID 05c6:9091 Qualcomm, Inc.
#The id for this line is 05c6
echo -n "Enter the id of your mobile device: "
read usbProviderId
cd /etc/udev/rules.d/
sudo touch 51-android.rules
(
sudo cat << _EOF_
SUBSYSTEM=="usb", ATTR{idVendor}=="$usbProviderId", MODE="0666", GROUP="plugdev"
_EOF_
) | sudo tee 51-android.rules
#Give read and write permissions to the file
sudo chmod a+r /etc/udev/rules.d/51-android.rules
#Kill the Android Debug Bridge server to restart it
cd $HOME/Android/Sdk/platform-tools
sudo ./adb kill-server
#If this still doesn't work unplug the usb cable and connect again.
#And repeat the last step Kill the ADB server.
What the F... ! :)
Note : I have seen it on android 8.1 on a One+5t...
Even we do all of above, it is necessary to make something on your android device .. in addition to go in dev options menu (usb debug) (don't hesitate to reset "cancel authorization" or something like this (I am in french version ;) )
If some people meet the same problem than me, maybe it could be usefull for you too :
Don't forget to authorize devices in your phone (each time of usb connect on the android device if you don't select always box). Beside, you can suppress the old authorized devices on your phone and start with proper parameter to authorize clearly your pc on your android device
When you connect the android device, a pop up or notification ask to authorize a mac address or equivalent to the device : authorize it if you want to authorize connection between your linux pc and your android device.
It is necessary to obtain autorisation on your android device when you use connect the usb cable (if you don't accept all the time but if it is the first time this box is going to appear on your devices) if you don't do it, adb devices show unauthorized even all rights are good (666, UDEV etc)
Note : thank you for your precious help.
A last thing, sorry for my english
I'm facing this issue while run flutter app from android studio 4.1, i did remove usb cable and plug into second usb port and its working :),
I'm writing this if someone face same issue then they can get help.
Same issue on Fedora 32, to fix this try this:
adb kill-server
adb start-server
For me and possibly many others the issue is to do with access rights to devices on the machine. Now that this is well documented in the android documentation, I think the best solution is here
On Debian based Systems you can run lsusb or dmesg to get vendor id if your vendor does not exist on the given list
I have face the same problem and i have resolved this by
Adding the path of your_android_sdk_path to the environment variable like
sudo export $PATH:/your_android_sdk_path/platform-tools/adb
its your wish how you want to add this to your account or system wide by editing these file ~/.bashrc file or ~/.profile
or
/etc/profile, /etc/bash.bashrc, or /etc/environment if u want to add to system wide access.
and then create the link of that in bin
sudo ln -s /your_android_sdk_path/platform-tools/adb /bin/adb
if you have used adb devices or any command then first kill the server like
adb kill-server
then start the server like
adb start-server
adb devices
now you can see your devices are listed properly without an issue
As the error message said, it is a permission insufficient problem. In my experience, it only happened on my Linux machine, and works well on MacOS and Windows. Launching your Android Studio with root permission could avoid this problem.
$sudo /your_android_studio_path/bin/studio.sh
In my situation:
cd /etc/udev/rules.d/
sudo chmod a+r ./*.rules #the name of your rules files.
Then,I can use adb without this error.
if accepted answer not worked for you then just simple follow steps:
Just open your android studio terminal:-
adb kill-server
adb start-server
it worked for me.
Without running Linux
sudo apt-get install adb. Don't forget to enable USB debugging.
Ref: https://developer.android.com/studio/run/device

How to run shell commands on Android phone when connected to a PC?

I need to run ping request on my Android phone using the following format:
ping google.com | while read pong; do echo " $pong #$(date)"; done
There are some applications, such as Terminal Emulator which do that. But just in case I'm curious if I can run shell commands on phone using my PC connection, when the phone is connected to my PC?
EDIT: Yes, it works with the command. But for > r.log it needs root. Any suggestions for that?
Enable developer mode on the phone and use adb tool from Android SDK to do that.
I am not sure how powerful adb's shell is, but give it a try.
You can do even more with adb, check its help.

Sending AT Commands Via ADB Android

I have a task at work to investigate if it is possible to send AT commands to an android device via ADB shell. So far,I have tried to echo out the AT commands but it passes them as normal strings.
Any help please anyone.
Please try this:
echo -e "AT+CFUN=?\r\n" > /dev/ttyUSB0
On your phone, the serial line must not necessarily be called ttyUSB0. If this is not working or not available, check out the other entries of the /dev/ directory.
So it could also be /dev/ttyGS0 or /dev/SMD0 (as found out by #Sani).
For further information, please check out this Guide
NOTE:
There might also be phones, that do not respond to AT commands on any of their serial (tty) devices.
I just tried my own procedure on a Samsung Galaxy S4 and did not have any success.
Echo them where? In Android you talk to the rild (Radio Interface Layer) daemon, which in turns talks to a proprietary library, which sends commands to the actual hardware. Check rild source code for details. You could probably write a command line program that talks to the rild and execute it via adb shell, if that fits your needs.
In order to find out which port to use :
You can check
# cat /proc/tty/drivers
Use logcat -b radio | grep dev to see wich tty the radio is using.
Yes you can run AT commands from adb shell too...
prerequsite :-
1. rooted android phone
2. you are aware of the port that RIL use for i/o operation.
3. to check which port is being used by RIl use `getprop rild.libargs`
To run AT command from ADB use:
echo -c "AT\r\n" > /dev/smd11
PS: smd11 is port used by RIL.This varies from device to device.
ALso to run AT commands from android application check this tutorial
http://tech-papers.org/executing-at-commands-android-application/
Kind of a combination of the above. We got it working with 2 terminals on a Pixel 4 XL.
On one we did:
cat /dev/smd7
in the other:
echo "AT\r" > /dev/smd7
The output shows up in the first terminal
Notes:
Have to be root!
None of the discovery mechanisms worked for us, so we blindly called into smdX until we got a response from "AT\r".
echo automatically adds a \n, so adding it is redundant.

Android Ouku tablet device drivers

I am developing (not end user), on Eclipse and I want to connect to Ouku tablet. I cannot find the drviers for this that work. Anyone know how to get Ouku tablet connected via USB. I cannot even see the device
Have you tried using the android update adb command, or manually putting the VID into your adb_usb.ini file (even though it telss you not to)?
more ~/.android/adb_usb.ini
# ANDROID 3RD PARTY USB VENDOR ID LIST -- DO NOT EDIT.
# USE 'android update adb' TO GENERATE.
# 1 USB VENDOR ID PER LINE.
You may need to use dmesg or lsusb or look in device manager to figure out the VID; also on linux you may need to put it in your udev rule.
Finally, do your know for a fact that this device has an adbd listening on USB? First make sure you have enabled USB debugging in settings. If you can get a shell open from a terminal program or connectbot on the device, you might want to try
getprop | grep adb
and
ps | grep adbd
Maybe this could also help, came accross this driver link
On this page
I had a P801W with VID: 0x05C6
After installing the driver package and updating the devices:
Update Driver
Select option: "Browse My Computer for Driver Software"
Select option: "Lett me pick from the list"
Select Mobile -> Google Inc -> ADB Interface
I had to to this for 4 new devices in my list, but after these steps $adb shell worked on me
Based on what I have learned today, this link could also provide good information in resolving this with the standard USB ADB Drivers from Google, by simply modifying the driver .inf description file.

Intermittent problems deploying and debugging android app to phone

I am currently investigating a problem I have where for some reason eclipse plugin/adb loses connection to my phone and gives me the message:
[2011-03-05 22:53:40 - projectOne] Attempting to connect debugger to 'com.testbed.input' on port 8633
[2011-03-05 23:04:02 - projectOne] ------------------------------
[2011-03-05 22:40:42 - projectOne] Android Launch!
[2011-03-05 22:40:42 - projectOne] adb is running normally.
[2011-03-05 22:40:42 - projectOne] Performing com.testbed.input.MainActivity activity launch
[2011-03-05 22:40:42 - projectOne] Automatic Target Mode: Unable to detect device compatibility. Please select a target device.
And on the device monitor log I see this:
[2011-03-05 23:10:13 - Logcat]device (HT971L900496) request rejected: device offline
java.io.IOException: device (HT971L900496) request rejected: device offline
I cant figure out what it is, it just works flawless one day and next I get this. I hope someone with a more expert knowledge of the tool chain can help as its really slowing me down so I am determined to get to the bottom of this.
Many thanks
I can confirm that intermittent "adb devices" problems can be put down to using the wrong USB port.
I think it has something to do with the power output of the various ports (i.e. not enough power).
I had intermittent problems with USB connection to Android Note II (Samsung Note 2 clone) for a week.
I didn't believe all the Google articles saying to use a different USB socket,
because I didn't think I had any others than the two on the front right of my Lenovo Thinkpad L420.
Guess what, after finally checking the back carefully, there it is, a single USB socket on the very end.
After plugging into that socket, "adb devices" always lists the device.
Hooray!
For the benefit of other (Ubuntu) users, I am showing my tips for getting "adb devices" to work.
Figure out how the device is recognized by Ubuntu Linux.
Plug in the device, do "lsusb" then use the first hex number of the device ("0bb4" here)
as the "idVendor" attribute in a file called, "/etc/udev/rules.d/99-android.rules",
with the following, one-line contents:
SUBSYSTEM=="usb",ATTR{idVendor}=="0bb4",MODE="0666",GROUP="plugdev"
** Do not put spaces after the commas in this line.
Then, "sudo service udev restart".
Don't forget to add yourself to the "plugdev" group: "sudo usermod -aG plugdev".
Execute: adb kill-server; adb start-server; adb devices.
The adb server listens on port 127.0.0.1:5037 (netstat -anp|grep LISTEN).
So if any adb command is hanging, check that you can "ping 127.0.0.1".
If localhost ping fails, check firewalls and also check "sudo iptables-save",
looking for a missing "allow" rule for localhost ("lo").
Also, "ifconfig -a" will expose whether localhost interface is up (Google "ifup").
I hope someone else finds this information useful.
I don't know why it happens but I have found a quick remedy - first kill any adb process.
Then start the adb again with the command 'adb start-server'.
This then allows me to connect to the phone again
Another nugget of information for others that I found:
http://groups.google.com/group/android-developers/browse_thread/thread/5fb922c2166eab68
I had the usb plugged into the front of my computer and I was experiancing problems - after pluging it at the back direct to the usb controller and not a hub it has become much more reliable.
I had the same problem. Here is my solution: you have to connect the USB cable from your PC to your phone while pressing the power button of you phone.

Categories

Resources