������������������.apk分析 / ax.java


package com.xiaomi.push.service;

import android.content.Context;
import android.content.SharedPreferences;
import android.util.Pair;
import com.xiaomi.channel.commonutils.logger.b;
import com.xiaomi.push.ag;
import com.xiaomi.push.bm;
import com.xiaomi.push.ho;
import com.xiaomi.push.hp;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;

public class ax {
    private static volatile ax a;

    /* renamed from: a  reason: collision with other field name */
    protected SharedPreferences f7546a;

    /* renamed from: a  reason: collision with other field name */
    private HashSet<a> f7547a = new HashSet<>();
    protected SharedPreferences b;

    public static abstract class a implements Runnable {
        private String mDescription;
        private int mId;

        public a(int i, String str) {
            this.mId = i;
            this.mDescription = str;
        }

        public boolean equals(Object obj) {
            return (obj instanceof a) && this.mId == ((a) obj).mId;
        }

        public int hashCode() {
            return this.mId;
        }

        /* access modifiers changed from: protected */
        public abstract void onCallback();

        public final void run() {
            onCallback();
        }
    }

    private ax(Context context) {
        this.f7546a = context.getSharedPreferences("mipush_oc_normal", 0);
        this.b = context.getSharedPreferences("mipush_oc_custom", 0);
    }

    public static ax a(Context context) {
        if (a == null) {
            synchronized (ax.class) {
                if (a == null) {
                    a = new ax(context);
                }
            }
        }
        return a;
    }

    private String a(int i) {
        return "oc_" + i;
    }

    private String a(hp hpVar) {
        return "oc_version_" + hpVar.a();
    }

    private void a(SharedPreferences.Editor editor, Pair<Integer, Object> pair, String str) {
        if (pair.second instanceof Integer) {
            editor.putInt(str, ((Integer) pair.second).intValue());
        } else if (pair.second instanceof Long) {
            editor.putLong(str, ((Long) pair.second).longValue());
        } else if (pair.second instanceof String) {
            String str2 = (String) pair.second;
            if (str.equals(a(ho.AppIsInstalledList.a()))) {
                editor.putString(str, bm.a(str2));
            } else {
                editor.putString(str, str2);
            }
        } else if (pair.second instanceof Boolean) {
            editor.putBoolean(str, ((Boolean) pair.second).booleanValue());
        }
    }

    public int a(int i, int i2) {
        try {
            String a2 = a(i);
            return this.b.contains(a2) ? this.b.getInt(a2, 0) : this.f7546a.contains(a2) ? this.f7546a.getInt(a2, 0) : i2;
        } catch (Exception e) {
            b.m9051a(i + " oc int error " + e);
            return i2;
        }
    }

    public int a(hp hpVar, int i) {
        try {
            return this.f7546a.getInt(a(hpVar), i);
        } catch (Exception e) {
            b.m9051a(hpVar + " version error " + e);
            return i;
        }
    }

    public long a(int i, long j) {
        try {
            String a2 = a(i);
            return this.b.contains(a2) ? this.b.getLong(a2, 0) : this.f7546a.contains(a2) ? this.f7546a.getLong(a2, 0) : j;
        } catch (Exception e) {
            b.m9051a(i + " oc long error " + e);
            return j;
        }
    }

    public String a(int i, String str) {
        try {
            String a2 = a(i);
            return this.b.contains(a2) ? this.b.getString(a2, null) : this.f7546a.contains(a2) ? this.f7546a.getString(a2, null) : str;
        } catch (Exception e) {
            b.m9051a(i + " oc string error " + e);
            return str;
        }
    }

    public synchronized void a() {
        this.f7547a.clear();
    }

    public synchronized void a(a aVar) {
        if (!this.f7547a.contains(aVar)) {
            this.f7547a.add(aVar);
        }
    }

    public void a(List<Pair<Integer, Object>> list) {
        if (!ag.a(list)) {
            SharedPreferences.Editor edit = this.b.edit();
            for (Pair<Integer, Object> pair : list) {
                if (pair.first != null) {
                    String a2 = a(((Integer) pair.first).intValue());
                    if (pair.second == null) {
                        edit.remove(a2);
                    } else {
                        a(edit, pair, a2);
                    }
                }
            }
            edit.apply();
        }
    }

    public void a(List<Pair<hp, Integer>> list, List<Pair<Integer, Object>> list2) {
        if (ag.a(list) || ag.a(list2)) {
            b.m9051a("not update oc, because versions or configs are empty");
            return;
        }
        SharedPreferences.Editor edit = this.f7546a.edit();
        edit.clear();
        for (Pair<hp, Integer> pair : list) {
            if (!(pair.first == null || pair.second == null)) {
                edit.putInt(a((hp) pair.first), ((Integer) pair.second).intValue());
            }
        }
        for (Pair<Integer, Object> pair2 : list2) {
            if (!(pair2.first == null || pair2.second == null)) {
                a(edit, pair2, a(((Integer) pair2.first).intValue()));
            }
        }
        edit.apply();
    }

    public boolean a(int i, boolean z) {
        try {
            String a2 = a(i);
            return this.b.contains(a2) ? this.b.getBoolean(a2, false) : this.f7546a.contains(a2) ? this.f7546a.getBoolean(a2, false) : z;
        } catch (Exception e) {
            b.m9051a(i + " oc boolean error " + e);
            return z;
        }
    }

    /* access modifiers changed from: package-private */
    public void b() {
        b.c("OC_Callback : receive new oc data");
        HashSet hashSet = new HashSet();
        synchronized (this) {
            hashSet.addAll(this.f7547a);
        }
        Iterator it = hashSet.iterator();
        while (it.hasNext()) {
            a aVar = (a) it.next();
            if (aVar != null) {
                aVar.run();
            }
        }
        hashSet.clear();
    }
}