| | |
| | |
|
| | | import android.os.Build;
|
| | | import android.text.TextUtils;
|
| | | import android.util.Log;
|
| | |
|
| | | import androidx.annotation.RequiresApi;
|
| | |
|
| | | import com.google.gson.reflect.TypeToken;
|
| | | import com.hdl.sdk.common.config.TopicConstant;
|
| | | import com.hdl.sdk.common.event.EventDispatcher;
|
| | | import com.hdl.sdk.common.exception.HDLLinkException;
|
| | | import com.hdl.sdk.common.utils.ByteUtils;
|
| | | import com.hdl.sdk.common.utils.LogUtils;
|
| | | import com.hdl.sdk.common.utils.SPUtils;
|
| | | import com.hdl.sdk.common.utils.gson.GsonConvert;
|
| | | import com.hdl.sdk.connect.HDLLink;
|
| | | import com.hdl.sdk.connect.bean.LinkResponse;
|
| | | import com.hdl.sdk.connect.bean.request.AuthenticateRequest;
|
| | | import com.hdl.sdk.connect.bean.response.DeviceDeleteResponse;
|
| | | import com.hdl.sdk.connect.bean.response.DeviceInfoResponse;
|
| | | import com.hdl.sdk.connect.callback.HDLLinkCallBack;
|
| | | import com.hdl.sdk.connect.config.HDLLinkConfig;
|
| | | import com.hdl.sdk.connect.socket.HDLAuthSocket;
|
| | | import com.hdl.sdk.connect.socket.HDLSocket;
|
| | | import com.hdl.sdk.connect.utils.AesUtil;
|
| | | import com.hdl.sdk.connect.utils.ByteBufferUtils;
|
| | | import com.hdl.sdk.socket.codec.ByteToMessageDecoder;
|
| | |
|
| | | import java.nio.ByteBuffer;
|
| | | import java.nio.charset.StandardCharsets;
|
| | | import java.util.ArrayList;
|
| | | import java.util.List;
|
| | |
|
| | | import android.util.Base64;
|
| | |
|
| | | import kotlin.ParameterName;
|
| | |
|
| | | /**
|
| | | * Created by Tong on 2021/9/22.
|
| | |
| | |
|
| | | if (encrypt(body)) {
|
| | | //需要解密
|
| | | byte[] bodyBytes = AesUtil.aesDecrypt(body, HDLLinkConfig.getInstance().getLocalSecret());
|
| | | if (bodyBytes != null) {
|
| | | response.setData(new String(bodyBytes, StandardCharsets.UTF_8));
|
| | | } else {
|
| | | LogUtils.e("解密失败\r\n" + topic);
|
| | | response.setData(new String(body, "utf-8"));
|
| | | continue;
|
| | | if (!TextUtils.isEmpty(HDLLinkConfig.getInstance().getLocalSecret())) {
|
| | | byte[] bodyBytes = AesUtil.aesDecrypt(body, HDLLinkConfig.getInstance().getLocalSecret());
|
| | | if (bodyBytes != null) {
|
| | | response.setData(new String(bodyBytes, StandardCharsets.UTF_8));
|
| | | } else {
|
| | | LogUtils.e("解密失败\r\n" + topic);
|
| | | response.setData(new String(body, "utf-8"));
|
| | | continue;
|
| | | }
|
| | | }
|
| | | } else {
|
| | | response.setData(new String(body, "utf-8"));
|