package com.ss.android.ugc.aweme.push.downgrade;

import X.2FV;
import X.2He;
import X.C08347s1;
import X.C11797xa;
import X.C22428Zd;
import X.C22438Ze;
import X.C25518ec;
import X.C28338jA;
import X.C42869Ft;
import X.C42909Fx;
import android.app.ActivityManager;
import android.content.ClipboardManager;
import android.content.Context;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.text.TextUtils;
import com.bytedance.covode.number.Covode;
import com.bytedance.frameworks.apm.trace.MethodCollector;
import java.lang.reflect.Field;
import java.util.List;

public class NotifyPushStatusTask implements C22438Ze {
    static {
        Covode.recordClassIndex(101353);
    }

    public boolean meetTrigger() {
        return true;
    }

    public String prefix() {
        return "task_";
    }

    public boolean serialExecute() {
        return false;
    }

    public int targetProcess() {
        return 34;
    }

    public List triggerOtherLegoComponents() {
        return null;
    }

    public C42869Ft triggerType() {
        return C22428Zd.LIZ(this);
    }

    public C42909Fx scenesType() {
        return C42909Fx.DEFAULT;
    }

    public C25518ec type() {
        return C25518ec.BACKGROUND;
    }

    public String key() {
        return getClass().getSimpleName();
    }

    public static boolean LIZ(Context context) {
        try {
            List<ActivityManager.RunningAppProcessInfo> runningAppProcesses = ((ActivityManager) LIZ(context, "activity")).getRunningAppProcesses();
            if (runningAppProcesses == null) {
                return false;
            }
            for (ActivityManager.RunningAppProcessInfo next : runningAppProcesses) {
                if (next != null && !TextUtils.isEmpty(next.processName) && TextUtils.equals(next.processName, context.getPackageName())) {
                    return true;
                }
            }
            return false;
        } catch (Throwable unused) {
            return false;
        }
    }

    public void run(Context context) {
        MethodCollector.i(5094);
        String LIZJ = C11797xa.LIZJ(context);
        if (!TextUtils.isEmpty(LIZJ) && ((LIZJ.endsWith(":push") || LIZJ.endsWith(":pushservice")) && LIZ(context))) {
            try {
                context.getContentResolver().call(Uri.parse("content://" + context.getPackageName() + ".push.status"), "", LIZJ, new Bundle());
                MethodCollector.o(5094);
                return;
            } catch (Throwable unused) {
            }
        }
        MethodCollector.o(5094);
    }

    public static Object LIZ(Context context, String str) {
        Object obj;
        MethodCollector.i(5117);
        if (Build.VERSION.SDK_INT > 27 || !"clipboard".equals(str)) {
            if (!2FV.LIZIZ && "connectivity".equals(str)) {
                try {
                    new C08347s1().LIZ();
                    2FV.LIZIZ = true;
                    obj = context.getSystemService(str);
                } catch (Throwable unused) {
                }
            }
            obj = context.getSystemService(str);
        } else if (2FV.LIZ) {
            synchronized (ClipboardManager.class) {
                try {
                    obj = context.getSystemService(str);
                    if (Thread.currentThread() != Looper.getMainLooper().getThread()) {
                        Field declaredField = ClipboardManager.class.getDeclaredField("mHandler");
                        declaredField.setAccessible(true);
                        declaredField.set(obj, new 2He((Handler) declaredField.get(obj)));
                    }
                } catch (Exception e) {
                    C28338jA.LIZ(e, "ClipboardManager Handler Reflect Fail");
                } catch (Throwable th) {
                    MethodCollector.o(5117);
                    throw th;
                }
                2FV.LIZ = false;
            }
        } else {
            obj = context.getSystemService(str);
        }
        MethodCollector.o(5117);
        return obj;
    }
}
