热修复框架

chengzhenyu лет %!s(int64=8): %!d(string=назад)
Родитель
Сommit
9acc2d92bd

BIN
app/libs/hotpatch_framework.jar


+ 5 - 1
app/src/main/java/ai/pai/client/app/PaiAiApplication.java

@@ -2,7 +2,6 @@ package ai.pai.client.app;
2 2
 
3 3
 import android.app.Application;
4 4
 
5
-import com.android.common.crashhandler.CrashHandler;
6 5
 import com.android.common.utils.LogHelper;
7 6
 import com.umeng.socialize.Config;
8 7
 import com.umeng.socialize.PlatformConfig;
@@ -12,7 +11,9 @@ import java.io.File;
12 11
 
13 12
 import ai.pai.client.BuildConfig;
14 13
 import ai.pai.client.utils.Constants;
14
+import ai.pai.client.utils.PatchManager;
15 15
 import ai.pai.client.utils.PhotoLoader;
16
+import ai.pai.client.utils.UrlContainer;
16 17
 
17 18
 /**
18 19
  * Created by chengzhenyu on 2015/12/9.
@@ -32,6 +33,7 @@ public class PaiAiApplication extends Application {
32 33
         PlatformConfig.setSinaWeibo("2730190333","ff16591583c7bcf4a0d781eae316635a");
33 34
         PhotoLoader.getInstance(this);
34 35
         checkAppDir();
36
+//        new PatchManager().patch(this, UrlContainer.PATCH_CONFIG_URL,Constants.APP_PATCH_DIR+File.separator+"patch.dex","");
35 37
     }
36 38
 
37 39
     private void checkAppDir(){
@@ -41,6 +43,8 @@ public class PaiAiApplication extends Application {
41 43
         appTmpDir.mkdirs();
42 44
         File appUploadDir = new File(Constants.APP_UPLOAD_DIR);
43 45
         appUploadDir.mkdirs();
46
+        File patchDir = new File(Constants.APP_PATCH_DIR);
47
+        patchDir.mkdirs();
44 48
     }
45 49
 
46 50
 }

+ 8 - 0
app/src/main/java/ai/pai/client/db/Preferences.java

@@ -133,6 +133,14 @@ public class Preferences {
133 133
         mPrefs.edit().putBoolean("isPermissionGranted",isPermissionGranted).commit();
134 134
     }
135 135
 
136
+    public void setPatchMD5(String md5){
137
+        mPrefs.edit().putString("md5",md5).commit();
138
+    }
139
+
140
+    public String getPatchMD5(){
141
+        return mPrefs.getString("md5",NullStr);
142
+    }
143
+
136 144
     public void clearPrefs(){
137 145
         mPrefs.edit().clear().commit();
138 146
     }

+ 1 - 1
app/src/main/java/ai/pai/client/utils/Constants.java

@@ -11,6 +11,6 @@ public class Constants {
11 11
     public static final String APP_TEMP_DIR                   = APP_ROOT_DIR + "/temp";
12 12
     public static final String APP_IMAGE_DIR                  = APP_ROOT_DIR + "/image";
13 13
     public static final String APP_UPLOAD_DIR                   = APP_ROOT_DIR + "/upload";
14
-
14
+    public static final String APP_PATCH_DIR                  = APP_ROOT_DIR+"/patch";
15 15
     public static final String APP_UPLOAD_CONFIG_PATH                   = APP_ROOT_DIR + "/upload.config";
16 16
 }

+ 49 - 0
app/src/main/java/ai/pai/client/utils/PatchManager.java

@@ -0,0 +1,49 @@
1
+package ai.pai.client.utils;
2
+
3
+
4
+import com.android.common.http.HttpUtils;
5
+import com.android.hotpatch.utils.IPatchManager;
6
+
7
+import org.json.JSONObject;
8
+
9
+import java.io.File;
10
+
11
+import ai.pai.client.db.Preferences;
12
+
13
+public class PatchManager extends IPatchManager{
14
+
15
+    private String md5;
16
+
17
+    public PatchManager(){
18
+        new File(Constants.APP_PATCH_DIR).mkdirs();
19
+    }
20
+
21
+    @Override
22
+    protected String getPatchFileDownloadUrl(String patchConfigUrl) {
23
+        String jsonStr = HttpUtils.doHttpPost(patchConfigUrl,null);
24
+        try{
25
+            JSONObject response = new JSONObject(jsonStr);
26
+            md5 = response.getString("md5");
27
+            return response.getString("patch_url");
28
+        }catch (Exception e){
29
+            e.printStackTrace();
30
+        }
31
+        return null;
32
+    }
33
+
34
+    @Override
35
+    protected boolean isNewPatchFound() {
36
+        if(!Preferences.getInstance(context).getPatchMD5().equals(md5)){
37
+            return true;
38
+        }
39
+        if(!new File(patchSavePath).exists()){
40
+            return true;
41
+        }
42
+        return false;
43
+    }
44
+
45
+    @Override
46
+    protected void afterPatchSuccess() {
47
+        Preferences.getInstance(context).setPatchMD5(md5);
48
+    }
49
+}

+ 3 - 1
app/src/main/java/ai/pai/client/utils/UrlContainer.java

@@ -83,6 +83,8 @@ public class UrlContainer {
83 83
     public static final String GUEST_LOGIN_URL = HOST_URL +"u/guest/login";
84 84
 
85 85
     public static final String GEO_LOCATION_URL = HOST_URL+"geo/submit";
86
-    //TODO
86
+
87 87
     public static final String TOUR_INFO_URL = HOST_URL +"pai2/tginfo";
88
+
89
+    public static final String PATCH_CONFIG_URL = HOST_URL+"patch";
88 90
 }