|
@@ -6,15 +6,23 @@ import android.content.ComponentName;
|
|
import android.content.Context;
|
|
import android.content.Context;
|
|
import android.content.Intent;
|
|
import android.content.Intent;
|
|
import android.content.ServiceConnection;
|
|
import android.content.ServiceConnection;
|
|
|
|
+import android.content.pm.PackageInfo;
|
|
|
|
+import android.content.pm.PackageManager;
|
|
import android.net.wifi.WifiManager;
|
|
import android.net.wifi.WifiManager;
|
|
|
|
+import android.os.Environment;
|
|
import android.os.IBinder;
|
|
import android.os.IBinder;
|
|
|
|
+import android.util.Log;
|
|
|
|
|
|
import com.wdkl.callingbed.service.APPService;
|
|
import com.wdkl.callingbed.service.APPService;
|
|
import com.wdkl.callingbed.util.UdpHelper;
|
|
import com.wdkl.callingbed.util.UdpHelper;
|
|
import com.wdkl.callingbed.util.anrfcutil.AnrFcExceptionUtil;
|
|
import com.wdkl.callingbed.util.anrfcutil.AnrFcExceptionUtil;
|
|
import com.wdkl.callingbed.util.ethernetwifiwithsipconnectstatus.WifiBindSipStatusConnector;
|
|
import com.wdkl.callingbed.util.ethernetwifiwithsipconnectstatus.WifiBindSipStatusConnector;
|
|
|
|
+import com.wdkl.callingbed.util.silentupdate.SilentUpdateUtil;
|
|
import com.zhy.http.okhttp.OkHttpUtils;
|
|
import com.zhy.http.okhttp.OkHttpUtils;
|
|
|
|
|
|
|
|
+import java.io.File;
|
|
|
|
+import java.io.FileOutputStream;
|
|
|
|
+import java.io.InputStream;
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.concurrent.TimeUnit;
|
|
import java.util.concurrent.TimeUnit;
|
|
@@ -49,6 +57,9 @@ public class MyApplication extends Application {
|
|
// return refWatcher;
|
|
// return refWatcher;
|
|
// }
|
|
// }
|
|
|
|
|
|
|
|
+ private boolean needCheckLaunch = true;
|
|
|
|
+ private boolean copyDone = false;
|
|
|
|
+
|
|
public static List<Activity> activities = new ArrayList<>();
|
|
public static List<Activity> activities = new ArrayList<>();
|
|
|
|
|
|
public static void addActivity(Activity activity) {
|
|
public static void addActivity(Activity activity) {
|
|
@@ -84,6 +95,69 @@ public class MyApplication extends Application {
|
|
Intent bindIntent = new Intent(this, APPService.class);
|
|
Intent bindIntent = new Intent(this, APPService.class);
|
|
bindService(bindIntent, connection, BIND_AUTO_CREATE);
|
|
bindService(bindIntent, connection, BIND_AUTO_CREATE);
|
|
|
|
|
|
|
|
+ //检查launch版本
|
|
|
|
+ if (needCheckLaunch) {
|
|
|
|
+ checkLaunch();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //检查launch版本
|
|
|
|
+ private void checkLaunch() {
|
|
|
|
+ Log.d("wzlll", "start check launch");
|
|
|
|
+ PackageManager pm = getPackageManager();
|
|
|
|
+ List<PackageInfo> packageInfo = pm.getInstalledPackages(0);
|
|
|
|
+ for (PackageInfo pInfo : packageInfo) {
|
|
|
|
+ final String apkName = "launch.apk";
|
|
|
|
+ final String launchName = "com.wdkl.launch";
|
|
|
|
+ String launchVersion = "1.3";
|
|
|
|
+ if (launchName.equals(pInfo.packageName)) {
|
|
|
|
+ Log.d("wzlll", "start check launch app: " + pInfo.versionName);
|
|
|
|
+ if (!launchVersion.equals(pInfo.versionName)) {
|
|
|
|
+ Log.d("wzlll", "need update launch, app name: " + pInfo.packageName + ", app version: " + pInfo.versionName);
|
|
|
|
+ new Thread(new Runnable() {
|
|
|
|
+ @Override
|
|
|
|
+ public void run() {
|
|
|
|
+ copyAssetsToDst(getApplicationContext(), apkName, Environment.getExternalStorageDirectory().getPath() + "/" + Environment.DIRECTORY_DOWNLOADS);
|
|
|
|
+ if (copyDone) {
|
|
|
|
+ String fileName = Environment.getExternalStorageDirectory().getPath() + "/" + Environment.DIRECTORY_DOWNLOADS + "/" + apkName;
|
|
|
|
+ if (SilentUpdateUtil.installApp(getPackageName(), fileName)) {
|
|
|
|
+ Log.d("wzlll", "install new launch success, reboot...");
|
|
|
|
+ SilentUpdateUtil.doRestart(getApplicationContext());
|
|
|
|
+ } else {
|
|
|
|
+ Log.d("wzlll", "install new launch failed...");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }).start();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //拷贝assets下面的文件到sd卡
|
|
|
|
+ private void copyAssetsToDst(Context context, String fileName, String dstPath) {
|
|
|
|
+ try {
|
|
|
|
+ copyDone = false;
|
|
|
|
+ File file = new File(dstPath);
|
|
|
|
+ if (!file.exists()) {
|
|
|
|
+ file.mkdirs();
|
|
|
|
+ }
|
|
|
|
+ File outFile = new File(dstPath + "/" + fileName);
|
|
|
|
+ InputStream is = context.getAssets().open(fileName);
|
|
|
|
+ FileOutputStream fos = new FileOutputStream(outFile);
|
|
|
|
+ byte[] buffer = new byte[1024];
|
|
|
|
+ int byteCount;
|
|
|
|
+ while ((byteCount = is.read(buffer)) != -1) {
|
|
|
|
+ fos.write(buffer, 0, byteCount);
|
|
|
|
+ }
|
|
|
|
+ fos.flush();
|
|
|
|
+ is.close();
|
|
|
|
+ fos.close();
|
|
|
|
+ copyDone = true;
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ copyDone = false;
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
public ServiceConnection connection = new ServiceConnection() {
|
|
public ServiceConnection connection = new ServiceConnection() {
|