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.framework.common.hianalytics.HianalyticsBaseData; 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 RequestHeader implements IMessageEntity { private static final String TAG = "RequestHeader"; @Packed private int apiLevel; @Packed private String api_name; @Packed private int kitSdkVersion; private Parcelable parcelable; @Packed private String pkg_name; @Packed private String session_id; @Packed private String srv_name; @Packed private String transaction_id; @Packed private String app_id = ""; @Packed private String version = "4.0"; @Packed private int sdk_version = 61100302; public boolean fromJson(String str) { try { JSONObject jSONObject = new JSONObject(str); this.version = JsonUtil.getStringValue(jSONObject, "version"); 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.sdk_version = JsonUtil.getIntValue(jSONObject, HianalyticsBaseData.SDK_VERSION); this.kitSdkVersion = JsonUtil.getIntValue(jSONObject, "kitSdkVersion"); this.apiLevel = JsonUtil.getIntValue(jSONObject, "apiLevel"); this.session_id = JsonUtil.getStringValue(jSONObject, "session_id"); this.transaction_id = JsonUtil.getStringValue(jSONObject, CommonCode.MapKey.TRANSACTION_ID); 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("version", this.version); 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); jSONObject.put(HianalyticsBaseData.SDK_VERSION, this.sdk_version); jSONObject.put("kitSdkVersion", this.kitSdkVersion); jSONObject.put("apiLevel", this.apiLevel); if (!TextUtils.isEmpty(this.session_id)) { jSONObject.put("session_id", this.session_id); } jSONObject.put(CommonCode.MapKey.TRANSACTION_ID, this.transaction_id); } 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("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(", sdk_version:"); sb.append(this.sdk_version); sb.append(", session_id:*, transaction_id:"); sb.append(this.transaction_id); sb.append(", kitSdkVersion:"); sb.append(this.kitSdkVersion); sb.append(", apiLevel:"); sb.append(this.apiLevel); return sb.toString(); } public void setVersion(String str) { this.version = str; } public void setTransactionId(String str) { this.transaction_id = str; } public void setSrvName(String str) { this.srv_name = str; } public void setSessionId(String str) { this.session_id = str; } public void setSdkVersion(int i) { this.sdk_version = i; } public void setPkgName(String str) { this.pkg_name = str; } public void setParcelable(Parcelable parcelable) { this.parcelable = parcelable; } public void setKitSdkVersion(int i) { this.kitSdkVersion = i; } public void setAppID(String str) { this.app_id = str; } public void setApiName(String str) { this.api_name = str; } public void setApiLevel(int i) { this.apiLevel = i; } public String getVersion() { return this.version; } public String getTransactionId() { return this.transaction_id; } public String getSrvName() { return this.srv_name; } public String getSessionId() { return this.session_id; } public int getSdkVersion() { return this.sdk_version; } public String getPkgName() { return this.pkg_name; } public Parcelable getParcelable() { return this.parcelable; } public int getKitSdkVersion() { return this.kitSdkVersion; } public String getAppID() { return this.app_id; } public String getApiName() { return this.api_name; } public int getApiLevel() { return this.apiLevel; } }