b.java 源代码


package com.iab.omid.library.inmobi.b;

import android.annotation.SuppressLint;
import android.app.KeyguardManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import androidx.annotation.NonNull;
import java.util.Iterator;

public class b {

    @SuppressLint({"StaticFieldLeak"})
    private static b f14406a = new b();

    private Context f14407b;

    private BroadcastReceiver f14408c;

    private boolean f14409d;

    private boolean f14410e;

    private a f14411f;

    public interface a {
        void a(boolean z6);
    }

    private b() {
    }

    public static b a() {
        return f14406a;
    }

    private void e() {
        this.f14408c = new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                KeyguardManager keyguardManager;
                if (intent == null) {
                    return;
                }
                if ("android.intent.action.SCREEN_OFF".equals(intent.getAction())) {
                    b.this.a(true);
                    return;
                }
                if ("android.intent.action.USER_PRESENT".equals(intent.getAction())) {
                    b.this.a(false);
                } else if ("android.intent.action.SCREEN_ON".equals(intent.getAction()) && (keyguardManager = (KeyguardManager) context.getSystemService("keyguard")) != null && !keyguardManager.inKeyguardRestrictedInputMode()) {
                    b.this.a(false);
                }
            }
        };
        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction("android.intent.action.SCREEN_OFF");
        intentFilter.addAction("android.intent.action.SCREEN_ON");
        intentFilter.addAction("android.intent.action.USER_PRESENT");
        this.f14407b.registerReceiver(this.f14408c, intentFilter);
    }

    private void f() {
        BroadcastReceiver broadcastReceiver;
        Context context = this.f14407b;
        if (context != null && (broadcastReceiver = this.f14408c) != null) {
            context.unregisterReceiver(broadcastReceiver);
            this.f14408c = null;
        }
    }

    private void g() {
        boolean z6 = !this.f14410e;
        Iterator<com.iab.omid.library.inmobi.adsession.a> it = com.iab.omid.library.inmobi.b.a.a().b().iterator();
        while (it.hasNext()) {
            it.next().getAdSessionStatePublisher().a(z6);
        }
    }

    public void b() {
        e();
        this.f14409d = true;
        g();
    }

    public void c() {
        f();
        this.f14409d = false;
        this.f14410e = false;
        this.f14411f = null;
    }

    public boolean d() {
        if (!this.f14410e) {
            return true;
        }
        return false;
    }

    public void a(@NonNull Context context) {
        this.f14407b = context.getApplicationContext();
    }

    public void a(a aVar) {
        this.f14411f = aVar;
    }

    public void a(boolean z6) {
        if (this.f14410e != z6) {
            this.f14410e = z6;
            if (this.f14409d) {
                g();
                a aVar = this.f14411f;
                if (aVar != null) {
                    aVar.a(d());
                }
            }
        }
    }
}