1

正如谷歌文档中提到的,我已经测试了以下过程

快速入门网址:https://colab.research.google.com/github/google/android-management-api-samples/blob/master/notebooks/quickstart.ipynb#scrollTo=pjHfDSb8BoBP

  1. 创建企业
  2. 创建策略
  3. 注册设备

然后,我使用 Android Enterprises 的 NODEJS API 开发了基于服务器的解决方案,根据文档,该解决方案对于获取、创建、删除策略、设备、企业等所有功能都可以正常工作。

我面临的问题是从 NODE 应用程序生成的二维码,当我扫描从 NODEJS 应用程序生成的二维码时,设备卡在系统更新中。

以下是我的政策更新功能

 router.post('/update/:id', async function(req, res) {
      const {title,policy_body,update_mask,enroll_url} = req.body;
      // here we are callng the android managment API to and then the response we will update to database
      const amApiBody  = {
        name: policy_body.name,
        updateMask:update_mask,
        requestBody:policy_body
      }
    const policy_update_response =  await  amApi.updatePolicy(amApiBody);
      const p =  await  policyModel.update(req.params.id,title,policy_update_response,enroll_url);
    res.json(p)
 });

AmAPI 文件

    this.updatePolicy = async function (body)
    { 
            const auth = new google.auth.GoogleAuth({
                scopes: ['https://www.googleapis.com/auth/androidmanagement'],
            });

            const authClient = await auth.getClient();
            google.options({auth: authClient});
            
            // Get the list of available policies
            const res = await androidmanagement.enterprises.policies.patch(body);
            console.log('requestFinalBody=',body);
            return res.data;

    }

以下是我通过运行上述函数获得的策略数据

policy_create_response= {
  name: 'enterprises/LC019rjnor/policies/policy1',
  version: '14',
  applications: [
    {
      packageName: 'com.google.samples.apps.iosched',
      installType: 'FORCE_INSTALLED',
      autoUpdateMode: 'AUTO_UPDATE_HIGH_PRIORITY'
    },
    {
      packageName: 'com.dekaisheng.courier',
      installType: 'FORCE_INSTALLED',
      autoUpdateMode: 'AUTO_UPDATE_HIGH_PRIORITY'
    }
  ],
  keyguardDisabledFeatures: [ 'KEYGUARD_DISABLED_FEATURE_UNSPECIFIED' ],
  defaultPermissionPolicy: 'GRANT',
  uninstallAppsDisabled: true,
  keyguardDisabled: true,
  tetheringConfigDisabled: true,
  dataRoamingDisabled: true,
  networkEscapeHatchEnabled: true,
  bluetoothDisabled: true,
  debuggingFeaturesAllowed: true,
  funDisabled: true,
  kioskCustomLauncherEnabled: true
}

请注意,在运行应用程序之前,我已将变量导出到终端,如下所示,auth.json 是服务帐户凭据文件。

export GOOGLE_APPLICATION_CREDENTIALS="/Users/Mac/Projects/wajid/mdm/server/env/auth.json"  

我在这里先向您的帮助表示感谢

4

1 回答 1

0

我发现在 nodeJS API 中,我在请求正文中传递了错误的策略值属性名称。

修复前的代码

        parent: this.getParent(policyName),
        requestBody:{
            “name”: “my_policy"
        }

修复后的代码

 parent: this.getParent(policyName),
        requestBody:{
            "policyName”: “my_policy"
        }
于 2021-09-20T12:08:02.693 回答