Android 管理 API 不应用政策

Android Management API doesn't apply policies

我一直在关注 Android 管理 API 指南快速入门: https://colab.research.google.com/github/google/android-management-api-samples/blob/master/notebooks/quickstart.ipynb

我创建了一个虚拟项目、企业和服务帐户。 我可以使用以下 python 脚本生成二维码:

from apiclient.discovery import build
import google.auth
import os
from urllib.parse import urlencode
import webbrowser


# set key as environment variable, so that google.auth.default() can automatically find the project
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "./celtic-bazaar-342809-6536138e074c.json"

credentials, project = google.auth.default()

# Create the API client.
androidmanagement = build('androidmanagement', 'v1')

print('\nAuthentication succeeded.')


enterprise_name = 'enterprises/LC0498xe68'

policy_name = enterprise_name + '/policies/policy2'

# define policy
policy_json = {
    'debuggingFeaturesAllowed': True,
    'locationMode': 'LOCATION_DISABLED'
}

result = androidmanagement.enterprises().policies().patch(
    name=policy_name,
    body=policy_json
).execute()

enrollment_token = androidmanagement.enterprises().enrollmentTokens().create(
    parent=enterprise_name,
    body={"policyName": policy_name}
).execute()

image = {
    'cht': 'qr',
    'chs': '500x500',
    'chl': enrollment_token['qrCode']
}

qrcode_url = 'https://chart.googleapis.com/chart?' + urlencode(image)

webbrowser.open(qrcode_url, new=0)

print('\nIf the code is not displayed automatically, visit this URL to scan the QR code:', qrcode_url)

然而,当我用我的设备扫描代码时,出现以下错误: “糟糕 无法设置您的设备。请联系您的 IT 部门。”

如果我只是将 policy_json 设置为 {'debuggingFeaturesAllowed': True} 我没有得到错误,但是添加任何其他选项(adjustVolumeDisabled、uninstallAppsDisabled 等)会导致错误并且选项是'应用。

如果我转到设备的设置 -> 安全 -> 设备管理员,我可以看到 'Device Policy' 在那里并且无法停用,但应用了 none 个选项。

我正在测试的设备是 Asus ZenPad Z380M 运行 Android 7.0

导致此错误的原因是什么?

您是在配置工作配置文件还是完全托管的设备(factory-reset 之后公司拥有的设备)?

https://developers.google.com/android/management/reference/rest/v1/enterprises.policies#locationmode

位置模式仅适用于公司自有设备。

但作为工作配置文件的此策略应该安装。

事实证明,即使没有错误,也根本没有使用此方法注册设备。我用 REST api 检查了这个: https://developers.google.com/android/management/reference/rest/v1/enterprises.devices/list

我绕过它的方法是按照注册 Android 6.0 设备的指南进行操作:

  1. 打开新设备或 factory-reset 设备。
  2. 按照设置向导操作并输入您的 Wi-Fi 详细信息。
  3. 当提示登录时,输入 afw#setup。
  4. 点击下一步,然后接受 Android 设备策略的安装。
  5. 扫描二维码

奇怪,因为设备肯定是 运行 Android 7.0,但它是一台旧设备,所以可能是因为这个。