package com.huawei.hms.common.internal; import android.os.Parcelable; import android.text.TextUtils; import com.huawei.hms.adapter.internal.CommonCode; import com.huawei.hms.core.aidl.IMessageEntity; import com.huawei.hms.core.aidl.annotation.Packed; import com.huawei.hms.support.hianalytics.HiAnalyticsConstant; import com.huawei.hms.support.log.HMSLog; import com.huawei.hms.utils.JsonUtil; import org.json.JSONException; import org.json.JSONObject; /* loaded from: classes2.dex */ public class ResponseHeader implements IMessageEntity, ResponseErrorCode { private static final String TAG = "ResponseHeader"; @Packed private String api_name; @Packed private String app_id = ""; @Packed private int error_code; @Packed private String error_reason; private Parcelable parcelable; @Packed private String pkg_name; @Packed private String resolution; @Packed private String session_id; @Packed private String srv_name; @Packed private int status_code; @Packed private String transaction_id; public ResponseHeader() { } public boolean fromJson(String str) { try { JSONObject jSONObject = new JSONObject(str); this.status_code = JsonUtil.getIntValue(jSONObject, "status_code"); this.error_code = JsonUtil.getIntValue(jSONObject, "error_code"); this.error_reason = JsonUtil.getStringValue(jSONObject, "error_reason"); this.srv_name = JsonUtil.getStringValue(jSONObject, "srv_name"); this.api_name = JsonUtil.getStringValue(jSONObject, "api_name"); this.app_id = JsonUtil.getStringValue(jSONObject, HiAnalyticsConstant.BI_KEY_APP_ID); this.pkg_name = JsonUtil.getStringValue(jSONObject, "pkg_name"); this.session_id = JsonUtil.getStringValue(jSONObject, "session_id"); this.transaction_id = JsonUtil.getStringValue(jSONObject, CommonCode.MapKey.TRANSACTION_ID); this.resolution = JsonUtil.getStringValue(jSONObject, CommonCode.MapKey.HAS_RESOLUTION); return true; } catch (JSONException e) { StringBuilder sb = new StringBuilder("fromJson failed: "); sb.append(e.getMessage()); HMSLog.e(TAG, sb.toString()); return false; } } public String getActualAppID() { if (TextUtils.isEmpty(this.app_id)) { return ""; } String[] split = this.app_id.split("\\|"); if (split.length == 0) { return ""; } if (split.length == 1) { return split[0]; } return split[1]; } public String toJson() { JSONObject jSONObject = new JSONObject(); try { jSONObject.put("status_code", this.status_code); jSONObject.put("error_code", this.error_code); jSONObject.put("error_reason", this.error_reason); jSONObject.put("srv_name", this.srv_name); jSONObject.put("api_name", this.api_name); jSONObject.put(HiAnalyticsConstant.BI_KEY_APP_ID, this.app_id); jSONObject.put("pkg_name", this.pkg_name); if (!TextUtils.isEmpty(this.session_id)) { jSONObject.put("session_id", this.session_id); } jSONObject.put(CommonCode.MapKey.TRANSACTION_ID, this.transaction_id); jSONObject.put(CommonCode.MapKey.HAS_RESOLUTION, this.resolution); } catch (JSONException e) { StringBuilder sb = new StringBuilder("toJson failed: "); sb.append(e.getMessage()); HMSLog.e(TAG, sb.toString()); } return jSONObject.toString(); } public String toString() { StringBuilder sb = new StringBuilder("status_code:"); sb.append(this.status_code); sb.append(", error_code:"); sb.append(this.error_code); sb.append(", api_name:"); sb.append(this.api_name); sb.append(", app_id:"); sb.append(this.app_id); sb.append(", pkg_name:"); sb.append(this.pkg_name); sb.append(", session_id:*, transaction_id:"); sb.append(this.transaction_id); sb.append(", resolution:"); sb.append(this.resolution); return sb.toString(); } public ResponseHeader(int i, int i2, String str) { this.status_code = i; this.error_code = i2; this.error_reason = str; } public void setTransactionId(String str) { this.transaction_id = str; } public void setStatusCode(int i) { this.status_code = i; } public void setSrvName(String str) { this.srv_name = str; } public void setSessionId(String str) { this.session_id = str; } public void setResolution(String str) { this.resolution = str; } public void setPkgName(String str) { this.pkg_name = str; } public void setParcelable(Parcelable parcelable) { this.parcelable = parcelable; } public void setErrorReason(String str) { this.error_reason = str; } public void setErrorCode(int i) { this.error_code = i; } public void setAppID(String str) { this.app_id = str; } public void setApiName(String str) { this.api_name = str; } public boolean isSuccess() { return this.status_code == 0; } @Override // com.huawei.hms.common.internal.ResponseErrorCode public boolean hasResolution() { return this.parcelable != null; } @Override // com.huawei.hms.common.internal.ResponseErrorCode public String getTransactionId() { return this.transaction_id; } @Override // com.huawei.hms.common.internal.ResponseErrorCode public int getStatusCode() { return this.status_code; } public String getSrvName() { return this.srv_name; } public String getSessionId() { return this.session_id; } @Override // com.huawei.hms.common.internal.ResponseErrorCode public String getResolution() { return this.resolution; } public String getPkgName() { return this.pkg_name; } @Override // com.huawei.hms.common.internal.ResponseErrorCode public Parcelable getParcelable() { return this.parcelable; } @Override // com.huawei.hms.common.internal.ResponseErrorCode public String getErrorReason() { return this.error_reason; } @Override // com.huawei.hms.common.internal.ResponseErrorCode public int getErrorCode() { return this.error_code; } public String getAppID() { return this.app_id; } public String getApiName() { return this.api_name; } }