Commit fc7bd62d by wjg

add update

parent d17da868
...@@ -73,4 +73,5 @@ dependencies { ...@@ -73,4 +73,5 @@ dependencies {
implementation 'com.umeng.umsdk:asms:1.6.3'// asms包依赖(必选) implementation 'com.umeng.umsdk:asms:1.6.3'// asms包依赖(必选)
implementation 'com.umeng.umsdk:apm:1.6.2'// U-APM产品包依赖(必选) implementation 'com.umeng.umsdk:apm:1.6.2'// U-APM产品包依赖(必选)
implementation 'io.socket:socket.io-client:1.0.0' implementation 'io.socket:socket.io-client:1.0.0'
implementation 'com.blankj:utilcode:1.28.6'
} }
\ No newline at end of file
...@@ -15,12 +15,19 @@ ...@@ -15,12 +15,19 @@
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" /> <uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission
android:name="android.permission.INSTALL_PACKAGES"
tools:ignore="ProtectedPermissions" />
<application <application
android:name=".HLApplication" android:name=".HLApplication"
android:allowBackup="true" android:allowBackup="true"
android:icon="@mipmap/hooloo_launcher" android:icon="@mipmap/hooloo_launcher"
android:label="@string/app_name" android:label="@string/app_name"
android:requestLegacyExternalStorage="true"
android:sharedUserId="android.uid.system"
android:theme="@style/AppTheme" android:theme="@style/AppTheme"
android:usesCleartextTraffic="true" android:usesCleartextTraffic="true"
tools:replace="android:allowBackup,android:icon"> tools:replace="android:allowBackup,android:icon">
...@@ -34,9 +41,9 @@ ...@@ -34,9 +41,9 @@
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" /> <category android:name="android.intent.category.LAUNCHER" />
<!-- <category android:name="android.intent.category.HOME" />--> <!-- <category android:name="android.intent.category.HOME" />-->
<!-- <category android:name="android.intent.category.DEFAULT" />--> <!-- <category android:name="android.intent.category.DEFAULT" />-->
<!-- <category android:name="android.intent.category.MONKEY" />--> <!-- <category android:name="android.intent.category.MONKEY" />-->
</intent-filter> </intent-filter>
</activity> </activity>
<activity <activity
......
package com.ihaoin.hooloo.device.component;
import android.annotation.SuppressLint;
import android.os.Environment;
import android.os.Handler;
import android.os.Message;
import androidx.annotation.NonNull;
import com.ihaoin.hooloo.device.HLApplication;
import com.ihaoin.hooloo.device.data.vo.CheckUpdateVo;
import com.ihaoin.hooloo.device.network.HttpUtil;
import com.ihaoin.hooloo.device.util.ApkUtils;
import com.ihaoin.hooloo.device.util.Utils;
import java.io.File;
@SuppressLint("HandlerLeak")
public class UpdateService extends Thread {
@Override
public void run() {
checkUpdate();
// 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 void checkUpdate() {
HttpUtil.checkUpdate(checkUpdateHandler);
}
private Handler checkUpdateHandler = new Handler() {
@Override
public void handleMessage(@NonNull Message msg) {
try {
CheckUpdateVo updateVo = new CheckUpdateVo();
updateVo.setUrl("https://testapi.pecktoy.com/files/upload_test/app-debug.apk");
updateVo.setVersion("1.0.1");
updateVo.setVersionCode(3);
// Object obj = msg.obj;
// if (msg.what == 0 || obj == null) {
// Utils.i("check update error");
// return;
// }
// CheckUpdateVo updateVo = JsonUtils.readValue(obj, CheckUpdateVo.class);
// if (updateVo.getVersionCode() <= 0) {
// Utils.i("version code is 0");
// return;
// }
// if (StringUtils.isEmpty(updateVo.getUrl())) {
// Utils.i("url is null");
// return;
// }
// if (StringUtils.isEmpty(updateVo.getVersion())) {
// Utils.i("version name is null");
// return;
// }
//
// PackageInfo packageInfo = Utils.getPackageInfo();
// if (updateVo.getVersionCode() <= packageInfo.versionCode) {
// Utils.i(String.format("dont update, current: %s, update: %s", packageInfo.versionCode, updateVo.getVersionCode()));
// return;
// }
startDownload(updateVo);
} catch (Exception e) {
e.printStackTrace();
Utils.i("check update error");
}
}
};
private void startDownload(CheckUpdateVo updateVo) {
String filename = "hooloo-device_" + updateVo.getVersion() + "_" + updateVo.getVersionCode() + ".apk";
String path = Environment.getExternalStorageDirectory().getAbsolutePath() + "/hooloo";
if (!new File(path).exists()) {
new File(path).mkdirs();
}
String file = path + "/" + filename;
Utils.i("start download file: " + file);
HttpUtil.download(updateVo.getUrl(), file, downloadHandler);
}
private Handler downloadHandler = new Handler() {
@Override
public void dispatchMessage(@NonNull Message msg) {
try {
Object obj = msg.obj;
if (msg.what == 0 || obj == null) {
Utils.i("download file error");
return;
}
ApkUtils.install(HLApplication.SELF, obj.toString());
} catch (Exception e) {
e.printStackTrace();
Utils.i("download file error");
}
}
};
}
package com.ihaoin.hooloo.device.data.po;
import java.io.Serializable;
public class CheckUpdate implements Serializable {
private String machineCode;
private Integer versionCode;
private String versionName;
public String getMachineCode() {
return machineCode;
}
public void setMachineCode(String machineCode) {
this.machineCode = machineCode;
}
public Integer getVersionCode() {
return versionCode;
}
public void setVersionCode(Integer versionCode) {
this.versionCode = versionCode;
}
public String getVersionName() {
return versionName;
}
public void setVersionName(String versionName) {
this.versionName = versionName;
}
}
package com.ihaoin.hooloo.device.data.vo;
import java.io.Serializable;
public class CheckUpdateVo 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;
}
}
...@@ -13,4 +13,6 @@ public class HttpParams { ...@@ -13,4 +13,6 @@ public class HttpParams {
public static final String POST_CONFIRM_ORDER = AppConfig.HOST + "/application/saveData?machineCode=%s"; public static final String POST_CONFIRM_ORDER = AppConfig.HOST + "/application/saveData?machineCode=%s";
/** 保存推送ID */ /** 保存推送ID */
public static final String POST_REGISTRATION_ID = AppConfig.HOST + "/application/jgRegister?machineCode=%s&registerId=%s"; public static final String POST_REGISTRATION_ID = AppConfig.HOST + "/application/jgRegister?machineCode=%s&registerId=%s";
/** 检查更新 */
public static final String POST_CHECK_UPDATE = "https://brain.ihaoin.com/mc/upgrade";
} }
...@@ -6,10 +6,12 @@ import android.os.Message; ...@@ -6,10 +6,12 @@ import android.os.Message;
import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.JsonNode;
import com.ihaoin.hooloo.device.config.AppConfig; import com.ihaoin.hooloo.device.config.AppConfig;
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.StringUtils; import com.ihaoin.hooloo.device.util.StringUtils;
import com.ihaoin.hooloo.device.util.Utils; import com.ihaoin.hooloo.device.util.Utils;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import okhttp3.Call; import okhttp3.Call;
...@@ -19,8 +21,50 @@ import okhttp3.OkHttpClient; ...@@ -19,8 +21,50 @@ import okhttp3.OkHttpClient;
import okhttp3.Request; import okhttp3.Request;
import okhttp3.RequestBody; import okhttp3.RequestBody;
import okhttp3.Response; import okhttp3.Response;
import okio.BufferedSink;
import okio.Okio;
import okio.Sink;
public class HttpUtil { public class HttpUtil {
public static void download(String url, String path, Handler handler) {
final long startTime = System.currentTimeMillis();
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder().url(url).build();
client.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
HttpUtil.onFailure(handler, call, e);
}
@Override
public void onResponse(Call call, Response response) throws IOException {
Sink sink = null;
BufferedSink buffered = null;
try {
sink = Okio.sink(new File(path));
buffered = Okio.buffer(sink);
buffered.writeAll(response.body().source());
buffered.close();
buffered = null;
Utils.i("download success");
Utils.i("download totalTime=" + (System.currentTimeMillis() - startTime));
sendHandlerMessage(1, handler, call, path);
} catch (Exception e) {
e.printStackTrace();
Utils.i("download failed");
} finally {
if (buffered != null) {
buffered.close();
}
if (sink != null) {
sink.close();
}
}
}
});
}
public static void post(String url, String body, Handler handler) { public static void post(String url, String body, Handler handler) {
if (body == null) { if (body == null) {
body = ""; body = "";
...@@ -134,6 +178,14 @@ public class HttpUtil { ...@@ -134,6 +178,14 @@ public class HttpUtil {
get(url, handler); get(url, handler);
} }
public static void checkUpdate(Handler handler) {
CheckUpdate checkUpdate = new CheckUpdate();
checkUpdate.setMachineCode(AppConfig.MACHINE_CODE);
checkUpdate.setVersionCode(Utils.getPackageInfo().versionCode);
checkUpdate.setVersionName(Utils.getPackageInfo().versionName);
post(HttpParams.POST_CHECK_UPDATE, JsonUtils.toString(checkUpdate), handler);
}
// public static String getMacAddress() { // public static String getMacAddress() {
// try { // try {
// List<NetworkInterface> all = Collections.list(NetworkInterface.getNetworkInterfaces()); // List<NetworkInterface> all = Collections.list(NetworkInterface.getNetworkInterfaces());
......
...@@ -3,6 +3,8 @@ package com.ihaoin.hooloo.device.util; ...@@ -3,6 +3,8 @@ package com.ihaoin.hooloo.device.util;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
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.PackageManager;
import android.graphics.Rect; import android.graphics.Rect;
import android.graphics.Typeface; import android.graphics.Typeface;
import android.util.DisplayMetrics; import android.util.DisplayMetrics;
...@@ -21,6 +23,7 @@ import androidx.coordinatorlayout.widget.ViewGroupUtils; ...@@ -21,6 +23,7 @@ import androidx.coordinatorlayout.widget.ViewGroupUtils;
import com.bumptech.glide.Glide; import com.bumptech.glide.Glide;
import com.bumptech.glide.RequestManager; import com.bumptech.glide.RequestManager;
import com.bumptech.glide.request.RequestOptions; import com.bumptech.glide.request.RequestOptions;
import com.ihaoin.hooloo.device.HLApplication;
import com.ihaoin.hooloo.device.R; import com.ihaoin.hooloo.device.R;
import com.ihaoin.hooloo.device.component.TouchDelegateComposite; import com.ihaoin.hooloo.device.component.TouchDelegateComposite;
import com.ihaoin.hooloo.device.config.AppConfig; import com.ihaoin.hooloo.device.config.AppConfig;
...@@ -46,6 +49,16 @@ import java.util.Optional; ...@@ -46,6 +49,16 @@ import java.util.Optional;
public class Utils { public class Utils {
public static PackageInfo getPackageInfo() {
PackageInfo packageInfo = null;
try {
packageInfo = HLApplication.SELF.getPackageManager().getPackageInfo(HLApplication.SELF.getPackageName(), 0);
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
return packageInfo;
}
public static void i(String s) { public static void i(String s) {
Utils.i(AppConfig.TAG, s); Utils.i(AppConfig.TAG, s);
} }
......
...@@ -39,6 +39,7 @@ import com.ihaoin.hooloo.device.component.InteractionSocket; ...@@ -39,6 +39,7 @@ import com.ihaoin.hooloo.device.component.InteractionSocket;
import com.ihaoin.hooloo.device.component.KDSSocket; import com.ihaoin.hooloo.device.component.KDSSocket;
import com.ihaoin.hooloo.device.component.NetworkHandler; import com.ihaoin.hooloo.device.component.NetworkHandler;
import com.ihaoin.hooloo.device.component.SettingsQueue; import com.ihaoin.hooloo.device.component.SettingsQueue;
import com.ihaoin.hooloo.device.component.UpdateService;
import com.ihaoin.hooloo.device.config.AppConfig; import com.ihaoin.hooloo.device.config.AppConfig;
import com.ihaoin.hooloo.device.config.Base; import com.ihaoin.hooloo.device.config.Base;
import com.ihaoin.hooloo.device.data.MainData; import com.ihaoin.hooloo.device.data.MainData;
...@@ -114,6 +115,8 @@ public class LauncherActivity extends Activity { ...@@ -114,6 +115,8 @@ public class LauncherActivity extends Activity {
startTimeoutThread(); startTimeoutThread();
getMachineCode(); getMachineCode();
new UpdateService().start();
} }
private void initViews() { private void initViews() {
...@@ -658,7 +661,7 @@ public class LauncherActivity extends Activity { ...@@ -658,7 +661,7 @@ public class LauncherActivity extends Activity {
private void requestPermissions() { private void requestPermissions() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
requestPermissions(new String[]{Manifest.permission.READ_PHONE_STATE, Manifest.permission.WRITE_EXTERNAL_STORAGE}, 100); requestPermissions(new String[]{Manifest.permission.READ_PHONE_STATE, Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE}, 100);
} }
} }
......
-----BEGIN CERTIFICATE-----
MIID+zCCAuOgAwIBAgIJAP8GQTI8+VUSMA0GCSqGSIb3DQEBCwUAMIGUMQswCQYD
VQQGEwJVUzETMBEGA1UECAwKQ2FsaWZvcm5pYTEWMBQGA1UEBwwNTW91bnRhaW4g
VmlldzEQMA4GA1UECgwHQW5kcm9pZDEQMA4GA1UECwwHQW5kcm9pZDEQMA4GA1UE
AwwHQW5kcm9pZDEiMCAGCSqGSIb3DQEJARYTYW5kcm9pZEBhbmRyb2lkLmNvbTAe
Fw0xNDEyMjMwNjQzNDFaFw00MjA1MTAwNjQzNDFaMIGUMQswCQYDVQQGEwJVUzET
MBEGA1UECAwKQ2FsaWZvcm5pYTEWMBQGA1UEBwwNTW91bnRhaW4gVmlldzEQMA4G
A1UECgwHQW5kcm9pZDEQMA4GA1UECwwHQW5kcm9pZDEQMA4GA1UEAwwHQW5kcm9p
ZDEiMCAGCSqGSIb3DQEJARYTYW5kcm9pZEBhbmRyb2lkLmNvbTCCASAwDQYJKoZI
hvcNAQEBBQADggENADCCAQgCggEBAKHY8Fl4XZzpJvgHoezYjhmKPvdq9DGYVc/X
9NQO5oUlYIA/Ci5rzvljz13KbNve/KxuEu9HN8SzsLg9EBhghOko8JxEg7I8W6uP
VOoRngNCMvXzjf6av77vxPqphlgq++Y4MIC+fiOxLd+gpYq0p6W7RWxEgrzLHnWi
CX0dRmWDs+ey2t4f1WKzGoRQQS0Tn21CViThrVEe+zNwANnhErUcvoQB2m4/PQot
uij7LZNccHJvUOUf5/4wIZd8JOgO3VLwzFO/HhrqUjafCvkpKTjW8oQmHLUz5m40
ljETGEjqQ6AuAwmaeFT+Bwj1DUaYg+m7AzalJ2aAtHVX0FftRUkCAQOjUDBOMB0G
A1UdDgQWBBQi+LgbyFfWSoWCbQ+NVDF4ZKTPCjAfBgNVHSMEGDAWgBQi+LgbyFfW
SoWCbQ+NVDF4ZKTPCjAMBgNVHRMEBTADAQH/MA0GCSqGSIb3DQEBCwUAA4IBAQBH
1kIQlSBjXRMuQdaDLytr8ZaJXIN1HApg2QA8azYQXOS/B16gwm6tBfh1dL86LL/7
w09oM9LZv8WwtQyFNjM97vvQvkaOGW/ubhrKOk3+8HTHkEx4n7H6tYGOLdpmWepD
fBSEFuLwq6yqG6wZFdd7IKO+sPlCxqUpqg40YAb4WOwzDbiuJnswDftP3wIaaJPh
li6OIjRKyd3Sgw1MtffHOy+WSwqHLkGNgH6GAgvZlvhPA/yim+rjnE9oKV5G6Pyg
QK7kJJjS/LdeqxE7M7pNRYPhcLT7qhE7MiuBuyqwAMTTBoU8u3lTdOZwNErbRT5t
SXkgVMffkfN7wBNqpSSY
-----END CERTIFICATE-----
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