props, boolean restart) throws IOException {
- // 参数校验
- if (padCode == null || padCode.isEmpty()) {
- throw new IllegalArgumentException("padCode 不能为空");
- }
- if (props == null) {
- throw new IllegalArgumentException("props 不能为 null");
- }
-
- // 构造请求体
- JSONObject json = new JSONObject();
-
- try {
- json.put("padCode", padCode);
- json.put("props", new JSONObject(props));
- json.put("restart", restart);
- } catch (JSONException e) {
- LogFileUtil.logAndWrite(Log.ERROR, "ArmCloudApiClient", "updateAndroidModProperties: JSON error", e);
- }
-
- String jsonBody = json.toString();
-
- // 生成时间戳
- String timestamp = String.valueOf(System.currentTimeMillis());
-
- String API_PATH = "/openapi/open/pad/updatePadAndroidProp";
-
- String signature = "";
- try {
- signature = calculateSignature(timestamp, API_PATH, jsonBody, secretKey);
- } catch (Exception e) {
- LogFileUtil.logAndWrite(Log.ERROR, "ArmCloudApiClient", "updateAndroidModProperties: Signature error", e);
- }
-
- RequestBody body = RequestBody.create(
- MediaType.parse("application/json; charset=utf-8"),
- jsonBody
- );
-
- Request request = new Request.Builder()
- .url(baseUrl + API_PATH)
- .addHeader("authver", "2.0")
- .addHeader("x-ak", accessKey)
- .addHeader("x-timestamp", timestamp)
- .addHeader("x-sign", signature)
- .post(body)
- .build();
-
- try (Response response = client.newCall(request).execute()) {
- if (!response.isSuccessful()) {
- throw new IOException("请求失败: " + response);
- }
-
- ResponseBody responseBody = response.body();
- if (responseBody == null) {
- throw new IOException("响应体为空");
- }
-
- return responseBody.string();
- }
- }
-
-
- /**
- * 修改实例属性 动态修改实例的属性信息,包括系统属性和设置 实例需要处于开机状态,该接口为即时生效
- *
- * 示例: String[] padCodes = new String[]{"AC21020010001"}; List systemProps = Arrays.asList( new PropertyItem("ro.build.id", "QQ3A.200805.001")
- * ); List oaidProps = Arrays.asList( new PropertyItem("oaid", "001") );
- *
- * String response = client.updateInstanceProperties( padCodes, null, // modemPersistProps null, // modemProps null, // systemPersistProps systemProps,
- * null, // settingProps oaidProps );
- */
- public String updateInstanceProperties(
- String[] padCodes,
- List modemPersistProps,
- List modemProps,
- List systemPersistProps,
- List systemProps,
- List settingProps,
- List oaidProps
- ) throws IOException {
- if (padCodes == null || padCodes.length == 0) {
- throw new IllegalArgumentException("padCodes 不能为空");
- }
-
- JSONObject json = new JSONObject();
- try {
- json.put("padCodes", new JSONArray(padCodes));
- putPropertyItems(json, "modemPersistPropertiesList", modemPersistProps);
- putPropertyItems(json, "modemPropertiesList", modemProps);
- putPropertyItems(json, "systemPersistPropertiesList", systemPersistProps);
- putPropertyItems(json, "systemPropertiesList", systemProps);
- putPropertyItems(json, "settingPropertiesList", settingProps);
- putPropertyItems(json, "oaidPropertiesList", oaidProps);
-
- } catch (JSONException e) {
- LogFileUtil.logAndWrite(Log.ERROR, "ArmCloudApiClient", "updateInstanceProperties: JSON error", e);
- }
-
- String jsonBody = json.toString();
- String timestamp = String.valueOf(System.currentTimeMillis());
- String API_PATH = "/openapi/open/pad/updatePadProperties";
-
- if (secretKey == null || secretKey.isEmpty()) {
- throw new IllegalArgumentException("secretKey 不能为空");
- }
-
- String signature = null;
- try {
- signature = calculateSignature(timestamp, API_PATH, jsonBody, secretKey);
- } catch (Exception e) {
- LogFileUtil.logAndWrite(Log.ERROR, "ArmCloudApiClient", "updateInstanceProperties: calculateSignature error", e);
- }
-
- RequestBody body = RequestBody.create(
- MediaType.parse("application/json; charset=utf-8"),
- jsonBody
- );
-
- Request request = new Request.Builder()
- .url(baseUrl + API_PATH)
- .addHeader("authver", "2.0")
- .addHeader("x-ak", accessKey)
- .addHeader("x-timestamp", timestamp)
- .addHeader("x-sign", signature)
- .post(body)
- .build();
-
- try (Response response = client.newCall(request).execute()) {
- if (!response.isSuccessful()) {
- throw new IOException("请求失败: " + response);
- }
-
- try (ResponseBody responseBody = response.body()) {
- return responseBody != null ? responseBody.string() : "";
- }
- }
- }
-
- private void putPropertyItems(JSONObject json, String key, List items) throws JSONException {
- if (items != null && !items.isEmpty()) {
- JSONArray array = new JSONArray();
- for (PropertyItem item : items) {
- array.put(item.toJson());
- }
- json.put(key, array);
- }
- }
-
-
- public static class PropertyItem {
-
- private String propertiesName;
- private String propertiesValue;
-
- public PropertyItem(String name, String value) {
- this.propertiesName = name;
- this.propertiesValue = value;
- }
-
- public JSONObject toJson() throws JSONException {
- JSONObject json = new JSONObject();
- json.put("propertiesName", propertiesName);
- json.put("propertiesValue", propertiesValue);
- return json;
- }
- }
-}
-
-