Commit 14c8c12e by wjg

v2

parent 00b09a2b
...@@ -10,8 +10,8 @@ android { ...@@ -10,8 +10,8 @@ android {
applicationId "com.ihaoin.hooloo.device" applicationId "com.ihaoin.hooloo.device"
minSdkVersion 26 minSdkVersion 26
targetSdkVersion 30 targetSdkVersion 30
versionCode 10 versionCode 5
versionName "1.0.10" versionName "1.0.5"
ndk { ndk {
//选择要添加的对应 cpu 类型的 .so 库。 //选择要添加的对应 cpu 类型的 .so 库。
......
...@@ -3,31 +3,40 @@ package com.ihaoin.hooloo.device.data.vo; ...@@ -3,31 +3,40 @@ package com.ihaoin.hooloo.device.data.vo;
import java.io.Serializable; import java.io.Serializable;
public class CheckUpdateVo implements Serializable { public class CheckUpdateVo implements Serializable {
private String url; private String requestId;
private Integer versionCode; private Integer code;
private String version; private String message;
private UpdateDataVo data;
public String getUrl() { public String getRequestId() {
return url; return requestId;
} }
public void setUrl(String url) { public void setRequestId(String requestId) {
this.url = url; this.requestId = requestId;
} }
public Integer getVersionCode() { public Integer getCode() {
return versionCode; return code;
} }
public void setVersionCode(Integer versionCode) { public void setCode(Integer code) {
this.versionCode = versionCode; this.code = code;
} }
public String getVersion() { public String getMessage() {
return version; return message;
} }
public void setVersion(String version) { public void setMessage(String message) {
this.version = version; this.message = message;
}
public UpdateDataVo getData() {
return data;
}
public void setData(UpdateDataVo data) {
this.data = data;
} }
} }
package com.ihaoin.hooloo.device.data.vo;
import java.io.Serializable;
public class UpdateDataVo implements Serializable {
private String url;
private Integer versionCode;
private String version;
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public Integer getVersionCode() {
return versionCode;
}
public void setVersionCode(Integer versionCode) {
this.versionCode = versionCode;
}
public String getVersion() {
return version;
}
public void setVersion(String version) {
this.version = version;
}
}
...@@ -127,8 +127,8 @@ public class LauncherActivity extends Activity { ...@@ -127,8 +127,8 @@ public class LauncherActivity extends Activity {
startMachineClient(); startMachineClient();
startTimeoutThread(); startTimeoutThread();
getMachineCode(); getMachineCode();
// startUpdateSocket(); startUpdateSocket();
// new UpdateService().start(); // new UpdateService(this).start();
View.OnClickListener l = v -> { View.OnClickListener l = v -> {
InteractionMsg msg = new InteractionMsg(); InteractionMsg msg = new InteractionMsg();
......
...@@ -135,13 +135,13 @@ public class FrameView extends SurfaceView implements SurfaceHolder.Callback { ...@@ -135,13 +135,13 @@ public class FrameView extends SurfaceView implements SurfaceHolder.Callback {
if (mod == frameCount - 1) { // 每次播放的最后一帧 if (mod == frameCount - 1) { // 每次播放的最后一帧
repeatCount++; repeatCount++;
Utils.i("play last, onAnimationRepeat " + (animatorListener != null)); // Utils.i("play last, onAnimationRepeat " + (animatorListener != null));
if (animatorListener != null) { if (animatorListener != null) {
animatorListener.onAnimationRepeat(null); animatorListener.onAnimationRepeat(null);
} }
} }
} }
Utils.i("play end, onAnimationEnd " + (animatorListener != null)); // Utils.i("play end, onAnimationEnd " + (animatorListener != null));
if (animatorListener != null) { if (animatorListener != null) {
animatorListener.onAnimationEnd(null); animatorListener.onAnimationEnd(null);
} }
......
...@@ -6,9 +6,9 @@ import android.os.Handler; ...@@ -6,9 +6,9 @@ import android.os.Handler;
import android.os.Message; import android.os.Message;
import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.JsonNode;
import com.ihaoin.hooloo.device.base.BizException;
import com.ihaoin.hooloo.device.HLApplication; import com.ihaoin.hooloo.device.HLApplication;
import com.ihaoin.hooloo.device.base.AppConfig; import com.ihaoin.hooloo.device.base.AppConfig;
import com.ihaoin.hooloo.device.base.BizException;
import com.ihaoin.hooloo.device.data.po.CheckUpdate; import com.ihaoin.hooloo.device.data.po.CheckUpdate;
import com.ihaoin.hooloo.device.util.JsonUtils; import com.ihaoin.hooloo.device.util.JsonUtils;
import com.ihaoin.hooloo.device.util.SharedPreferencesUtils; import com.ihaoin.hooloo.device.util.SharedPreferencesUtils;
...@@ -17,6 +17,7 @@ import com.ihaoin.hooloo.device.util.Utils; ...@@ -17,6 +17,7 @@ import com.ihaoin.hooloo.device.util.Utils;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.HashMap;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import okhttp3.Call; import okhttp3.Call;
...@@ -202,9 +203,11 @@ public class HttpUtil { ...@@ -202,9 +203,11 @@ public class HttpUtil {
checkUpdate.setVersionCode(packageInfo.versionCode); checkUpdate.setVersionCode(packageInfo.versionCode);
checkUpdate.setVersionName(packageInfo.versionName); checkUpdate.setVersionName(packageInfo.versionName);
checkUpdate.setType(String.valueOf(SharedPreferencesUtils.getScreenNo(HLApplication.SELF))); checkUpdate.setType(String.valueOf(SharedPreferencesUtils.getScreenNo(HLApplication.SELF)));
String content = JsonUtils.toString(checkUpdate).replaceAll("\"", "'"); String content = JsonUtils.toString(checkUpdate);
String params = String.format("{\"params\": \"%s\"}", content);
HashMap<String, String> map = new HashMap<>();
map.put("params", content);
String params = JsonUtils.toString(map);
post(HttpParams.POST_CHECK_UPDATE, params, handler); post(HttpParams.POST_CHECK_UPDATE, params, handler);
} }
......
package com.ihaoin.hooloo.device.update; package com.ihaoin.hooloo.device.update;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.content.Context; import android.app.Activity;
import android.content.pm.PackageInfo; import android.content.pm.PackageInfo;
import android.os.Environment; import android.os.Environment;
import android.os.Handler; import android.os.Handler;
import android.os.Message; import android.os.Message;
import android.widget.Toast;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import com.ihaoin.hooloo.device.HLApplication; import com.ihaoin.hooloo.device.HLApplication;
import com.ihaoin.hooloo.device.base.AppConfig; import com.ihaoin.hooloo.device.base.AppConfig;
import com.ihaoin.hooloo.device.data.vo.CheckUpdateVo; import com.ihaoin.hooloo.device.data.vo.UpdateDataVo;
import com.ihaoin.hooloo.device.network.HttpUtil; import com.ihaoin.hooloo.device.network.HttpUtil;
import com.ihaoin.hooloo.device.network.NetworkHandler; import com.ihaoin.hooloo.device.network.NetworkHandler;
import com.ihaoin.hooloo.device.util.ApkUtils; import com.ihaoin.hooloo.device.util.ApkUtils;
...@@ -23,34 +24,15 @@ import java.io.File; ...@@ -23,34 +24,15 @@ import java.io.File;
@SuppressLint("HandlerLeak") @SuppressLint("HandlerLeak")
public class UpdateService extends Thread { public class UpdateService extends Thread {
private Context mContext; private Activity mContext;
public UpdateService(Context context) { public UpdateService(Activity context) {
this.mContext = context; this.mContext = context;
} }
// @Nullable
// @Override
// public IBinder onBind(Intent intent) {
// checkUpdate();
// return null;
// }
@Override @Override
public void run() { public void run() {
HttpUtil.checkUpdate(checkUpdateHandler); HttpUtil.checkUpdate(checkUpdateHandler);
// while (true) {
// try {
// if (System.currentTimeMillis() / 1000 % 60 == 0) {
// Utils.i("check");
// }
// checkUpdate();
// Thread.sleep(1000);
// } catch (Exception e) {
// e.printStackTrace();
// Utils.i("check update error");
// }
// }
} }
private CheckUpdateHandler checkUpdateHandler = new CheckUpdateHandler(); private CheckUpdateHandler checkUpdateHandler = new CheckUpdateHandler();
...@@ -65,46 +47,74 @@ public class UpdateService extends Thread { ...@@ -65,46 +47,74 @@ public class UpdateService extends Thread {
// updateVo.setVersionCode(10); // updateVo.setVersionCode(10);
Object obj = msg.obj; Object obj = msg.obj;
if (msg.what == 0 || obj == null) { if (msg.what == 0 || obj == null) {
Utils.i(AppConfig.TAG_UPDATE, "检查更新返回¬失败"); Utils.i(AppConfig.TAG_UPDATE, "检查更新返回失败");
if (AppConfig.DEBUG) {
Utils.showToast(mContext, "检查更新返回失败", Toast.LENGTH_LONG);
}
return; return;
} }
CheckUpdateVo updateVo = JsonUtils.readValue(obj, CheckUpdateVo.class); UpdateDataVo dataVo = JsonUtils.readValue(obj, UpdateDataVo.class);
if (updateVo.getVersionCode() == null || updateVo.getVersionCode() <= 0) { if (dataVo == null) {
Utils.i(AppConfig.TAG_UPDATE, "version code 为空"); Utils.i(AppConfig.TAG_UPDATE, "检查更新返回为空");
if (AppConfig.DEBUG) {
Utils.showToast(mContext, "检查更新返回为空", Toast.LENGTH_LONG);
}
return; return;
} }
if (StringUtils.isEmpty(updateVo.getUrl())) { if (dataVo.getVersionCode() == null || dataVo.getVersionCode() <= 0) {
Utils.i(AppConfig.TAG_UPDATE, "url 为空"); Utils.i(AppConfig.TAG_UPDATE, "version code为空");
if (AppConfig.DEBUG) {
Utils.showToast(mContext, "version code为空", Toast.LENGTH_LONG);
}
return; return;
} }
if (StringUtils.isEmpty(updateVo.getVersion())) { if (StringUtils.isEmpty(dataVo.getUrl())) {
Utils.i(AppConfig.TAG_UPDATE, "version 为空"); Utils.i(AppConfig.TAG_UPDATE, "url为空");
if (AppConfig.DEBUG) {
Utils.showToast(mContext, "url为空", Toast.LENGTH_LONG);
}
return;
}
if (StringUtils.isEmpty(dataVo.getVersion())) {
Utils.i(AppConfig.TAG_UPDATE, "version为空");
if (AppConfig.DEBUG) {
Utils.showToast(mContext, "version为空", Toast.LENGTH_LONG);
}
return; return;
} }
PackageInfo packageInfo = Utils.getPackageInfo(); PackageInfo packageInfo = Utils.getPackageInfo();
if (updateVo.getVersionCode() <= packageInfo.versionCode) { if (dataVo.getVersionCode() <= packageInfo.versionCode) {
Utils.i(AppConfig.TAG_UPDATE, String.format("不需要更新, current: %s, update: %s", packageInfo.versionCode, updateVo.getVersionCode())); Utils.i(AppConfig.TAG_UPDATE, String.format("不需要更新, current: %s, update: %s", packageInfo.versionCode, dataVo.getVersionCode()));
if (AppConfig.DEBUG) {
Utils.showToast(mContext, String.format("不需要更新, current: %s, update: %s", packageInfo.versionCode, dataVo.getVersionCode()), Toast.LENGTH_LONG);
}
return; return;
} }
startDownload(updateVo); startDownload(dataVo);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
Utils.i(AppConfig.TAG_UPDATE, "检查更新失败"); Utils.i(AppConfig.TAG_UPDATE, "检查更新失败");
if (AppConfig.DEBUG) {
Utils.showToast(mContext, "检查更新失败", Toast.LENGTH_LONG);
}
} }
} }
} }
private void startDownload(CheckUpdateVo updateVo) { private void startDownload(UpdateDataVo dataVo) {
String filename = "hooloo-device_" + updateVo.getVersion() + "_" + updateVo.getVersionCode() + "_" + System.currentTimeMillis() + ".apk"; String filename = "hooloo-device_" + dataVo.getVersion() + "_" + dataVo.getVersionCode() + "_" + System.currentTimeMillis() + ".apk";
String path = Environment.getExternalStorageDirectory().getAbsolutePath() + "/hooloo"; String path = Environment.getExternalStorageDirectory().getAbsolutePath() + "/hooloo";
if (!new File(path).exists()) { if (!new File(path).exists()) {
new File(path).mkdirs(); new File(path).mkdirs();
} }
String file = path + "/" + filename; String file = path + "/" + filename;
Utils.i(AppConfig.TAG_UPDATE, String.format("开始下载文件 url: %s, file: %s", updateVo.getUrl(), file)); Utils.i(AppConfig.TAG_UPDATE, String.format("开始下载文件 url: %s, file: %s", dataVo.getUrl(), file));
HttpUtil.download(updateVo.getUrl(), file, downloadHandler); if (AppConfig.DEBUG) {
Utils.showToast(mContext, String.format("开始下载文件 url: %s, file: %s", dataVo.getUrl(), file), Toast.LENGTH_LONG);
}
HttpUtil.download(dataVo.getUrl(), file, downloadHandler);
} }
private Handler downloadHandler = new Handler() { private Handler downloadHandler = new Handler() {
...@@ -113,17 +123,24 @@ public class UpdateService extends Thread { ...@@ -113,17 +123,24 @@ public class UpdateService extends Thread {
try { try {
Object obj = msg.obj; Object obj = msg.obj;
if (msg.what == 0 || obj == null) { if (msg.what == 0 || obj == null) {
Utils.i(AppConfig.TAG_UPDATE, "download file error"); Utils.i(AppConfig.TAG_UPDATE, "下载文件失败");
if (AppConfig.DEBUG) {
Utils.showToast(mContext, "下载文件失败", Toast.LENGTH_LONG);
}
return; return;
} }
if (AppConfig.DEBUG) { if (AppConfig.DEBUG) {
Utils.showToast(mContext, "下载文件完成,测试版本不能自动升级", Toast.LENGTH_LONG);
return; // 测试不实际升级 return; // 测试不实际升级
} }
ApkUtils.install(HLApplication.SELF, obj.toString()); ApkUtils.install(HLApplication.SELF, obj.toString());
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
Utils.i(AppConfig.TAG_UPDATE, "下载文件错误"); Utils.i(AppConfig.TAG_UPDATE, "下载文件错误");
if (AppConfig.DEBUG) {
Utils.showToast(mContext, "下载文件错误", Toast.LENGTH_LONG);
}
} }
} }
}; };
......
package com.ihaoin.hooloo.device.update; package com.ihaoin.hooloo.device.update;
import android.content.Context; import android.annotation.SuppressLint;
import android.app.Activity;
import android.os.Handler;
import android.os.Message;
import android.widget.Toast;
import androidx.annotation.NonNull;
import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.JsonNode;
import com.ihaoin.hooloo.device.base.AppConfig; import com.ihaoin.hooloo.device.base.AppConfig;
...@@ -19,10 +25,10 @@ import io.socket.emitter.Emitter; ...@@ -19,10 +25,10 @@ import io.socket.emitter.Emitter;
/** Linux通信 检查更新 */ /** Linux通信 检查更新 */
public class UpdateSocket extends Thread { public class UpdateSocket extends Thread {
private Context mContext; private Activity mContext;
private Socket mSocket; private Socket mSocket;
public UpdateSocket(Context context) { public UpdateSocket(Activity context) {
this.mContext = context; this.mContext = context;
} }
...@@ -34,25 +40,39 @@ public class UpdateSocket extends Thread { ...@@ -34,25 +40,39 @@ public class UpdateSocket extends Thread {
private void connectSocket() { private void connectSocket() {
try { try {
mSocket = IO.socket(Base.NSP_UPGRADE); mSocket = IO.socket(Base.NSP_UPGRADE);
mSocket.connect();
mSocket.on("connect", onConnect); mSocket.on("connect", onConnect);
mSocket.on("disconnect", onDisconnect); mSocket.on("disconnect", onDisconnect);
mSocket.on("upgrade", onUpgrade); mSocket.on("upgrade", onUpgrade);
mSocket.connect();
} catch (Exception e) { } catch (Exception e) {
Utils.i(AppConfig.TAG_UPDATE, "连接server失败,错误原因:" + e.getMessage()); Utils.i(AppConfig.TAG_UPDATE, "连接server失败,错误原因:" + e.getMessage());
if (AppConfig.DEBUG) {
Utils.showToast(mContext, "连接server失败,错误原因:" + e.getMessage(), Toast.LENGTH_LONG);
}
e.printStackTrace(); e.printStackTrace();
} }
} }
private Emitter.Listener onConnect = args -> { private Emitter.Listener onConnect = args -> {
Utils.i(AppConfig.TAG_UPDATE, "update socket connected"); Utils.i(AppConfig.TAG_UPDATE, "update socket connected");
if (AppConfig.DEBUG) {
Utils.showToast(mContext, "update socket, 成功连接", Toast.LENGTH_LONG);
}
mSocket.emit("state", "", (Ack) ack -> process("state", ack)); mSocket.emit("state", "", (Ack) ack -> process("state", ack));
}; };
private Emitter.Listener onDisconnect = args -> Utils.i(AppConfig.TAG_UPDATE, "update socket disconnected"); private Emitter.Listener onDisconnect = args -> {
Utils.i(AppConfig.TAG_UPDATE, "update socket disconnected");
if (AppConfig.DEBUG) {
Utils.showToast(mContext, "update socket, 断开连接", Toast.LENGTH_LONG);
}
};
private Emitter.Listener onUpgrade = args -> { private Emitter.Listener onUpgrade = args -> {
Utils.i(AppConfig.TAG_UPDATE, "update socket upgrade"); Utils.i(AppConfig.TAG_UPDATE, "update socket upgrade");
if (AppConfig.DEBUG) {
Utils.showToast(mContext, "update socket, onUpgrade", Toast.LENGTH_LONG);
}
process("upgrade", args); process("upgrade", args);
}; };
...@@ -79,6 +99,9 @@ public class UpdateSocket extends Thread { ...@@ -79,6 +99,9 @@ public class UpdateSocket extends Thread {
return; return;
} }
String content = args[0].toString(); String content = args[0].toString();
if (AppConfig.DEBUG) {
Utils.showToast(mContext, "update socket, 接收消息: " + content, Toast.LENGTH_LONG);
}
if (StringUtils.isEmpty(content)) { if (StringUtils.isEmpty(content)) {
Utils.i(AppConfig.TAG_UPDATE, func + " content empty"); Utils.i(AppConfig.TAG_UPDATE, func + " content empty");
return; return;
...@@ -90,10 +113,18 @@ public class UpdateSocket extends Thread { ...@@ -90,10 +113,18 @@ public class UpdateSocket extends Thread {
return; return;
} }
if (node.get("upgrade") != null && node.get("upgrade").asBoolean()) { if (node.get("upgrade") != null && node.get("upgrade").asBoolean()) {
new UpdateService(mContext).start(); startUpdateServiceHandler.sendEmptyMessage(0);
} }
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
@SuppressLint("HandlerLeak")
private Handler startUpdateServiceHandler = new Handler() {
@Override
public void handleMessage(@NonNull Message msg) {
new UpdateService(mContext).start();
}
};
} }
package com.ihaoin.hooloo.device.util; package com.ihaoin.hooloo.device.util;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.pm.PackageInfo; import android.content.pm.PackageInfo;
...@@ -305,6 +306,19 @@ public class Utils { ...@@ -305,6 +306,19 @@ public class Utils {
showToast(context, text, Toast.LENGTH_SHORT); showToast(context, text, Toast.LENGTH_SHORT);
} }
public static void showToast(Activity activity, String text, int t) {
activity.runOnUiThread(() -> {
View view = LayoutInflater.from(activity).inflate(R.layout.view_toast, null);
TextView textView = view.findViewById(R.id.txt_toast);
textView.setText(text);
Toast toast = Toast.makeText(activity, text, t);
toast.setGravity(Gravity.CENTER, 0, 0);
toast.setView(view);
toast.show();
});
}
public static void showToast(Context context, String text, int t) { public static void showToast(Context context, String text, int t) {
View view = LayoutInflater.from(context).inflate(R.layout.view_toast, null); View view = LayoutInflater.from(context).inflate(R.layout.view_toast, null);
TextView textView = view.findViewById(R.id.txt_toast); TextView textView = view.findViewById(R.id.txt_toast);
......
...@@ -150,7 +150,7 @@ ...@@ -150,7 +150,7 @@
<dimen name="interaction_recommend_margin_bottom">140px</dimen> <dimen name="interaction_recommend_margin_bottom">140px</dimen>
<dimen name="interaction_recommend_image_margin">80px</dimen> <dimen name="interaction_recommend_image_margin">80px</dimen>
<dimen name="interaction_goods_icon_width">260px</dimen> <dimen name="interaction_goods_icon_width">260px</dimen>
<dimen name="interaction_goods_icon_height">260px</dimen> <dimen name="interaction_goods_icon_height">195px</dimen>
<dimen name="ts_interaction_line1">260px</dimen> <dimen name="ts_interaction_line1">260px</dimen>
<dimen name="ts_interaction_line2">100px</dimen> <dimen name="ts_interaction_line2">100px</dimen>
......
...@@ -166,7 +166,7 @@ ...@@ -166,7 +166,7 @@
<dimen name="interaction_recommend_margin_bottom">140px</dimen> <dimen name="interaction_recommend_margin_bottom">140px</dimen>
<dimen name="interaction_recommend_image_margin">80px</dimen> <dimen name="interaction_recommend_image_margin">80px</dimen>
<dimen name="interaction_goods_icon_width">260px</dimen> <dimen name="interaction_goods_icon_width">260px</dimen>
<dimen name="interaction_goods_icon_height">260px</dimen> <dimen name="interaction_goods_icon_height">195px</dimen>
<dimen name="ts_interaction_line1">260px</dimen> <dimen name="ts_interaction_line1">260px</dimen>
<dimen name="ts_interaction_line2">100px</dimen> <dimen name="ts_interaction_line2">100px</dimen>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment