chore: 删除 ArmCloudApiClient 类并添加代码检查配置
- 删除了 app/src/main/java/com/example/studyapp/device/ArmCloudApiClient.java 文件 - 在项目根目录下添加了 .idea/inspectionProfiles/Project_Default.xml 文件,配置代码检查规则
This commit is contained in:
parent
b8acabc545
commit
a9b5ae4831
|
@ -0,0 +1,84 @@
|
||||||
|
<component name="InspectionProjectProfileManager">
|
||||||
|
<profile version="1.0">
|
||||||
|
<option name="myName" value="Project Default" />
|
||||||
|
<inspection_tool class="CodeBlock2Expr" enabled="true" level="WARNING" enabled_by_default="true" editorAttributes="INFO_ATTRIBUTES" />
|
||||||
|
<inspection_tool class="CssMissingSemicolon" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||||
|
<inspection_tool class="EmptyCatchBlockJS" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||||
|
<inspection_tool class="EmptyFinallyBlockJS" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||||
|
<inspection_tool class="EmptyTryBlockJS" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||||
|
<inspection_tool class="Eslint" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||||
|
<inspection_tool class="IfCanBeSwitch" enabled="true" level="WARNING" enabled_by_default="true">
|
||||||
|
<option name="minimumBranches" value="3" />
|
||||||
|
<option name="suggestIntSwitches" value="true" />
|
||||||
|
<option name="suggestEnumSwitches" value="true" />
|
||||||
|
</inspection_tool>
|
||||||
|
<inspection_tool class="InnerClassReferencedViaSubclass" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||||
|
<inspection_tool class="InterfaceMayBeAnnotatedFunctional" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||||
|
<inspection_tool class="JSArrowFunctionBracesCanBeRemoved" enabled="true" level="WARNING" enabled_by_default="true" editorAttributes="WARNING_ATTRIBUTES" />
|
||||||
|
<inspection_tool class="JSFunctionExpressionToArrowFunction" enabled="true" level="INFORMATION" enabled_by_default="true" editorAttributes="INFORMATION_ATTRIBUTES" />
|
||||||
|
<inspection_tool class="JSRemoveUnnecessaryParentheses" enabled="true" level="WARNING" enabled_by_default="true" editorAttributes="WARNING_ATTRIBUTES" />
|
||||||
|
<inspection_tool class="JSStringConcatenationToES6Template" enabled="true" level="WARNING" enabled_by_default="true" editorAttributes="WARNING_ATTRIBUTES" />
|
||||||
|
<inspection_tool class="JavadocDeclaration" enabled="true" level="WARNING" enabled_by_default="true">
|
||||||
|
<option name="ADDITIONAL_TAGS" value="TableName,createDate,description,createDate,description,createDate,description,createDate,description,createDate,description,createDate,description,createDate,description,createDate,description,createDate,description,createDate,description,createDate,description,createDate,description,createDate,description,createDate,description,createDate,description,createDate,description,createDate,description,createDate,description,createDate,description,createDate,description,createDate,description,createDate,description,createDate,description,createDate,description,createDate,description,createDate,description,createDate,description,createDate,description,createDate,description,Entity,createDate,description,createDate,description,Entity,createDate,description,Entity,createDate,description,createDate,description,createDate,description,Entity,createDate,description,Entity,createDate,description,createDate,description,createDate,description,Entity,createDate,description,createDate,description,Entity,createDate,description,Entity,createDate,description,createDate,description,createDate,description,createDate,description,Entity,createDate,description,createDate,description,createDate,description,Entity,createDate,description,createDate,description,createDate,description,Entity,createDate,description,createDate,description,Entity,createDate,description,Entity,createDate,description,createDate,description,Entity,createDate,description,Entity,createDate,description,Entity,createDate,description,Entity,createDate,description,Entity,createDate,description,Entity,createDate,description,createDate,description,Entity,createDate,description,createDate,description,Entity,createDate,description,createDate,description,createDate,description,Entity,createDate,description,createDate,description,Entity,createDate,description,Entity,createDate,description,Entity,createDate,description,createDate,description,Entity,createDate,description,createDate,description,createDate,description,createDate,description,createDate,description,createDate,description,createDate,description,createDate,description,createDate,description,createDate,description,createDate,description,createDate,description,createDate,description,createDate,description,createDate,description,createDate,description,createDate,description,createDate,description,createDate,description,createDate,description,createDate,description,createDate,description,createDate,description,createDate,description,createDate,description,createDate,description,createDate,description,createDate,description,createDate,description,createDate,description,createDate,description,createDate,description,createDate,description,createDate,description,createDate,description,Entity,createDate,description,TableName,Entity,createDate,description,createDate,description,Entity,createDate,description,createDate,description,createDate,description,Entity,createDate,description,createDate,description,Entity,createDate,description,Entity,createDate,description,createDate,description,createDate,description,Entity,createDate,description,Entity,createDate,description,createDate,description,Entity,createDate,description,TableName,Entity,createDate,description,Entity,createDate,description,Entity,createDate,description,Entity,createDate,description,Entity,createDate,description,createDate,description,Entity,createDate,description,Entity,createDate,description,createDate,description,Entity,createDate,description,createDate,description,Entity,createDate,description,createDate,description,Entity,createDate,description,createDate,description,Entity,createDate,description,createDate,description,createDate,description,createDate,description,createDate,description,createDate,description,Entity,createDate,description,Entity,createDate,description,createDate,description,TableName,Entity,createDate,description,createDate,description,Entity,createDate,description,createDate,description,Entity,createDate,description,createDate,description,Entity,createDate,description,createDate,description,Entity,createDate,description,createDate,description,createDate,description,Entity,createDate,description" />
|
||||||
|
</inspection_tool>
|
||||||
|
<inspection_tool class="LambdaParameterTypeCanBeSpecified" enabled="true" level="INFORMATION" enabled_by_default="true" editorAttributes="INFORMATION_ATTRIBUTES" />
|
||||||
|
<inspection_tool class="LocalCanBeFinal" enabled="true" level="WARNING" enabled_by_default="true">
|
||||||
|
<option name="REPORT_VARIABLES" value="true" />
|
||||||
|
<option name="REPORT_PARAMETERS" value="true" />
|
||||||
|
</inspection_tool>
|
||||||
|
<inspection_tool class="MissingJavadoc" enabled="false" level="INFORMATION" enabled_by_default="false" editorAttributes="INFORMATION_ATTRIBUTES" />
|
||||||
|
<inspection_tool class="NonBlockStatementBodyJS" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||||
|
<inspection_tool class="OverlyLongLambda" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||||
|
<inspection_tool class="PyPep8NamingInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true">
|
||||||
|
<option name="ignoredErrors">
|
||||||
|
<list>
|
||||||
|
<option value="N802" />
|
||||||
|
</list>
|
||||||
|
</option>
|
||||||
|
</inspection_tool>
|
||||||
|
<inspection_tool class="RedundantExplicitVariableType" enabled="true" level="INFORMATION" enabled_by_default="true" editorAttributes="INFORMATION_ATTRIBUTES" />
|
||||||
|
<inspection_tool class="StaticCallOnSubclass" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||||
|
<inspection_tool class="StaticFieldReferenceOnSubclass" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||||
|
<inspection_tool class="Stylelint" enabled="true" level="ERROR" enabled_by_default="true" />
|
||||||
|
<inspection_tool class="SuspiciousGetterSetter" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||||
|
<inspection_tool class="ThrowablePrintStackTrace" enabled="true" level="WARNING" enabled_by_default="true">
|
||||||
|
<scope name="Tests" level="WARNING" enabled="false" />
|
||||||
|
<scope name="Tests" level="WARNING" enabled="false" />
|
||||||
|
<scope name="Tests" level="WARNING" enabled="false" />
|
||||||
|
<scope name="Tests" level="WARNING" enabled="false" />
|
||||||
|
<scope name="Tests" level="WARNING" enabled="false" />
|
||||||
|
<scope name="Tests" level="WARNING" enabled="false" />
|
||||||
|
<scope name="Tests" level="WARNING" enabled="false" />
|
||||||
|
<scope name="Tests" level="WARNING" enabled="false" />
|
||||||
|
<scope name="Tests" level="WARNING" enabled="false" />
|
||||||
|
<scope name="Tests" level="WARNING" enabled="false" />
|
||||||
|
<scope name="Tests" level="WARNING" enabled="false" />
|
||||||
|
<scope name="Tests" level="WARNING" enabled="false" />
|
||||||
|
<scope name="Tests" level="WARNING" enabled="false" />
|
||||||
|
<scope name="Tests" level="WARNING" enabled="false" />
|
||||||
|
<scope name="Tests" level="WARNING" enabled="false" />
|
||||||
|
<scope name="Tests" level="WARNING" enabled="false" />
|
||||||
|
<scope name="Tests" level="WARNING" enabled="false" />
|
||||||
|
<scope name="Tests" level="WARNING" enabled="false" />
|
||||||
|
<scope name="Tests" level="WARNING" enabled="false" />
|
||||||
|
<scope name="Tests" level="WARNING" enabled="false" />
|
||||||
|
<scope name="Tests" level="WARNING" enabled="false" />
|
||||||
|
<scope name="Tests" level="WARNING" enabled="false" />
|
||||||
|
<scope name="Tests" level="WARNING" enabled="false" />
|
||||||
|
<scope name="Tests" level="WARNING" enabled="false" />
|
||||||
|
<scope name="Tests" level="WARNING" enabled="false" />
|
||||||
|
<scope name="Tests" level="WARNING" enabled="false" />
|
||||||
|
</inspection_tool>
|
||||||
|
<inspection_tool class="TypeScriptExplicitMemberType" enabled="true" level="INFORMATION" enabled_by_default="true" editorAttributes="INFORMATION_ATTRIBUTES" />
|
||||||
|
<inspection_tool class="UnnecessaryInheritDoc" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||||
|
<inspection_tool class="UnnecessaryJavaDocLink" enabled="true" level="WARNING" enabled_by_default="true">
|
||||||
|
<option name="ignoreInlineLinkToSuper" value="false" />
|
||||||
|
</inspection_tool>
|
||||||
|
<inspection_tool class="UnqualifiedFieldAccess" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||||
|
<inspection_tool class="UnqualifiedMethodAccess" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||||
|
<inspection_tool class="UnterminatedStatementJS" enabled="true" level="WARNING" enabled_by_default="true">
|
||||||
|
<option name="ignoreSemicolonAtEndOfBlock" value="true" />
|
||||||
|
</inspection_tool>
|
||||||
|
<inspection_tool class="VariableTypeCanBeExplicit" enabled="true" level="WEAK WARNING" enabled_by_default="true" editorAttributes="INFO_ATTRIBUTES" />
|
||||||
|
</profile>
|
||||||
|
</component>
|
|
@ -1,253 +0,0 @@
|
||||||
package com.example.studyapp.device;
|
|
||||||
|
|
||||||
import android.os.Build.VERSION;
|
|
||||||
import android.os.Build.VERSION_CODES;
|
|
||||||
import android.util.Log;
|
|
||||||
import com.example.studyapp.utils.LogFileUtil;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.time.Instant;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
import javax.crypto.Mac;
|
|
||||||
import javax.crypto.spec.SecretKeySpec;
|
|
||||||
import okhttp3.Call;
|
|
||||||
import okhttp3.Callback;
|
|
||||||
import okhttp3.MediaType;
|
|
||||||
import okhttp3.OkHttpClient;
|
|
||||||
import okhttp3.OkHttpClient.Builder;
|
|
||||||
import okhttp3.Request;
|
|
||||||
import okhttp3.RequestBody;
|
|
||||||
import okhttp3.Response;
|
|
||||||
import okhttp3.ResponseBody;
|
|
||||||
import org.json.JSONArray;
|
|
||||||
import org.json.JSONException;
|
|
||||||
import org.json.JSONObject;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @Time: 2025-06-08 17:06
|
|
||||||
* @Creator: 初屿贤
|
|
||||||
* @File: ArmCloudApiClient
|
|
||||||
* @Project: study.App
|
|
||||||
* @Description:
|
|
||||||
*/
|
|
||||||
public class ArmCloudApiClient {
|
|
||||||
|
|
||||||
private final OkHttpClient client;
|
|
||||||
private final String baseUrl;
|
|
||||||
private final String accessKey;
|
|
||||||
private final String secretKey;
|
|
||||||
|
|
||||||
public ArmCloudApiClient(String baseUrl, String accessKey, String secretKey) {
|
|
||||||
this.client = new Builder()
|
|
||||||
.connectTimeout(10, TimeUnit.SECONDS)
|
|
||||||
.readTimeout(10, TimeUnit.SECONDS)
|
|
||||||
.build();
|
|
||||||
this.baseUrl = baseUrl;
|
|
||||||
this.accessKey = accessKey;
|
|
||||||
this.secretKey = secretKey;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final String ALGORITHM = "HmacSHA256";
|
|
||||||
|
|
||||||
public static String calculateSignature(String timestamp, String path, String body, String secretKey) throws Exception {
|
|
||||||
String stringToSign = timestamp + path + (body != null ? body : "");
|
|
||||||
Mac hmacSha256 = Mac.getInstance(ALGORITHM);
|
|
||||||
SecretKeySpec secretKeySpec = new SecretKeySpec(secretKey.getBytes(StandardCharsets.UTF_8), ALGORITHM);
|
|
||||||
hmacSha256.init(secretKeySpec);
|
|
||||||
byte[] hash = hmacSha256.doFinal(stringToSign.getBytes(StandardCharsets.UTF_8));
|
|
||||||
return bytesToHex(hash);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String bytesToHex(byte[] bytes) {
|
|
||||||
StringBuilder hexString = new StringBuilder();
|
|
||||||
for (byte b : bytes) {
|
|
||||||
String hex = Integer.toHexString(0xff & b);
|
|
||||||
if (hex.length() == 1) {
|
|
||||||
hexString.append('0');
|
|
||||||
}
|
|
||||||
hexString.append(hex);
|
|
||||||
}
|
|
||||||
return hexString.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 修改实例安卓改机属性 静态设置安卓改机属性,需要重启实例才能够生效,一般用于修改设备信息 该接口与修改实例属性接口的区别在于生效时机,该接口生效时间为每次开机初始化 设置实例属性后,属性数据会持久化存储,重启或重置实例无需再调用该接口
|
|
||||||
*
|
|
||||||
* @param padCode 实例 ID,非空
|
|
||||||
* @param props 属性映射,非空
|
|
||||||
* @param restart 是否自动重启
|
|
||||||
* @return 接口返回结果字符串
|
|
||||||
* @throws IOException 请求失败或网络错误
|
|
||||||
*/
|
|
||||||
public String updateAndroidModProperties(String padCode, Map<String, String> 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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 修改实例属性 动态修改实例的属性信息,包括系统属性和设置 实例需要处于开机状态,该接口为即时生效
|
|
||||||
* <p>
|
|
||||||
* 示例: String[] padCodes = new String[]{"AC21020010001"}; List<PropertyItem> systemProps = Arrays.asList( new PropertyItem("ro.build.id", "QQ3A.200805.001")
|
|
||||||
* ); List<PropertyItem> oaidProps = Arrays.asList( new PropertyItem("oaid", "001") );
|
|
||||||
* <p>
|
|
||||||
* String response = client.updateInstanceProperties( padCodes, null, // modemPersistProps null, // modemProps null, // systemPersistProps systemProps,
|
|
||||||
* null, // settingProps oaidProps );
|
|
||||||
*/
|
|
||||||
public String updateInstanceProperties(
|
|
||||||
String[] padCodes,
|
|
||||||
List<PropertyItem> modemPersistProps,
|
|
||||||
List<PropertyItem> modemProps,
|
|
||||||
List<PropertyItem> systemPersistProps,
|
|
||||||
List<PropertyItem> systemProps,
|
|
||||||
List<PropertyItem> settingProps,
|
|
||||||
List<PropertyItem> 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<PropertyItem> 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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue