1、相心美颜So文件静默加载增加下载失败、解压失败重试机制和多次失败后的提示
This commit is contained in:
@@ -186,19 +186,17 @@ public class LauncherActivity extends AppCompatActivity implements View.OnClickL
|
||||
//解压后的文件数量必须要有2个
|
||||
//如果文件存在,解压后 文件数量一致,直接进入下一步
|
||||
if (fileSo.exists() && getFileCount(fileSoList.getAbsolutePath()) == 2){
|
||||
MainActivity.faceSDKIsLoadSuceness = true;
|
||||
CommonAppConfig.faceSDKIsLoadSuceness = true;
|
||||
mHandler.sendEmptyMessageDelayed(WHAT_GET_CONFIG, 1000);
|
||||
return;
|
||||
}
|
||||
// https://downs.yaoulive.com/androidLibs/t3/faceunity2-so-arm64-v8a.zip
|
||||
String soUrl = String.format("https://downs.yaoulive.com/androidLibs/t3/faceunity2-so-%s.zip", cpuAbi);
|
||||
Log.i("download", soUrl);
|
||||
|
||||
downLoadFaceSDK_OutputDir = outputDir.getAbsolutePath();
|
||||
if (!fileSo.exists()) {
|
||||
downloadSo(outputDir.getAbsolutePath(), soUrl,Constants.FaceUnity_SO_Name,false);
|
||||
downloadSo(downLoadFaceSDK_OutputDir, downLoadFaceSDK_downloadUrl,Constants.FaceUnity_SO_Name,false);
|
||||
}else if (fileSo.exists() && getFileCount(outputDir.getAbsolutePath()) < 3) {
|
||||
fileSo.delete();
|
||||
downloadSo(outputDir.getAbsolutePath(), soUrl,Constants.FaceUnity_SO_Name,false);
|
||||
downloadSo(outputDir.getAbsolutePath(), downLoadFaceSDK_downloadUrl,Constants.FaceUnity_SO_Name,false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -244,9 +242,13 @@ public class LauncherActivity extends AppCompatActivity implements View.OnClickL
|
||||
}
|
||||
}
|
||||
|
||||
Dialog progressDialog;
|
||||
private Dialog progressDialog;
|
||||
public ProgressBar progressBar;
|
||||
public TextView tvProgress;
|
||||
private int downLoadFaceSDKCount = 0;
|
||||
private int unZipFaceSDKCount = 0;
|
||||
private String downLoadFaceSDK_OutputDir;
|
||||
private String downLoadFaceSDK_downloadUrl = String.format("https://downs.yaoulive.com/androidLibs/t3/faceunity2-so-%s.zip", Build.CPU_ABI);
|
||||
|
||||
private void showDialog(Activity context) {
|
||||
progressDialog = new Dialog(context, com.yunbao.common.R.style.dialog);
|
||||
@@ -268,6 +270,9 @@ public class LauncherActivity extends AppCompatActivity implements View.OnClickL
|
||||
progressDialog.setCancelable(false);
|
||||
progressDialog.show();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void downloadSo(String outputDir, String downloadUrl,String fileName,boolean isShowDialog) {
|
||||
DownloadUtil downloadUtil = new DownloadUtil();
|
||||
if(isShowDialog){
|
||||
@@ -280,17 +285,7 @@ public class LauncherActivity extends AppCompatActivity implements View.OnClickL
|
||||
progressDialog.dismiss();
|
||||
mHandler.sendEmptyMessageDelayed(WHAT_GET_CONFIG, 20);
|
||||
}
|
||||
File fileSo = new File(outputDir, fileName);
|
||||
try {
|
||||
unzip(fileSo.getAbsolutePath(), outputDir);
|
||||
MainActivity.faceSDKIsLoadSuceness = true;
|
||||
if (BuildConfig.DEBUG){
|
||||
ToastUtil.showDebug("美颜SDK加载成功...");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.e("ZipCheck", "Error reading ZIP file", e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
unZipFaceSDK(outputDir, fileName);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -304,12 +299,36 @@ public class LauncherActivity extends AppCompatActivity implements View.OnClickL
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
//资源下载失败
|
||||
|
||||
downLoadFaceSDKCount++;
|
||||
if (downLoadFaceSDKCount < 3) {
|
||||
downloadSo(downLoadFaceSDK_OutputDir, downLoadFaceSDK_downloadUrl,Constants.FaceUnity_SO_Name,false);
|
||||
} else {
|
||||
CommonAppConfig.faceSDKDownLoadOrUnZipFailed = true;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private void unZipFaceSDK(String outputDir, String fileName) {
|
||||
File fileSo = new File(outputDir, fileName);
|
||||
try {
|
||||
unzip(fileSo.getAbsolutePath(), outputDir);
|
||||
} catch (Exception e) {
|
||||
Log.e("ZipCheck", "Error reading ZIP file", e);
|
||||
unZipFaceSDKCount++;
|
||||
if (unZipFaceSDKCount < 3) {
|
||||
unZipFaceSDK(outputDir, fileName);
|
||||
} else {
|
||||
CommonAppConfig.faceSDKDownLoadOrUnZipFailed = true;
|
||||
}
|
||||
}
|
||||
CommonAppConfig.faceSDKIsLoadSuceness = true;
|
||||
if (BuildConfig.DEBUG){
|
||||
ToastUtil.showDebug("美颜SDK加载成功...");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 解压 .zip 文件到目标目录
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user