NetWorkStateReceiver.java 源代码


package com.mbridge.msdk.advanced.common;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.telephony.TelephonyManager;
import android.util.Base64;
import android.webkit.WebView;
import com.mbridge.msdk.foundation.tools.m;
import com.mbridge.msdk.foundation.tools.q;
import com.mbridge.msdk.mbsignalcommon.windvane.g;
import org.json.JSONObject;

public class NetWorkStateReceiver extends BroadcastReceiver {

    private static final String f16257a = "NetWorkStateReceiver";

    private WebView f16258b;

    private int f16259c;

    public NetWorkStateReceiver(WebView webView) {
        this.f16258b = webView;
    }

    public final void a() {
        this.f16258b = null;
    }

    @Override
    public void onReceive(Context context, Intent intent) {
        try {
            ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService("connectivity");
            if (connectivityManager == null) {
                a(this.f16258b, 0);
                return;
            }
            if (com.mbridge.msdk.foundation.same.a.f16839b) {
                NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
                if (activeNetworkInfo == null) {
                    a(this.f16258b, 0);
                    return;
                }
                if (activeNetworkInfo.getState() != NetworkInfo.State.CONNECTING && activeNetworkInfo.getState() != NetworkInfo.State.DISCONNECTING) {
                    if (activeNetworkInfo.getType() == 1) {
                        a(this.f16258b, 9);
                        return;
                    }
                    TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService("phone");
                    if (telephonyManager == null) {
                        a(this.f16258b, 0);
                        return;
                    }
                    int networkType = telephonyManager.getNetworkType();
                    this.f16259c = networkType;
                    int a7 = m.a(networkType);
                    this.f16259c = a7;
                    a(this.f16258b, a7);
                    return;
                }
                return;
            }
            a(this.f16258b, 0);
        } catch (Throwable th) {
            q.a(f16257a, th.getMessage());
        }
    }

    private void a(WebView webView, int i6) {
        if (webView != null) {
            try {
                JSONObject jSONObject = new JSONObject();
                jSONObject.put("netstat", i6);
                g.a().a(webView, "onNetstatChanged", Base64.encodeToString(jSONObject.toString().getBytes(), 2));
            } catch (Throwable th) {
                q.a(f16257a, th.getMessage());
            }
        }
    }
}