Android 4.1 SuperSU Shell grants no root access - android

I recently upgraded on a Stock Android 4.1 on my transformer tf101. In my app, i need root access my USB camera plugged in to the device. Till now, i have done this by the following code:
Runtime.getRuntime().exec("su");
DataOutputStream oOutSream = new DataOutputStream( process.getOutputStream());
oOutSream.writeBytes( "chmod -R 777 /dev/bus/usb/* \n" );
oOutSream.flush();
oOutSream.writeBytes("exit\n");
oOutSream.flush();
I know, chmod 777 is NOT a good idea, but i haven't found any other solution so far. Well, after upgrading to 4.1 this is NOT working anymore. SuperSU prompts a Messagebox informing me that the app has requested root access, but it wont work. the strange thing is.. when i open up the adb shell from the pc, and enter those commands, it works flawlessly.
If i granted su access by the pc, my app works correctly, although random toasts show up informing me "root acces granted" or "root acces denied". Could it be a bug in SuperSU?
Thanks for the help!

A better idea is to look at what permissions the usb devices have you want access.
For example using ls on your phone:
$ ls -l /dev/bus/usb/001/
crw-rw---- system usb 189, 1 2012-09-15 19:18 002
crw-rw---- system usb 189, 0 2012-09-15 19:18 001
I might be wrong here but I think in every android version the usb group has rw permissions for all usb devices. What you want to do is, launching your application with usb as group id.
You could do this, for example, by using su to elevate your process to root and then setting your group id using setgid. After that you can write to your usb devices without that chmod fiddeling which is really really not good.
Edit: Also, don't forget to drop the root permissions using setuid(whateverAppUID) after you're done setting the group id!

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

android app can't root but shell can

I read lots of websites about how to root an android device and give the app root privileges.
Now I have installed superuser app. When I enter su in a console to the device then superuser comes to ask for rights. This looks fine.
But when I do Runtime.getRuntime().exec("su"); in my app nothing happens.
Error code is 1, message is permission denied. No superuser message appears. This looks like my app can't call su. Funny: when I let my app call Runtime.getRuntime().exec("su -v"); I get a result! (namely the su version).
Call to su only fails.
What am I missing?
Btw. I added permission android.permission.ACCESS_SUPERUSER to the manifest as stated somewhere.
There are so many threads about root privileges, but none of them explains what can go wrong.
Is this CyanogenMod? Look in the settings: you can choose whether to allow apps to request root, and whether to allow adb to do so. You might have got it set to "ADB only". If so, change it to "ADB and apps".
Your su -V tells you that you're successfully executing an external program; but su itself is refusing to let you become root.

Android: adbd cannot run as root in production builds

I have an Android-based phone (2.3.6) with unlocked root privileges.
Since i'd like to have access to my phone through my computer, today i've installed QtAdb and Android SDK.
If i open a command prompt and i do
adb shell su
i get
#
And so I am able to copy, remove, push files on my phone (on the phone i get a notification using the app "SuperSU".)
But if i launch QtAdb - under Windows 7 - i get the following error: "adbd cannot run as root in production builds". I miss something? There's something wrong with QtAdb?
The problem is that, even though your phone is rooted, the 'adbd' server on the phone does not use root permissions. You can try to bypass these checks or install a different adbd on your phone or install a custom kernel/distribution that includes a patched adbd.
Or, a much easier solution is to use 'adbd insecure' from chainfire which will patch your adbd on the fly. It's not permanent, so you have to run it before starting up the adb server (or else set it to run every boot). You can get the app from the google play store for a couple bucks:
https://play.google.com/store/apps/details?id=eu.chainfire.adbd&hl=en
Or you can get it for free, the author has posted a free version on xda-developers:
http://forum.xda-developers.com/showthread.php?t=1687590
Install it to your device (copy it to the device and open the apk file with a file manager), run adb insecure on the device, and finally kill the adb server on your computer:
% adb kill-server
And then restart the server and it should already be root.
For those who rooted the Android device with Magisk, you can install adb_root from https://github.com/evdenis/adb_root. Then adb root can run smoothly.
Use adb shell; su;
I still have not found any other solution for android 12 rooted with magisk. adb_root does not work with android 12. adbd insecure does not work for me and throws error could not patch adbd.
if anyone is still having issues, heres how i fixed it
you have to start the shell with the phone and go into the magisk app and in the superuser tab (bottom) you have to enable root access for the shell and it works!
You have to grant the Superuser right to the shell app (com.anroid.shell).
In my case, I use Magisk to root my phone Nexsus 6P (Oreo 8.1). So I can grant Superuser right in the Magisk Manager app, whih is in the left upper option menu.

Unable to test android application directly on android device instead of android simulator

hi I have developed small Android application.I want to run it on android device.I copied .apk and run on my android device it's working fine.But I don't want to every time copy .apk file when I changing my code.I just want to directly run it on my mobile device through Titanium Run --> Android Device option.I already set vender id for my device. When I tried to run my application on android device it gives me error insufficient permissions for device.I keep USB debugging enable on my device. I also tried to resolve adb issues.
cd android-sdk-linux-linux/tools
./adb kill-server
./adb start-server
./adb devices
but it shows me
List of devices attached
???????????? no permissions
I check in the DDMS but it not showing my device.It showing my simulator but not device.It shows one device icon with name as ???????? and unknown so is there any way to solve this problem.Thank you.
You don't have the right permission to access your device.
Try adding something like this to some file (usually 51-android.rules) in /etc/udev/rules.d:
SUBSYSTEM=="usb",SYSFS{idVendor}=="XXXX",MODE="0600",SYMLINK+="mydev-%n",OWNER="my-user-name"
Replace my-user-name and XXXX by the vendor id of your device which you can find using
$ lsusb
Then restart udev
$ sudo service udev restart
Finally, add the vendor id to ~/.android/adb_usb.ini:
# USB devices
0xXXXX
EDIT - NEW ANSWER
I reopened this issue and sth was fishy about starting adb in root mode. So, when I plugged in Sony Z1, I run
mdzeko#pc ~ $ lsusb
...
Bus 001 Device 011: ID 0fce:519e Sony Ericsson Mobile Communications AB
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
...
Automaticaly, I saw the vendor ID connected to Sony Z1. It said that 0fce was it's vendor id. Checking google page here I noticed that there is a difference between Sony and Sony Ericsson.
Checking my udev rules, it turned out that inside I had Sony vendor id (which is 054c) instead of Sony Ericsson (which is 0fce). Changing that code in udev made it work.
mdzeko#pc ~ $ cat /etc/udev/rules.d/51-android.rules
SUBSYSTEM=="usb", ATTR{idVendor}=="0fce", MODE="0666", GROUP="plugdev"
OLD ANSWER
Ok, after several hours of resarch, I've come up a solution. Maybe it will apply to you aswell.
I was using Sony Z1 on Linux Mint. It gave me the same error when trying to connect it to usb. This is what I've done:
Add the udev rule by folowing VERY simple tutorial here
run adb kill-server
There might be an option in the developer options on the device saying Revoke USB debugging authorization.... You can go through with that option. If there isn't an option like this, never mind, skip to the next step.
Run sudo adb usb or sudo adb start-server
If there wasn't a permission for using that device saved, You will have a dialog on the device asking you to grant the permission. Select option granting you the permission.
That's it, your device should work. If it still doesn't, commment below and I will try to see why.
P.S. I admit it is bad practice to run adb as root, but I couldn't get it to work without it. By switching to non-root adb, I got the same error again.

How to connect to a dev phone and gain the root permission through "adb shell"

I'm using a dev phone (Nexus One). I connected to it through "adb shell" but I couldn't get the root permission. When I run "su" in the shell, I got
$ su
su: permission denied
Actually I cannot access "/sbin" at all.
When I used the "root" option in "adb", I got errors too:
./adb root -s xxx shell
adbd cannot run as root in production builds
I got this error no matter I used a downloaded SDK or I compiled an SDK from the source. I'm not sure about what "production builds" actually means. Does it mean that I need to compile Android and put it on the phone? I thought a dev phone already has the root permission unlocked.
Thanks for your help.
You should unlock your phone - root it. Nexus One comes with this option, but you have to enable it. You can read this article or google for more.

Categories

Resources