Kaynağa Gözat

fixbug:修复版本更新判断错误的问题

Sora 1 yıl önce
ebeveyn
işleme
93b2ca74da

+ 172 - 149
app/src/main/java/com/sheep/gamegroup/util/SysAppUtil.java

@@ -1,5 +1,7 @@
 package com.sheep.gamegroup.util;
 
+import static com.sheep.gamegroup.util.UMConfigUtils.Event.UPGRADE_DIALOG_BT;
+
 import android.app.Activity;
 import android.app.Dialog;
 import android.app.PendingIntent;
@@ -23,9 +25,6 @@ import android.graphics.drawable.Icon;
 import android.net.Uri;
 import android.os.Build;
 import android.provider.AlarmClock;
-import androidx.core.content.pm.ShortcutInfoCompat;
-import androidx.core.content.pm.ShortcutManagerCompat;
-import androidx.core.graphics.drawable.IconCompat;
 import android.text.TextUtils;
 import android.text.format.Formatter;
 import android.util.Log;
@@ -33,6 +32,11 @@ import android.view.Gravity;
 import android.view.View;
 import android.widget.TextView;
 
+import androidx.annotation.RequiresApi;
+import androidx.core.content.pm.ShortcutInfoCompat;
+import androidx.core.content.pm.ShortcutManagerCompat;
+import androidx.core.graphics.drawable.IconCompat;
+
 import com.alibaba.fastjson.JSON;
 import com.allen.android.lib.rom.HuaweiUtils;
 import com.allen.android.lib.rom.MeizuUtils;
@@ -78,7 +82,6 @@ import java.util.List;
 import java.util.Locale;
 import java.util.regex.Pattern;
 
-import androidx.annotation.RequiresApi;
 import io.reactivex.Observable;
 import io.reactivex.android.schedulers.AndroidSchedulers;
 import io.reactivex.functions.Function;
@@ -87,8 +90,6 @@ import okhttp3.Call;
 import ren.yale.android.cachewebviewlib.WebViewCacheInterceptorInst;
 import rx.functions.Action1;
 
-import static com.sheep.gamegroup.util.UMConfigUtils.Event.UPGRADE_DIALOG_BT;
-
 /**
  * Created by realicing on 2018/5/29.
  * realicing@sina.com
@@ -96,9 +97,10 @@ import static com.sheep.gamegroup.util.UMConfigUtils.Event.UPGRADE_DIALOG_BT;
 public class SysAppUtil {
 
     private static Dialog dialog;
-    public static void startAlermApp(Context context, String msg, int hour, int min){
+
+    public static void startAlermApp(Context context, String msg, int hour, int min) {
         boolean notDone = true;
-        if(Build.VERSION.SDK_INT > 18) {
+        if (Build.VERSION.SDK_INT > 18) {
             try {
                 Intent intent = new Intent(AlarmClock.ACTION_SET_ALARM);
                 intent.putExtra(AlarmClock.EXTRA_MESSAGE, msg);
@@ -123,23 +125,24 @@ public class SysAppUtil {
                 e.printStackTrace();
             }
         }
-        if(notDone){
+        if (notDone) {
             G.showToast(R.string.coming_soon);
         }
     }
 
     /**
      * 是否第一次运行新的小绵羊
+     *
      * @return
      */
     public static boolean isNewSmallSheep() {
-        if(DataUtil.getInstance().notInitVersion()){
+        if (DataUtil.getInstance().notInitVersion()) {
             int version_code = ForeverCacheUtil.getInstance().getVersionCode();
             int cur_version_code = 3000005;//要想发新版本后让用户显示引导页面,就直接修改为一个更大的值
             ForeverCacheUtil.getInstance().saveVersionCode(cur_version_code);
             boolean isNewSmallSheep = version_code != cur_version_code
 //                || BuildConfig.DEBUG
-                ;
+                    ;
             DataUtil.getInstance().setIsNewSmallSheep(isNewSmallSheep);
         }
         return DataUtil.getInstance().isNewSmallSheep();
@@ -161,6 +164,7 @@ public class SysAppUtil {
                 .observeOn(AndroidSchedulers.mainThread())
                 .subscribe(action1);
     }
+
     public static String getAppCacheSize() {
         try {
 //            File filesDir = SheepApp.getInstance().getExternalFilesDir(null);
@@ -170,18 +174,19 @@ public class SysAppUtil {
             long screenShotsSize = getFolderSize(DataUtil.getScreenShotsDir());
             long apkSize = getFolderSize(new File(ClassFileHelper.DIR));
             File cacheDirPath = SheepApp.getInstance().getCacheDir();
-            long glideSize = getFolderSize(new File( cacheDirPath, InternalCacheDiskCacheFactory.DEFAULT_DISK_CACHE_DIR));
+            long glideSize = getFolderSize(new File(cacheDirPath, InternalCacheDiskCacheFactory.DEFAULT_DISK_CACHE_DIR));
             return getFormatSize(//filesDirSize+cacheSize+
-                    screenShotsSize+apkSize+glideSize);
+                    screenShotsSize + apkSize + glideSize);
         } catch (Exception e) {
             e.printStackTrace();
         }
         return null;
     }
+
     // 获取文件大小
     //Context.getExternalFilesDir() --> SDCard/Android/data/你的应用的包名/files/ 目录,一般放一些长时间保存的数据
     //Context.getExternalCacheDir() --> SDCard/Android/data/你的应用包名/cache/目录,一般存放临时缓存数据
-    public static long getFolderSize(File file){
+    public static long getFolderSize(File file) {
         long size = 0;
         try {
             File[] fileList = file.listFiles();
@@ -201,6 +206,7 @@ public class SysAppUtil {
 
     /**
      * 格式化单位
+     *
      * @param size
      * @return
      */
@@ -235,6 +241,7 @@ public class SysAppUtil {
         return result4.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString()
                 + "TB";
     }
+
     public static String getFileFormatSize(double size) {
         double kiloByte = size / 1024;
         if (kiloByte < 1) {
@@ -265,11 +272,13 @@ public class SysAppUtil {
         return result4.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString()
                 + "TB";
     }
+
     /**
      * 返回正确的UserAgent
+     *
      * @return
      */
-    public  static String getUserAgent(){
+    public static String getUserAgent() {
         StringBuilder sb = null;
         try {
             String userAgent;
@@ -318,7 +327,7 @@ public class SysAppUtil {
 //                });
     }
 
-    public static List<AppInfo> getAppInfos(){
+    public static List<AppInfo> getAppInfos() {
         //首先获取到包的管理者
         PackageManager packageManager = SheepApp.getInstance().getPackageManager();
         //获取到所有的安装包
@@ -331,7 +340,7 @@ public class SysAppUtil {
     }
 
     public static AppInfo getAppInfo(PackageManager packageManager, PackageInfo item) {
-        if(item == null){
+        if (item == null) {
             return null;
         }
         AppInfo appInfo = new AppInfo();
@@ -351,24 +360,24 @@ public class SysAppUtil {
         //获取到安装apk的大小
         long apkSize = file.length();
         //格式化apk的大小
-        appInfo.setApkSize(Formatter.formatFileSize(SheepApp.getInstance(),apkSize));
+        appInfo.setApkSize(Formatter.formatFileSize(SheepApp.getInstance(), apkSize));
         appInfo.setSha1(getSHA1(item));
 
         int flags = item.applicationInfo.flags;
         //判断当前是否是系统app
-        if((flags & ApplicationInfo.FLAG_SYSTEM) !=0){
+        if ((flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
             //那么就是系统app
             appInfo.setUserApp(false);
-        }else{
+        } else {
             //那么就是用户app
             appInfo.setUserApp(true);
         }
 
-        if((flags & ApplicationInfo.FLAG_EXTERNAL_STORAGE)!=0){
+        if ((flags & ApplicationInfo.FLAG_EXTERNAL_STORAGE) != 0) {
             //那么当前安装的就是sd卡
             appInfo.setSD(true);
 
-        }else{
+        } else {
             //那么就是手机内存
             appInfo.setSD(false);
         }
@@ -391,7 +400,7 @@ public class SysAppUtil {
                 hexString.append(":");
             }
             String result = hexString.toString();
-            return result.substring(0, result.length()-1);
+            return result.substring(0, result.length() - 1);
         } catch (NoSuchAlgorithmException e) {
             e.printStackTrace();
         }
@@ -405,12 +414,12 @@ public class SysAppUtil {
             BufferedReader br = new BufferedReader(new InputStreamReader(
                     p.getInputStream()));
             String readLine;
-            while((readLine = br.readLine()) != null) {
+            while ((readLine = br.readLine()) != null) {
                 LogUtil.println("execShell", "getInputStream", readLine);
             }
             BufferedReader errorBr = new BufferedReader(new InputStreamReader(
                     p.getErrorStream()));
-            while((readLine = errorBr.readLine()) != null) {
+            while ((readLine = errorBr.readLine()) != null) {
                 LogUtil.println("execShell", "getErrorStream", readLine);
             }
             br.close();
@@ -451,36 +460,35 @@ public class SysAppUtil {
     }
 
 
-
-
-
     /**
      * 显示升级对话框
+     *
      * @param ignoreMd5 用户手动时传null;进入主要界面时不要传null,传保存的忽略md5值,为空字符串时传""
      */
     public static void showVersionInfo(Activity activity, final String ignoreMd5) {
         /**
          *游戏认证过来的不提示升级
          */
-        if(!TextUtils.isEmpty(SheepApp.getInstance().getGamePackgeName()))
+        if (!TextUtils.isEmpty(SheepApp.getInstance().getGamePackgeName()))
             return;
         showVersionInfo(activity, ignoreMd5, null);
     }
 
     /**
      * 显示升级对话框
+     *
      * @param ignoreMd5 用户手动时传null;进入主要界面时不要传null,传保存的忽略md5值,为空字符串时传""
-     * @param action1 动作完成后的回调
+     * @param action1   动作完成后的回调
      */
     public static void showVersionInfo(Activity activity, final String ignoreMd5, final Action1<Integer> action1) {
-        if(!ConfigUtil.getInstance().isUpgrade()) {
-            if(action1 != null)
+        if (!ConfigUtil.getInstance().isUpgrade()) {
+            if (action1 != null)
                 action1.call(0);
             return;
         }
-        if(dialog != null){
+        if (dialog != null) {
             try {
-                if(dialog.isShowing()) {
+                if (dialog.isShowing()) {
                     dialog.dismiss();
                 }
             } catch (Exception e) {
@@ -494,6 +502,7 @@ public class SysAppUtil {
 //            TestUtil.checkUpdateFromJenkins(ignoreMd5, action1);
 //        }
     }
+
     //通过接口检查更新
     public static void checkUpdateNewVersion(Activity activity, final String ignoreMd5, final Action1<Integer> action1) {
         SheepApp.getInstance().getNetComponent().getApiService().getNewVersion(SheepApp.getInstance().getConnectAddress().getVersionType())
@@ -502,8 +511,13 @@ public class SysAppUtil {
                 .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.getInstance()) {
                     @Override
                     public void onNext(BaseMessage baseMessage) {
+
                         Version version = baseMessage.getData(Version.class);
-                        loadVersion(activity, ignoreMd5, action1, version);
+                        int versionCode = ApkUtils.getCurrentPkgVersionCode(activity);
+                        if (versionCode >= version.getVersion_number()) {
+                        } else {
+                            loadVersion(activity, ignoreMd5, action1, version);
+                        }
                     }
 
                     @Override
@@ -518,18 +532,18 @@ public class SysAppUtil {
     }
 
     private static void loadVersion(Activity activity, final String ignoreMd5, final Action1<Integer> action1, final Version version) {
-        if(version == null){
-            if(ignoreMd5 == null)
+        if (version == null) {
+            if (ignoreMd5 == null)
                 G.showToast("当前版本为最新版本,无需更新");
-            if(action1 != null)
+            if (action1 != null)
                 action1.call(0);
             return;
         }
         boolean isNewApp;
-        if(TestUtil.isSheep()) {
-            if(ignoreMd5 != null && TextUtils.equals(ignoreMd5, version.getVersion_number()+"") && !version.isForceUpdate()){
+        if (TestUtil.isSheep()) {
+            if (ignoreMd5 != null && TextUtils.equals(ignoreMd5, version.getVersion_number() + "") && !version.isForceUpdate()) {
                 LogUtil.println("showVersionInfo", "忽略", ignoreMd5, version.getVersion_name());
-                if(action1 != null)
+                if (action1 != null)
                     action1.call(0);
                 return;
             }
@@ -543,9 +557,9 @@ public class SysAppUtil {
             }
             isNewApp = versionCode >= version.getVersion_number();
         } else {
-            if(ignoreMd5 != null && TextUtils.equals(ignoreMd5, version.getMd5_address()) && !version.isForceUpdate()){
+            if (ignoreMd5 != null && TextUtils.equals(ignoreMd5, version.getMd5_address()) && !version.isForceUpdate()) {
                 LogUtil.println("showVersionInfo", "忽略", ignoreMd5, version.getVersion_name());
-                if(action1 != null)
+                if (action1 != null)
                     action1.call(0);
                 return;
             }
@@ -559,11 +573,11 @@ public class SysAppUtil {
             }
             isNewApp = fileMD5.equalsIgnoreCase(version.getMd5_address());
         }
-        if(isNewApp){//已经是最新版本
+        if (isNewApp) {//已经是最新版本
             ACache.get(SheepApp.getInstance()).put("version_url", "");
-            if(ignoreMd5 == null)
+            if (ignoreMd5 == null)
                 G.showToast("当前版本为最新版本,无需更新");
-            if(action1 != null)
+            if (action1 != null)
                 action1.call(0);
         } else {//有新版本
             showUpgradeByVersion(activity, version, action1);
@@ -571,77 +585,79 @@ public class SysAppUtil {
     }
 
     public static void showUpgradeByVersion(Activity activity, Version version, Action1<Integer> action1) {
-        if(!TextUtils.isEmpty(version.getAddress()))
+        if (!TextUtils.isEmpty(version.getAddress()))
             ACache.get(SheepApp.getInstance()).put("version_url", version.getAddress());
-        final String fileName = version.getMd5_address()+".apk";
+        final String fileName = version.getMd5_address() + ".apk";
         final File file = new File(ClassFileHelper.DIR, fileName);
         DialogConfig dialogConfig = new DialogConfig();
-        dialogConfig.setTitle("小绵羊V"+version.getVersion_name());
-        dialogConfig.setMsg(TextUtils.isEmpty(version.getUpdate_content()) ? "当前版本小绵羊V"+getConnectAdrressPackageInfo().versionName : version.getUpdate_content()).setMsgGravity(Gravity.START)
+        dialogConfig.setTitle("小绵羊V" + version.getVersion_name());
+        dialogConfig.setMsg(TextUtils.isEmpty(version.getUpdate_content()) ? "当前版本小绵羊V" + getConnectAdrressPackageInfo().versionName : version.getUpdate_content()).setMsgGravity(Gravity.START)
                 .setBtnLeftText(file.exists() ? "立即安装" : "立即更新").setBtnLeftNotDissDialog(true).setBtnLeftOnClickListener(new View.OnClickListener() {
-            private void installApk(File file){
-                if(file != null && file.exists()) {
-                    //升级后继承渠道
-                    String channel = ChannelContent.getInstance().getChannel_name();
-                    try {
-                        if(!TextUtils.isEmpty(channel) && !ZipChannelUtil.isAddQUA(file)){
-                            ZipChannelUtil.writeQUA(file, channel);
-                        }
-                    } catch (IOException e) {
-                        e.printStackTrace();
-                    }
-                    ApkUtils.installApk(SheepApp.getInstance(), file.getAbsolutePath());
-                }
-            }
-            @Override
-            public void onClick(final View view) {
-                if(view instanceof TextView)
-                    UPGRADE_DIALOG_BT.onEvent("action", ((TextView) view).getText());
-                if(file.exists() && Md5Util.checkMD5(version.getMd5_address(), file)){//文件存在并且md5值相同则直接安装
-                    installApk(file);
-                } else if(TextUtils.isEmpty(version.getAddress())){//地址错误
-                    G.showToast(R.string.error_download_link);
-                } else {//下载安装
-                    OkHttpUtils.get().url(version.getAddress()).build().execute(new FileCallBack(ClassFileHelper.DIR, fileName) {
-                        @Override
-                        public void inProgress(float progress, long total, int id) {
-                            if(view instanceof TextView) {
-                                TextView btnLeftTextView = (TextView) view;
-                                btnLeftTextView.setEnabled(false);
-                                btnLeftTextView.setText(String.format(Locale.CHINA, "%d%%", Math.round(progress * 100)));
-                            }
-                        }
-                        @Override
-                        public void onError(Call call, Exception e, int id) {
-                            if(view instanceof TextView) {
-                                TextView btnLeftTextView = (TextView) view;
-                                btnLeftTextView.setEnabled(true);
-                                btnLeftTextView.setText("重新下载");
+                    private void installApk(File file) {
+                        if (file != null && file.exists()) {
+                            //升级后继承渠道
+                            String channel = ChannelContent.getInstance().getChannel_name();
+                            try {
+                                if (!TextUtils.isEmpty(channel) && !ZipChannelUtil.isAddQUA(file)) {
+                                    ZipChannelUtil.writeQUA(file, channel);
+                                }
+                            } catch (IOException e) {
+                                e.printStackTrace();
                             }
+                            ApkUtils.installApk(SheepApp.getInstance(), file.getAbsolutePath());
                         }
+                    }
 
-                        @Override
-                        public void onResponse(File response, int id) {
-                            if(response != null && response.exists()) {
-                                if(view instanceof TextView){
-                                    TextView btnLeftTextView = (TextView) view;
-                                    btnLeftTextView.setEnabled(false);
-                                    btnLeftTextView.setText("安装中...");
+                    @Override
+                    public void onClick(final View view) {
+                        if (view instanceof TextView)
+                            UPGRADE_DIALOG_BT.onEvent("action", ((TextView) view).getText());
+                        if (file.exists() && Md5Util.checkMD5(version.getMd5_address(), file)) {//文件存在并且md5值相同则直接安装
+                            installApk(file);
+                        } else if (TextUtils.isEmpty(version.getAddress())) {//地址错误
+                            G.showToast(R.string.error_download_link);
+                        } else {//下载安装
+                            OkHttpUtils.get().url(version.getAddress()).build().execute(new FileCallBack(ClassFileHelper.DIR, fileName) {
+                                @Override
+                                public void inProgress(float progress, long total, int id) {
+                                    if (view instanceof TextView) {
+                                        TextView btnLeftTextView = (TextView) view;
+                                        btnLeftTextView.setEnabled(false);
+                                        btnLeftTextView.setText(String.format(Locale.CHINA, "%d%%", Math.round(progress * 100)));
+                                    }
                                 }
 
-                                installApk(response);
-                            }
+                                @Override
+                                public void onError(Call call, Exception e, int id) {
+                                    if (view instanceof TextView) {
+                                        TextView btnLeftTextView = (TextView) view;
+                                        btnLeftTextView.setEnabled(true);
+                                        btnLeftTextView.setText("重新下载");
+                                    }
+                                }
+
+                                @Override
+                                public void onResponse(File response, int id) {
+                                    if (response != null && response.exists()) {
+                                        if (view instanceof TextView) {
+                                            TextView btnLeftTextView = (TextView) view;
+                                            btnLeftTextView.setEnabled(false);
+                                            btnLeftTextView.setText("安装中...");
+                                        }
+
+                                        installApk(response);
+                                    }
+                                }
+                            });
                         }
-                    });
-                }
-            }
-        });
-        if(version.isForceUpdate()){//强更
+                    }
+                });
+        if (version.isForceUpdate()) {//强更
             dialogConfig.setCancelable(!TestUtil.isSheep());
         } else {
             dialogConfig.setBtnRightText("下次更新").setBtnRightOnClickListener(view -> {
-                SpUtils.saveIgnoreMd5(TestUtil.isSheep() ? version.getVersion_number()+"" : version.getMd5_address());
-                if(view instanceof TextView)
+                SpUtils.saveIgnoreMd5(TestUtil.isSheep() ? version.getVersion_number() + "" : version.getMd5_address());
+                if (view instanceof TextView)
                     UPGRADE_DIALOG_BT.onEvent("action", ((TextView) view).getText());
             });
         }
@@ -655,9 +671,10 @@ public class SysAppUtil {
     private static PackageInfo getConnectAdrressPackageInfo() {
         return ApkUtils.getPackageInfo(SheepApp.getInstance().getConnectAddress().getPackageName());
     }
+
     public static String getConnectAdrressFileMD5() {
         PackageInfo packageInfo = getConnectAdrressPackageInfo();
-        if(packageInfo == null || TextUtils.isEmpty(packageInfo.applicationInfo.sourceDir)){
+        if (packageInfo == null || TextUtils.isEmpty(packageInfo.applicationInfo.sourceDir)) {
             return "";
         }
         String fileMD5 = Md5Util.getFileMD5(new File(packageInfo.applicationInfo.sourceDir));
@@ -678,25 +695,25 @@ public class SysAppUtil {
     /**
      * bugly 检查更新
      */
-    public static Version checkBuglyUpdate(){
+    public static Version checkBuglyUpdate() {
 //        Beta.checkUpgrade();
         UpgradeInfo upgradeInfo = Beta.getUpgradeInfo();
-        if(upgradeInfo != null) {
+        if (upgradeInfo != null) {
             Version version = new Version();
             version.setAddress(upgradeInfo.apkUrl);
             version.setMd5_address(upgradeInfo.apkMd5);
-            version.setStrong_update(upgradeInfo.upgradeType-1);//version.getStrong_update == 1/upgradeInfo.upgradeType == 2 为强更
-            version.setUpdate_content(upgradeInfo.newFeature+"\n"+upgradeInfo.publishType);
+            version.setStrong_update(upgradeInfo.upgradeType - 1);//version.getStrong_update == 1/upgradeInfo.upgradeType == 2 为强更
+            version.setUpdate_content(upgradeInfo.newFeature + "\n" + upgradeInfo.publishType);
             version.setVersion_name(upgradeInfo.versionName);
             version.setVersion_number(upgradeInfo.versionCode);
-            version.setUpdate_time((int) (upgradeInfo.publishTime/1000));
+            version.setUpdate_time((int) (upgradeInfo.publishTime / 1000));
             return version;
         }
         return null;
     }
 
     //获取设备的信息
-    public static String getUserAgentOrDeviceInfo(){
+    public static String getUserAgentOrDeviceInfo() {
         StringBuilder sb = null;
         try {
             String userAgent;
@@ -721,7 +738,7 @@ public class SysAppUtil {
     /**
      * 获取当前手机系统版本号
      *
-     * @return  系统版本号
+     * @return 系统版本号
      */
     public static String getSystemVersion() {
         return android.os.Build.VERSION.RELEASE;
@@ -765,48 +782,53 @@ public class SysAppUtil {
     /**
      * 获取厂商
      */
-    public static String getDeviceManufacturer(){
+    public static String getDeviceManufacturer() {
         return Build.MANUFACTURER;
     }
+
     /**
      * 获取产品名
      */
-    public static String getDeviceProduct(){
+    public static String getDeviceProduct() {
         return Build.PRODUCT;
     }
+
     /**
      * 获取手机品牌
      */
-    public static String getDeviceBrand(){
+    public static String getDeviceBrand() {
         return Build.BRAND;
     }
+
     /**
      * 获取手机型号
      */
-    public static String getDeviceModel(){
+    public static String getDeviceModel() {
         return Build.MODEL;
     }
+
     /**
      * 获取主板名
      */
-    public static String getDeviceBoard(){
+    public static String getDeviceBoard() {
         return Build.BOARD;
     }
+
     /**
      * 获取设备名
      */
-    public static String getDeviceDevice(){
+    public static String getDeviceDevice() {
         return Build.DEVICE;
     }
+
     /**
      * 获取mac地址
      */
-    public static String getDeviceMac(){
+    public static String getDeviceMac() {
         return MacDeviceUtil.getMac(SheepApp.getInstance());
     }
 
 
-
     /**
      * 启动应用的设置
      */
@@ -864,7 +886,7 @@ public class SysAppUtil {
     //添加有范商城快捷入口
     public static void addShortcut(Activity activity) {
         boolean hasShortcut = SysAppUtil.hasShortcut(SheepApp.getInstance(), Config.YF_SHOP_NAME);
-        if(hasShortcut){
+        if (hasShortcut) {
             showShortcutTip3();
         } else {
             showShortcutTip2();
@@ -874,10 +896,10 @@ public class SysAppUtil {
 
     //添加有范商城快捷入口
     public static void addShortcutTest(Activity activity) {
-        if(installShortCut(activity)){
-        } else if(Build.VERSION.SDK_INT >=  Build.VERSION_CODES.O){
+        if (installShortCut(activity)) {
+        } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
             SysAppUtil.addShortcutTest8(activity);
-        } else if(Build.VERSION.SDK_INT >=  Build.VERSION_CODES.N_MR1){
+        } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
             SysAppUtil.addShortcutTest7(activity);
         } else {
             SysAppUtil.addShortcutTest6(activity);
@@ -885,13 +907,12 @@ public class SysAppUtil {
     }
 
 
-
     @androidx.annotation.RequiresApi(api = Build.VERSION_CODES.O)
     public static void addShortcutTest8(Activity activity) {
         String mShortcutName = Config.YF_SHOP_NAME;
         ShortcutManager shortcutManager = (ShortcutManager) activity.getSystemService(Context.SHORTCUT_SERVICE);
         boolean requestPinShortcutSupported = shortcutManager.isRequestPinShortcutSupported();
-        LogUtil.println("addShortcutTest8", "启动器是否支持固定快捷方式: "+requestPinShortcutSupported);
+        LogUtil.println("addShortcutTest8", "启动器是否支持固定快捷方式: " + requestPinShortcutSupported);
 
         if (requestPinShortcutSupported) {
 
@@ -917,6 +938,7 @@ public class SysAppUtil {
     public static void showShortcutTip2() {
         G.showToast("已尝试添加有范商城到桌面,若添加失败,请打开小绵羊\"创建桌面快捷方式\"的权限");
     }
+
     public static void showShortcutTip3() {
         G.showToast("添加有范商城到桌面成功,若添加失败,请打开小绵羊\"创建桌面快捷方式\"的权限");
     }
@@ -992,7 +1014,9 @@ public class SysAppUtil {
         // 为某个包创建快捷方式
         // ShortcutSuperUtils.addShortcutByPackageName(this, this.getPackageName());
     }
+
     public static final Class<? extends Activity> yfCls = ActWebX5YF.class;
+
     private static Intent getShortCutIntent(Context context) {
         // 使用MAIN,可以避免部分手机(比如华为、HTC部分机型)删除应用时无法删除快捷方式的问题
         Intent intent = new Intent(Intent.ACTION_MAIN);
@@ -1002,27 +1026,25 @@ public class SysAppUtil {
     }
 
 
-
-
     //是否有快捷方式的权限
     public static boolean hasShortcut(Context context, String appName) {
         LogUtil.println("hasShortcut appName = " + appName);
-        if(Build.VERSION.SDK_INT >=  Build.VERSION_CODES.O){
+        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
             ShortcutManager shortcutManager = (ShortcutManager) context.getSystemService(Context.SHORTCUT_SERVICE);
             List<ShortcutInfo> list = shortcutManager.getPinnedShortcuts();
-            if(!ListUtil.isEmpty(list)) {
+            if (!ListUtil.isEmpty(list)) {
                 for (ShortcutInfo shortcutInfo : list) {
-                    if(shortcutInfo.getLongLabel() != null && TextUtils.equals(shortcutInfo.getLongLabel().toString(), appName)){
+                    if (shortcutInfo.getLongLabel() != null && TextUtils.equals(shortcutInfo.getLongLabel().toString(), appName)) {
                         return true;
                     }
                 }
             }
-        } else if(Build.VERSION.SDK_INT >=  Build.VERSION_CODES.N_MR1){
+        } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
             ShortcutManager systemService = context.getSystemService(ShortcutManager.class);
             List<ShortcutInfo> list = systemService.getDynamicShortcuts();
-            if(!ListUtil.isEmpty(list)) {
+            if (!ListUtil.isEmpty(list)) {
                 for (ShortcutInfo shortcutInfo : list) {
-                    if(shortcutInfo.getLongLabel() != null && TextUtils.equals(shortcutInfo.getLongLabel().toString(), appName)){
+                    if (shortcutInfo.getLongLabel() != null && TextUtils.equals(shortcutInfo.getLongLabel().toString(), appName)) {
                         return true;
                     }
                 }
@@ -1038,13 +1060,14 @@ public class SysAppUtil {
         String url = "content://" + authority + "/favorites?notify=true";
         return hasShortcut(context, appName, url);
     }
+
     //是否有快捷方式的权限
     public static boolean hasShortcut(Context context, String appName, String url) {
         Cursor cursor = null;
         try {
             Uri CONTENT_URI = Uri.parse(url);
             ContentResolver contentResolver = context.getContentResolver();
-            if(contentResolver != null) {
+            if (contentResolver != null) {
                 cursor = contentResolver.query(CONTENT_URI, null, " title= ? ", new String[]{appName}, null);
                 if (cursor != null && cursor.moveToNext()) {
                     return true;
@@ -1052,10 +1075,10 @@ public class SysAppUtil {
             }
         } catch (Exception e) {
             e.printStackTrace();
-            if(TestUtil.isDev())
+            if (TestUtil.isDev())
                 G.showToast(e);
         } finally {
-            if(cursor != null){
+            if (cursor != null) {
                 cursor.close();
             }
         }
@@ -1088,38 +1111,35 @@ public class SysAppUtil {
         return null;
     }
 
-    public static boolean skipActivity(Context context, String packageName, String className, String action, String extraPkgName){
+    public static boolean skipActivity(Context context, String packageName, String className, String action, String extraPkgName) {
         Intent intent;
-        if(TextUtils.isEmpty(action))
+        if (TextUtils.isEmpty(action))
             intent = new Intent();
         else
             intent = new Intent(action);
-        if(!TextUtils.isEmpty(extraPkgName)) {
+        if (!TextUtils.isEmpty(extraPkgName)) {
             intent.putExtra("extra_pkgname", extraPkgName);
         }
         intent.setClassName(packageName, className);
-        if(QQUtil.isValidIntent(context, intent)){
-            try{
+        if (QQUtil.isValidIntent(context, intent)) {
+            try {
                 context.startActivity(intent);
-                if(TestUtil.isDev())
+                if (TestUtil.isDev())
                     G.showToast("启动成功");
                 return true;
             } catch (Exception e) {
                 e.printStackTrace();
-                if(TestUtil.isDev())
+                if (TestUtil.isDev())
                     G.showToast(e);
             }
         } else {
-            if(TestUtil.isDev())
+            if (TestUtil.isDev())
                 G.showToast("启动失败");
         }
         return false;
     }
 
 
-
-
-
     public static void enableComponentYf() {
         new Thread(() -> {
             //启用有范商城
@@ -1127,11 +1147,13 @@ public class SysAppUtil {
             enableComponent(testComponent, true);
         }).start();
     }
+
     public static boolean isEnableComponentYf() {
         //启用有范商城
         ComponentName testComponent = new ComponentName(SheepApp.getInstance(), "com.sheep.gamegroup.view.activity.ActYfX5");
         return isEnableComponent(testComponent);
     }
+
     /**
      * 是否已经启用组件
      *
@@ -1142,6 +1164,7 @@ public class SysAppUtil {
         int state = packageManager.getComponentEnabledSetting(componentName);
         return state == PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
     }
+
     /**
      * 启用组件或者禁用组件
      *
@@ -1150,7 +1173,7 @@ public class SysAppUtil {
     private static void enableComponent(ComponentName componentName, boolean enable) {
         PackageManager packageManager = SheepApp.getInstance().getPackageManager();
         packageManager.setComponentEnabledSetting(componentName,
-                enable ?  PackageManager.COMPONENT_ENABLED_STATE_ENABLED : PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
+                enable ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED : PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
                 PackageManager.DONT_KILL_APP);
     }
 

+ 1 - 1
app/src/main/java/com/sheep/gamegroup/view/activity/ActSetting.java

@@ -158,7 +158,7 @@ public class ActSetting extends BaseActivity {
                     public void onNext(BaseMessage baseMessage) {
                         Version version = baseMessage.getData(Version.class);
                         int versionCode = ApkUtils.getCurrentPkgVersionCode(ActSetting.this);
-                        if (versionCode == version.getVersion_number()) {
+                        if (versionCode >= version.getVersion_number()) {
                             ViewUtil.setText(binding.checkUpgradeView, "已经是最新版本: V" + ApkUtils.getCurrentPkgVersionName(ActSetting.this));
                         } else {
                             ViewUtil.setText(binding.checkUpgradeView, "发现新版本: V" + version.getVersion_name());