zengjiebin 7 vuotta sitten
vanhempi
commit
e53ab1f44f

+ 1 - 0
app/build.gradle

@@ -423,6 +423,7 @@ dependencies {
         exclude group: 'com.squareup.okhttp3', module: 'okhttp'
     }
     implementation project(':media_share_lib')
+    //https://github.com/didi/VirtualAPK
     implementation 'com.didi.virtualapk:core:0.9.8'
     //fast json
     implementation 'com.alibaba:fastjson:1.2.52'

+ 15 - 15
app/src/main/java/com/sheep/gamegroup/greendao/download/DaoMaster.java

@@ -21,26 +21,26 @@ public class DaoMaster extends AbstractDaoMaster {
 
     /** Creates underlying database table using DAOs. */
     public static void createAllTables(Database db, boolean ifNotExists) {
-        ProcessRecordDao.createTable(db, ifNotExists);
-        AppdownloadBeanDao.createTable(db, ifNotExists);
-        SdkLoginUserDao.createTable(db, ifNotExists);
-        ScreenShotRecordDao.createTable(db, ifNotExists);
         AcceptTaskRecordDao.createTable(db, ifNotExists);
         AccountDao.createTable(db, ifNotExists);
-        SearchRecordDao.createTable(db, ifNotExists);
+        AppdownloadBeanDao.createTable(db, ifNotExists);
         DownLoadInfoDao.createTable(db, ifNotExists);
+        ProcessRecordDao.createTable(db, ifNotExists);
+        ScreenShotRecordDao.createTable(db, ifNotExists);
+        SdkLoginUserDao.createTable(db, ifNotExists);
+        SearchRecordDao.createTable(db, ifNotExists);
     }
 
     /** Drops underlying database table using DAOs. */
     public static void dropAllTables(Database db, boolean ifExists) {
-        ProcessRecordDao.dropTable(db, ifExists);
-        AppdownloadBeanDao.dropTable(db, ifExists);
-        SdkLoginUserDao.dropTable(db, ifExists);
-        ScreenShotRecordDao.dropTable(db, ifExists);
         AcceptTaskRecordDao.dropTable(db, ifExists);
         AccountDao.dropTable(db, ifExists);
-        SearchRecordDao.dropTable(db, ifExists);
+        AppdownloadBeanDao.dropTable(db, ifExists);
         DownLoadInfoDao.dropTable(db, ifExists);
+        ProcessRecordDao.dropTable(db, ifExists);
+        ScreenShotRecordDao.dropTable(db, ifExists);
+        SdkLoginUserDao.dropTable(db, ifExists);
+        SearchRecordDao.dropTable(db, ifExists);
     }
 
     /**
@@ -59,14 +59,14 @@ public class DaoMaster extends AbstractDaoMaster {
 
     public DaoMaster(Database db) {
         super(db, SCHEMA_VERSION);
-        registerDaoClass(ProcessRecordDao.class);
-        registerDaoClass(AppdownloadBeanDao.class);
-        registerDaoClass(SdkLoginUserDao.class);
-        registerDaoClass(ScreenShotRecordDao.class);
         registerDaoClass(AcceptTaskRecordDao.class);
         registerDaoClass(AccountDao.class);
-        registerDaoClass(SearchRecordDao.class);
+        registerDaoClass(AppdownloadBeanDao.class);
         registerDaoClass(DownLoadInfoDao.class);
+        registerDaoClass(ProcessRecordDao.class);
+        registerDaoClass(ScreenShotRecordDao.class);
+        registerDaoClass(SdkLoginUserDao.class);
+        registerDaoClass(SearchRecordDao.class);
     }
 
     public DaoSession newSession() {

+ 61 - 61
app/src/main/java/com/sheep/gamegroup/greendao/download/DaoSession.java

@@ -8,23 +8,23 @@ import org.greenrobot.greendao.database.Database;
 import org.greenrobot.greendao.identityscope.IdentityScopeType;
 import org.greenrobot.greendao.internal.DaoConfig;
 
-import com.sheep.gamegroup.greendao.download.ProcessRecord;
-import com.sheep.gamegroup.greendao.download.AppdownloadBean;
-import com.sheep.gamegroup.greendao.download.SdkLoginUser;
-import com.sheep.gamegroup.greendao.download.ScreenShotRecord;
 import com.sheep.gamegroup.greendao.download.AcceptTaskRecord;
 import com.sheep.gamegroup.greendao.download.Account;
-import com.sheep.gamegroup.greendao.download.SearchRecord;
+import com.sheep.gamegroup.greendao.download.AppdownloadBean;
 import com.sheep.gamegroup.greendao.download.DownLoadInfo;
+import com.sheep.gamegroup.greendao.download.ProcessRecord;
+import com.sheep.gamegroup.greendao.download.ScreenShotRecord;
+import com.sheep.gamegroup.greendao.download.SdkLoginUser;
+import com.sheep.gamegroup.greendao.download.SearchRecord;
 
-import com.sheep.gamegroup.greendao.download.ProcessRecordDao;
-import com.sheep.gamegroup.greendao.download.AppdownloadBeanDao;
-import com.sheep.gamegroup.greendao.download.SdkLoginUserDao;
-import com.sheep.gamegroup.greendao.download.ScreenShotRecordDao;
 import com.sheep.gamegroup.greendao.download.AcceptTaskRecordDao;
 import com.sheep.gamegroup.greendao.download.AccountDao;
-import com.sheep.gamegroup.greendao.download.SearchRecordDao;
+import com.sheep.gamegroup.greendao.download.AppdownloadBeanDao;
 import com.sheep.gamegroup.greendao.download.DownLoadInfoDao;
+import com.sheep.gamegroup.greendao.download.ProcessRecordDao;
+import com.sheep.gamegroup.greendao.download.ScreenShotRecordDao;
+import com.sheep.gamegroup.greendao.download.SdkLoginUserDao;
+import com.sheep.gamegroup.greendao.download.SearchRecordDao;
 
 // THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
 
@@ -35,112 +35,112 @@ import com.sheep.gamegroup.greendao.download.DownLoadInfoDao;
  */
 public class DaoSession extends AbstractDaoSession {
 
-    private final DaoConfig processRecordDaoConfig;
-    private final DaoConfig appdownloadBeanDaoConfig;
-    private final DaoConfig sdkLoginUserDaoConfig;
-    private final DaoConfig screenShotRecordDaoConfig;
     private final DaoConfig acceptTaskRecordDaoConfig;
     private final DaoConfig accountDaoConfig;
-    private final DaoConfig searchRecordDaoConfig;
+    private final DaoConfig appdownloadBeanDaoConfig;
     private final DaoConfig downLoadInfoDaoConfig;
+    private final DaoConfig processRecordDaoConfig;
+    private final DaoConfig screenShotRecordDaoConfig;
+    private final DaoConfig sdkLoginUserDaoConfig;
+    private final DaoConfig searchRecordDaoConfig;
 
-    private final ProcessRecordDao processRecordDao;
-    private final AppdownloadBeanDao appdownloadBeanDao;
-    private final SdkLoginUserDao sdkLoginUserDao;
-    private final ScreenShotRecordDao screenShotRecordDao;
     private final AcceptTaskRecordDao acceptTaskRecordDao;
     private final AccountDao accountDao;
-    private final SearchRecordDao searchRecordDao;
+    private final AppdownloadBeanDao appdownloadBeanDao;
     private final DownLoadInfoDao downLoadInfoDao;
+    private final ProcessRecordDao processRecordDao;
+    private final ScreenShotRecordDao screenShotRecordDao;
+    private final SdkLoginUserDao sdkLoginUserDao;
+    private final SearchRecordDao searchRecordDao;
 
     public DaoSession(Database db, IdentityScopeType type, Map<Class<? extends AbstractDao<?, ?>>, DaoConfig>
             daoConfigMap) {
         super(db);
 
-        processRecordDaoConfig = daoConfigMap.get(ProcessRecordDao.class).clone();
-        processRecordDaoConfig.initIdentityScope(type);
+        acceptTaskRecordDaoConfig = daoConfigMap.get(AcceptTaskRecordDao.class).clone();
+        acceptTaskRecordDaoConfig.initIdentityScope(type);
+
+        accountDaoConfig = daoConfigMap.get(AccountDao.class).clone();
+        accountDaoConfig.initIdentityScope(type);
 
         appdownloadBeanDaoConfig = daoConfigMap.get(AppdownloadBeanDao.class).clone();
         appdownloadBeanDaoConfig.initIdentityScope(type);
 
-        sdkLoginUserDaoConfig = daoConfigMap.get(SdkLoginUserDao.class).clone();
-        sdkLoginUserDaoConfig.initIdentityScope(type);
+        downLoadInfoDaoConfig = daoConfigMap.get(DownLoadInfoDao.class).clone();
+        downLoadInfoDaoConfig.initIdentityScope(type);
+
+        processRecordDaoConfig = daoConfigMap.get(ProcessRecordDao.class).clone();
+        processRecordDaoConfig.initIdentityScope(type);
 
         screenShotRecordDaoConfig = daoConfigMap.get(ScreenShotRecordDao.class).clone();
         screenShotRecordDaoConfig.initIdentityScope(type);
 
-        acceptTaskRecordDaoConfig = daoConfigMap.get(AcceptTaskRecordDao.class).clone();
-        acceptTaskRecordDaoConfig.initIdentityScope(type);
-
-        accountDaoConfig = daoConfigMap.get(AccountDao.class).clone();
-        accountDaoConfig.initIdentityScope(type);
+        sdkLoginUserDaoConfig = daoConfigMap.get(SdkLoginUserDao.class).clone();
+        sdkLoginUserDaoConfig.initIdentityScope(type);
 
         searchRecordDaoConfig = daoConfigMap.get(SearchRecordDao.class).clone();
         searchRecordDaoConfig.initIdentityScope(type);
 
-        downLoadInfoDaoConfig = daoConfigMap.get(DownLoadInfoDao.class).clone();
-        downLoadInfoDaoConfig.initIdentityScope(type);
-
-        processRecordDao = new ProcessRecordDao(processRecordDaoConfig, this);
-        appdownloadBeanDao = new AppdownloadBeanDao(appdownloadBeanDaoConfig, this);
-        sdkLoginUserDao = new SdkLoginUserDao(sdkLoginUserDaoConfig, this);
-        screenShotRecordDao = new ScreenShotRecordDao(screenShotRecordDaoConfig, this);
         acceptTaskRecordDao = new AcceptTaskRecordDao(acceptTaskRecordDaoConfig, this);
         accountDao = new AccountDao(accountDaoConfig, this);
-        searchRecordDao = new SearchRecordDao(searchRecordDaoConfig, this);
+        appdownloadBeanDao = new AppdownloadBeanDao(appdownloadBeanDaoConfig, this);
         downLoadInfoDao = new DownLoadInfoDao(downLoadInfoDaoConfig, this);
+        processRecordDao = new ProcessRecordDao(processRecordDaoConfig, this);
+        screenShotRecordDao = new ScreenShotRecordDao(screenShotRecordDaoConfig, this);
+        sdkLoginUserDao = new SdkLoginUserDao(sdkLoginUserDaoConfig, this);
+        searchRecordDao = new SearchRecordDao(searchRecordDaoConfig, this);
 
-        registerDao(ProcessRecord.class, processRecordDao);
-        registerDao(AppdownloadBean.class, appdownloadBeanDao);
-        registerDao(SdkLoginUser.class, sdkLoginUserDao);
-        registerDao(ScreenShotRecord.class, screenShotRecordDao);
         registerDao(AcceptTaskRecord.class, acceptTaskRecordDao);
         registerDao(Account.class, accountDao);
-        registerDao(SearchRecord.class, searchRecordDao);
+        registerDao(AppdownloadBean.class, appdownloadBeanDao);
         registerDao(DownLoadInfo.class, downLoadInfoDao);
+        registerDao(ProcessRecord.class, processRecordDao);
+        registerDao(ScreenShotRecord.class, screenShotRecordDao);
+        registerDao(SdkLoginUser.class, sdkLoginUserDao);
+        registerDao(SearchRecord.class, searchRecordDao);
     }
     
     public void clear() {
-        processRecordDaoConfig.clearIdentityScope();
-        appdownloadBeanDaoConfig.clearIdentityScope();
-        sdkLoginUserDaoConfig.clearIdentityScope();
-        screenShotRecordDaoConfig.clearIdentityScope();
         acceptTaskRecordDaoConfig.clearIdentityScope();
         accountDaoConfig.clearIdentityScope();
-        searchRecordDaoConfig.clearIdentityScope();
+        appdownloadBeanDaoConfig.clearIdentityScope();
         downLoadInfoDaoConfig.clearIdentityScope();
+        processRecordDaoConfig.clearIdentityScope();
+        screenShotRecordDaoConfig.clearIdentityScope();
+        sdkLoginUserDaoConfig.clearIdentityScope();
+        searchRecordDaoConfig.clearIdentityScope();
     }
 
-    public ProcessRecordDao getProcessRecordDao() {
-        return processRecordDao;
+    public AcceptTaskRecordDao getAcceptTaskRecordDao() {
+        return acceptTaskRecordDao;
+    }
+
+    public AccountDao getAccountDao() {
+        return accountDao;
     }
 
     public AppdownloadBeanDao getAppdownloadBeanDao() {
         return appdownloadBeanDao;
     }
 
-    public SdkLoginUserDao getSdkLoginUserDao() {
-        return sdkLoginUserDao;
+    public DownLoadInfoDao getDownLoadInfoDao() {
+        return downLoadInfoDao;
     }
 
-    public ScreenShotRecordDao getScreenShotRecordDao() {
-        return screenShotRecordDao;
+    public ProcessRecordDao getProcessRecordDao() {
+        return processRecordDao;
     }
 
-    public AcceptTaskRecordDao getAcceptTaskRecordDao() {
-        return acceptTaskRecordDao;
+    public ScreenShotRecordDao getScreenShotRecordDao() {
+        return screenShotRecordDao;
     }
 
-    public AccountDao getAccountDao() {
-        return accountDao;
+    public SdkLoginUserDao getSdkLoginUserDao() {
+        return sdkLoginUserDao;
     }
 
     public SearchRecordDao getSearchRecordDao() {
         return searchRecordDao;
     }
 
-    public DownLoadInfoDao getDownLoadInfoDao() {
-        return downLoadInfoDao;
-    }
-
 }

+ 0 - 193
app/src/main/java/com/sheep/gamegroup/module/plugin/util/PluginUtil.java

@@ -1,193 +0,0 @@
-package com.sheep.gamegroup.module.plugin.util;
-
-import android.content.Context;
-
-import com.alibaba.fastjson.JSONObject;
-import com.didi.virtualapk.PluginManager;
-import com.sheep.gamegroup.model.entity.BaseMessage;
-import com.sheep.gamegroup.model.util.SheepSubscriber;
-import com.sheep.gamegroup.module.plugin.model.ClientPackage;
-import com.sheep.gamegroup.module.plugin.model.Plugin;
-import com.sheep.gamegroup.util.DataUtil;
-import com.sheep.gamegroup.util.DownloadUtil;
-import com.sheep.gamegroup.util.ListUtil;
-import com.sheep.gamegroup.util.LogUtil;
-import com.sheep.gamegroup.util.Md5Util;
-import com.sheep.gamegroup.util.TestUtil;
-import com.sheep.jiuyan.samllsheep.BuildConfig;
-import com.sheep.jiuyan.samllsheep.SheepApp;
-import com.sheep.jiuyan.samllsheep.utils.ClassFileHelper;
-import com.sheep.jiuyan.samllsheep.utils.G;
-import com.zhy.http.okhttp.OkHttpUtils;
-import com.zhy.http.okhttp.callback.FileCallBack;
-
-import org.afinal.simplecache.ApiKey;
-
-import java.io.File;
-import java.util.Locale;
-
-import io.reactivex.Observable;
-import io.reactivex.ObservableOnSubscribe;
-import io.reactivex.android.schedulers.AndroidSchedulers;
-import io.reactivex.schedulers.Schedulers;
-import okhttp3.Call;
-
-/**
- * Created by realicing on 2018/12/6.
- * realicing@sina.com
- */
-public class PluginUtil {
-
-//    public static final String[] ABIS = { "armeabi-v7a", "arm64-v8a", "x86", "mips", "x86_64", "armeabi"};
-    public static final String[] ABIS = { "armeabi-v7a", "arm64-v8a", "x86"};
-    public static Observable<Plugin> startPlugin(Plugin plugin) {
-        return Observable.create((ObservableOnSubscribe<Plugin>) emitter -> {
-//            if(TextUtils.equals(getCPU_ABI(), "x86") && TestUtil.isSheep()){
-//                emitter.onError(new Throwable("暂不支持该设备"));
-//                return;
-//            }
-            int downloadPluginState = DataUtil.getAsInt(getDownloadPluginKey(plugin), DownloadUtil.STATUS_INIT);
-            switch (downloadPluginState){
-                case DownloadUtil.STATUS_FINISH:
-                    if (PluginManager.getInstance(SheepApp.getInstance()).getLoadedPlugin(plugin.getPackageName()) == null) {
-//                String cpuAbi = getCPU_ABI();
-//                String pluginPath = String.format(Locale.CHINA, "%s/media_%s.apk", ClassFileHelper.DIR, cpuAbi);
-                        String pluginPath = ClassFileHelper.DIR + "/media_release.apk";
-//                LogUtil.println(PluginUtil.class.getSimpleName(), "CPU_ABI =", cpuAbi, "pluginPath =", pluginPath);
-                        File file = new File(pluginPath);
-                        boolean isUserTestFile = TestUtil.isTest() && file.exists();
-                        LogUtil.println("startPlugin", isUserTestFile);
-                        File pluginFile = isUserTestFile ? file : getFile(plugin);
-                        if(!pluginFile.exists()){
-                            emitter.onError(new Throwable("更新数据中,请稍候再试"));
-                            return;
-                        }
-                        try {
-                            PluginManager.getInstance(SheepApp.getInstance()).loadPlugin(pluginFile);
-                            emitter.onNext(plugin);
-                        } catch (Exception e) {
-                            e.printStackTrace();
-                            emitter.onError(e);
-                        }
-                    } else {
-                        emitter.onNext(plugin);
-                    }
-                    break;
-                case DownloadUtil.STATUS_ING:
-                    emitter.onError(new Throwable("更新数据中,请稍候再试"));
-                    break;
-                case DownloadUtil.STATUS_INIT:
-                    initPlugin();
-                    emitter.onError(new Throwable("更新数据中,请稍候再试"));
-                    break;
-                case DownloadUtil.STATUS_FAIL:
-                default:
-                    emitter.onError(new Throwable("敬请期待"));
-                    break;
-            }
-        }).subscribeOn(Schedulers.io());
-    }
-
-    /**
-     * 根据系统的cpu_abi来获取最接近的cpu_abi
-     * @return
-     */
-    public static String getCPU_ABI() {
-        String CPU_ABI = android.os.Build.CPU_ABI;
-        if(!ListUtil.contains(ABIS, CPU_ABI)){
-            LogUtil.println(PluginUtil.class.getSimpleName(), "not contains", CPU_ABI);
-            CPU_ABI = ABIS[0];
-        }
-        return CPU_ABI;
-//        return "x86";
-    }
-
-
-    //初始化插件
-    public static void initPlugin() {
-        Plugin plugin = Plugin.media;
-        String packageName = plugin.getPackageName();
-        String type = PluginUtil.getCPU_ABI();
-        int versionCode = BuildConfig.VERSION_CODE;
-        SheepApp.getInstance().getNetComponent().getApiService().getPackageVersion(packageName, type, versionCode)
-                .subscribeOn(Schedulers.io())
-                .observeOn(AndroidSchedulers.mainThread())
-                .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.getInstance()) {
-                    @Override
-                    public void onNext(BaseMessage baseMessage) {
-                        LogUtil.println("initPlugin", JSONObject.toJSONString(baseMessage.getData()));
-                        ClientPackage result = baseMessage.getData(ClientPackage.class);
-                        if(result != null && result.getMd_5() != null){
-                            String key = ApiKey.getPackageVersion(packageName, type, versionCode);
-                            File file = getFile(key);
-                            if(file.exists()){
-                                if(Md5Util.checkMD5(result.getMd_5(), file)){
-                                    DataUtil.putAsInt(getDownloadPluginKey(plugin), DownloadUtil.STATUS_FINISH);
-                                    return;
-                                }
-                            }
-                            downloadPlugin(result.getDowload_url(), plugin);
-                        }
-//                        boolean isNewData = DataUtil.getInstance().isNewData(key);
-//                        if(isNewData){
-//
-//                        }
-                    }
-
-                    @Override
-                    public void onError(BaseMessage baseMessage) {
-                        if(TestUtil.isDev()) G.showToast(baseMessage);
-                    }
-                });
-    }
-
-    private static void downloadPlugin(String dowload_url, Plugin plugin) {
-        DataUtil.putAsInt(getDownloadPluginKey(plugin), DownloadUtil.STATUS_ING);
-        OkHttpUtils.get().url(dowload_url).build().execute(new FileCallBack(getDirPath(), getFileName(plugin)) {
-            @Override
-            public void inProgress(float progress, long total, int id) {
-                LogUtil.println("downloadPlugin", dowload_url, String.format(Locale.CHINA, "%d%%", Math.round(progress * 100)));
-            }
-
-            @Override
-            public void onError(Call call, Exception e, int id) {
-                LogUtil.println("downloadPlugin", dowload_url, "下载失败");
-                DataUtil.putAsInt(getDownloadPluginKey(plugin), DownloadUtil.STATUS_FAIL);
-            }
-
-            @Override
-            public void onResponse(File response, int id) {
-                LogUtil.println("downloadPlugin", dowload_url, "下载完成");
-                DataUtil.putAsInt(getDownloadPluginKey(plugin), DownloadUtil.STATUS_FINISH);
-            }
-        });
-    }
-
-    public static File getDir() {
-        return SheepApp.getInstance().getDir("plugin", Context.MODE_PRIVATE);
-    }
-
-    public static String getDirPath() {
-        return SheepApp.getInstance().getDir("plugin", Context.MODE_PRIVATE).getPath();
-    }
-    public static File getFile(Plugin plugin) {
-        String key = getKey(plugin);
-        return getFile(key);
-    }
-    public static String getDownloadPluginKey(Plugin plugin){
-        return "download_plugin_" + getKey(plugin);
-    }
-    public static String getKey(Plugin plugin){
-        String packageName = plugin.getPackageName();
-        String type = PluginUtil.getCPU_ABI();
-        int versionCode = BuildConfig.VERSION_CODE;
-        return ApiKey.getPackageVersion(packageName, type, versionCode);
-    }
-    public static String getFileName(Plugin plugin) {
-        String key = getKey(plugin);
-        return key.hashCode()+".apk";
-    }
-    public static File getFile(String key) {
-        return new File(getDir(), key.hashCode()+".apk");
-    }
-}

+ 227 - 0
app/src/main/java/com/sheep/gamegroup/module/plugin/util/SheepPluginUtil.java

@@ -0,0 +1,227 @@
+package com.sheep.gamegroup.module.plugin.util;
+
+import android.app.Activity;
+import android.content.Context;
+import android.text.TextUtils;
+
+import com.alibaba.fastjson.JSONObject;
+import com.didi.virtualapk.PluginManager;
+import com.didi.virtualapk.internal.LoadedPlugin;
+import com.didi.virtualapk.internal.utils.PluginUtil;
+import com.sheep.gamegroup.absBase.AbsObserver;
+import com.sheep.gamegroup.model.entity.BaseMessage;
+import com.sheep.gamegroup.model.util.SheepSubscriber;
+import com.sheep.gamegroup.module.plugin.model.ClientPackage;
+import com.sheep.gamegroup.module.plugin.model.Plugin;
+import com.sheep.gamegroup.util.DataUtil;
+import com.sheep.gamegroup.util.DownloadUtil;
+import com.sheep.gamegroup.util.ListUtil;
+import com.sheep.gamegroup.util.LogUtil;
+import com.sheep.gamegroup.util.Md5Util;
+import com.sheep.gamegroup.util.TestUtil;
+import com.sheep.gamegroup.util.ViewUtil;
+import com.sheep.gamegroup.view.dialog.DialogProgress;
+import com.sheep.jiuyan.samllsheep.BuildConfig;
+import com.sheep.jiuyan.samllsheep.SheepApp;
+import com.sheep.jiuyan.samllsheep.utils.ClassFileHelper;
+import com.sheep.jiuyan.samllsheep.utils.G;
+import com.zhy.http.okhttp.OkHttpUtils;
+import com.zhy.http.okhttp.callback.FileCallBack;
+
+import org.afinal.simplecache.ApiKey;
+
+import java.io.File;
+import java.util.Locale;
+
+import io.reactivex.Observable;
+import io.reactivex.ObservableEmitter;
+import io.reactivex.ObservableOnSubscribe;
+import io.reactivex.ObservableSource;
+import io.reactivex.android.schedulers.AndroidSchedulers;
+import io.reactivex.functions.Function;
+import io.reactivex.functions.Predicate;
+import io.reactivex.schedulers.Schedulers;
+import okhttp3.Call;
+
+/**
+ * Created by realicing on 2018/12/6.
+ * realicing@sina.com
+ */
+public class SheepPluginUtil {
+
+    //    public static final String[] ABIS = { "armeabi-v7a", "arm64-v8a", "x86", "mips", "x86_64", "armeabi"};
+    public static final String[] ABIS = {"armeabi-v7a", "arm64-v8a", "x86"};
+
+    //检查并更新插件
+    public static Observable<Plugin> checkAndRunPlugin(Activity activity, Plugin plugin) {
+        return Observable.create((ObservableOnSubscribe<Plugin>) emitter -> {
+            String packageName = plugin.getPackageName();
+            String type = SheepPluginUtil.getCPU_ABI();
+            int versionCode = BuildConfig.VERSION_CODE;
+            SheepApp.getInstance().getNetComponent().getApiService().getPackageVersion(packageName, type, versionCode)
+                    .subscribeOn(Schedulers.io())
+                    .map(baseMessage -> {
+                        LogUtil.println("initPlugin", JSONObject.toJSONString(baseMessage.getData()));
+                        return baseMessage.getData(ClientPackage.class);
+                    })
+                    .map(clientPackage -> {
+                        if (clientPackage != null && clientPackage.getMd_5() != null) {
+                            String key = ApiKey.getPackageVersion(packageName, type, versionCode);
+                            File file = getFile(key);
+                            if (file.exists()) {
+                                if (Md5Util.checkMD5(clientPackage.getMd_5(), file)) {
+                                    return null;
+                                }
+                            }
+                            return clientPackage.getDowload_url();
+                        }
+                        return null;
+                    })
+                    .subscribeOn(Schedulers.io())
+                    .observeOn(AndroidSchedulers.mainThread())
+                    .subscribe(new AbsObserver<String>(){
+                        @Override
+                        public void onNext(String downloadUrl) {
+                            downloadPlugin(activity, emitter, downloadUrl, plugin);
+                        }
+
+                        @Override
+                        public void onError(Throwable e) {
+                            e.printStackTrace();
+                            new Thread(() -> emitter.onNext(plugin)).start();
+                        }
+                    });
+        }).subscribeOn(Schedulers.io())
+                .filter(plugin1 -> {
+                    if (PluginManager.getInstance(SheepApp.getInstance()).getLoadedPlugin(plugin1.getPackageName()) == null) {
+//                String cpuAbi = getCPU_ABI();
+//                String pluginPath = String.format(Locale.CHINA, "%s/media_%s.apk", ClassFileHelper.DIR, cpuAbi);
+                        String pluginPath = ClassFileHelper.DIR + "/media_release.apk";
+//                LogUtil.println(PluginUtil.class.getSimpleName(), "CPU_ABI =", cpuAbi, "pluginPath =", pluginPath);
+                        File file = new File(pluginPath);
+                        boolean isUserTestFile = TestUtil.isTest() && file.exists();
+                        LogUtil.println("startPlugin", isUserTestFile);
+                        File pluginFile = isUserTestFile ? file : getFile(plugin1);
+                        if (!pluginFile.exists()) {
+                            return false;
+                        }
+                        try {
+                            PluginManager.getInstance(SheepApp.getInstance()).loadPlugin(pluginFile);
+                        } catch (Exception e) {
+                            e.printStackTrace();
+                            return false;
+                        }
+                    }
+                    return true;
+                });
+    }
+
+    /**
+     * 根据系统的cpu_abi来获取最接近的cpu_abi
+     *
+     * @return
+     */
+    public static String getCPU_ABI() {
+        String CPU_ABI = android.os.Build.CPU_ABI;
+        if (!ListUtil.contains(ABIS, CPU_ABI)) {
+            LogUtil.println(SheepPluginUtil.class.getSimpleName(), "not contains", CPU_ABI);
+            CPU_ABI = ABIS[0];
+        }
+        return CPU_ABI;
+//        return "x86";
+    }
+
+
+    //下载插件
+    private static void downloadPlugin(Activity activity, ObservableEmitter<Plugin> emitter, String downloadUrl, Plugin plugin) {
+        if(TextUtils.isEmpty(downloadUrl)){
+            emitter.onNext(plugin);
+            return;
+        }
+        DialogProgress dialogProgress = DialogProgress.showDialog(activity, false);
+        ViewUtil.setText(dialogProgress.getTextView(), "更新中,请稍等");
+        DataUtil.putAsInt(getDownloadPluginKey(plugin), DownloadUtil.STATUS_ING);
+        OkHttpUtils.get().url(downloadUrl).build().execute(new FileCallBack(getDirPath(), getFileName(plugin)) {
+            private int lastProgress = -1;
+            @Override
+            public void inProgress(float percent, long total, int id) {
+                int progress = Math.round(percent * 100);
+                String progressText = String.format(Locale.CHINA, "%d%%", progress);
+                LogUtil.println("downloadPlugin", downloadUrl, progressText);
+                if(progress > lastProgress) {
+                    ViewUtil.setText(dialogProgress.getTextView(), progressText);
+                    lastProgress = progress;
+                }
+            }
+
+            @Override
+            public void onError(Call call, Exception e, int id) {
+                LogUtil.println("downloadPlugin", downloadUrl, "下载失败");
+                if (TestUtil.isDev()) {
+                    ViewUtil.setText(dialogProgress.getTextView(), "下载失败");
+                    ViewUtil.delay(new AbsObserver<Integer>() {
+                        @Override
+                        public void onComplete() {
+                            dialogProgress.getAlertDialog().dismiss();
+                            new Thread(() -> emitter.onNext(plugin)).start();
+                        }
+                    }, 1);
+                } else {
+                    dialogProgress.getAlertDialog().dismiss();
+                    new Thread(() -> emitter.onNext(plugin)).start();
+                }
+            }
+
+            @Override
+            public void onResponse(File response, int id) {
+                LogUtil.println("downloadPlugin", downloadUrl, "下载完成");
+                if (TestUtil.isDev()) {
+                    ViewUtil.setText(dialogProgress.getTextView(), "下载完成");
+                    ViewUtil.delay(new AbsObserver<Integer>() {
+                        @Override
+                        public void onComplete() {
+                            dialogProgress.getAlertDialog().dismiss();
+                            new Thread(() -> emitter.onNext(plugin)).start();
+                        }
+                    }, 1);
+                } else {
+                    dialogProgress.getAlertDialog().dismiss();
+                    new Thread(() -> emitter.onNext(plugin)).start();
+                }
+            }
+        });
+    }
+
+    public static File getDir() {
+        return SheepApp.getInstance().getDir("plugin", Context.MODE_PRIVATE);
+    }
+
+    public static String getDirPath() {
+        return SheepApp.getInstance().getDir("plugin", Context.MODE_PRIVATE).getPath();
+    }
+
+    public static File getFile(Plugin plugin) {
+        String key = getKey(plugin);
+        return getFile(key);
+    }
+
+    public static String getDownloadPluginKey(Plugin plugin) {
+        return "download_plugin_" + getKey(plugin);
+    }
+
+    public static String getKey(Plugin plugin) {
+        String packageName = plugin.getPackageName();
+        String type = SheepPluginUtil.getCPU_ABI();
+        int versionCode = BuildConfig.VERSION_CODE;
+        return ApiKey.getPackageVersion(packageName, type, versionCode);
+    }
+
+    public static String getFileName(Plugin plugin) {
+        String key = getKey(plugin);
+        return key.hashCode() + ".apk";
+    }
+
+    public static File getFile(String key) {
+        return new File(getDir(), key.hashCode() + ".apk");
+    }
+}

+ 3 - 4
app/src/main/java/com/sheep/gamegroup/util/Jump2View.java

@@ -7,9 +7,7 @@ import android.content.pm.PackageManager;
 import android.net.Uri;
 import android.os.Build;
 import android.os.Bundle;
-import android.os.Handler;
 import android.text.TextUtils;
-import android.util.Log;
 import android.view.Gravity;
 import android.view.View;
 
@@ -53,7 +51,7 @@ import com.sheep.gamegroup.module.find.activity.ActMediaChoose;
 import com.sheep.gamegroup.module.login.ChangePasswordAct;
 import com.sheep.gamegroup.module.login.LoginAct;
 import com.sheep.gamegroup.module.plugin.model.Plugin;
-import com.sheep.gamegroup.module.plugin.util.PluginUtil;
+import com.sheep.gamegroup.module.plugin.util.SheepPluginUtil;
 import com.sheep.gamegroup.util.share.ShareLinkConfig;
 import com.sheep.gamegroup.view.activity.ActApprenticeRedPacket;
 import com.sheep.gamegroup.view.activity.ActArticleComment;
@@ -2309,7 +2307,7 @@ public class Jump2View {
      * @param data 视频数据,包括地址与时长,宽高等
      */
     public void goActCutVideo(Activity activity, Video data) {
-        PluginUtil.startPlugin(Plugin.media)
+        SheepPluginUtil.checkAndRunPlugin(activity, Plugin.media)
                 .flatMap((Function<Plugin, ObservableSource<BaseMessage>>) plugin -> SheepApp.getInstance().getNetComponent().getApiService().getVideoTopic())
                 .subscribeOn(Schedulers.io())
                 .observeOn(AndroidSchedulers.mainThread())
@@ -2327,6 +2325,7 @@ public class Jump2View {
 
                     @Override
                     public void onError(Throwable e) {
+                        e.printStackTrace();
                         G.showToast(e.getMessage());
                     }
                 });

+ 2 - 2
app/src/main/java/com/sheep/gamegroup/util/TestUtil.java

@@ -41,7 +41,7 @@ import com.sheep.gamegroup.model.entity.UserEntity;
 import com.sheep.gamegroup.model.entity.Video;
 import com.sheep.gamegroup.model.util.SheepSubscriber;
 import com.sheep.gamegroup.module.plugin.model.Plugin;
-import com.sheep.gamegroup.module.plugin.util.PluginUtil;
+import com.sheep.gamegroup.module.plugin.util.SheepPluginUtil;
 import com.sheep.gamegroup.usage.AppUsageManager;
 import com.sheep.gamegroup.view.activity.ActInstallApkList;
 import com.sheep.gamegroup.view.activity.ActMain;
@@ -618,7 +618,7 @@ public class TestUtil {
 
     //测试插件
     private static void testPlugin(Activity activity) {
-        PluginUtil.startPlugin(Plugin.media)
+        SheepPluginUtil.checkAndRunPlugin(activity, Plugin.media)
                 .subscribeOn(Schedulers.io())
                 .observeOn(AndroidSchedulers.mainThread())
                 .subscribe(new AbsObserver<Plugin>(){

+ 0 - 5
app/src/main/java/com/sheep/jiuyan/samllsheep/SheepApp.java

@@ -3,7 +3,6 @@ package com.sheep.jiuyan.samllsheep;
 import android.app.Activity;
 import android.content.Context;
 import android.content.Intent;
-import android.os.Build;
 import android.os.Bundle;
 import android.os.StrictMode;
 import android.support.multidex.MultiDex;
@@ -24,7 +23,6 @@ import com.sheep.gamegroup.di.components.DaggerNetComponent;
 import com.sheep.gamegroup.di.components.NetComponent;
 import com.sheep.gamegroup.di.modules.NetModule;
 import com.sheep.gamegroup.module.login.LoginAct;
-import com.sheep.gamegroup.module.plugin.util.PluginUtil;
 import com.sheep.gamegroup.usage.AppUsageManager;
 import com.sheep.gamegroup.util.AppUtil;
 import com.sheep.gamegroup.util.CertificationUtil;
@@ -39,7 +37,6 @@ import com.sheep.gamegroup.util.MyFileNameGenerator;
 import com.sheep.gamegroup.util.RefreshUtil;
 import com.sheep.gamegroup.util.SysAppUtil;
 import com.sheep.gamegroup.util.UMConfigUtils;
-import com.sheep.gamegroup.view.activity.ActMain;
 import com.sheep.gamegroup.view.activity.GameCertificationActivity;
 import com.sheep.jiuyan.samllsheep.service.AutoCheckService;
 import com.sheep.jiuyan.samllsheep.service.DownloadService;
@@ -409,8 +406,6 @@ public class SheepApp extends MultiDexApplication {
                 SysAppUtil.showVersionInfo(activity, SpUtils.getIgnoreMd5());
             } else if (YmConfig.isAvf(activity)) {
                 YmConfig.showTipDialog(activity, YmConfig.TYPE_ADD_VIEW);
-            } else if (activity instanceof ActMain) {//进入主页时检查插件更新
-                PluginUtil.initPlugin();
             }
 
             if (mActivityCount == 0) {