简体   繁体   English

如何查看Android App是否为设备所有者?

[英]How to check if an Android App is a device owner?

I am executing one test case using robot framework where I have to install an app and make it as device owner and then check if the same app has become a device owner or not.我正在使用机器人框架执行一个测试用例,我必须在其中安装一个应用程序并将其设为设备所有者,然后检查同一个应用程序是否已成为设备所有者。 I have searched though Stack Overflow and other search engine results but there, they have mentioned on how to make an app as device owner but not the way how to check if an app is a device owner.我搜索了 Stack Overflow 和其他搜索引擎结果,但在那里,他们提到了如何将应用程序作为设备所有者,但没有提到如何检查应用程序是否是设备所有者。

I have used following command to make my app as device owner:我使用以下命令使我的应用程序成为设备所有者:

adb shell dpm set-device-owner com.myapp.package/.main.receiver.DeviceAdminReceiver

Now, I wanted to validate whether it is a device owner or now using ADB command.现在,我想验证它是设备所有者还是现在使用 ADB 命令。

adb shell dumpsys device_policy

This command will give you a bunch of policies including the device owner (it's the first policy) with the package name and the corresponding receiver.此命令将为您提供一系列策略,包括设备所有者(这是第一个策略)以及包名称和相应的接收者。

To make it easier to check it use adb shell dumpsys device_policy | grep "admin"为了更容易检查它,请使用adb shell dumpsys device_policy | grep "admin" adb shell dumpsys device_policy | grep "admin"

adb shell getprop ro.device_owner

如果启用了设备所有者模式,则返回true

you need to interrogate the system and return A LOT of data.您需要询问系统并返回大量数据。 This is not feasible, however as a tip for others, you can use "findstr" or "grep" as a second command to search the results.这是不可行的,但是作为对其他人的提示,您可以使用“findstr”“grep”作为第二个命令来搜索结果。 Each line is a result, not an excerpt:每一行都是结果,而不是摘录:
NOTE: A blank response means there was NO match of against Device-Owner / DeviceOwner APK installed.注意:空白响应表示未安装与 Device-Owner / DeviceOwner APK 的匹配项。

> adb shell dumpsys device_policy | findstr "admin"

  admin=ComponentInfo{com.pdp.deviceowner/com.pdp.deviceowner.receivers.AdminReceiver}
    com.wtmp.svdsoftware/com.wtmp.core.admin.AdminReceiver:
        179: com.ms.office365admin

> adb shell "dumpsys device_policy | grep deviceowner"

  admin=ComponentInfo{com.pdp.deviceowner/com.pdp.deviceowner.receivers.AdminReceiver}
    package=com.pdp.deviceowner
    com.pdp.deviceowner/.receivers.AdminReceiver:

However, a BETTER answer would be to change the query:但是,更好的答案是更改查询:

> adb shell dumpsys device_policy | findstr "package="
> adb shell "dumpsys device_policy | grep package="

  package=com.pdp.deviceowner

(just noticed @Natfoli mentioned similar answer.) (刚刚注意到@Natfoli提到了类似的答案。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM