l.java 源代码
package com.xiaomi.miui.pushads.sdk;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;
import android.util.Log;
import com.huawei.hms.push.constant.RemoteMessageConst;
import com.ss.android.socialbase.downloader.utils.DownloadExpSwitchCode;
import com.xiaomi.mipush.sdk.MiPushClient;
import com.xiaomi.push.cd;
import com.xiaomi.push.ce;
import com.xiaomi.push.cg;
import com.xiaomi.push.cj;
import java.util.List;
import org.json.JSONException;
import org.json.JSONObject;
public class l extends MiPushClient.MiPushClientCallback implements c {
private static l a = null;
static final boolean f118a = true;
private int f119a;
private Context f120a;
private SharedPreferences f121a;
private Handler f122a;
private e f123a;
private g f124a;
private cd f125a;
private cj f126a;
private String f127a;
private int b;
private String f128b;
private String c;
private PendingIntent a(h hVar, int i) {
Intent intent = new Intent(this.f120a, (Class<?>) MiPushRelayTraceService.class);
Bundle bundle = new Bundle();
bundle.putAll(hVar.a());
bundle.putInt("intenttype", i);
if (i == 2 && this.f123a != null) {
PendingIntent a2 = this.f123a.a(new h(hVar));
if (a2 != null) {
bundle.putParcelable("pendingintent", a2);
}
}
intent.putExtras(bundle);
int i2 = (int) hVar.f196a;
return PendingIntent.getService(this.f120a, (i2 * i2) + i, intent, DownloadExpSwitchCode.BUGFIX_SIGBUS_24_25);
}
public static synchronized l a() {
l lVar;
synchronized (l.class) {
lVar = a;
}
return lVar;
}
private void a(h hVar) {
Bitmap decodeFile;
a("sdk handle notify");
int hashCode = hVar.a.hashCode() + hVar.d.hashCode();
int a2 = this.f123a.a();
Notification.Builder builder = new Notification.Builder(this.f120a);
if (a2 != 0) {
builder.setSmallIcon(a2);
}
NotificationBaseRemoteView notificationBaseRemoteView = new NotificationBaseRemoteView(this.f120a);
notificationBaseRemoteView.a(hVar.d, hVar.e);
notificationBaseRemoteView.a(a2);
a(hVar, hashCode, notificationBaseRemoteView);
builder.setContent(notificationBaseRemoteView);
builder.setTicker(hVar.c).setAutoCancel(true);
builder.setContentIntent(a(hVar, 2));
builder.setDeleteIntent(a(hVar, 1));
Notification build = builder.build();
if (!TextUtils.isEmpty(hVar.a()) && (decodeFile = BitmapFactory.decodeFile(hVar.a())) != null) {
a("big picture");
NotificationBigRemoteView notificationBigRemoteView = new NotificationBigRemoteView(this.f120a);
notificationBigRemoteView.a(hVar.d, hVar.e);
notificationBigRemoteView.a(a2);
notificationBigRemoteView.a(decodeFile);
a(hVar, hashCode, notificationBigRemoteView);
build.bigContentView = notificationBigRemoteView;
}
((NotificationManager) this.f120a.getSystemService(RemoteMessageConst.NOTIFICATION)).notify(hashCode, build);
}
private void a(h hVar, int i, NotificationBaseRemoteView notificationBaseRemoteView) {
e eVar;
PendingIntent b = (hVar.g == null || TextUtils.isEmpty(hVar.g.trim()) || (eVar = this.f123a) == null) ? null : eVar.b(new h(hVar));
if (b == null) {
return;
}
Intent intent = new Intent(this.f120a, (Class<?>) MiPushRelayTraceService.class);
Bundle bundle = new Bundle();
bundle.putAll(hVar.a());
bundle.putInt("intenttype", 2);
bundle.putInt("notifyid", i);
bundle.putParcelable("pendingintent", b);
intent.putExtras(bundle);
int i2 = (int) hVar.f196a;
notificationBaseRemoteView.a(hVar.g, PendingIntent.getService(this.f120a, (i2 * i2) + 3, intent, DownloadExpSwitchCode.BUGFIX_SIGBUS_24_25));
}
private void a(ce ceVar) {
if (this.f126a != null) {
a(this.f128b + "--->receivedT " + ceVar.f196a);
this.f126a.c(new cg(ceVar));
}
}
public static void a(String str) {
Log.d("ads-notify-fd5dfce4", str);
}
private void a(String str, int i, String str2) {
new j(this.f120a, this.f121a, str, i, str2, this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, new String[0]);
}
private void a(String str, long j, int i) {
this.b++;
d.a("存入cache 的数量: " + this.b);
g gVar = this.f124a;
if (gVar != null) {
gVar.a(str, j, i);
this.f124a.a();
}
}
private void a(String str, String str2) {
a(str, 0, str2);
}
private boolean m115a(ce ceVar) {
int i;
SharedPreferences sharedPreferences;
String str;
int i2;
if (ceVar.c <= 0) {
a("white user");
return true;
}
int i3 = ceVar.a;
if (i3 == 1) {
i = ceVar.c * 4;
a("bubble uplimit: " + i);
sharedPreferences = this.f121a;
str = "bubblecount";
} else {
if (i3 != 2) {
i = 0;
i2 = 0;
if (i2 > i) {
return true;
}
a("reach up limit---already count: " + i2 + " 上限: " + i);
return false;
}
i = ceVar.c;
a("notify uplimit: " + i);
sharedPreferences = this.f121a;
str = "notifycount";
}
i2 = sharedPreferences.getInt(str, 0);
if (i2 > i) {
}
}
private boolean m116a(String str) {
try {
JSONObject jSONObject = new JSONObject(str);
if (jSONObject.optInt("showType") != 1000) {
return false;
}
cd cdVar = this.f125a;
if (cdVar != null) {
cdVar.a(jSONObject.optString("content"));
return true;
}
Log.e("ads-notify-fd5dfce4", "接受到外部的消息,但是外部的listener");
return true;
} catch (JSONException unused) {
return true;
}
}
private void b(ce ceVar) {
a(ceVar);
if (ceVar.a == 1) {
a aVar = (a) ceVar;
e eVar = this.f123a;
if (eVar != null) {
eVar.a(aVar);
return;
}
return;
}
if (ceVar.a == 2) {
h hVar = (h) ceVar;
try {
a(this.f128b + "--->get notify");
if (this.f123a != null) {
if (this.f123a.m111a(new h(hVar))) {
return;
}
a(hVar);
}
} catch (Exception unused) {
Log.e("ads-notify-fd5dfce4", "SDK 发出notification 失败");
}
}
}
public synchronized int a(int i) {
int i2;
SharedPreferences sharedPreferences;
String str;
i2 = 0;
try {
if (i == 2) {
sharedPreferences = this.f121a;
str = "notifycount";
} else if (i == 1) {
sharedPreferences = this.f121a;
str = "bubblecount";
}
i2 = sharedPreferences.getInt(str, 0);
} catch (Throwable th) {
throw th;
}
return i2;
}
public synchronized void m117a(int i) {
SharedPreferences.Editor putInt;
try {
if (i == 2) {
putInt = this.f121a.edit().putInt("notifycount", this.f121a.getInt("notifycount", 0) + 1);
} else if (i == 1) {
putInt = this.f121a.edit().putInt("bubblecount", this.f121a.getInt("bubblecount", 0) + 1);
}
putInt.commit();
} catch (Throwable th) {
throw th;
}
}
@Override
public void a(int i, ce ceVar, j jVar) {
String str;
if (ceVar == null) {
a(this.f128b + "--->cell is null");
return;
}
if (i == -1) {
a(this.f128b + "--->download failed: " + ceVar.f196a);
ceVar.d = ceVar.d + 1;
if (ceVar.d < 10) {
d.a("下载失败写入缓存 " + ceVar.h + " " + ceVar.f198b + " " + ceVar.d);
a(ceVar.h, ceVar.f198b, ceVar.d);
} else {
str = "下载失败次数超过 10 不写入缓存";
d.a(str);
}
} else if (i == 0) {
if (ceVar.c > 0) {
this.f119a++;
a().m117a(ceVar.a);
}
a(this.f128b + "--->download sucess: id: " + ceVar.f196a + " type: " + ceVar.a + " count: " + a().a(ceVar.a));
} else {
Log.w("com.miui.ads", "广告无效或者超过限制 " + i);
str = "广告无效或者超过限制";
d.a(str);
}
if (this.f123a == null || i != 0) {
return;
}
if (m115a(ceVar)) {
b(ceVar);
return;
}
a(this.f128b + "--->reach limit, no return to app");
}
@Override
public void onCommandResult(String str, long j, String str2, List<String> list) {
a(this.f128b + "--->onCommandResult == " + str + " resultCode: " + j + " reason: " + str2);
for (int i = 0; i < list.size(); i++) {
a("param: " + list.get(i));
}
if (TextUtils.equals(MiPushClient.COMMAND_SET_ALIAS, str)) {
boolean z = false;
for (int i2 = 0; i2 < list.size(); i2++) {
if (TextUtils.equals(this.f127a, list.get(i2))) {
a(this.f128b + "--->alias ok: ");
z = true;
}
}
if (z) {
return;
}
a(this.f128b + "--->alias failed, retry: ");
}
}
@Override
public void onInitializeResult(long j, String str, String str2) {
if (this.f123a != null) {
Message obtainMessage = this.f122a.obtainMessage();
obtainMessage.what = 4;
obtainMessage.arg1 = (int) j;
obtainMessage.obj = str2;
this.f122a.sendMessage(obtainMessage);
}
if (0 != j) {
a(this.f128b + "--->chanle failed, need app reopen");
return;
}
a(this.f128b + "--->cahnel OK");
this.f122a.sendEmptyMessage(3);
if (!f.a(this.c)) {
this.f122a.sendEmptyMessage(6);
}
this.f122a.sendEmptyMessage(5);
}
@Override
public void onReceiveMessage(String str, String str2, String str3, boolean z) {
a(this.f128b + "--->##" + str3);
if (f.a(this.f127a) && f.a(this.c)) {
a(this.f128b + "--->no alias,ignore the msg " + str + "##" + str3);
return;
}
if (!f.a(str2) && !f.a(this.f127a) && !TextUtils.equals(this.f127a, str2)) {
a(this.f128b + "--->get msg for different alias. unset " + str + "##" + str3);
MiPushClient.unsetAlias(this.f120a, str2, getCategory());
return;
}
if (f.a(str3) || f.a(this.c) || TextUtils.equals(this.c, str3)) {
if (m116a(str)) {
return;
}
a(str, this.f128b);
return;
}
a(this.f128b + "--->get msg for old topic, unset " + str + "##" + str3);
MiPushClient.unsubscribe(this.f120a, str3, getCategory());
}
@Override
public void onSubscribeResult(long j, String str, String str2) {
a(this.f128b + "--->topic resultCode: " + j + " reason: " + str + " topic: " + str2);
if (j != 0) {
this.f122a.sendEmptyMessageDelayed(6, 3600000L);
}
}
@Override
public void onUnsubscribeResult(long j, String str, String str2) {
a(this.f128b + "--->unsuscribe topic resultCode: " + j + " reason: " + str + " topic: " + str2);
}
}