I wrote a device owner kiosk app that I'd like to remove the device owner status on so I can uninstall it without having to factory reset the device. The following works on Nougat and Oreo, but not Marshmallow for Samsung tablets.
The specifics of how I'm coding the device owner stuff:
To set the app as device owner, I am running this adb shell command after installing the app:
adb shell dpm set-device-owner com.dps.myapp/.DeviceAdminReceiver
Then when I am trying to remove device owner status and uninstall the app, I am running these shell commands:
adb shell am force-stop com.dps.myapp
adb shell am start -n com.dps.myapp/.DeactivateDeviceOwnerActivity
adb shell pm uninstall com.dps.myapp
DeactivateDeviceOwnerActivity is an Activity in my app that contains the following code to clear the device owner status:
DevicePolicyManager mDevicePolicyManager = (DevicePolicyManager)getSystemService(Context.DEVICE_POLICY_SERVICE);
mDevicePolicyManager.clearDeviceOwnerApp(getApplicationContext().getPackageName());
if (mDevicePolicyManager.isDeviceOwnerApp(getApplicationContext().getPackageName())) {
Toast.makeText(getApplicationContext(),
"Failure! App is still device owner.",Toast.LENGTH_LONG)
.show();
}
else {
Toast.makeText(getApplicationContext(),
"Success!", Toast.LENGTH_LONG).show();
}
What is so weird is that my Activity is displaying the Toast that the clearDeviceOwnerApp call worked, but when I run the uninstall command immediately after, I get the "Failure [DELETE_FAILED_DEVICE_POLICY_MANAGER]" return from it, so obviously the device owner was not cleared for my app.
Does anyone know of any specific differences between Marshmallow and subsequent APIs, regarding device ownership or DevicePolicyManager that would cause this code, that works on Nougat and Oreo, to not work on Marshmallow? When I issue the start command to have DeactivateDeviceOwnerActivity clear the device owner, I'm looking in the system log and I'm not seeing anything that indicates any exceptions occurring. Any help would be appreciated.
I have not faced such an issue on Marshmallow.
This is strange, although I can't give an answer, I will suggest something
1) This might be a bug. So, you can factory reset device and try again.
2) It is very convenient to use the emulator for this type of testing as you can easily just delete and create a new one.
I hope it helps.
Related
I am trying to make a form where people can toggle notifications on and off. I figured the easiest way to do that would be set the permissions to allow or deny but I can't figure out how to remove the permission once it has been granted.
I am triggering the initial permission request by doing the following in android and not too sure what I will do with iOS as it requests the permissions somewhat automatically.
string rec = "android.c2dm.intent.RECEIVE";
string reg = "android.c2dm.intent.REGISTRATION";
ActivityCompat.RequestPermissions(Plugin.CurrentActivity.CrossCurrentActivity.Current.Activity, new string[] { rec, reg },0);
I essentially would like a page that has a few Switch controls to enable/disable permissions.
any help would be greatly appreciated.
Thanks,
There's no built in method for you to toggle a permission (ie, allow, then disallow), but you could do it if your app can run an adb command.
To undo a permission:
adb shell pm revoke <package_name> <permission_name>
https://stackoverflow.com/a/32683390/6668797
To run an adb command within your app, a couple of variations, but all involve:
Process process = Runtime.getRuntime().exec("your command")
how to run adb shell commands from android code?
Is it possible to execute adb commands through my android app?
I'm trying to hide/disable an app using pm hide com.myapp but I'm getting an error Error: java.lang.SecurityException: Neither user 10225 nor current process has android.permission.MANAGE_USERS.
I'm using an unrooted phone could anyone tell me why I can't use pm hide or if there's another command I can use
In case anyone is still looking for an answer to this, disabling OEM bloatware through adb is still possible on Android M+ using pm uninstall. While its true that uninstalling a system app requires root access, you can however uninstall the app for a particular user (yourself or user 0) without any root like this:
pm uninstall --user 0 com.micromax.trendingapps
But be careful and make absolutely sure that its a bloatware you are uninstalling because the above changes are permanent! You may not undo the damage done to a system app without factory resetting your device again.
Android disabled this feature in some security update in android 6
I need to launch an app which is in different work profile (Android For Work). If install the app in personal profile then I am able to launch the app from the personal profile on the same device.
However, When I install the app only in the work profile then I am not able to launch the app through adb command.
As per my understanding, google keeps two different containers for personal and work profile. I think the work profile has different space and adb does not have any access to that app and workspace of work profile.
I need to launch the app through appium
If anyone has the answer to the above problem, please answer. Thanks in Advance !
Do you mean launching application on different user account ? check this link please : https://stackoverflow.com/a/24093533/5093606
You can get try to get list of accounts using
adb shell pm list users
and if you working account is there, try
adb shell am start --user WORKING_ACCOUNT com.example.MainActivity
Yes, there is way to launch the apps by using Appium/Adb commands. Instead of appium use adb commands to launch the apps.
The app which you have used for AndroidForWork enrollment, it should be in android:debuggable mode. Set debuggable mode to true and build the apk.
Once the device is enrolled/Configured Androidfor work then get the list of users.
adb shell pm list users UserInfo{0:Drew:13} running UserInfo{10:Work profile:30} running
Get the workprofile user id. In this case 10 is the id. Use the user id to launch the apps.
adb shell am start --user 10 -n "com.android.vending/com.google.android.finsky.activities.MainActivity"
Note: If the provision app is not enabled in Debug mode then you don't have the access to the work profile user.
Turns out I was able to accomplish this with Appium Desktop by adding another parameter to the inspector:
optionalIntentArguments text --user 12
Where '12' is the work profile id you'd see from typing this:
adb -d shell pm list users
Users:
UserInfo{0:Ken Corey:13} running
UserInfo{12:Workspace:50100030} running
We are creating an app for android watch (in my case sony 3) that needs a kiosk mode.
Using
adb shell
dpm set-device-owner com.example/.MyDeviveAdminReceiver
I get
Can't set package com.example as device owner.
using
db shell pm list features
I get
feature:reqGlEsVersion=0x20000
feature:android.hardware.bluetooth
feature:android.hardware.bluetooth_le
feature:android.hardware.faketouch
feature:android.hardware.location
feature:android.hardware.location.gps
feature:android.hardware.microphone
feature:android.hardware.screen.portrait
feature:android.hardware.sensor.accelerometer
feature:android.hardware.sensor.compass
feature:android.hardware.sensor.gyroscope
feature:android.hardware.sensor.light
feature:android.hardware.sensor.stepcounter
feature:android.hardware.sensor.stepdetector
feature:android.hardware.touchscreen
feature:android.hardware.touchscreen.multitouch
feature:android.hardware.type.watch
feature:android.hardware.usb.accessory
feature:android.hardware.wifi
feature:android.software.home_screen
feature:android.software.live_wallpaper
feature:android.software.voice_recognizers
feature:com.sonymobile.watch
Does anyone has an experiance own creating a device owner app for android wear watch ?
Haven't tried this with wearables, but most of the times I got errors setting up DeviceOwner through adb was due to an existing google account on the device, meaning it is already provisioned. Device Owner setup requires the device to not be fully provisioned.
More on this: How do you un-provision a device in order to set the Device Owner?
I am trying to record my device screen using the shell command as outlined here:
http://developer.android.com/tools/help/adb.html#screenrecord
Using the verbose flag, I am getting a Permission Denial that I think is connected to the fact there is an Owner profile on the device, as it references User 0 and User 1 in the error message.
Does anyone know how I can remove the Owner profile (can't see any options to do so) or how I can set the Owner to user 0?
EDIT - clarification, the error states "broadcast asks to run as user -1 but is calling from user 0"
I got the recording to work.
It seems that for whatever reason, you need to do this via adb shell.
Whilst adb shell is running shell commands on the connected device, running the screenrecord commands directly on the device just doesn't want to work.