1、相心美颜So文件静默加载增加下载失败、解压失败重试机制和多次失败后的提示

This commit is contained in:
老皮 2024-09-26 09:40:53 +08:00
parent e69796e158
commit 2e84e799d4
7 changed files with 56 additions and 27 deletions

View File

@ -186,19 +186,17 @@ public class LauncherActivity extends AppCompatActivity implements View.OnClickL
//解压后的文件数量必须要有2个 //解压后的文件数量必须要有2个
//如果文件存在解压后 文件数量一致直接进入下一步 //如果文件存在解压后 文件数量一致直接进入下一步
if (fileSo.exists() && getFileCount(fileSoList.getAbsolutePath()) == 2){ if (fileSo.exists() && getFileCount(fileSoList.getAbsolutePath()) == 2){
MainActivity.faceSDKIsLoadSuceness = true; CommonAppConfig.faceSDKIsLoadSuceness = true;
mHandler.sendEmptyMessageDelayed(WHAT_GET_CONFIG, 1000); mHandler.sendEmptyMessageDelayed(WHAT_GET_CONFIG, 1000);
return; return;
} }
// https://downs.yaoulive.com/androidLibs/t3/faceunity2-so-arm64-v8a.zip // 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); downLoadFaceSDK_OutputDir = outputDir.getAbsolutePath();
Log.i("download", soUrl);
if (!fileSo.exists()) { 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) { }else if (fileSo.exists() && getFileCount(outputDir.getAbsolutePath()) < 3) {
fileSo.delete(); 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 ProgressBar progressBar;
public TextView tvProgress; 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) { private void showDialog(Activity context) {
progressDialog = new Dialog(context, com.yunbao.common.R.style.dialog); 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.setCancelable(false);
progressDialog.show(); progressDialog.show();
} }
public void downloadSo(String outputDir, String downloadUrl,String fileName,boolean isShowDialog) { public void downloadSo(String outputDir, String downloadUrl,String fileName,boolean isShowDialog) {
DownloadUtil downloadUtil = new DownloadUtil(); DownloadUtil downloadUtil = new DownloadUtil();
if(isShowDialog){ if(isShowDialog){
@ -280,17 +285,7 @@ public class LauncherActivity extends AppCompatActivity implements View.OnClickL
progressDialog.dismiss(); progressDialog.dismiss();
mHandler.sendEmptyMessageDelayed(WHAT_GET_CONFIG, 20); mHandler.sendEmptyMessageDelayed(WHAT_GET_CONFIG, 20);
} }
File fileSo = new File(outputDir, fileName); unZipFaceSDK(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);
}
} }
@Override @Override
@ -304,12 +299,36 @@ public class LauncherActivity extends AppCompatActivity implements View.OnClickL
@Override @Override
public void onError(Throwable e) { 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 文件到目标目录 * 解压 .zip 文件到目标目录
*/ */

View File

@ -145,6 +145,10 @@ public class CommonAppConfig {
private int mAppIconRes; private int mAppIconRes;
private String mAppName; private String mAppName;
private Boolean mTiBeautyEnable;//是否使用萌颜 true使用萌颜 false 使用基础美颜 private Boolean mTiBeautyEnable;//是否使用萌颜 true使用萌颜 false 使用基础美颜
// 美颜SDK是否已经加载成功
public static boolean faceSDKIsLoadSuceness;
// 美颜SDK是否下载失败或者解压失败(自动试3次)
public static boolean faceSDKDownLoadOrUnZipFailed = false;
public String getUid() { public String getUid() {
if (TextUtils.isEmpty(mUid)) { if (TextUtils.isEmpty(mUid)) {

View File

@ -827,6 +827,7 @@
<string name="only_open_anchor">暫時只對主播開放</string> <string name="only_open_anchor">暫時只對主播開放</string>
<string name="wait_face_sdk_load">請稍等美顏SDK加載中</string> <string name="wait_face_sdk_load">請稍等美顏SDK加載中</string>
<string name="face_sdk_load_failed">美顏SDK加載失敗請重啟App</string>
<string name="facebook_app_id">2011402032399020</string> <string name="facebook_app_id">2011402032399020</string>
<string name="facebook_client_token">959584e054a33614996361f0044e5253</string> <string name="facebook_client_token">959584e054a33614996361f0044e5253</string>

View File

@ -787,6 +787,7 @@
<string name="only_open_anchor">For the time being, it is only open to the anchor</string> <string name="only_open_anchor">For the time being, it is only open to the anchor</string>
<string name="wait_face_sdk_load">Please wait, the beauty SDK is loading.</string> <string name="wait_face_sdk_load">Please wait, the beauty SDK is loading.</string>
<string name="face_sdk_load_failed">Beauty SDK failed to load, please restart the App</string>
<string name="facebook_app_id">2011402032399020</string> <string name="facebook_app_id">2011402032399020</string>
<string name="facebook_client_token">959584e054a33614996361f0044e5253</string> <string name="facebook_client_token">959584e054a33614996361f0044e5253</string>

View File

@ -215,14 +215,14 @@ public class LiveSwAnchorActivity extends LiveActivity implements LiveFunctionCl
super.main(); super.main();
Bus.getOn(this); Bus.getOn(this);
Intent intent = getIntent(); Intent intent = getIntent();
if(CommonAppConfig.IS_GOOGLE_PLAY == 0){ /* if(CommonAppConfig.IS_GOOGLE_PLAY == 0){
// 美颜SO设置 // 美颜SO设置
File file_FaceUnity = new File(mContext.getDir("lib", Context.MODE_PRIVATE).getAbsoluteFile(), com.yunbao.common.Constants.DOWNLOAD_FaceUnity_SO + File.separator + Build.CPU_ABI); File file_FaceUnity = new File(mContext.getDir("lib", Context.MODE_PRIVATE).getAbsoluteFile(), com.yunbao.common.Constants.DOWNLOAD_FaceUnity_SO + File.separator + Build.CPU_ABI);
faceunity.LoadConfig.loadLibrary(file_FaceUnity.getAbsolutePath()); faceunity.LoadConfig.loadLibrary(file_FaceUnity.getAbsolutePath());
Log.i("downLoad", "美颜SO Path = " + file_FaceUnity.getAbsolutePath()); Log.i("downLoad", "美颜SO Path = " + file_FaceUnity.getAbsolutePath());
} }*/
initFaceManager(); // initFaceManager();
leave_img = findViewById(R.id.leave_img); leave_img = findViewById(R.id.leave_img);
mLiveSDK = intent.getIntExtra(Constants.LIVE_SDK, Constants.LIVE_SDK_KSY); mLiveSDK = intent.getIntExtra(Constants.LIVE_SDK, Constants.LIVE_SDK_KSY);
if (mLiveSDK == Constants.LIVE_SDK_SW) { if (mLiveSDK == Constants.LIVE_SDK_SW) {

View File

@ -205,10 +205,7 @@ public class MainActivity extends AbsActivity implements MainAppBarLayoutListene
private View floatWarOrder;//战令浮窗 private View floatWarOrder;//战令浮窗
private List<AnchorStartLiveBean> startListNotifyList = new ArrayList<>(); private List<AnchorStartLiveBean> startListNotifyList = new ArrayList<>();
private String[] libNameList = new String[]{"agora-core", "agora-ffmpeg", "agora-fdkaac", "agora-soundtouch","agora-rtc-sdk"}; // private String[] libNameList = new String[]{"agora-core", "agora-ffmpeg", "agora-fdkaac", "agora-soundtouch","agora-rtc-sdk"};
// 美颜SDK是否已经加载成功
public static boolean faceSDKIsLoadSuceness = false;
@Override @Override
protected int getLayoutId() { protected int getLayoutId() {

View File

@ -168,11 +168,18 @@ public class MainStartDialogFragment extends AbsDialogFragment implements View.O
public void onLiveClick() { public void onLiveClick() {
boolean isAnchor = IMLoginManager.get(mContext).getUserInfo().anchorUserType(); boolean isAnchor = IMLoginManager.get(mContext).getUserInfo().anchorUserType();
if (isAnchor) { if (isAnchor) {
if (CommonAppConfig.faceSDKDownLoadOrUnZipFailed){
// 美颜SDK下载或解压失败并且重试三次还是失败提示用户重启
ToastUtil.show(getString(R.string.face_sdk_load_failed));
return;
}
// 判断美颜SDK是否加载成功 // 判断美颜SDK是否加载成功
if (!MainActivity.faceSDKIsLoadSuceness){ if (!CommonAppConfig.faceSDKIsLoadSuceness){
ToastUtil.show(getString(R.string.wait_face_sdk_load)); ToastUtil.show(getString(R.string.wait_face_sdk_load));
return; return;
} }
String[] permissions; String[] permissions;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
permissions = new String[]{ permissions = new String[]{