简体   繁体   English

Android 管理 API 更改设备策略

[英]Android Management API change Policy for device

I created 2 policies in my enterprise.我在我的企业中创建了 2 个策略。

I would like to switch one device to the other policy without re-enroling it.我想在不重新注册的情况下将一台设备切换到另一项策略。

I tried to use android management enterprises devices.patch with following JSON我尝试使用 android management enterprises devices.patch 与以下 JSON

{ "policyName": "policy2" }

this link 这个链接

When i execute this command i always get follwoing error Message:当我执行此命令时,我总是收到以下错误消息:

{
 "error": {
  "code": 400,
  "message": "Illegal state transition from ACTIVE to DEVICE_STATE_UNSPECIFIED",
  "status": "INVALID_ARGUMENT"
 }
}

Does anybody know how to change policy for a device without wiping it?有谁知道如何在不擦除设备的情况下更改设备的策略?

It is indeed possible to change the policy of a device without re-enrolling it, and you're not far from the solution. 确实可以在不重新注册的情况下更改设备的策略,并且您距离解决方案不远。

You get this error because you implicitly attempt to change other fields of the Device resource (in particular the state field) by not setting them in the resource that you send in devices.patch . 您收到此错误是因为您隐式尝试更改Device资源的其他字段(特别是state字段),方法是不在您在devices.patch发送的资源中设置它们。

You have two options: 您有两种选择:

  1. Set the updateMask in devices.patch to "policyName" , to tell the API that you only want to change the policyName field. devices.patchupdateMask设置为"policyName" ,告诉API您只想更改policyName字段。

  2. Call devices.get to get the current Device resource, and then send back the entire resource with only the policyName field changed in to devices.patch . 调用devices.get来获取当前的Device资源,然后发送回整个资源,只将policyName字段更改为devices.patch

Using updateMask is preferable because it does an atomic read-modify-write. 使用updateMask是首选,因为它执行原子读 - 修改 - 写。

As Fred mentioned, updateMask is the preferred way to go. 正如弗雷德所说, updateMask是首选方式。 Here's an example of how to use the updateMask approach in the Google colab 以下是如何在Google colab中使用updateMask方法的示例

swap_result = androidmanagement.enterprises().devices().patch(
name='enterprises/ENTERPRISE_NAME/devices/DEVICE_ID', updateMask='policyName', body={ "policyName": "enterprises/ENTERPRISE_NAME/policies/NEW_POLICY_NAME"}).execute()

i foudn a solution for my problem: 我为我的问题找到了解决方案:

{ "policyName": "policy2" , "state":"active"} {“policyName”:“policy2”,“state”:“active”}

If you try this from management api test site then add updateMask as "policyName"如果您从管理 api 测试站点尝试此操作,则将 updateMask 添加为“policyName”

在此处输入图像描述

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

相关问题 Android Management api - 是否可以在 android 应用程序中获取设备 ID/名称? (设备特定的 QR 是不可能的,生成策略特定的 - Android Management api - Is it possible to get device id/name in android app? ( Device specific QR is not possible, Generating Policy specific Android设备策略管理仅适用于系统应用程序吗 - Is Android Device Policy Management possible with system apps only 使用 Android Management API Policy 时 Android Kiosk 模式不起作用 - Android Kiosk mode not working when using Android Management API Policy Android Management API 如何识别注册设备 - Android Management API How to Identify Enrolled Device 无法使用 Android 管理 API 重新启动设备 - Unable to REBOOT a device using Android Management API 使用Android Management API创建策略-Quickstart Colab - Create a policy using Android Management API - Quickstart Colab Android 管理 API:在 android Q 上的设备列表中查找设备 - Android management API: find device in list of devices on android Q 如何在Android管理api中保留专用设备的唯一ID? - How to keep the unique id for dedicated device in Android management api? 有什么方法可以从应用程序获取 Android Management API 设备 ID - Is there any way to get Android Management API device id from app Android Management API:如何擦除专用设备而不是EMM控制台? - Android Management API: How to wipe a dedicated device not from EMM console?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM