Android ADB shell: Enable USB app installation - android

I have a question about APK installation internals.
If you want to install an APK on some Android devices via ADB (adb install APK.apk or pm install /data/local/tmp/APK.apk) you have to enable USB installation in Developer Options. If the USB installation is not enabled, you'll be presented an error on installation, most likely something like
adb: failed to install app.apk: Failure [INSTALL_FAILED_USER_RESTRICTED: Installation blocked]
My questions are:
How is enabling/disabling of the USB installation implemented in the system? At what point does the error above occur?
Is there a way how to enable USB app installation via ADB? I know I could write a script that calls input tap X Y or similar GUI commands, but that's not what I want. What I'd like to know is whether there is an entirely non-GUI way of doing this, something like setprop install.via.usb 1 or echo 1 > /system/etc/install_via_usb
I'm interested in ways to do this for both rooted and unrooted devices.

Related

How to enable installation of apk over usb debugging if denied permission earlier?

I want to use Redmi Note 7 Pro for debugging my react native applications over ADB. But I accidentally denied installing apps over USB and chose don't ask again. Now I'm not able to allow it.
I've tried:
Disabling & enabling Install via USB in Developer Options.
Turn off developer options & enable it again.
But it has not worked out so far. And I'm not able to find anything related to this in google searches. I'm also not getting any popup asking when I try to install over USB.
I get this error:
java.lang.SecurityException: You need the android.permission.INSTALL_GRANT_RUNTIME_PERMISSIONS
Try the following:
Open the terminal of your computer.
Navigate to the Android SDK folder.
run cd platform-tools
run sudo ./adb kill-server
run sudo ./adb devices
All this with your phone connected via USB, the message should pop up again.
Did you tried revoking permission and connecting mobile again ?
"Revoke USB debugging authorisations"

Android Studio (3.1.2) problems with ADB-service [duplicate]

This question already has answers here:
android studio adb Syntax error: ")" unexpected
(4 answers)
Closed 3 years ago.
I'm using Linux Mint Sylvia on a pretty old laptop that do not support the emulators. Therefore I try to connect my Sony XA2 (pretty new with Oreo, 8.0)
I'm trying to detect my device but I seems to have some problem with Android Studio and the ADB-service.
In the log I get:
9:39 PM Unable to detect adb version, adb output: /home/fredrik/Android/Sdk/platform-tools/adb: 1: /home/fredrik/Android/Sdk/platform-tools/adb: Syntax error: "(" unexpected
If I run the lsusb I can find the device:
Bus 002 Device 011: ID 0fce:51f7 Sony Ericsson Mobile Communications AB
I tried to run the adb devices, but first I got this:
adb devices
The program 'adb' can be found in the following packages:
* adb
* android-tools-adb
Try: sudo apt install <selected package>
So I installed the adb with:
sudo apt install android-tools-adb
Then I could run the adb like:
adb devices
* daemon not running. starting it now on port 5037 *
* daemon started successfully *
List of devices attached
CQ3000KKV4 unauthorized
But still I got the error above in Android Studio.
Do you guys got any clue?
Best regards
Fredrik
Adb after installation seems to run correct.
Your device is listed as unauthorized so I guess you did not turn on developer tools on your device, or on your device you did not accept debuging with connected computer.
To turn on developer options on device:
Open Settings on your Android O running device.
Select System » About phone.
Scroll down and tap seven times on the Build number entry.
Now go back to Settings » System » and select Developer options from there.
In these options you should allow usb debuging if it’s not on by default.
After connecting usb cable to your device and conputer you should see prompt on your device asking for permissions to allow debuging. If you accept that you should be able to run adb tools, logcat etc on your connected device.
EDIT
Looking at the error you described in comments, it looks like it is error specific for 32-bit version systems. So I see there two possible solutions:
reinstall your system for 64-bit version
or more likely:
downgrade your adb platform tools
How to downgrade adb platform tools:
Download platform tools from this archive:
https://dl-ssl.google.com/android/repository/platform-tools_r23.0.1-linux.zip
Go to your Android SDK folder (so in your case it will bee /home/fredrik/Android/sdk/)
Remove old platform-tools
Insert data from link downloaded above
Hope it will be your case. Please keep in mind that updates of Android Studio will probably restore that error again.
There are other problems that manifest as showing unauthorized even when developer mode is on to allow usb access. Sometimes in Linux you may be running adb in user mode which may not allow usb access. In this case I've needed to disconnect adb and restart it using root privileges.
adb kill-server
sudo adb start-server

ADB not showing logs on Studio and ADB applications on phone

I am having a note edge Verizon N915V with Marshmallow updated (V6.0.1). The device is also rooted. After the update I am not able to see the ADB logs when I connect the device on Android Studio (V2.1.2). I have also installed the ADB Logcat applications from playstore but those also show no logs on the application.
Things I have tried.
I have enabled the USB debugging.
Tried restarting and reconnecting the device and tried on other machines.
Note: There is no USB permission revoke option present in my developer option. I tried removing /system/etc/permissions android.hardware.usb.host.xml still no use.
adb commands works adb devices list my device as device only (not unauthorized, so its valid). adb push , adb pull also works
adb logcat is not working, when I enter that its on waiting mode.
In My studio when I connect the device its listed on the android monitor window and all the process are listed on the dropdown, but what ever process I choose no adb logs comes. verbose and no filter options all methods tried no hope.

How do I install an APK without any internet connection?

My phone's antenna died so it can't connect to the internet by cellular or wi-fi but I still want to use the phone for portable entertainment. I need a way to install an app strictly through the USB connection.
Unfortunately, every article I've looked at for how to install APKs without Google Play tells me to start by getting a file manager from Google Play.
You have two way can do that:
Note: you have to connect phone with PC througth USB cable before.
Copy any apk to phone from your PC/latop and open file browser in phone to open apk which you want to install
Use can use ADB command line tool:
Type command: adb install [apk_name_with_full_path]
Ex: adb install C:\your_package.apk
You can download APKs on your PC and install it using following command:
adb install -r [apk path]
Note: make sure that you have adb utility in your PC and in your phone developer options is switched on with USB Debugging enabled.
Enable USB Debugging

Why is ADB unauthorised to debug my device on which I installed AOSP?

I am using a nexus 5 (hammerhead), and I just built AOSP marshmallow from source. I was trying various build configurations (user-debug vs user etc), and along the way, I did something which causes both my mac (yosemite) and my ubuntu vm (14.04), to not be authorised to debug via adb. ie. if I type "adb devices", then I see a message:
0c4a84901a7ce6a2 unauthorized
Facts -
Although I built the source code, and flashed the device on the ubuntu vm, yosemite is not authorised either - same message (can't understand why).
Fastboot has the same problem, if I try rebooting into the boot loader by issuing a command from the terminal. If I use the hardware buttons to launch the boot loader menu, then I can flash files, lock / unlock the boot loader etc.
I have tried killing / restarting the adb server (e.g.: adb kill-server / adb start-server)
I have tried deleting ~./.android/adbkey.pub in my ubuntu vm. Since it made no difference, I did not delete it in my mac.
I have tried restarting my mac, ubuntu vm, adb in combination...
When I enable / disable USB debugging on the device, no message pops up asking me to verify the computers finger print, and there is no option in the setting to revoke all the fingerprints (which is present in regular stock android roms / factory images)
I'm not sure what to do now. I know I can flash the factory image of marshmallow, so everything on the phone should be pristine. But What I want to know is why adb is unauthorised right now, and how to fix it - so I can get back to making aosp roms.
EDIT:
I just flashed the marshmallow factory image, and now adb is authorised on my mac, but in ubuntu, I'm still listed as unauthorized, even after killing / restarting the server.
EDIT: I built and flashed AOSP 6.0 with build configuration set as user-debug, and it seems dab is authorised again. So I imagine this is because when the build configuration is "user", adb is prevented from debugging. I wonder why, and how to fix this?
In case of AOSP user build, you may wish to check if ro.adb.secure=1, in your build default.prop. If not defined, then the popup to verify computer fingerprint may not come up.
I find that my android devices are "unauthorized" if usb-debugging is not enabled, or my computer's fingerprint was never accepted as authorized. Also, USB connection mode needs to be set to File transfer or photo transfer (MTP or PTP) for some versions of Android.
Try the following:
Connect usb cable to computer.
Go to Developer-options
Revoke USB Debugging authorizations
Disable and then enable USB Debugging
Accept "Allow USB Debugging" message
After this sequence, I always get message to accept computer's fingerprint on Ubuntu.

Categories

Resources