Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Throw error if DELETE_FAILED_DEVICE_POLICY_MANAGER is sent #513

Merged

Conversation

tburakdemir
Copy link

Hi,
Some of our client's apk can not be installed due to DELETE_FAILED_DEVICE_POLICY_MANAGER error of adb. In codebase returns true either way so we can't catch the apk is actually uninstalled.

This apk has device admin permission. If it is authorized then it can not be uninstalled regular way. First we must disable policy with "adb shell pm disable-user pkg" then uninstall it with normal way.

I share you an example apk has this permission:
https://apkcombo.com/device-administrator/io.ebeck.jacob.deviceadmin/download/apk

After the installation apk;
Open the app
Click the Enable Device Admin
It opens android permision pop-up
Click activate.

Then you could not uninstall the apk in normal way. It responds with "Failure [DELETE_FAILED_DEVICE_POLICY_MANAGER]"
So In the code i made some changes that throws an error if this event occurs. So in my workspace i can catch it then solved like above solution.

`import { Adb } from './src';

const client = Adb.createClient();

const udid = 'emulator-5554';
const element = 'io.ebeck.jacob.deviceadmin';
const device = client.getDevice(udid);

async function uninstall() {
try {
const result = await device.uninstall(element);
console.log(result);
} catch (error: any) {
console.log(error.message);
await device.shell("pm disable-user " + element)
.then(Adb.util.readAll)
.then((output) => {
console.log('[%s] %s', device.serial, output.toString().trim());
})
const result = await device.uninstall(element);
console.log(result);
}
}

uninstall();
`

image

https://developer.android.com/reference/android/app/admin/DevicePolicyManager
https://stackoverflow.com/questions/13911444/disable-deviceadmin-from-shell

@koral--
Copy link
Member

koral-- commented Oct 20, 2023

LGTM, but the sign-off is missing.

Signed-off-by: Burak Demir <tburakdemir@gmail.com>
@tburakdemir
Copy link
Author

signed off, thank you

@koral-- koral-- merged commit b70ae36 into DeviceFarmer:master Oct 20, 2023
2 checks passed
@tburakdemir
Copy link
Author

How can I get this pr from npm. Is there any planning of version update?

@koral--
Copy link
Member

koral-- commented Jan 18, 2024

Sorry for the delay, I've just released version 3.2.6.

UrielCh added a commit to UrielCh/adbkit that referenced this pull request Jan 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants