You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@weex.apache.org by GitBox <gi...@apache.org> on 2019/07/16 13:25:13 UTC

[GitHub] [incubator-weex] YorkShen commented on a change in pull request #2712: Update for libweexjsb path

YorkShen commented on a change in pull request #2712: Update for libweexjsb path
URL: https://github.com/apache/incubator-weex/pull/2712#discussion_r303906650
 
 

 ##########
 File path: android/sdk/src/main/java/com/taobao/weex/utils/WXSoInstallMgrSdk.java
 ##########
 @@ -208,110 +211,83 @@ public static boolean initSo(String libName, int version, IWXUserTrackAdapter ut
     return InitSuc;
   }
 
+  private static File _desSoCopyFile(String soName) {
+    String cpuType = _cpuType();
+    String copyPath = WXEnvironment.copySoDesDir();
+    if (TextUtils.isEmpty(copyPath)) {
+      return null;
+    }
+    File desDir = new File(copyPath, soName + "/" + cpuType);
+    return desDir;
+  }
+
   /**
    * copyStartUpSo
    */
   public static void copyStartUpSo() {
     try {
-      boolean installOnSdcard = true;
-      String pkgName = WXEnvironment.getApplication().getPackageName();
-      // cp weexjsb any way
-//      try {
-//        PackageManager pm = WXEnvironment.getApplication().getApplicationContext().getPackageManager();
-//        ApplicationInfo appInfo = pm.getApplicationInfo(pkgName, 0);
-//        if ((appInfo.flags & ApplicationInfo.FLAG_EXTERNAL_STORAGE) != 0) {
-//          // App on sdcard
-//          installOnSdcard = true;
-//        }
-//      } catch (Throwable e) {
-//      }
+      // copy libjsb.so to cache/weex/jsb/cputype
 
-      if (installOnSdcard) {
-
-        String cacheFile = WXEnvironment.getApplication().getApplicationContext().getCacheDir().getPath();
-        // if android api < 16 copy libweexjst.so else copy libweexjsb.so
-        boolean pieSupport = true;
-        File newfile;
-        String startSoName = WXEnvironment.CORE_JSB_SO_NAME;
-        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
-          pieSupport = false;
-          newfile = new File(cacheFile + STARTUPSOANDROID15);
-          startSoName = WXEnvironment.CORE_JST_SO_NAME;
-        } else {
-          newfile = new File(cacheFile + STARTUPSO);
-        }
-
-        String jsbVersionFile = "jsb.version";
-
-        File versionFile = new File(cacheFile,jsbVersionFile);
-        Closeable r = null;
 
-        if(newfile.exists() && versionFile.exists()) {
-          try {
-            FileReader fileReader = new FileReader(versionFile);
-            r = fileReader;
-            BufferedReader br = new BufferedReader(fileReader);
-            String s = br.readLine();
-            if(!TextUtils.isEmpty(s)) {
-              boolean same = String.valueOf(WXEnvironment.CORE_JSB_SO_VERSION).equals(s.trim());
-              if(same)
-                return;
-            }
-          } catch (FileNotFoundException e) {
-            //do nothing and copy so file
-          } finally {
-            if (r != null)
-              r.close();
-          }
-        }
-
-        String path = "/data/data/" + pkgName + "/lib";
-        if (cacheFile != null && cacheFile.indexOf("/cache") > 0) {
-          path = cacheFile.replace("/cache", "/lib");
-        }
-
-        String soName;
-        if (pieSupport) {
-          soName = path + STARTUPSO;
-        } else {
-          soName = path + STARTUPSOANDROID15;
-        }
+      String pkgName = WXEnvironment.getApplication().getPackageName();
+      String cacheFile = WXEnvironment.getApplication().getApplicationContext().getCacheDir().getPath();
 
-        File oldfile = new File(soName);
+      // cp weexjsb any way
+      // if android api < 16 copy libweexjst.so else copy libweexjsb.so
+      boolean pieSupport = true;
+      File newfile;
+      String startSoName = WXEnvironment.CORE_JSB_SO_NAME;
+      String startSoPath = STARTUPSO;
+      if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
+        pieSupport = false;
+        startSoName = WXEnvironment.CORE_JST_SO_NAME;
+        startSoPath = STARTUPSOANDROID15;
+      }
 
+      final File copyPath = _desSoCopyFile(startSoName);
+      if(!copyPath.exists()) {
+        copyPath.mkdirs();
+      }
+      newfile = new File(copyPath + startSoPath);
+      WXEnvironment.CORE_JSB_SO_PATH = newfile.getAbsolutePath();
+      String jsb = WXEnvironment.getDefaultSettingValue(startSoName, "-1");
+      if(newfile.exists() && TextUtils.equals(WXEnvironment.getAppVersionName(), jsb)) {
+        // no update so skip copy
+        return;
+      }
 
-        if(!oldfile.exists()) {
-          try {
-            String weexjsb = ((PathClassLoader) (WXSoInstallMgrSdk.class.getClassLoader())).findLibrary(startSoName);
-            oldfile = new File(weexjsb);
-          } catch (Throwable throwable) {
-            // do nothing
-          }
+      String path = "/data/data/" + pkgName + "/lib";
+      if (cacheFile != null && cacheFile.indexOf("/cache") > 0) {
+        path = cacheFile.replace("/cache", "/lib");
+      }
 
-        }
+      String soName;
+      if (pieSupport) {
+        soName = path + STARTUPSO;
+      } else {
+        soName = path + STARTUPSOANDROID15;
+      }
 
-        if (oldfile.exists()) {
-          WXFileUtils.copyFile(oldfile, newfile);
-        } else {
-          WXEnvironment.extractSo();
-        }
+      File oldfile = new File(soName);
 
-        Closeable w = null;
+      if (!oldfile.exists()) {
         try {
-          if(!versionFile.exists())
-            versionFile.createNewFile();
-          FileWriter fileWriter = new FileWriter(versionFile);
-          w = fileWriter;
-          fileWriter.write(String.valueOf(WXEnvironment.CORE_JSB_SO_VERSION));
-          fileWriter.flush();
-        } catch (Exception e ) {
+          String weexjsb = ((PathClassLoader) (WXSoInstallMgrSdk.class.getClassLoader())).findLibrary(startSoName);
+          oldfile = new File(weexjsb);
+        } catch (Throwable throwable) {
           // do nothing
-        } finally {
-          if(w != null)
-            w.close();
         }
+      }
+
+      if(!oldfile.exists()) {
+        WXEnvironment.extractSo();
+        oldfile = new File(copyPath, STARTUPSO);
+      }
 
+      if (oldfile.exists()) {
 
 Review comment:
   The old code for line 287 is a `else` case. You are changing the behaviour in new code.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services