导航菜单

页面标题

页面副标题

哔哩哔哩 v1.6.6 - nc.java 源代码

正在查看: 哔哩哔哩 v1.6.6 应用的 nc.java JAVA 源代码文件

本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。


package bl;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
import android.support.annotation.VisibleForTesting;
import android.text.TextUtils;
import android.util.JsonReader;
import android.util.JsonWriter;
import android.util.Log;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import org.json.JSONException;
import org.json.JSONObject;
import tv.danmaku.videoplayer.core.danmaku.DanmakuConfig;

public class nc {

    @VisibleForTesting
    static nc a;

    @VisibleForTesting
    static boolean b;
    private nb c;
    private long d;
    private Map<String, String> e;
    private String f;
    private boolean g;
    private ConnectivityManager h;

    @VisibleForTesting
    nc(Context context) {
        b(context);
        this.h = (ConnectivityManager) context.getSystemService("connectivity");
    }

    private void b(final Context context) {
        synchronized (this) {
            this.g = false;
        }
        lv.d(3, new Runnable() {
            @Override
            public void run() {
                synchronized (nc.this) {
                    nc.this.c = new nb(context.getApplicationContext().getFileStreamPath("bili_params.dat"));
                    nc.this.c();
                }
            }
        });
    }

    private void b() {
        synchronized (this) {
            if (this.c == null) {
                return;
            }
            if (b) {
                Log.d("BLRemoteConfig", "reloading!");
            }
            this.g = false;
            c();
        }
    }

    public void c() {
        InputStreamReader inputStreamReader;
        Map<String, String> map;
        IOException e;
        if (this.g) {
            return;
        }
        String str = null;
        try {
            inputStreamReader = new InputStreamReader(this.c.b());
        } catch (FileNotFoundException unused) {
            inputStreamReader = null;
        }
        Map<String, String> emptyMap = Collections.emptyMap();
        if (inputStreamReader != null) {
            JsonReader jsonReader = new JsonReader(inputStreamReader);
            try {
                try {
                    map = nd.c(jsonReader);
                } finally {
                    try {
                        jsonReader.close();
                    } catch (IOException unused2) {
                    }
                }
            } catch (IOException e2) {
                map = emptyMap;
                e = e2;
            }
            try {
                String str2 = map.get("__ver__");
                try {
                    jsonReader.close();
                } catch (IOException unused3) {
                }
                str = str2;
            } catch (IOException e3) {
                e = e3;
                if (b) {
                    Log.w("BLRemoteConfig", "Fail to parse!", e);
                }
                this.e = map;
                this.f = str;
                this.d = this.c.c();
                this.g = true;
                notifyAll();
            }
        } else {
            map = emptyMap;
        }
        this.e = map;
        this.f = str;
        this.d = this.c.c();
        this.g = true;
        notifyAll();
    }

    public static void a(Context context) {
        if (a != null) {
            return;
        }
        a = new nc(context);
    }

    public static nc a() {
        d();
        return a;
    }

    private static void d() {
        if (a == null) {
            throw new IllegalStateException("BLRemoteConfig has not been initialized!");
        }
    }

    public void a(final String str, final int i, final String str2) {
        lv.d(2, new Runnable() {
            @Override
            public void run() {
                NetworkInfo activeNetworkInfo;
                synchronized (nc.this) {
                    nc.this.e();
                }
                try {
                    activeNetworkInfo = nc.this.h.getActiveNetworkInfo();
                } catch (SecurityException unused) {
                    if (nc.b) {
                        Log.w("BLRemoteConfig", "No android.permission.ACCESS_NETWORK_STATE, but try to update");
                    }
                }
                if (activeNetworkInfo != null) {
                    if (!activeNetworkInfo.isConnected()) {
                        return;
                    }
                    nc.this.b(str, i, str2);
                }
            }
        });
    }

    public void b(String str, int i, String str2) {
        Uri.Builder buildUpon = Uri.parse("http://app.snm0516.aisee.tv/x/v2/param").buildUpon();
        if (str != null) {
            buildUpon.appendQueryParameter(u.aly.au.b, str);
        }
        if (i > 0) {
            buildUpon.appendQueryParameter("build", String.valueOf(i));
        }
        if (this.f != null) {
            buildUpon.appendQueryParameter("ver", this.f);
        }
        if (str2 != null) {
            buildUpon.appendQueryParameter("mobi_app", str2);
        }
        String builder = buildUpon.toString();
        if (b) {
            Log.d("BLRemoteConfig", "check update " + builder);
        }
        HttpURLConnection b2 = b(builder);
        if (b2 == null) {
            return;
        }
        try {
            if (b2.getResponseCode() == 200) {
                try {
                    try {
                        JSONObject a2 = nd.a(new JsonReader(new InputStreamReader(b2.getInputStream(), "UTF-8")));
                        int optInt = a2.optInt("code");
                        if (optInt == -304) {
                            if (b) {
                                Log.i("BLRemoteConfig", "Not modified!");
                            }
                        } else if (optInt == 0) {
                            a(a(a2));
                        } else if (b) {
                            Log.w("BLRemoteConfig", "Unexpected code " + optInt);
                        }
                    } catch (JSONException e) {
                        if (b) {
                            Log.w("BLRemoteConfig", "Unexpected json error", e);
                        }
                    }
                } finally {
                }
            }
        } catch (Throwable unused) {
        }
        b2.disconnect();
    }

    private void a(Map<String, String> map) {
        synchronized (this) {
            e();
            if (TextUtils.equals(map.get("__ver__"), this.f)) {
                if (b) {
                    Log.d("BLRemoteConfig", "Ignored !");
                }
            } else {
                this.e = map;
                lv.d(3, new Runnable() {
                    @Override
                    public void run() {
                        synchronized (nc.this) {
                            try {
                                try {
                                    FileOutputStream a2 = nc.this.c.a();
                                    JsonWriter jsonWriter = new JsonWriter(new BufferedWriter(new OutputStreamWriter(a2)));
                                    boolean b2 = nc.b(nc.this.e, jsonWriter);
                                    try {
                                        jsonWriter.close();
                                    } catch (IOException unused) {
                                    }
                                    if (nc.b) {
                                        Log.d("BLRemoteConfig", "Write params to cache file? " + b2);
                                        if (nc.this.e.size() > 1) {
                                            Log.d("BLRemoteConfig", "================== dump params ==================");
                                            for (Map.Entry entry : nc.this.e.entrySet()) {
                                                Log.v("BLRemoteConfig", ((String) entry.getKey()) + " = " + ((String) entry.getValue()));
                                            }
                                            Log.d("BLRemoteConfig", "==================================================");
                                        }
                                    }
                                    if (b2) {
                                        nc.this.c.a(a2);
                                    } else {
                                        nc.this.c.b(a2);
                                    }
                                    nc.this.d = nc.this.c.c();
                                } catch (IOException unused2) {
                                }
                            } catch (Throwable th) {
                                throw th;
                            }
                        }
                    }
                });
            }
        }
    }

    public static boolean b(Map<String, String> map, JsonWriter jsonWriter) {
        try {
            jsonWriter.beginObject();
            for (Map.Entry<String, String> entry : map.entrySet()) {
                jsonWriter.name(entry.getKey());
                jsonWriter.value(entry.getValue());
            }
            jsonWriter.endObject();
            jsonWriter.flush();
            return true;
        } catch (IOException unused) {
            return false;
        }
    }

    private static HttpURLConnection b(String str) {
        try {
            HttpURLConnection httpURLConnection = (HttpURLConnection) new URL(str).openConnection();
            try {
                httpURLConnection.setConnectTimeout(DanmakuConfig.DEFAULT_FLY_DURATION_MILLIS);
                httpURLConnection.setReadTimeout(10000);
                httpURLConnection.setInstanceFollowRedirects(false);
                return httpURLConnection;
            } catch (IOException unused) {
                return httpURLConnection;
            }
        } catch (IOException unused2) {
            return null;
        }
    }

    private static Map<String, String> a(JSONObject jSONObject) throws JSONException {
        HashMap hashMap = new HashMap();
        hashMap.put("__ver__", jSONObject.getString("ver"));
        JSONObject optJSONObject = jSONObject.optJSONObject("data");
        if (optJSONObject != null) {
            Iterator<String> keys = optJSONObject.keys();
            while (keys.hasNext()) {
                String next = keys.next();
                hashMap.put(next, optJSONObject.optString(next));
            }
        }
        return hashMap;
    }

    public boolean a(String str, boolean z) {
        String a2 = a(str, (String) null);
        if (TextUtils.isEmpty(a2)) {
            return z;
        }
        if (a2.length() == 1) {
            return '1' == a2.charAt(0);
        }
        return "true".equalsIgnoreCase(a2);
    }

    public int a(String str, int i) throws NumberFormatException {
        String a2 = a(str, (String) null);
        return TextUtils.isEmpty(a2) ? i : Integer.parseInt(a2);
    }

    public String a(String str, String str2) {
        if (this.g && this.d < this.c.c()) {
            synchronized (this) {
                if (this.d < this.c.c()) {
                    b();
                }
            }
        }
        synchronized (this) {
            e();
            String str3 = this.e.get(str);
            if (str3 == null) {
                return str2;
            }
            return str3.toString();
        }
    }

    public String a(String str) {
        return a(str, (String) null);
    }

    public void e() {
        while (!this.g) {
            try {
                wait();
            } catch (InterruptedException unused) {
            }
        }
    }
}