k.java 源代码


package com.xiaomi.miui.pushads.sdk;

import android.content.Context;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;
import android.util.Log;
import com.xiaomi.mipush.sdk.MiPushClient;
import com.xiaomi.push.ce;
import com.xiaomi.push.cf;
import java.util.List;

public class k extends MiPushClient.MiPushClientCallback implements c {
    private static k a;

    private int f109a;

    private Context f110a;

    private SharedPreferences f111a;

    private Handler f112a;

    private g f113a;

    private cf f114a;

    private String f115a;
    private int b;

    private String f116b;

    public enum a {
        NONE,
        Wifi,
        MN2G,
        MN3G,
        MN4G
    }

    public static synchronized k a() {
        k kVar;
        synchronized (k.class) {
            kVar = a;
        }
        return kVar;
    }

    public static void a(String str) {
        Log.d("ads-notify-fd5dfce4", str);
    }

    private void a(String str, int i, String str2) {
        new j(this.f110a, this.f111a, 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);
        this.f113a.a(str, j, i);
        this.f113a.a();
    }

    private void a(String str, String str2) {
        a(str, 0, str2);
    }

    private boolean a(ce ceVar) {
        int i;
        SharedPreferences sharedPreferences;
        String str;
        int i2;
        if (ceVar.c <= 0) {
            a("白名单用户");
            return true;
        }
        int i3 = ceVar.a;
        if (i3 == 1) {
            i = ceVar.c * 4;
            a("冒泡上限: " + i);
            sharedPreferences = this.f111a;
            str = "bubblecount";
        } else {
            if (i3 != 2) {
                i = 0;
                i2 = 0;
                if (i2 > i) {
                    return true;
                }
                a("广告次数超过上限---已经获得次数: " + i2 + " 上限: " + i);
                return false;
            }
            i = ceVar.c;
            a("通知上限: " + i);
            sharedPreferences = this.f111a;
            str = "notifycount";
        }
        i2 = sharedPreferences.getInt(str, 0);
        if (i2 > i) {
        }
    }

    public synchronized int a(int i) {
        int i2;
        SharedPreferences sharedPreferences;
        String str;
        i2 = 0;
        try {
            if (i == 2) {
                sharedPreferences = this.f111a;
                str = "notifycount";
            } else if (i == 1) {
                sharedPreferences = this.f111a;
                str = "bubblecount";
            }
            i2 = sharedPreferences.getInt(str, 0);
        } catch (Throwable th) {
            throw th;
        }
        return i2;
    }

    public synchronized void m114a(int i) {
        SharedPreferences.Editor putInt;
        try {
            if (i == 2) {
                putInt = this.f111a.edit().putInt("notifycount", this.f111a.getInt("notifycount", 0) + 1);
            } else if (i == 1) {
                putInt = this.f111a.edit().putInt("bubblecount", this.f111a.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("返回广告为null");
            return;
        }
        if (i == -1) {
            a("广告下载失败: " + 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.f109a++;
                a().m114a(ceVar.a);
            }
            a("广告下载成功: id: " + ceVar.f196a + " 类型: " + ceVar.a + " 成功次数: " + a().a(ceVar.a));
        } else {
            Log.w("com.miui.ads", "广告无效或者超过限制 " + i);
            str = "广告无效或者超过限制";
            d.a(str);
        }
        if (this.f114a == null || i != 0) {
            return;
        }
        if (!a(ceVar)) {
            a("广告数量超过限制,不返回给APP");
        } else {
            a("===========给APP 发送广告信息");
            this.f114a.a(ceVar);
        }
    }

    @Override
    public void onCommandResult(String str, long j, String str2, List<String> list) {
        if (j != 0) {
            a("命令失败: " + str + " code: " + 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.f115a, list.get(i2))) {
                    a("设置别名成功: ");
                    z = true;
                }
            }
            if (z) {
                return;
            }
            a("设置别名失败,重新设置: ");
            this.f112a.sendEmptyMessage(2);
        }
    }

    @Override
    public void onInitializeResult(long j, String str, String str2) {
        if (this.f114a != null) {
            Message obtainMessage = this.f112a.obtainMessage();
            obtainMessage.what = 4;
            obtainMessage.arg1 = (int) j;
            obtainMessage.obj = str2;
            this.f112a.sendMessage(obtainMessage);
        }
        if (0 != j) {
            a("通道初始化失败, 已经通知了app,需要重新 open 通道");
            return;
        }
        a("通道进行初始化OK");
        this.f112a.sendEmptyMessage(3);
        this.f112a.sendEmptyMessage(5);
    }

    @Override
    public void onReceiveMessage(String str, String str2, String str3, boolean z) {
        a("接受到消息 " + str + "##" + str3 + "##");
        if (f.a(this.f115a)) {
            a("没有有效alias,忽略消息 " + str + "##" + str3 + "##");
            return;
        }
        if (f.a(str2) || f.a(this.f115a) || TextUtils.equals(this.f115a, str2)) {
            a(str, this.f116b);
            return;
        }
        a("接受到不同alias 的消息,注销旧的 " + str + "##" + str3 + "##");
        MiPushClient.unsetAlias(this.f110a, str2, getCategory());
    }

    @Override
    public void onSubscribeResult(long j, String str, String str2) {
    }

    @Override
    public void onUnsubscribeResult(long j, String str, String str2) {
    }
}