Disable DeviceAdmin from shell? - android

I'm trying to uninstall an application from shell, however this application is running as a device administrator and thus shell> adb uninstall com.example.test did not work.
How can I disable a device admin from shell?

Typically, administrative access is revoked via the Device Administrators screen, then the app is uninstalled. In the subsequent examples, I'll assume airdroid (com.sand.airdroid), has been configured as a device administrator, and is to be uninstalled. So to tailor this example, replace instances of com.sand.airdroid with your own app name.
The clean method
To access Device Administrators, navigate: Settings → Security → Device Administrators. Then, uncheck the application to un-set administrative access for.
It's also possible to open up this activity using the shell:
adb shell am start -S "com.android.settings/.Settings\$DeviceAdminSettingsActivity"
Once this is done, the activity can be uninstalled normally:
adb uninstall com.sand.airdroid
The brute-force method (requires root)
A brute-force method does exist. It involves searching for all files in the /system and /data filesystems, and deleting each found item. Disclaimer: Use with care (test on an emulator first).
adb shell
# Switch to root
su -
# Search for all installed files using the fully-qualified app name
find /system /data -name \*com.sand.airdroid\*
...a list of files (including directories) appears -- for each file, cause it to be deleted by prefixing it with a rm -f:
rm -r /data/media/0/Android/data/com.sand.airdroid
rm -r /data/data/com.sand.airdroid
rm -r /data/app-lib/com.sand.airdroid-1
rm -r /data/app/com.sand.airdroid-1.apk
rm -r /data/dalvik-cache/data#app#com.sand.airdroid-1.apk#classes.dex
# Run the find command again to ensure nothing was missed
find /system /data -name \*com.sand.airdroid\*
# exit root
exit
# exit Android shell
exit
To allow Android to clean up its files, reboot the device.
adb reboot
Once the device has restarted, the application can be uninstalled with the uninstall command to finalize clean-up.
adb uninstall com.sand.airdroid

adb shell pm disable-user (package name) will deactivate DeviceAdmin and disable the app. It will not be activated even if you enable the app again.

You can not uninstall app directly if it is set as Admin. First you have to disable the admin mode and then you will be able to uninstall app. To remove active admin first you run this command:
adb shell dpm remove-active-admin com.kiosk.example/com.kiosk.example.MyDeviceAdminReceiver
(com.kiosk.example) is package name, replace it with your own and MyDeviceAdminReceiver is receiver name. When this command give success then you can uninstall app, or run this command to uninstall:
adb uninstall com.kiosk.example

Related

adb install system app

I am aware that using adb install command installs an app in the /data/app folder. Also I know the in order to install an app as a system app I need to push it directly to the system. Is it possible to use adb install directly to the /system/priv-app/ on rooted phones?
if I got your question, this should do the work:
adb root
adb remount
adb push apk-filename-here /system/app/
adb shell chmod 644 /system/app/apk-filename-here
adb reboot
See this or this link for more info.
You can not use adb to directly install app at /system/priv-app/. Even If you copy your .apk, .odex files to this path device can not recognize your app as system app. For this you have to use same certificate with which your system apps are signed.

How to open "adb shell" in context of application being debugged (on non-rooted device)?

When I just run adb shell, I get shell running from uid=2000(shell) gid=2000(shell), without ptrace access to my application.
How to open a shell with the same UID as launched application?
Use run-as <your package name> to switch to your app's UID or run-as <your package name> <command> to run a single command with your app's UID.
From this answer:
The packages.xml file present in /data/system
The packages.list file present in /data/system
Contain the list of applications installed and their corresponding UID's.
Another answer in the same question suggests:
adb shell dumpsys package com.example.myapp | grep userId=
You can then open your shell as normal and run:
$ su <UID>
You should then have the same access and privileges as the app that uses that UID.
Workaround way using socat:
Add android.permission.INTERNET to your application;
Put socat binary (mirror) to /data/local/tmp/. Ensure everybody can start it;
Add Runtime.getRuntime().exec("/data/local/tmp/socat tcp-l:4446,fork,reuseaddr exec:/system/bin/sh,pty,stderr,setsid"); at startup of your Java-based application;
adb forward tcp:4446 tcp:4446
Use socat `tty`,raw,echo=0,opost=1 tcp:127.0.0.1:4446 on host to connect to the shell in your application context.
Note that this setup is not secure and should not be left in production app.

Cannot adb pull database even after chmod 777 on my device

I am unable to pull a the database from the device even after changing the permission. I have a rooted phone.
It used to work. I could pull before. For some unknown reason now I cannot.
The error I receive is
remote object '/data/data/com.thuptencho.transitbus/databases/ttc.db' does not exist
Does anybody know why this is happening?
Below is what I did in command window.
C:\users\thupten>adb shell
shell#android:/ $ su
su
root#android:/ # cd /data/data/com.thuptencho.transitbus/databases/
cd /data/data/com.thuptencho.transitbus/databases/
root#android:/data/data/com.thuptencho.transitbus/databases # ls
ls
ttc.db
ttc.db-journal
webview.db
webview.db-journal
webviewCookiesChromium.db
webviewCookiesChromiumPrivate.db
root#android:/data/data/com.thuptencho.transitbus/databases # chmod 755 ttc.db
5 ttc.db <
root#android:/data/data/com.thuptencho.transitbus/databases # chmod 777 ttc.db
7 ttc.db <
root#android:/data/data/com.thuptencho.transitbus/databases # exit
exit
shell#android:/ $ exit
exit
C:\users\thupten>adb pull /data/data/com.thuptencho.transitbus/databases/ttc.db
remote object '/data/data/com.thuptencho.transitbus/databases/ttc.db' does not exist
I using these commands to get data from /data/data folders, no changing permission required
adb kill-server
adb root
I figured it out.
I had to chmod the databases folder as well and then the file.
The problem is that you need permission not just to the file, but also to its parent directories.
(That permission should not be 777 though!)
Rather than trying to change the permission, what you probably want to do is get adb running as root if that is supported, (ie, if you have an engineering build, rather than an aftermarket "rooting" of a secured device) or else use your root access (or the app itself, or the stock run-as command if you have a debug apk) to copy the file of interest somewhere accessible and then adb pull the copy.
My preferred solution was:
Install Chainfire's adbd insecure app
From within the adbd insecure app, select "Enable Insecure adbd"
adb pull /data/data/com.package.name/databases/database.db
Caution - adb insecure means adb is running as root on your device.
for i in `adb shell ls /data/ -1`;do adb pull /data/$i data; done

How to upgrade app in /system/app?

We've Android app 1.0 and make it in /system/app for the special ROM.
Now we have released upgrade version 1.1 of that app, after installation, the version is changed to 1.1 in App list in Android settings. But when I reboot the system, the updated version is missed, back in 1.0.
How resolve this problem? Any detailed introductions about it?
Thanks.
You can use this:
adb shell
su
mount -o remount, rw /system
cat ApplicationName.apk > /system/app/ApplicationName.apk
chmod 644 ApplicationName.apk
reboot
as far as I know pm install only updates user-applications.
If you are deploying the app from Eclipse or from another IDE (it is as far as I know the same thing as doing pm install) the app goes under data/app.
The app location now is /data/app/com.package.name-1.apk
After the deploying you can do
adb shell
su
mount -o remount, rw /system
cat /data/app/com.package.name-1.apk > /system/app/ApplicationName.apk
chmod 644 /system/app/ApplicationName.apk
reboot, for the changes to take effect
Cat is normally the same as copy or cp, but when you cat from the /data/app/ the original com.package.name-1.apk disappears (i guess android takes care of this automatically somehow)
You can test this by doing ls -al when under /data/app/ folder
Increase versionCode before you update your app.
In fact, the latest version of your app is installed into /data/app, when device reboot, the device will check whether the old app(v1.0) should be updated or not. However, according to scanPackageLI() in frameworks/base/services/java/com/android/server/PackageManagerService.java
if (ps != null && !ps.codePath.equals(scanFile)) {
// The path has changed from what was last scanned... check the
// version of the new path against what we have stored to determine
// what to do.
if (pkg.mVersionCode < ps.versionCode) {
// The system package has been updated and the code path does not match
// Ignore entry. Skip it.
......
} else {
......
}
......
}
You can find if versionCode is the same, old app will not update. So you need to increase versionCode in your app when you want to update old app.
PS: Replacing old app with new one using command line can meet your need but I really don't think it is good.
because the app is in System/app so,you should use push command
adb root
adb remount
adb shell rm /system/app/your.apk
adb push your.apk /system/app
to update it.
maybe you need delete it first.
Usually, if you push an app to system/app, and then install it into data/app, the app system/app only works after you reboot your device.
In case, you can check whether there is the app in data/app after you reboot your device.
adb shell ls /data/app
if you find it, you can delete it to make sure you don't have the same app:
adb shell rm /data/app/your-1.apk
Maybe you have install your application to /data/app not /system/app
try to move this app to /system/app

adb uninstall failed

I am writing some sample apps.
After I debug these apps, I don't see an uninstall button in my device's application management.
When I do adb uninstall, it always says Failure without any reason.
In DDMS I saw that my apk is stored in /data/app/com.k2g.leaveDemo-1.apk.
I am not sure what am I missing.
I always have to reset my device to get rid of these apps :(
Do I need to do sign something?
Do I need to do something in debug mode?
Or does it depend on the version?
I am using Samsung S2.
I assume that you enable developer mode on your android device and you are connected to your device and you have shell access (adb shell).
Once this is done you can uninstall application with this command pm uninstall --user 0 <package.name>. Where 0 is ID of main user in Android system. This way you don't need to root your device.
Here is an example how I did on my Huawei p10 lite device.
# gain shell access
$ adb shell
# check who you are
$ whoami
shell
# obtain user id
$ id
uid=2000(shell) gid=2000(shell)
# list packages
$ pm list packages | grep google
package:com.google.android.youtube
package:com.google.android.ext.services
package:com.google.android.googlequicksearchbox
package:com.google.android.onetimeinitializer
package:com.google.android.ext.shared
package:com.google.android.apps.docs.editors.sheets
package:com.google.android.configupdater
package:com.google.android.marvin.talkback
package:com.google.android.apps.tachyon
package:com.google.android.instantapps.supervisor
package:com.google.android.setupwizard
package:com.google.android.music
package:com.google.android.apps.docs
package:com.google.android.apps.maps
package:com.google.android.webview
package:com.google.android.syncadapters.contacts
package:com.google.android.packageinstaller
package:com.google.android.gm
package:com.google.android.gms
package:com.google.android.gsf
package:com.google.android.tts
package:com.google.android.partnersetup
package:com.google.android.videos
package:com.google.android.feedback
package:com.google.android.printservice.recommendation
package:com.google.android.apps.photos
package:com.google.android.syncadapters.calendar
package:com.google.android.gsf.login
package:com.google.android.backuptransport
package:com.google.android.inputmethod.latin
# uninstall google play services (warning: take backup first!)
pm uninstall --user 0 com.google.android.gms
Yes, mobile device management would bring its own problems, but i bet 'Failure' is a dos2unix problem. On my Linux machines, adb is appending a DOS newline which causes 'Failure' because uninstall thinks the CR character is part of the package name. Also remove '-1.apk' from the end of the package-1.apk filename.
adb root
adb shell
pm list packages
pm uninstall com.android.chrome
In my case, i have a phone that is in permanent 'Safe mode' so only apps under /system/app/ have a chance of running. So i install them to get the .apk files copied off, then uninstall in bulk and copy to /system/app/, wipe the /cache and reboot. Now i have more apps running even though in safe mdoe.
# adb root
# pm list packages -3 > /root/bulkuninstall.txt
# vi /root/bulkuninstall.txt and check ^M characters at end of each line.
If ^M, then must run dos2unix /root/bulkuninstall.txt.
Remove '-1.apk' using vi search and replace:
:%s/-1\.apk//g
Or sed...
# cp /data/app/* /storage/sdcard1/APKs/
# for f in `cat /root/bulkuninstall.txt`; do echo $f; pm uninstall $f; done;
#
# echo Now remount system and copy the APK files to /system/app/
# mount | grep system
# mount -o remount,rw /dev/block/(use block device from previous step) /system
# cp /storage/sdcard1/APKs/* /system/app/
# reboot
wipe cache
power on.
This is not an exact answer, but if you're looking to uninstall the app because you have an updated .apk to install, you can try this:
adb install -r yourapp.apk
The -r option tells adb to reinstall the app
If it is an Android internal app you may need to:
adb shell
mount -o rw,remount -t yaffs2 /dev/block/mtdblock3 /system
rm /system/app/your_app
rm /data/data/your_app
remove any entries in /data/system/packages.xml
remove any entries in /data/system/packages.list
edit AndroidManifest.xml and get rid of android:sharedUserId="android.uid.shared"
This is at your own risk;-|, try in emulator first...
Just run ADB and use the following command:
adb shell pm uninstall -k --user 0 <package name>
And you should get this return:
successful
okey I was in same situation I tried all of this without result.. and the last answer was close.. I got it doing the follow:
in order to get the right name of your package do the follow:
adb shell pm list packages | grep "name of your app here"
you should see the right name of your app.. so now this one just works:
adb uninstall com.your-real-app-name
finally the command run works again:
ionic run android
Seems like you have an app that contains a hidden Device Administrator like this one here: http://www.symantec.com/security_response/writeup.jsp?docid=2013-060411-4146-99
you can only uninstall such an app when you disable the device admin first. You can use https://play.google.com/store/apps/details?id=com.trendmicro.mtrt.hiddenDAcleaner to disable it or do it by your own by sending the intent to the app that invokes the receiver that will disable the device admin.
I find that adb shell pm uninstall <package> works consistently, where adb uninstall <package> does not.
Try disable "Instant run" from settings window
Open your application Manifest and check the application's package first.
After that, be sure that your device is set into debugger mode.
Check if ADB can interact with your device:
adb devices
If your device is listed, then run:
adb uninstall PACKAGE_WRITTEN_IN_MANIFEST
Maybe you're trying to uninstall an app that is a phone administrator.
To be able to uninstall it, go to Seetings > Security > Phone Administrators.
If the app is listed, uncheck it and confirm the operation.
After that, you should be able to uninstall it using the App settings area or adb.
You should have to manually delete apps. got to Setting-> Application Management -> Running application, tap on it and you can remove, stop apps from there.
This worked for me:
This is the directory where all the APKs are stored:
cd /system/app
List them:
ls
Choose one to remove.
pm install -r <app_to_remove>.apk
Example:
$ pm install -r Google-Play-services.apk
pkg: Google-Play-services.apk
Success
I noticed that I get failure if the application I'm trying to remove is running, so kill it first.
Also, I noticed you might have to run (on a rooted device):
$ su
# mount -o remount +rw /
In my case I often get this issue when I first complise a app in debug mode and later try to install the google signed app.
That is because both apps have the same package name but diffent signatures.
Since I upgraded to Android lollypop I sometimes even get this error if I uninstall the app via the settings\Apps.
If you have this problem check if the app is installed in a other User profile and uninstall it in all user accounts.
If you have problems uninstalling through adb, I can recommend the following tool:
https://github.com/patrickfav/uber-adb-tools
you can use wildcards and supports multiple devices, also has some better error handling than the vanilla ADB (but uses it in background of course). Will work on your platform.
Full disclaimer: I am the developer
Make sure you enter the full package name with application name:
com.domain.app
I had a instance of an emulator running and a device connected.
When I ran command `adb -d uninstall PACKAGE_NAME', I got an error 'DELETE_FAILED_INTERNAL_ERROR' but when I killed the Emulator instance, I got a 'success' in un-installation process.
It can be something as simple as typing the package name in the wrong case...
I had the same problem - turned out I was entering the package name in all lower case when the actual package name included upper case characters.
adb uninstall -k <packageName - eg. com.test.app>
( If you're explicitly uninstalling you probably don't want the -k which keeps the app data and cache directories around. )
You can follow below steps to uninstall the app from the device via command prompt.
execute the command : adb -s [devicename] uninstall -k [packagename].
this command will retain the data and cache in the device but will remove the app from the device.
To remove the data and cache also from the device along with the application execute the command below.
adb shell pm uninstall -k [packagename].
if it shows sucess your app is uninstalled successfully'
If You use Xiomi Device then You need to Login in MI Account.
After Successful Registration you can install and Uninstall via ADB.
You have the name of the apk and not the package name:
You should first know the package name. Fot this tape:
adb shell pm list packages
Once you have the package name (be carefull, package name is like com.intel.... and not package:com.intel...), tape:
adb shell pm uninstall -k "package_name"
and Bingo!
In my case this was happening because I was trying to uninstall the wrong APK. I didn't realize that my bundleId had appended .demo to the ID.
I had a failure when using adb shell uninstall com.package.app/
removed / (so adb shell uninstall com.package.app) and it works
Try disable "Instant run" from Preference!
It's working for me.

Categories

Resources