- 28,932 files - Full Java source code - Smali files - Resources Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
502 lines
21 KiB
Java
502 lines
21 KiB
Java
package com.mbridge.msdk.mbbanner.common.c;
|
||
|
||
import android.content.Context;
|
||
import android.graphics.Bitmap;
|
||
import android.net.Uri;
|
||
import android.text.TextUtils;
|
||
import androidx.work.WorkRequest;
|
||
import com.mbridge.msdk.MBridgeConstans;
|
||
import com.mbridge.msdk.foundation.db.g;
|
||
import com.mbridge.msdk.foundation.db.j;
|
||
import com.mbridge.msdk.foundation.entity.CampaignEx;
|
||
import com.mbridge.msdk.foundation.entity.CampaignUnit;
|
||
import com.mbridge.msdk.foundation.same.c;
|
||
import com.mbridge.msdk.foundation.same.net.f.e;
|
||
import com.mbridge.msdk.foundation.tools.SameMD5;
|
||
import com.mbridge.msdk.foundation.tools.af;
|
||
import com.mbridge.msdk.foundation.tools.ak;
|
||
import com.mbridge.msdk.foundation.tools.ap;
|
||
import com.mbridge.msdk.foundation.tools.aq;
|
||
import com.mbridge.msdk.mbbanner.common.util.BannerUtils;
|
||
import com.mbridge.msdk.newreward.function.common.MBridgeCommon;
|
||
import com.mbridge.msdk.out.MBridgeIds;
|
||
import java.io.File;
|
||
import java.io.FileOutputStream;
|
||
import java.util.ArrayList;
|
||
import java.util.List;
|
||
import java.util.Timer;
|
||
import java.util.TimerTask;
|
||
|
||
/* loaded from: classes4.dex */
|
||
public class b {
|
||
private static final String a = "b";
|
||
private Context b;
|
||
private com.mbridge.msdk.mbbanner.common.a.b d;
|
||
private com.mbridge.msdk.mbbanner.common.util.a e;
|
||
private com.mbridge.msdk.mbbanner.common.b.b f;
|
||
private com.mbridge.msdk.mbbanner.common.b.d g;
|
||
private int c = 0;
|
||
private volatile boolean h = false;
|
||
private Timer i = new Timer();
|
||
private volatile List<String> j = new ArrayList();
|
||
private volatile boolean k = false;
|
||
private volatile boolean l = false;
|
||
private volatile boolean m = false;
|
||
private String n = "";
|
||
|
||
public b(Context context, com.mbridge.msdk.mbbanner.common.a.b bVar, com.mbridge.msdk.mbbanner.common.b.b bVar2, com.mbridge.msdk.mbbanner.common.util.a aVar) {
|
||
this.b = context.getApplicationContext();
|
||
this.d = bVar;
|
||
this.f = bVar2;
|
||
this.e = aVar;
|
||
}
|
||
|
||
private void a(String str, int i) {
|
||
if (this.m) {
|
||
return;
|
||
}
|
||
if ((this.k || this.l) && this.j.size() == 0) {
|
||
af.c(a, "在子线程处理业务逻辑 完成");
|
||
this.h = true;
|
||
this.m = true;
|
||
this.i.cancel();
|
||
this.e.a(this.f, str, i);
|
||
this.g.a(str);
|
||
}
|
||
}
|
||
|
||
public final void a(String str, int i, String str2, boolean z, CampaignEx campaignEx) {
|
||
if (z) {
|
||
if (i == 1) {
|
||
af.c(a, "downloadResource--> Success Image");
|
||
synchronized (this) {
|
||
try {
|
||
this.j.remove(str2);
|
||
if (this.j.size() == 0) {
|
||
a(str, i);
|
||
}
|
||
} finally {
|
||
}
|
||
}
|
||
return;
|
||
}
|
||
if (i == 2) {
|
||
af.c(a, "downloadResource--> Success banner_html");
|
||
this.l = true;
|
||
a(str, i);
|
||
return;
|
||
} else {
|
||
if (i == 3) {
|
||
af.c(a, "downloadResource--> Success banner_url");
|
||
this.k = true;
|
||
a(str, i);
|
||
return;
|
||
}
|
||
return;
|
||
}
|
||
}
|
||
if (i == -1) {
|
||
af.b(a, " unitId =" + str + " --> time out!");
|
||
}
|
||
this.i.cancel();
|
||
String str3 = a;
|
||
af.c(str3, "在子线程处理业务逻辑 完成");
|
||
af.c(str3, "downloadResource--> Fail");
|
||
this.h = true;
|
||
com.mbridge.msdk.foundation.c.b bVar = new com.mbridge.msdk.foundation.c.b(880027);
|
||
MBridgeIds mBridgeIds = new MBridgeIds();
|
||
mBridgeIds.setUnitId(str);
|
||
bVar.a(mBridgeIds);
|
||
bVar.b(this.d.d());
|
||
bVar.a(campaignEx);
|
||
this.e.b(this.f, bVar);
|
||
this.g.a(str);
|
||
}
|
||
|
||
public final void a(String str, String str2, final com.mbridge.msdk.mbbanner.common.a.a aVar, com.mbridge.msdk.mbbanner.common.b.d dVar) {
|
||
boolean z;
|
||
try {
|
||
af.c(a, "requestCampaign--> started");
|
||
this.g = dVar;
|
||
com.mbridge.msdk.mbbanner.common.f.a aVar2 = new com.mbridge.msdk.mbbanner.common.f.a() { // from class: com.mbridge.msdk.mbbanner.common.c.b.2
|
||
@Override // com.mbridge.msdk.mbbanner.common.f.a
|
||
public final void a(CampaignUnit campaignUnit) {
|
||
try {
|
||
af.c(b.a, "requestCampaign--> Succeed");
|
||
campaignUnit.setLocalRequestId(aVar.e());
|
||
b.this.e.a(b.this.f, campaignUnit, this.unitId);
|
||
b.a(b.this, this.unitId, aVar.e(), campaignUnit);
|
||
} catch (Exception e) {
|
||
af.c(b.a, "requestCampaign--> Fail with exception = " + e.getMessage());
|
||
com.mbridge.msdk.foundation.c.b bVar = new com.mbridge.msdk.foundation.c.b(880000);
|
||
bVar.a(new MBridgeIds(this.placementId, this.unitId));
|
||
bVar.b(aVar.e());
|
||
bVar.a((campaignUnit == null || campaignUnit.getAds() == null || campaignUnit.getAds().isEmpty()) ? null : campaignUnit.getAds().get(0));
|
||
bVar.a((Throwable) e);
|
||
b.this.e.a(b.this.f, bVar);
|
||
b.this.g.a(this.unitId);
|
||
}
|
||
}
|
||
|
||
@Override // com.mbridge.msdk.mbbanner.common.f.a
|
||
public final void a(int i, String str3) {
|
||
af.c(b.a, "requestCampaign--> Fail errorCode:" + i + " msg:" + str3);
|
||
com.mbridge.msdk.foundation.c.b bVar = new com.mbridge.msdk.foundation.c.b(880003);
|
||
bVar.a(i + "#" + str3);
|
||
bVar.a(new MBridgeIds(this.placementId, this.unitId));
|
||
bVar.b(aVar.e());
|
||
b.this.e.a(b.this.f, bVar);
|
||
b.this.g.a(this.unitId);
|
||
}
|
||
};
|
||
aVar2.setUnitId(str2);
|
||
aVar2.setPlacementId(str);
|
||
aVar2.setAdType(296);
|
||
com.mbridge.msdk.mbbanner.common.e.a aVar3 = new com.mbridge.msdk.mbbanner.common.e.a(this.b);
|
||
this.c = a(str2);
|
||
e a2 = com.mbridge.msdk.mbbanner.common.a.c.a(false, this.b, str2, this.d.a(), this.c, aVar);
|
||
String d = ak.d(str2);
|
||
if (!TextUtils.isEmpty(d)) {
|
||
a2.a("j", d);
|
||
}
|
||
String c = aVar.c();
|
||
if (TextUtils.isEmpty(c)) {
|
||
z = false;
|
||
} else {
|
||
aVar2.a(c);
|
||
z = true;
|
||
}
|
||
this.e.a(z);
|
||
aVar3.choiceV3OrV5BySetting(1, a2, aVar2, c, WorkRequest.DEFAULT_BACKOFF_DELAY_MILLIS);
|
||
} catch (Exception e) {
|
||
af.b(a, e.getMessage());
|
||
com.mbridge.msdk.foundation.c.b bVar = new com.mbridge.msdk.foundation.c.b(880002);
|
||
bVar.a(new MBridgeIds(str, str2));
|
||
this.e.a(this.f, bVar);
|
||
this.g.a(str2);
|
||
}
|
||
}
|
||
|
||
private List<CampaignEx> a(final String str, CampaignUnit campaignUnit) {
|
||
ArrayList arrayList = new ArrayList();
|
||
if (campaignUnit != null) {
|
||
try {
|
||
if (campaignUnit.getAds() != null && campaignUnit.getAds().size() > 0) {
|
||
ArrayList<CampaignEx> ads = campaignUnit.getAds();
|
||
af.c(a, "getNeedShowList 总共返回的campaign有:" + ads.size());
|
||
for (int i = 0; i < ads.size(); i++) {
|
||
final CampaignEx campaignEx = ads.get(i);
|
||
if (campaignEx != null) {
|
||
if (campaignEx.getOfferType() != 99) {
|
||
if (TextUtils.isEmpty(campaignEx.getBannerUrl()) && TextUtils.isEmpty(campaignEx.getBannerHtml()) && TextUtils.isEmpty(campaignEx.getImageUrl())) {
|
||
}
|
||
if (ak.c(campaignEx)) {
|
||
campaignEx.setRtinsType(ak.c(this.b, campaignEx.getPackageName()) ? 1 : 2);
|
||
}
|
||
if (com.mbridge.msdk.foundation.same.c.a(this.b, campaignEx)) {
|
||
arrayList.add(campaignEx);
|
||
} else {
|
||
ak.a(str, campaignEx, com.mbridge.msdk.foundation.same.a.x);
|
||
this.n = "APP ALREADY INSTALLED";
|
||
}
|
||
final Context context = this.b;
|
||
final com.mbridge.msdk.foundation.same.report.d.a.a aVar = null;
|
||
try {
|
||
com.mbridge.msdk.foundation.same.c.a(campaignEx, context, null, new c.a() { // from class: com.mbridge.msdk.mbbanner.common.c.b.3
|
||
@Override // com.mbridge.msdk.foundation.same.c.a
|
||
public final void a(String str2, com.mbridge.msdk.foundation.same.report.d.c cVar) {
|
||
if (TextUtils.isEmpty(str2)) {
|
||
return;
|
||
}
|
||
com.mbridge.msdk.foundation.same.report.d.e eVar = new com.mbridge.msdk.foundation.same.report.d.e();
|
||
eVar.a(MBridgeConstans.PROPERTIES_UNIT_ID, str);
|
||
cVar.a(str2, eVar);
|
||
try {
|
||
com.mbridge.msdk.foundation.same.report.d.d.a().a(str2, cVar, campaignEx, context, aVar);
|
||
} catch (Exception e) {
|
||
af.b("BannerReport", e.getMessage());
|
||
}
|
||
}
|
||
});
|
||
} catch (Exception e) {
|
||
af.b(a, e.getMessage());
|
||
}
|
||
}
|
||
}
|
||
}
|
||
af.c(a, "getNeedShowList 返回有以下带有视频素材的campaign:" + arrayList.size());
|
||
}
|
||
} catch (Exception e2) {
|
||
af.b(a, e2.getMessage());
|
||
}
|
||
}
|
||
return arrayList;
|
||
}
|
||
|
||
private void a(String str, List<CampaignEx> list) {
|
||
if (list == null || list.isEmpty()) {
|
||
return;
|
||
}
|
||
for (CampaignEx campaignEx : list) {
|
||
if (!TextUtils.isEmpty(campaignEx.getImageUrl())) {
|
||
this.j.add(campaignEx.getImageUrl());
|
||
com.mbridge.msdk.foundation.same.c.b.a(this.b).a(campaignEx.getImageUrl(), new a(this, str, campaignEx));
|
||
com.mbridge.msdk.foundation.same.report.d.c a2 = com.mbridge.msdk.mbbanner.common.d.a.a(str, campaignEx.getCurrentLocalRid());
|
||
a2.a(campaignEx);
|
||
a2.a(10);
|
||
com.mbridge.msdk.foundation.same.report.d.e eVar = new com.mbridge.msdk.foundation.same.report.d.e();
|
||
eVar.a("resource_type", 10);
|
||
com.mbridge.msdk.mbbanner.common.d.a.a("m_download_start", a2, eVar);
|
||
}
|
||
}
|
||
}
|
||
|
||
public static class a implements com.mbridge.msdk.foundation.same.c.c {
|
||
private b a;
|
||
private String b;
|
||
private CampaignEx c;
|
||
|
||
public a(b bVar, String str, CampaignEx campaignEx) {
|
||
this.a = bVar;
|
||
this.b = str;
|
||
this.c = campaignEx;
|
||
}
|
||
|
||
@Override // com.mbridge.msdk.foundation.same.c.c
|
||
public final void onSuccessLoad(Bitmap bitmap, String str) {
|
||
if (MBridgeConstans.DEBUG) {
|
||
af.c(b.a, "DownloadImageListener campaign image success");
|
||
}
|
||
b bVar = this.a;
|
||
if (bVar != null) {
|
||
bVar.a(this.b, 1, str, true, this.c);
|
||
}
|
||
try {
|
||
com.mbridge.msdk.foundation.same.report.d.c a = com.mbridge.msdk.mbbanner.common.d.a.a(this.b, this.c.getCurrentLocalRid());
|
||
a.a(this.c);
|
||
a.a(10);
|
||
a.a(10);
|
||
com.mbridge.msdk.foundation.same.report.d.e eVar = new com.mbridge.msdk.foundation.same.report.d.e();
|
||
eVar.a("resource_type", 10);
|
||
eVar.a("result", 1);
|
||
eVar.a("url", str);
|
||
com.mbridge.msdk.mbbanner.common.d.a.a("m_download_end", a, eVar);
|
||
} catch (Throwable th) {
|
||
af.b(b.a, th.getMessage());
|
||
}
|
||
}
|
||
|
||
@Override // com.mbridge.msdk.foundation.same.c.c
|
||
public final void onFailedLoad(String str, String str2) {
|
||
if (MBridgeConstans.DEBUG) {
|
||
af.c(b.a, "DownloadImageListener campaign image fail");
|
||
}
|
||
b bVar = this.a;
|
||
if (bVar != null) {
|
||
bVar.a(this.b, 1, str2, false, this.c);
|
||
}
|
||
try {
|
||
com.mbridge.msdk.foundation.same.report.d.c a = com.mbridge.msdk.mbbanner.common.d.a.a(this.b, this.c.getCurrentLocalRid());
|
||
a.a(this.c);
|
||
a.a(10);
|
||
com.mbridge.msdk.foundation.same.report.d.e eVar = new com.mbridge.msdk.foundation.same.report.d.e();
|
||
a.a(10);
|
||
eVar.a("resource_type", 10);
|
||
eVar.a("result", 3);
|
||
eVar.a("url", str2);
|
||
com.mbridge.msdk.mbbanner.common.d.a.a("m_download_end", a, eVar);
|
||
} catch (Throwable th) {
|
||
af.b(b.a, th.getMessage());
|
||
}
|
||
}
|
||
}
|
||
|
||
private String a(String str, String str2, CampaignEx campaignEx) {
|
||
File file;
|
||
Throwable th;
|
||
File file2;
|
||
FileOutputStream fileOutputStream;
|
||
String str3 = "";
|
||
if (!TextUtils.isEmpty(str2)) {
|
||
FileOutputStream fileOutputStream2 = null;
|
||
try {
|
||
try {
|
||
try {
|
||
String a2 = com.mbridge.msdk.foundation.same.b.e.a(com.mbridge.msdk.foundation.same.b.c.MBRIDGE_700_HTML);
|
||
String md5 = SameMD5.getMD5(aq.b(str2));
|
||
if (TextUtils.isEmpty(md5)) {
|
||
md5 = String.valueOf(System.currentTimeMillis());
|
||
}
|
||
file2 = new File(a2, md5.concat(".html"));
|
||
Uri.parse(str2).getPath();
|
||
fileOutputStream = new FileOutputStream(file2);
|
||
} catch (Exception e) {
|
||
e = e;
|
||
}
|
||
} catch (Throwable th2) {
|
||
th = th2;
|
||
}
|
||
} catch (Exception e2) {
|
||
af.b(a, e2.getMessage());
|
||
}
|
||
try {
|
||
fileOutputStream.write(str2.getBytes());
|
||
fileOutputStream.flush();
|
||
str3 = file2.getAbsolutePath();
|
||
fileOutputStream.close();
|
||
} catch (Exception e3) {
|
||
e = e3;
|
||
fileOutputStream2 = fileOutputStream;
|
||
af.b(a, e.getMessage());
|
||
if (fileOutputStream2 != null) {
|
||
fileOutputStream2.close();
|
||
}
|
||
file = new File(str3);
|
||
if (file.exists()) {
|
||
}
|
||
a(str, 2, str2, false, campaignEx);
|
||
return str3;
|
||
} catch (Throwable th3) {
|
||
th = th3;
|
||
fileOutputStream2 = fileOutputStream;
|
||
if (fileOutputStream2 != null) {
|
||
try {
|
||
fileOutputStream2.close();
|
||
throw th;
|
||
} catch (Exception e4) {
|
||
af.b(a, e4.getMessage());
|
||
throw th;
|
||
}
|
||
}
|
||
throw th;
|
||
}
|
||
file = new File(str3);
|
||
if (file.exists() || !file.isFile() || !file.canRead()) {
|
||
a(str, 2, str2, false, campaignEx);
|
||
} else {
|
||
a(str, 2, str2, true, campaignEx);
|
||
}
|
||
}
|
||
return str3;
|
||
}
|
||
|
||
private int a(String str) {
|
||
try {
|
||
int b = this.d.b();
|
||
if (b > this.d.c()) {
|
||
return 0;
|
||
}
|
||
return b;
|
||
} catch (Exception e) {
|
||
e.printStackTrace();
|
||
return 0;
|
||
}
|
||
}
|
||
|
||
public static /* synthetic */ void a(b bVar, final String str, String str2, final CampaignUnit campaignUnit) {
|
||
com.mbridge.msdk.foundation.c.b bVar2;
|
||
CampaignEx campaignEx;
|
||
if (campaignUnit == null) {
|
||
com.mbridge.msdk.foundation.c.b bVar3 = new com.mbridge.msdk.foundation.c.b(880003);
|
||
MBridgeIds mBridgeIds = new MBridgeIds();
|
||
mBridgeIds.setUnitId(str);
|
||
bVar3.a(mBridgeIds);
|
||
bVar3.b(str2);
|
||
bVar.e.a(bVar.f, bVar3);
|
||
bVar.g.a(str);
|
||
return;
|
||
}
|
||
List<CampaignEx> a2 = bVar.a(str, campaignUnit);
|
||
new Thread(new Runnable() { // from class: com.mbridge.msdk.mbbanner.common.c.b.4
|
||
@Override // java.lang.Runnable
|
||
public final void run() {
|
||
af.c(b.a, "在单独子线程保存数据库 开始");
|
||
j.a(g.a(b.this.b)).a();
|
||
CampaignUnit campaignUnit2 = campaignUnit;
|
||
if (campaignUnit2 != null && campaignUnit2.getAds() != null && campaignUnit.getAds().size() > 0) {
|
||
BannerUtils.uisList(b.this.b, campaignUnit.getAds());
|
||
}
|
||
af.c(b.a, "在单独子线程保存数据库 完成");
|
||
}
|
||
}).start();
|
||
int i = 0;
|
||
if (a2 == null || a2.size() == 0) {
|
||
af.c(a, "tryDownloadOnLoadSuccess 返回的campaign 没有符合下载规则的");
|
||
if (bVar.n.contains("INSTALLED")) {
|
||
bVar2 = new com.mbridge.msdk.foundation.c.b(880021, "APP ALREADY INSTALLED");
|
||
} else {
|
||
bVar2 = new com.mbridge.msdk.foundation.c.b(880003);
|
||
}
|
||
MBridgeIds mBridgeIds2 = new MBridgeIds();
|
||
mBridgeIds2.setUnitId(str);
|
||
bVar2.a(mBridgeIds2);
|
||
bVar2.b(str2);
|
||
if (campaignUnit.getAds() != null && campaignUnit.getAds().size() > 0 && (campaignEx = campaignUnit.getAds().get(0)) != null) {
|
||
bVar2.a(campaignEx);
|
||
}
|
||
bVar.e.a(bVar.f, bVar2);
|
||
bVar.g.a(str);
|
||
return;
|
||
}
|
||
String str3 = a;
|
||
af.c(str3, "在子线程处理业务逻辑 开始");
|
||
final CampaignEx campaignEx2 = a2.get(0);
|
||
bVar.i.schedule(new TimerTask() { // from class: com.mbridge.msdk.mbbanner.common.c.b.1
|
||
@Override // java.util.TimerTask, java.lang.Runnable
|
||
public final void run() {
|
||
if (b.this.h) {
|
||
return;
|
||
}
|
||
b.this.h = true;
|
||
b.this.a(str, -1, "", false, campaignEx2);
|
||
}
|
||
}, MBridgeCommon.DEFAULT_LOAD_TIMEOUT);
|
||
bVar.d.a(campaignUnit.getSessionId());
|
||
int i2 = bVar.c;
|
||
try {
|
||
if (a2.size() > 0) {
|
||
i2 += a2.size();
|
||
}
|
||
if (i2 > bVar.d.c()) {
|
||
af.c(str3, "saveNextOffset 重置offset为0");
|
||
i2 = 0;
|
||
}
|
||
af.c(str3, "saveNextOffset 算出 下次的offset是:" + i2);
|
||
if (ap.b(str)) {
|
||
bVar.d.a(i2);
|
||
}
|
||
} catch (Exception e) {
|
||
e.printStackTrace();
|
||
}
|
||
String trim = campaignEx2.getBannerUrl().trim();
|
||
if (TextUtils.isEmpty(trim)) {
|
||
String trim2 = campaignEx2.getBannerHtml().trim();
|
||
if (!TextUtils.isEmpty(trim2)) {
|
||
String a3 = bVar.a(str, trim2, campaignEx2);
|
||
if (a2.size() > 0) {
|
||
while (i < a2.size()) {
|
||
a2.get(i).setBannerHtml(a3);
|
||
a2.get(i).setHasMBTplMark(trim2.contains("<MBTPLMARK>"));
|
||
i++;
|
||
}
|
||
}
|
||
} else {
|
||
bVar.l = true;
|
||
bVar.k = true;
|
||
}
|
||
} else {
|
||
if (!TextUtils.isEmpty(trim)) {
|
||
bVar.a(str, 3, trim, true, campaignEx2);
|
||
}
|
||
if (a2.size() > 0) {
|
||
while (i < a2.size()) {
|
||
a2.get(i).setBannerUrl(campaignEx2.getBannerUrl());
|
||
a2.get(i).setHasMBTplMark(true);
|
||
i++;
|
||
}
|
||
}
|
||
}
|
||
bVar.a(str, a2);
|
||
}
|
||
}
|