花瓣 v4.6.12版本的 MD5 值为:6a3515d4d16d98931f1b3d25a91b257e
以下内容为反编译后的 d.java 源代码,内容仅作参考
package com.bytedance.sdk.openadsdk.downloadnew;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Environment;
import android.text.TextUtils;
import android.widget.Toast;
import com.bytedance.sdk.openadsdk.TTAdConstant;
import com.bytedance.sdk.openadsdk.TTAdManager;
import com.bytedance.sdk.openadsdk.TTAdSdk;
import com.bytedance.sdk.openadsdk.TTAppContextHolder;
import com.bytedance.sdk.openadsdk.TTDownloadEventLogger;
import com.bytedance.sdk.openadsdk.downloadnew.c;
import com.bytedance.sdk.openadsdk.downloadnew.core.DialogBuilder;
import com.bytedance.sdk.openadsdk.downloadnew.core.ExitInstallListener;
import com.bytedance.sdk.openadsdk.downloadnew.core.IDialogStatusChangedListener;
import com.bytedance.sdk.openadsdk.downloadnew.core.ITTDownloadAdapter;
import com.bytedance.sdk.openadsdk.downloadnew.core.ITTDownloadVisitor;
import com.bytedance.sdk.openadsdk.downloadnew.core.ITTHttpCallback;
import com.bytedance.sdk.openadsdk.downloadnew.core.ITTPermissionCallback;
import com.bytedance.sdk.openadsdk.downloadnew.core.TTDownloadEventModel;
import com.bytedance.sdk.openadsdk.downloadnew.core.TTDownloadField;
import com.ss.android.download.api.config.IDownloadButtonClickListener;
import com.ss.android.download.api.config.g;
import com.ss.android.download.api.config.h;
import com.ss.android.download.api.config.i;
import com.ss.android.download.api.config.j;
import com.ss.android.download.api.config.l;
import com.ss.android.download.api.config.q;
import com.ss.android.download.api.config.r;
import com.ss.android.download.api.config.t;
import com.ss.android.download.api.download.DownloadController;
import com.ss.android.download.api.download.DownloadEventConfig;
import com.ss.android.download.api.download.DownloadModel;
import com.ss.android.download.api.model.DownloadAlertDialogInfo;
import com.ss.android.download.api.model.a;
import com.ss.android.downloadlib.addownload.a.a;
import com.ss.android.downloadlib.addownload.model.f;
import com.ss.android.downloadlib.constants.EventConstants;
import com.ss.android.socialbase.downloader.depend.IDownloadSettings;
import com.ss.android.socialbase.downloader.depend.IInstallAppHandler;
import com.ss.android.socialbase.downloader.downloader.DownloaderBuilder;
import com.ss.android.socialbase.downloader.exception.BaseException;
import com.ss.android.socialbase.downloader.logger.Logger;
import com.ss.android.socialbase.downloader.model.DownloadInfo;
import com.ss.android.socialbase.downloader.model.HttpHeader;
import com.ss.android.socialbase.downloader.network.IDownloadHttpConnection;
import com.ss.android.socialbase.downloader.network.IDownloadHttpService;
import java.io.IOException;
import java.io.InputStream;
import java.lang.ref.WeakReference;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.WeakHashMap;
import java.util.concurrent.atomic.AtomicBoolean;
import org.json.JSONException;
import org.json.JSONObject;
public class d {
public static volatile String a;
public static ITTDownloadVisitor c;
private static Context f3048e;
private static Map<Integer, ITTDownloadAdapter.OnEventLogHandler> f3049f;
private static final com.ss.android.download.api.download.a.a f3050g;
private static final AtomicBoolean f3047d = new AtomicBoolean(false);
public static boolean b = true;
public static class e implements IDownloadHttpService {
@Override
public IDownloadHttpConnection downloadWithConnection(int i2, String str, List<HttpHeader> list) throws IOException {
final c.a a = com.bytedance.sdk.openadsdk.downloadnew.c.a(str, list);
if (a != null) {
return new IDownloadHttpConnection() {
@Override
public void cancel() {
}
@Override
public void end() {
try {
a.f3045d.disconnect();
} catch (Exception unused) {
}
}
@Override
public InputStream getInputStream() {
return a.a;
}
@Override
public int getResponseCode() {
return a.c;
}
@Override
public String getResponseHeaderField(String str2) {
Map<String, String> map = a.b;
if (map != null) {
return map.get(str2);
}
return null;
}
};
}
return null;
}
}
static {
try {
a = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getPath();
} catch (Throwable unused) {
}
f3050g = new com.ss.android.download.api.download.a.a() {
@Override
public void a(DownloadModel downloadModel, DownloadController downloadController, DownloadEventConfig downloadEventConfig) {
com.bytedance.sdk.openadsdk.api.a.b("TTDownloadVisitor", "completeListener: onDownloadStart");
}
@Override
public void b(DownloadInfo downloadInfo, String str) {
com.bytedance.sdk.openadsdk.api.a.b("TTDownloadVisitor", "completeListener: onInstalled");
d.c(str);
}
@Override
public void a(DownloadInfo downloadInfo, String str) {
com.bytedance.sdk.openadsdk.api.a.b("TTDownloadVisitor", "completeListener: onDownloadFinished");
}
@Override
public void a(DownloadInfo downloadInfo, BaseException baseException, String str) {
com.bytedance.sdk.openadsdk.api.a.b("TTDownloadVisitor", "completeListener: onDownloadFailed");
}
@Override
public void a(DownloadInfo downloadInfo) {
com.bytedance.sdk.openadsdk.api.a.b("TTDownloadVisitor", "completeListener: onCanceled");
}
};
}
public static void c(String str) {
com.ss.android.downloadad.api.a.b a2;
JSONObject g2;
if (TextUtils.isEmpty(str) || (a2 = f.a().a(str)) == null || (g2 = a2.g()) == null || e() == null) {
return;
}
e().checkAutoControl(g2, str);
}
static ITTDownloadVisitor d() {
return e();
}
private static ITTDownloadVisitor e() {
ITTDownloadVisitor iTTDownloadVisitor = c;
if (iTTDownloadVisitor == null) {
TTAdManager adManager = TTAdSdk.getAdManager();
if (adManager == null) {
return null;
}
return (ITTDownloadVisitor) adManager.getExtra(ITTDownloadVisitor.class, com.bytedance.sdk.openadsdk.downloadnew.b.a(1));
}
return iTTDownloadVisitor;
}
private static Context getContext() {
Context context = f3048e;
return context == null ? TTAppContextHolder.getContext() : context;
}
public static class a implements g {
private void c(com.ss.android.download.api.model.b bVar) {
if (bVar == null) {
return;
}
Object l = bVar.l();
TTDownloadEventModel label = TTDownloadEventModel.builder().setTag(bVar.b()).setExtJson(bVar.h()).setMaterialMeta(l instanceof JSONObject ? (JSONObject) l : null).setLabel(bVar.c());
boolean z = EventConstants.Tag.NOTIFICATION.equals(bVar.b()) || EventConstants.Tag.LANDING_H5_DOWNLOAD_AD_BUTTON.equals(bVar.b());
if (d.d() != null) {
d.d().executeLogUpload(label, z);
}
}
@Override
public void a(com.ss.android.download.api.model.b bVar) {
com.bytedance.sdk.openadsdk.api.a.b("LibEventLogger", "onV3Event");
a(bVar, true);
}
@Override
public void b(com.ss.android.download.api.model.b bVar) {
com.bytedance.sdk.openadsdk.api.a.b("LibEventLogger", "onEvent called");
a(bVar, false);
c(bVar);
}
private void a(com.ss.android.download.api.model.b bVar, boolean z) {
TTDownloadEventLogger tTDownloadEventLogger;
if (d.d() == null || (tTDownloadEventLogger = d.d().getTTDownloadEventLogger()) == null || bVar == null) {
return;
}
if (tTDownloadEventLogger.shouldFilterOpenSdkLog() && d.d().isOpenSdkEvent(bVar.toString())) {
return;
}
if (z) {
tTDownloadEventLogger.onV3Event(d.b(bVar));
} else {
tTDownloadEventLogger.onEvent(d.b(bVar));
}
}
}
public static class c implements i {
@Override
public void a(Activity activity, int i2, String[] strArr, int[] iArr) {
}
@Override
public void a(Activity activity, String[] strArr, final t tVar) {
if (d.d() != null) {
d.d().requestPermission(activity, strArr, new ITTPermissionCallback() {
@Override
public void onDenied(String str) {
t tVar2 = tVar;
if (tVar2 != null) {
tVar2.a(str);
}
}
@Override
public void onGranted() {
t tVar2 = tVar;
if (tVar2 != null) {
tVar2.a();
}
}
});
}
}
@Override
public boolean a(Context context, String str) {
if (d.d() != null) {
return d.d().hasPermission(context, str);
}
return false;
}
}
public static void a(Context context) {
if (context == null) {
context = TTAppContextHolder.getContext();
}
if (context == null || f3047d.get()) {
return;
}
synchronized (d.class) {
if (!f3047d.get()) {
f3048e = context.getApplicationContext();
if (e() != null) {
String initPath = e().initPath(b);
if (!TextUtils.isEmpty(initPath)) {
a = initPath;
}
}
f3047d.set(b(f3048e));
}
}
}
public static void b() {
a().g();
if (e() != null) {
e().clearAllData(a);
}
}
public static class b implements h {
private b() {
}
@Override
public void a(String str, String str2, Map<String, Object> map, final r rVar) {
char c;
int hashCode = str.hashCode();
int i2 = 1;
if (hashCode != 70454) {
if (hashCode == 2461856 && str.equals("POST")) {
c = 1;
}
c = 65535;
} else {
if (str.equals("GET")) {
c = 0;
}
c = 65535;
}
i2 = (c == 0 || c != 1) ? 0 : 0;
if (d.d() != null) {
d.d().execute(i2, str2, map, new ITTHttpCallback() {
@Override
public void onError(Throwable th) {
r rVar2 = rVar;
if (rVar2 != null) {
rVar2.a(th);
}
}
@Override
public void onResponse(String str3) {
r rVar2 = rVar;
if (rVar2 != null) {
rVar2.a(str3);
}
}
});
}
}
@Override
public void a(String str, byte[] bArr, String str2, int i2, final r rVar) {
if (d.d() != null) {
d.d().postBody(str, bArr, str2, new ITTHttpCallback() {
@Override
public void onError(Throwable th) {
r rVar2 = rVar;
if (rVar2 != null) {
rVar2.a(th);
}
}
@Override
public void onResponse(String str3) {
r rVar2 = rVar;
if (rVar2 != null) {
rVar2.a(str3);
}
}
});
}
}
}
public static class C0126d implements l {
private final WeakReference<Context> a;
public C0126d(Context context) {
this.a = new WeakReference<>(context);
}
private DialogBuilder c(final DownloadAlertDialogInfo downloadAlertDialogInfo) {
return DialogBuilder.builder().setTitle(downloadAlertDialogInfo.b).setMessage(downloadAlertDialogInfo.c).setNegativeBtnText(downloadAlertDialogInfo.f11681e).setPositiveBtnText(downloadAlertDialogInfo.f11680d).setIcon(downloadAlertDialogInfo.f11683g).setDialogStatusChangedListener(new IDialogStatusChangedListener() {
@Override
public void onCancel(DialogInterface dialogInterface) {
DownloadAlertDialogInfo.b bVar = downloadAlertDialogInfo.f11684h;
if (bVar != null) {
bVar.c(dialogInterface);
}
}
@Override
public void onNegativeBtnClick(DialogInterface dialogInterface) {
DownloadAlertDialogInfo.b bVar = downloadAlertDialogInfo.f11684h;
if (bVar != null) {
try {
bVar.b(dialogInterface);
} catch (Exception e2) {
e2.printStackTrace();
}
}
}
@Override
public void onPositiveBtnClick(DialogInterface dialogInterface) {
DownloadAlertDialogInfo.b bVar = downloadAlertDialogInfo.f11684h;
if (bVar != null) {
bVar.a(dialogInterface);
}
}
});
}
@Override
public void a(int i2, Context context, DownloadModel downloadModel, String str, Drawable drawable, int i3) {
try {
if (TextUtils.isEmpty(str)) {
return;
}
Toast.makeText(context, str, 0).show();
} catch (Exception e2) {
Logger.e("LibUIFactory", "showToastWithDuration e " + e2.getMessage());
}
}
@Override
public AlertDialog b(DownloadAlertDialogInfo downloadAlertDialogInfo) {
if (downloadAlertDialogInfo != null && d.d() != null) {
Context context = downloadAlertDialogInfo.a;
if (context != null && (context instanceof Activity)) {
return d.d().showDialogBySelf((Activity) downloadAlertDialogInfo.a, downloadAlertDialogInfo.j == 1, c(downloadAlertDialogInfo));
}
d.d().showDialogByDelegate(this.a, downloadAlertDialogInfo.j == 1, c(downloadAlertDialogInfo));
}
return null;
}
}
private static boolean b(Context context) {
if (context == null) {
return false;
}
Context applicationContext = context.getApplicationContext();
String packageName = applicationContext.getPackageName();
if (TextUtils.isEmpty(packageName)) {
packageName = "";
}
com.ss.android.download.api.a a2 = com.ss.android.downloadlib.h.a(applicationContext).a();
if (a2 == null) {
return false;
}
com.ss.android.download.api.a a3 = a2.a(new c()).a(new a()).a(new C0126d(applicationContext)).a(new b()).a(new j() {
@Override
public JSONObject a() {
if (d.d() != null) {
return d.d().getDownloadSettings();
}
return new JSONObject();
}
}).a(new com.ss.android.download.api.config.b() {
@Override
public boolean a() {
if (d.d() != null) {
return d.d().getAppIsBackground();
}
return false;
}
}).a(new a.C0712a().b("143").a(TTAdConstant.APP_NAME).c("4.9.0.4").d(String.valueOf(4904)).a()).a(new q() {
@Override
public byte[] a(byte[] bArr, int i2) {
return new byte[0];
}
});
a3.a(packageName + ".TTFileProvider").a(a(applicationContext, e() != null ? e().getDownloadSettings() : new JSONObject())).a();
com.ss.android.downloadlib.utils.a.a();
com.ss.android.downloadlib.h.a(applicationContext).d().a(1);
com.ss.android.downloadlib.h.a(applicationContext).a(f3050g);
com.ss.android.socialbase.appdownloader.d.j().a(new IInstallAppHandler() {
@Override
public boolean installApp(Intent intent) {
return false;
}
});
TTDownloadEventLogger tTDownloadEventLogger = e().getTTDownloadEventLogger();
if (tTDownloadEventLogger != null) {
tTDownloadEventLogger.onDownloadConfigReady();
}
return true;
}
public static Map<Integer, ITTDownloadAdapter.OnEventLogHandler> c() {
return f3049f;
}
public static void a(String str) {
if (TextUtils.isEmpty(str)) {
return;
}
a = str;
}
public static com.ss.android.downloadlib.h a() {
a(getContext());
return com.ss.android.downloadlib.h.a(getContext());
}
public static boolean a(Context context, Uri uri, DownloadModel downloadModel, DownloadEventConfig downloadEventConfig, DownloadController downloadController, IDownloadButtonClickListener iDownloadButtonClickListener) {
return a().e().a(context, uri, downloadModel, downloadEventConfig, downloadController, iDownloadButtonClickListener);
}
public static boolean a(Context context, Uri uri, DownloadModel downloadModel, DownloadEventConfig downloadEventConfig, DownloadController downloadController) {
return a().e().a(context, uri, downloadModel, downloadEventConfig, downloadController);
}
public static boolean a(Uri uri) {
return com.ss.android.downloadlib.b.j.a(uri);
}
public static void a(int i2) {
Map<Integer, ITTDownloadAdapter.OnEventLogHandler> map = f3049f;
if (map != null) {
map.remove(Integer.valueOf(i2));
}
}
public static void a(int i2, ITTDownloadAdapter.OnEventLogHandler onEventLogHandler) {
if (onEventLogHandler != null) {
if (f3049f == null) {
f3049f = Collections.synchronizedMap(new WeakHashMap());
}
f3049f.put(Integer.valueOf(i2), onEventLogHandler);
}
}
public static boolean a(String str, String str2, JSONObject jSONObject, Object obj) {
Map<Integer, ITTDownloadAdapter.OnEventLogHandler> c2;
boolean z = false;
if (!TextUtils.isEmpty(str) && !TextUtils.isEmpty(str2) && jSONObject != null && (c2 = c()) != null) {
for (Map.Entry<Integer, ITTDownloadAdapter.OnEventLogHandler> entry : c2.entrySet()) {
int intValue = entry.getKey().intValue();
ITTDownloadAdapter.OnEventLogHandler value = entry.getValue();
if (value != null) {
boolean onEventLog = value.onEventLog(intValue, jSONObject.toString(), str, str2, obj);
if (!z && !onEventLog) {
z = true;
}
}
}
}
return z;
}
private static DownloaderBuilder a(Context context, JSONObject jSONObject) {
return new DownloaderBuilder(context).downloadSetting(new IDownloadSettings() {
@Override
public JSONObject get() {
if (d.d() != null) {
return d.d().getDownloadSettings();
}
return new JSONObject();
}
}).downloadExpSwitch(jSONObject.optInt("download_exp_switch_temp", 1040187391)).httpService(new e());
}
public static JSONObject b(com.ss.android.download.api.model.b bVar) {
JSONObject jSONObject = new JSONObject();
try {
jSONObject.put("category", bVar.a());
jSONObject.put("tag", bVar.b());
jSONObject.put(TTDownloadField.TT_LABEL, bVar.c());
jSONObject.put("isAd", bVar.d());
jSONObject.put("adId", bVar.e());
jSONObject.put(TTDownloadField.TT_LOG_EXTRA, bVar.f());
jSONObject.put("extValue", bVar.g());
jSONObject.put("extJson", bVar.h());
jSONObject.put("paramsJson", bVar.i());
jSONObject.put("eventSource", bVar.k());
jSONObject.put("extraObject", bVar.l());
jSONObject.put("clickTrackUrl", bVar.j());
jSONObject.put("isV3", bVar.m());
jSONObject.put("V3EventName", bVar.n());
jSONObject.put("V3EventParams", bVar.o());
} catch (JSONException e2) {
e2.printStackTrace();
}
return jSONObject;
}
public static boolean a(Context context, String str) {
if (context != null && !TextUtils.isEmpty(str)) {
List<DownloadInfo> b2 = com.ss.android.socialbase.appdownloader.d.j().b(context);
if (!b2.isEmpty()) {
for (DownloadInfo downloadInfo : b2) {
if (downloadInfo != null && str.equals(downloadInfo.getUrl())) {
return true;
}
}
}
}
return false;
}
public static boolean a(Activity activity, final ExitInstallListener exitInstallListener) {
return com.ss.android.downloadlib.addownload.a.a.a().a(activity, false, new a.InterfaceC0717a() {
@Override
public void a() {
ExitInstallListener exitInstallListener2 = ExitInstallListener.this;
if (exitInstallListener2 != null) {
exitInstallListener2.onExitInstall();
}
}
});
}
}