百草园 v7.5版本的 MD5 值为:17f49811374a404d232d5b2cc35bf30f

以下内容为反编译后的 C0124k.java 源代码,内容仅作参考


package com.baidu.cyberplayer.utils;

import android.content.Context;
import android.content.SharedPreferences;
import android.net.Uri;
import android.text.TextUtils;
import android.util.Log;
import com.bumptech.glide.load.Key;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.HttpGet;
import org.json.JSONException;
import org.json.JSONObject;

public class C0124k {

    private static final String f519a = "k";

    private Context f521a;

    private boolean f522a = false;
    private static final String b = C0125l.m516a("cyberplayer_auth");
    private static volatile C0124k a = null;

    private static final List<String> f520a = Collections.unmodifiableList(Arrays.asList("01", "02", "03", "04", "05", "06", "07", "08"));
    private static String c = "";
    private static String d = "";
    private static String e = "";

    private C0124k(Context context) {
        this.f521a = null;
        C0121h.a(context, "android.permission.WRITE_SETTINGS");
        this.f521a = context.getApplicationContext();
        e = C0122i.a(this.f521a);
    }

    private long a() {
        long j = this.f521a.getSharedPreferences(b, 0).getLong("time", -1L);
        if (-1 != j) {
            return j;
        }
        c();
        return 0L;
    }

    public static C0124k a(Context context) {
        if (context == null) {
            Log.e(f519a, "Error occurs with mContext");
            return null;
        }
        if (a == null) {
            a = new C0124k(context);
        }
        return a;
    }

    private String m504a() {
        return this.f521a.getSharedPreferences(b, 0).getString("access", null);
    }

    private String a(long j, long j2, String str) {
        try {
            return C0125l.m516a(URLEncoder.encode(String.valueOf(j) + String.valueOf(j2) + str, Key.STRING_CHARSET_NAME));
        } catch (UnsupportedEncodingException e2) {
            e2.printStackTrace();
            return "";
        }
    }

    private String a(InputStream inputStream) {
        return C0125l.a(inputStream);
    }

    private String a(String str, String str2) {
        return a(str, "req_videoauth", str2);
    }

    private String a(String str, String str2, String str3) {
        try {
            return C0125l.m516a(URLEncoder.encode(str + str2 + str3, Key.STRING_CHARSET_NAME));
        } catch (UnsupportedEncodingException e2) {
            e2.printStackTrace();
            return "";
        }
    }

    private void a(long j) {
        SharedPreferences.Editor edit = this.f521a.getSharedPreferences(b, 0).edit();
        edit.putLong("timeout", j);
        edit.commit();
    }

    private void a(String str) {
        SharedPreferences.Editor edit = this.f521a.getSharedPreferences(b, 0).edit();
        edit.putString("access", str);
        edit.commit();
    }

    private void a(String str, int i) {
        SharedPreferences.Editor edit = this.f521a.getSharedPreferences(b, 0).edit();
        edit.putInt(str, i);
        edit.commit();
    }

    public static void m506a(String str, String str2) {
        if (str2.length() < 16) {
            c = "";
            d = "";
            return;
        }
        c = str;
        if (16 == c.length()) {
            d = str2;
        } else {
            d = str2.substring(0, 16);
        }
    }

    public void a(boolean z) {
        this.f522a = z;
    }

    private boolean m507a() {
        return this.f522a;
    }

    private boolean m508a(long j, long j2, String str) {
        return str != null && str.equals(a(j, j2, d));
    }

    private boolean m509a(String str, String str2, String str3) {
        return str3.equals(a(str, "res_videoauth", str2));
    }

    private long b() {
        long j = this.f521a.getSharedPreferences(b, 0).getLong("timeout", -1L);
        if (-1 != j) {
            return j;
        }
        a(604800000L);
        return 604800000L;
    }

    private String m510b() {
        String string = this.f521a.getSharedPreferences(b, 0).getString("sign", null);
        if (string == null) {
            c();
        }
        return string;
    }

    public void m511b() {
        long b2 = b();
        long a2 = a();
        long currentTimeMillis = System.currentTimeMillis();
        if (!c.equals(m504a())) {
            c();
            return;
        }
        if (b2 <= 0 || a2 <= 0) {
            c();
            return;
        }
        if (currentTimeMillis - a2 > b2) {
            c();
        } else {
            if (!m508a(a2, b2, m510b())) {
                c();
                return;
            }
            Iterator<String> it = f520a.iterator();
            while (it.hasNext()) {
                m513a(it.next());
            }
        }
    }

    private void b(long j) {
        SharedPreferences.Editor edit = this.f521a.getSharedPreferences(b, 0).edit();
        edit.putLong("time", j);
        edit.commit();
    }

    private void b(String str) {
        SharedPreferences.Editor edit = this.f521a.getSharedPreferences(b, 0).edit();
        edit.putString("sign", str);
        edit.commit();
    }

    private void c() {
        if (m507a() || c.equals("") || d.equals("") || e.equals("")) {
            return;
        }
        a(true);
        new Thread(new Runnable() {
            @Override
            public void run() {
                if (C0128o.m518a(C0124k.this.f521a)) {
                    C0124k.this.e();
                }
                C0124k.this.a(false);
            }
        }, "CyberplayerAuQuery").start();
    }

    private void c(String str) {
        long b2;
        try {
            JSONObject jSONObject = new JSONObject(str);
            if (m509a(String.valueOf(jSONObject.getLong("time")), e, jSONObject.getString("sign"))) {
                if (!jSONObject.has("errno") || jSONObject.getInt("errno") == 200) {
                    a(c);
                    String string = jSONObject.getString("01");
                    if (TextUtils.isEmpty(string)) {
                        return;
                    }
                    if (string.equals("0")) {
                        d();
                    } else {
                        JSONObject jSONObject2 = jSONObject.getJSONObject("02");
                        for (String str2 : f520a) {
                            if (jSONObject2.has("au_" + str2)) {
                                try {
                                    a("au_sub_" + str2, Integer.parseInt(jSONObject2.getString("au_" + str2)));
                                } catch (Exception unused) {
                                }
                            }
                        }
                    }
                    if (jSONObject.has("timeout")) {
                        double d2 = jSONObject.getDouble("timeout");
                        if (d2 < 3.0d || d2 > 10.0d) {
                            d2 = 7.0d;
                        }
                        b2 = ((long) d2) * com.umeng.analytics.a.m;
                        a(b2);
                    } else {
                        b2 = b();
                    }
                    long currentTimeMillis = System.currentTimeMillis();
                    b(currentTimeMillis);
                    b(a(currentTimeMillis, b2, d));
                }
            }
        } catch (JSONException e2) {
            e2.printStackTrace();
        }
    }

    private void d() {
        Iterator<String> it = f520a.iterator();
        while (it.hasNext()) {
            a("au_sub_" + it.next(), 0);
        }
    }

    public void e() {
        if (C0128o.m518a(this.f521a)) {
            String valueOf = String.valueOf(System.currentTimeMillis());
            Uri build = Uri.parse("http://cybertran.baidu.com").buildUpon().path("/mediasdk/video").appendQueryParameter("method", "sdkauth").appendQueryParameter("ak", c).appendQueryParameter("time", valueOf).appendQueryParameter("sign", a(valueOf, d)).appendQueryParameter("uuid", e).appendQueryParameter("platform", "Android").build();
            C0118e c0118e = new C0118e(this.f521a);
            try {
                HttpResponse execute = c0118e.execute(new HttpGet(build.toString()));
                if (execute.getStatusLine().getStatusCode() == 200) {
                    HttpEntity entity = execute.getEntity();
                    InputStream a2 = C0127n.a(entity);
                    if (a2 == null) {
                        a2 = entity.getContent();
                    }
                    c(a(a2));
                }
            } catch (ClientProtocolException | IOException | Exception unused) {
            } catch (Throwable th) {
                c0118e.a();
                throw th;
            }
            c0118e.a();
        }
    }

    public void m512a() {
        new Thread(new Runnable() {
            @Override
            public void run() {
                C0124k.this.m511b();
            }
        }, "CyberplayerAuCheck").start();
    }

    public boolean m513a(String str) {
        if (this.f521a == null) {
            Log.e(f519a, "Error occurs with mContext");
            return true;
        }
        if (c.equals("") || d.equals("") || !f520a.contains(str)) {
            return false;
        }
        int i = this.f521a.getSharedPreferences(b, 0).getInt("au_sub_" + str, -1);
        if (-1 != i) {
            return i != 0;
        }
        c();
        return true;
    }
}