diff --git a/android/sdk/src/main/java/org/apache/weex/WXEnvironment.java b/android/sdk/src/main/java/org/apache/weex/WXEnvironment.java index f85b7c8484..8477c21e96 100644 --- a/android/sdk/src/main/java/org/apache/weex/WXEnvironment.java +++ b/android/sdk/src/main/java/org/apache/weex/WXEnvironment.java @@ -310,7 +310,7 @@ public static String copySoDesDir() { if (!desDir.exists()) { desDir.mkdirs(); } - COPY_SO_DES_DIR = desDir.getAbsolutePath(); + COPY_SO_DES_DIR = desDir.getCanonicalPath(); } } catch (Throwable e) { WXLogUtils.e(WXLogUtils.getStackTrace(e)); @@ -473,7 +473,12 @@ public static String getCrashFilePath(Context context) { if (dir == null) return ""; - String crashDir = dir.getAbsolutePath(); + String crashDir = null; + try { + crashDir = dir.getCanonicalPath(); + } catch (IOException e) { + e.printStackTrace(); + } return crashDir; } @@ -523,7 +528,7 @@ public static String extractSo() { final String soDesPath = copySoDesDir(); if (sourceFile.exists() && !TextUtils.isEmpty(soDesPath)) { try { - WXFileUtils.extractSo(sourceFile.getAbsolutePath(), soDesPath); + WXFileUtils.extractSo(sourceFile.getCanonicalPath(), soDesPath); } catch (IOException e) { WXLogUtils.e("extractSo error " + e.getMessage()); // e.printStackTrace(); @@ -593,7 +598,11 @@ public static String findSoPath(String libName) { File soFile = new File(soPath); if (soFile.exists()) { WXLogUtils.e(libName + "'s Path is" + soPath); - return soFile.getAbsolutePath(); + try { + return soFile.getCanonicalPath(); + } catch (IOException e) { + e.printStackTrace(); + } } else { WXLogUtils.e(libName + "'s Path is " + soPath + " but file does not exist"); } @@ -608,10 +617,12 @@ public static String findSoPath(String libName) { if (cacheDir.indexOf("/cache") > 0) { - soPath = new File(cacheDir.replace("/cache", "/lib"), realName).getAbsolutePath(); + try { + soPath = new File(cacheDir.replace("/cache", "/lib"), realName).getCanonicalPath(); + } catch (IOException e) { + e.printStackTrace(); + } } - - final File soFile = new File(soPath); if (soFile.exists()) { WXLogUtils.e(libName + "use lib so"); @@ -620,7 +631,11 @@ public static String findSoPath(String libName) { //unzip from apk file final String extractSoPath = extractSo(); if (!TextUtils.isEmpty(extractSoPath)) { - return new File(extractSoPath, realName).getAbsolutePath(); + try { + return new File(getCacheDir(), realName).getCanonicalPath(); + } catch (IOException e) { + e.printStackTrace(); + } } } return soPath; diff --git a/android/sdk/src/main/java/org/apache/weex/utils/TypefaceUtil.java b/android/sdk/src/main/java/org/apache/weex/utils/TypefaceUtil.java index a028c4d948..f9af544629 100644 --- a/android/sdk/src/main/java/org/apache/weex/utils/TypefaceUtil.java +++ b/android/sdk/src/main/java/org/apache/weex/utils/TypefaceUtil.java @@ -147,9 +147,14 @@ public static void loadTypeface(final FontDO fontDo, boolean notify) { if(!dir.exists()){ dir.mkdirs(); } - final String fullPath = dir.getAbsolutePath()+ File.separator +fileName; - if (!loadLocalFontFile(fullPath, fontFamily, false)) { - downloadFontByNetwork(url, fullPath, fontFamily); + final String fullPath; + try { + fullPath = dir.getCanonicalPath()+ File.separator +fileName; + if (!loadLocalFontFile(fullPath, fontFamily, false)) { + downloadFontByNetwork(url, fullPath, fontFamily); + } + } catch (IOException e) { + e.printStackTrace(); } } else if (fontDo.getType() == FontDO.TYPE_FILE || fontDo.getType() == FontDO.TYPE_BASE64) { boolean result = loadLocalFontFile(fontDo.getUrl(), fontDo.getFontFamilyName(), false); diff --git a/android/sdk/src/main/java/org/apache/weex/utils/WXFileUtils.java b/android/sdk/src/main/java/org/apache/weex/utils/WXFileUtils.java index 6b1e94179a..0a6ecd503b 100644 --- a/android/sdk/src/main/java/org/apache/weex/utils/WXFileUtils.java +++ b/android/sdk/src/main/java/org/apache/weex/utils/WXFileUtils.java @@ -253,7 +253,11 @@ public static void copyFile(File oldFile, File newFile) { inputStream.close(); outputStream.close(); } catch (Exception e) { - WXLogUtils.e("copyFile " + e.getMessage() + ": " + oldFile.getAbsolutePath() + ": " + newFile.getAbsolutePath()); + try { + WXLogUtils.e("copyFile " + e.getMessage() + ": " + oldFile.getCanonicalPath() + ": " + newFile.getCanonicalPath()); + } catch (IOException ioException) { + ioException.printStackTrace(); + } if (inputStream != null) { try { inputStream.close(); diff --git a/android/sdk/src/main/java/org/apache/weex/utils/WXSoInstallMgrSdk.java b/android/sdk/src/main/java/org/apache/weex/utils/WXSoInstallMgrSdk.java index a5da705745..0dc3a909f9 100644 --- a/android/sdk/src/main/java/org/apache/weex/utils/WXSoInstallMgrSdk.java +++ b/android/sdk/src/main/java/org/apache/weex/utils/WXSoInstallMgrSdk.java @@ -241,7 +241,7 @@ public static void copyStartUpSo() { copyPath.mkdirs(); } newfile = new File(copyPath, startSoPath); - WXEnvironment.CORE_JSB_SO_PATH = newfile.getAbsolutePath(); + WXEnvironment.CORE_JSB_SO_PATH = newfile.getCanonicalPath(); String jsb = WXEnvironment.getDefaultSettingValue(startSoName, "-1"); if(newfile.exists() && TextUtils.equals(WXEnvironment.getAppVersionName(), jsb)) { // no update so skip copy @@ -307,7 +307,7 @@ public static void copyJssRuntimeSo(){ if (!TextUtils.equals(WXEnvironment.getAppVersionName(),defaultSettingValue)){ targetFile.delete(); }else { - WXEnvironment.CORE_JSS_SO_PATH= targetFile.getAbsolutePath(); + WXEnvironment.CORE_JSS_SO_PATH= targetFile.getCanonicalPath(); WXEnvironment.sUseRunTimeApi = true; WXLogUtils.e("weex", "copyJssRuntimeSo exist: return"); return; @@ -321,7 +321,7 @@ public static void copyJssRuntimeSo(){ targetFile.createNewFile(); WXFileUtils.copyFileWithException(new File(fromPath),targetFile); /**3. update flag **/ - WXEnvironment.CORE_JSS_SO_PATH= targetFile.getAbsolutePath(); + WXEnvironment.CORE_JSS_SO_PATH= targetFile.getCanonicalPath(); WXEnvironment.writeDefaultSettingsValue(keyVersionCode,WXEnvironment.getAppVersionName()); WXEnvironment.sUseRunTimeApi = true; WXLogUtils.e("weex", "copyJssRuntimeSo: cp end and return "); diff --git a/android/sdk/src/main/java/org/apache/weex/utils/WXViewToImageUtil.java b/android/sdk/src/main/java/org/apache/weex/utils/WXViewToImageUtil.java index 07b30ddf43..76d1225e69 100755 --- a/android/sdk/src/main/java/org/apache/weex/utils/WXViewToImageUtil.java +++ b/android/sdk/src/main/java/org/apache/weex/utils/WXViewToImageUtil.java @@ -115,15 +115,24 @@ public static String saveBitmapToGallery(Context context, Bitmap bitmap, final O // Insert the image file into the system gallery try { MediaStore.Images.Media.insertImage(context.getContentResolver(), - file.getAbsolutePath(), fileName, null); - } catch (FileNotFoundException e) { + file.getCanonicalPath(), fileName, null); + } catch (Exception e) { e.printStackTrace(); } // Notify the system gallery update - context.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.parse("file://" + appDir.getAbsolutePath() + "/" + fileName))); + try { + context.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.parse("file://" + appDir.getCanonicalPath() + "/" + fileName))); + } catch (IOException e) { + e.printStackTrace(); + } - return file.getAbsolutePath(); + try { + return file.getCanonicalPath(); + } catch (IOException e) { + e.printStackTrace(); + } + return ""; } /**