花瓣 v4.6.12版本的 MD5 值为:6a3515d4d16d98931f1b3d25a91b257e
以下内容为反编译后的 LiveInitMaterialManager.java 源代码,内容仅作参考
package com.bytedance.android.openliveplugin.material;
import android.app.Application;
import android.content.Context;
import android.text.TextUtils;
import com.bytedance.android.openliveplugin.net.NetApi;
import com.ss.android.socialbase.downloader.depend.AbsDownloadListener;
import com.ss.android.socialbase.downloader.downloader.BaseDownloader;
import com.ss.android.socialbase.downloader.exception.BaseException;
import com.ss.android.socialbase.downloader.model.DownloadInfo;
import com.ss.android.socialbase.downloader.model.DownloadTask;
import java.io.File;
import java.util.concurrent.atomic.AtomicInteger;
import org.json.JSONException;
import org.json.JSONObject;
public class LiveInitMaterialManager {
private static final String FETCH_PLUGIN_SETTINGS_URL = "/webcast/openapi/pangle/setting/";
private static final String HOST = "https://webcast-open.douyin.com";
private static final String MATERIAL_NAME = "material";
private static final String TAG = "LiveInitMaterialManager";
private volatile boolean isDownloading;
private final AtomicInteger mRetryCount = new AtomicInteger(0);
public void download(final Context context, final String str, final String str2, final String str3, final ILiveMaterialGet iLiveMaterialGet) {
DownloadTask with;
if (this.isDownloading) {
TTLogger.d(TAG, "live init : Downloading...");
return;
}
try {
with = BaseDownloader.with(context);
with.url(str).savePath(str2).name(str3).retryCount(3).needRetryDelay(false).subThreadListener(new AbsDownloadListener() {
@Override
public void onCanceled(DownloadInfo downloadInfo) {
TTLogger.d(LiveInitMaterialManager.TAG, "live init : Download task canceled.");
LiveInitMaterialManager.this.isDownloading = false;
}
@Override
public void onFailed(DownloadInfo downloadInfo, BaseException baseException) {
TTLogger.e(LiveInitMaterialManager.TAG, "live init : Download failed. " + baseException);
LiveInitMaterialManager.this.isDownloading = false;
if (LiveInitMaterialManager.this.mRetryCount.getAndIncrement() < 3) {
LiveInitMaterialManager.this.download(context, str, str2, str3, iLiveMaterialGet);
}
}
@Override
public void onSuccessed(DownloadInfo downloadInfo) {
try {
ZipFileUtil.unZipFolder(new File(downloadInfo.getSavePath(), downloadInfo.getName()).getAbsolutePath(), downloadInfo.getSavePath());
} catch (Exception e2) {
e2.printStackTrace();
}
ConfigParams localConfigParams = LiveInitMaterialManager.this.getLocalConfigParams(context);
ILiveMaterialGet iLiveMaterialGet2 = iLiveMaterialGet;
if (iLiveMaterialGet2 != null) {
iLiveMaterialGet2.onMaterialGet(localConfigParams);
}
TTLogger.d(LiveInitMaterialManager.TAG, "live init : Download end.");
LiveInitMaterialManager.this.isDownloading = false;
}
}).download();
TTLogger.d(TAG, "live init : Download start.");
this.isDownloading = true;
} catch (Throwable th) {
TTLogger.e(TAG, "live init : Download file error: " + th);
}
}
public ConfigParams getLocalConfigParams(Context context) {
File[] listFiles;
File file = new File(getMaterialDownloadPath(context));
ConfigParams configParams = null;
if (!file.exists() || (listFiles = file.listFiles()) == null || listFiles.length <= 0) {
return null;
}
File file2 = null;
File file3 = null;
for (File file4 : listFiles) {
if (file4.isFile() && file4.getName().contains("_config")) {
file2 = file4;
}
if (file4.isFile() && file4.getAbsolutePath().endsWith(".lic")) {
file3 = file4;
}
if (file2 != null && file3 != null) {
break;
}
}
if (file2 == null) {
return null;
}
try {
JSONObject jSONObject = new JSONObject(ZipFileUtil.readTextFile(file2));
ConfigParams configParams2 = new ConfigParams();
try {
configParams2.appID = jSONObject.optLong("appid");
configParams2.webcastAppID = jSONObject.optLong("webcast_appid");
configParams2.ttsdkAppID = jSONObject.optLong("ttsdk_appid");
configParams2.clientKey = jSONObject.optString("client_key");
configParams2.version = jSONObject.optLong("version");
if (file3 != null) {
configParams2.ttSDKLicensePath = file3.getAbsolutePath();
}
return configParams2;
} catch (JSONException e2) {
e = e2;
configParams = configParams2;
TTLogger.e(TAG, "live init : parse local file error : " + e);
e.printStackTrace();
return configParams;
}
} catch (JSONException e3) {
e = e3;
}
}
private String getMaterialDownloadPath(Context context) {
return context.getFilesDir() + File.separator + "pangle_com.byted.live.lite" + File.separator + ".msdata_lc" + File.separator;
}
private ResPackage startCheckLiveInitMaterial(String str, Application application) {
if (!TextUtils.isEmpty(str) && application != null) {
String request = NetApi.getInstance().request(false, "https://webcast-open.douyin.com/webcast/openapi/pangle/setting/?app_id=" + str + "&package_name=" + application.getPackageName(), null);
if (TextUtils.isEmpty(request)) {
return null;
}
try {
JSONObject jSONObject = new JSONObject(request);
ResPackage resPackage = new ResPackage();
resPackage.statusCode = jSONObject.optLong("status_code");
JSONObject optJSONObject = jSONObject.optJSONObject("data");
resPackage.resUrl = optJSONObject.optString("setting_url");
resPackage.version = optJSONObject.optLong("version");
return resPackage;
} catch (JSONException unused) {
}
}
return null;
}
public void run(String str, Application application, ILiveMaterialGet iLiveMaterialGet) {
ResPackage startCheckLiveInitMaterial = startCheckLiveInitMaterial(str, application);
if (startCheckLiveInitMaterial != null && startCheckLiveInitMaterial.isLegal()) {
ConfigParams localConfigParams = getLocalConfigParams(application);
if (startCheckLiveInitMaterial.version <= (localConfigParams != null ? localConfigParams.version : 0L)) {
if (iLiveMaterialGet != null) {
iLiveMaterialGet.onMaterialGet(localConfigParams);
return;
}
return;
} else if (TextUtils.isEmpty(startCheckLiveInitMaterial.resUrl)) {
TTLogger.e("live init : material task res download url empty error");
return;
} else {
ZipFileUtil.removeDir(new File(getMaterialDownloadPath(application)));
File file = new File(getMaterialDownloadPath(application));
if (!file.exists()) {
file.mkdir();
}
TTLogger.d("live init : start download material res");
download(application, startCheckLiveInitMaterial.resUrl, getMaterialDownloadPath(application), "material", iLiveMaterialGet);
return;
}
}
TTLogger.e("live init : material task res package null error");
ConfigParams localConfigParams2 = getLocalConfigParams(application);
if (localConfigParams2 == null || iLiveMaterialGet == null) {
return;
}
iLiveMaterialGet.onMaterialGet(localConfigParams2);
}
}