导航菜单

页面标题

页面副标题

Tasker v6.5.11 - to.java 源代码

正在查看: Tasker v6.5.11 应用的 to.java JAVA 源代码文件

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


package net.dinglisch.android.taskerm;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.net.Uri;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Base64;
import com.joaomgcd.taskerm.util.TaskerApp;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import net.dinglisch.android.taskerm.c2;
import net.dinglisch.android.taskerm.cl;
import net.dinglisch.android.taskerm.dk;
import net.dinglisch.android.taskerm.g6;
import net.dinglisch.android.taskerm.hk;
import net.dinglisch.android.taskerm.qi;
import net.dinglisch.android.taskerm.ri;
import net.dinglisch.android.taskerm.tn;
import net.dinglisch.android.taskerm.wo;
import net.dinglisch.android.taskerm.yj;

public class to implements pi, uo {
    private static boolean F;
    private boolean i = false;
    private Map<String, Integer> q = new HashMap();
    private Set<Integer> r = new HashSet();
    private Set<Integer> s = new HashSet();
    private Set<Integer> t = new HashSet();
    private Map<Integer, wo> u = new ConcurrentHashMap();
    private Map<Integer, tn> v = new ConcurrentHashMap();
    private Map<String, dk> w = new HashMap();
    private List<xi> x = new ArrayList();
    private d5 y = new d5(this);
    private static final Object z = new Object();
    private static final int[] A = {4, 5, 6, 7, 1};
    public static Object[] B = {new Object(), new Object()};
    private static to[] C = new to[g.values().length];
    private static int D = -2;
    private static int E = 1;

    class a implements Comparator<wo> {
        final Context i;

        a(Context context) {
            this.i = context;
        }

        @Override
        public int compare(wo woVar, wo woVar2) {
            return (woVar.u() ? woVar.getName() : woVar.v0(this.i, true, false, false)).compareToIgnoreCase(woVar2.u() ? woVar2.getName() : woVar2.v0(this.i, true, false, false));
        }
    }

    class b implements Comparator<wo> {
        b() {
        }

        @Override
        public int compare(wo woVar, wo woVar2) {
            return Long.compare(woVar.d(), woVar2.d());
        }
    }

    class c implements Comparator<dk> {
        c() {
        }

        @Override
        public int compare(dk dkVar, dk dkVar2) {
            return dkVar.getName().compareToIgnoreCase(dkVar2.getName());
        }
    }

    class d implements Comparator<dk> {
        d() {
        }

        @Override
        public int compare(dk dkVar, dk dkVar2) {
            return Long.compare(dkVar2.d(), dkVar.d());
        }
    }

    class e implements Comparator<dk> {
        e() {
        }

        @Override
        public int compare(dk dkVar, dk dkVar2) {
            return Long.compare(dkVar.d(), dkVar2.d());
        }
    }

    static class f {
        static final int[] a;
        static final int[] b;

        static {
            int[] iArr = new int[c2.a.values().length];
            b = iArr;
            try {
                iArr[c2.a.Profile.ordinal()] = 1;
            } catch (NoSuchFieldError unused) {
            }
            try {
                b[c2.a.Task.ordinal()] = 2;
            } catch (NoSuchFieldError unused2) {
            }
            try {
                b[c2.a.Scene.ordinal()] = 3;
            } catch (NoSuchFieldError unused3) {
            }
            try {
                b[c2.a.Variable.ordinal()] = 4;
            } catch (NoSuchFieldError unused4) {
            }
            int[] iArr2 = new int[yj.b.values().length];
            a = iArr2;
            try {
                iArr2[yj.b.Profile.ordinal()] = 1;
            } catch (NoSuchFieldError unused5) {
            }
            try {
                a[yj.b.Task.ordinal()] = 2;
            } catch (NoSuchFieldError unused6) {
            }
            try {
                a[yj.b.Scene.ordinal()] = 3;
            } catch (NoSuchFieldError unused7) {
            }
        }
    }

    public enum g {
        Active,
        Passive
    }

    private static String A1(Context context, to toVar, String str, int i) {
        return str + "://" + Base64.encodeToString(jr.d(toVar.C1(context, i)), 2);
    }

    public static boolean A3(String str) {
        return str.startsWith("taskertask");
    }

    private String B1(Context context, wo woVar, int i) {
        return A1(context, l2(woVar), "taskerprofile", i);
    }

    public static boolean B3(int i) {
        return i < -1;
    }

    private void C0(tn tnVar, Set<Integer> set) {
        for (net.dinglisch.android.taskerm.c cVar : tnVar.D0()) {
            set.add(Integer.valueOf(cVar.j()));
            if (cVar.T0()) {
                for (k7 k7Var : cVar.B0()) {
                    if (k7Var.l()) {
                        set.add(Integer.valueOf(k7Var.d().j()));
                    }
                }
            }
        }
    }

    public Boolean C3(qi qiVar, boolean z2, Context context, boolean z3) {
        String str;
        qi w;
        int i;
        qiVar.e("dvi");
        qiVar.e("tv");
        qiVar.e("nid");
        if (qiVar.d("dmetric")) {
            String x = qiVar.x("dmetric");
            qiVar.e("dmetric");
            str = x;
        } else {
            str = null;
        }
        if (!z2) {
            try {
                if (qiVar.d("matterdevices")) {
                    String x2 = qiVar.x("matterdevices");
                    if (x2 != null) {
                        id.i.M(context, x2);
                    }
                    qiVar.e("matterdevices");
                }
            } catch (Throwable th2) {
                r7.l("TD", "Error restoring matter devices", th2);
            }
        }
        boolean z4 = false;
        int i2 = 0;
        while (true) {
            String F2 = qi.F("proj", i2);
            if (!qiVar.d(F2)) {
                break;
            }
            try {
                xi xiVar = new xi(qiVar.w(F2));
                this.x.add(xiVar);
                r7.f("TD", "added project: " + xiVar.getName());
            } catch (qi.a e2) {
                r7.G("TD", "unpack project failure: " + e2.toString());
                z4 = true;
            }
            qiVar.e(F2);
            i2++;
        }
        r7.f("TD", "fpo: found " + this.x.size() + " projects");
        Set<String> D2 = qiVar.D();
        qi.X(D2);
        Iterator<String> it = D2.iterator();
        SharedPreferences.Editor edit = dq.R0(context).edit();
        HashMap hashMap = null;
        int i3 = 9999;
        boolean z5 = false;
        boolean z6 = false;
        while (it.hasNext()) {
            try {
                w = qiVar.w(it.next());
            } catch (qi.a e3) {
                e = e3;
            }
            if (w != null) {
                if (w.H("Task")) {
                    tn tnVar = new tn(w);
                    B0(tnVar, -1);
                    if (tnVar.M1()) {
                        z6 = true;
                    }
                } else if (w.H("Profile")) {
                    if (z2) {
                        HashMap hashMap2 = hashMap == null ? new HashMap() : hashMap;
                        try {
                            hashMap2.put(Integer.valueOf(w.p(c6.EXTRA_ID)), Integer.valueOf(i3));
                            hashMap = hashMap2;
                        } catch (qi.a e4) {
                            e = e4;
                            hashMap = hashMap2;
                            r7.G("TD", "unpack object: " + e.toString());
                            z4 = true;
                        }
                    }
                    if (z2) {
                        int i4 = i3;
                        i3++;
                        i = i4;
                    } else {
                        i = -1;
                    }
                    wo woVar = new wo(context, w, i);
                    if (woVar.m1() > 0) {
                        v0(woVar, -1);
                        for (int i5 = 0; i5 < woVar.I0(); i5++) {
                            int V0 = woVar.V0(i5);
                            if (V0 == 7) {
                                this.s.add(Integer.valueOf(((k2) woVar.S0(i5)).j()));
                            } else if (V0 == 4 || V0 == 5 || V0 == 6) {
                                this.t.add(Integer.valueOf(((pn) woVar.S0(i5)).j()));
                            }
                        }
                    } else {
                        r7.G("TD", "dropping profile with no valid contexts: " + woVar.H0());
                        z4 = true;
                    }
                } else if (w.H("Scene")) {
                    y0(new dk(w), -1);
                } else if (z3 && w.H("Variable")) {
                    fq fqVar = new fq(context, w);
                    kq.U1(context, fqVar.getName(), fqVar.b0(), false, null, "TD");
                } else if (z3 && w.H("Setting")) {
                    new com.joaomgcd.taskerm.settings.p(context, w).c0(edit);
                    z5 = true;
                } else {
                    r7.G("TD", "unpack: bad object class: " + w.u());
                    z4 = true;
                }
            }
        }
        if (z5) {
            edit.commit();
        }
        if (z2 && hashMap != null) {
            for (xi xiVar2 : this.x) {
                for (Map.Entry entry : hashMap.entrySet()) {
                    xiVar2.f0(((Integer) entry.getKey()).intValue(), ((Integer) entry.getValue()).intValue());
                }
            }
        }
        if (z6) {
            b1();
        }
        K0();
        if (str != null && d2() > 0) {
            String[] split = str.split(",");
            if (split == null || split.length != 2) {
                r7.G("TD", "bad base metric spec: " + str);
            } else {
                if (!dq.v1()) {
                    dq.N2(context);
                }
                if (dq.v1()) {
                    float parseFloat = Float.parseFloat(split[0]);
                    float parseFloat2 = Float.parseFloat(split[1]);
                    Iterator<dk> it2 = this.w.values().iterator();
                    while (it2.hasNext()) {
                        it2.next().m0("TD", parseFloat, parseFloat2, dq.D0(), dq.A0(), false);
                    }
                } else {
                    r7.G("TD", "have no display metrics for this device");
                }
            }
        }
        T0();
        return Boolean.valueOf(z4);
    }

    private static void C4(b5 b5Var, int i, Set<Integer> set) {
        for (int i2 = 0; i2 < b5Var.Y(); i2++) {
            if (b5Var.p0(i2) == 4) {
                set.add(Integer.valueOf(b5Var.g0(i2).T()));
            } else if (i != -1 && b5Var.p0(i2) == 1 && a1.D0(i, i2) == "col") {
                j N = b5Var.N(i2);
                if (N.k()) {
                    String w = N.w();
                    if (dh.f(w)) {
                        set.add(Integer.valueOf(dh.b(w)));
                    }
                }
            }
        }
    }

    public java.lang.String D3(android.content.Context r5, int r6, boolean r7) {
        throw new UnsupportedOperationException("Method not decompiled: net.dinglisch.android.taskerm.to.D3(android.content.Context, int, boolean):java.lang.String");
    }

    public static Map<Long, File> E1() {
        File F1 = F1(false);
        HashMap hashMap = new HashMap();
        if (F1 != null) {
            String[] list = F1.list();
            if (!dq.r(list)) {
                for (String str : list) {
                    if (str.length() == 35) {
                        String substring = str.substring(18, 22);
                        String substring2 = str.substring(22, 24);
                        String substring3 = str.substring(24, 26);
                        String substring4 = str.substring(27, 29);
                        String substring5 = str.substring(30, 32);
                        String substring6 = str.substring(33, 35);
                        Calendar calendar = Calendar.getInstance();
                        try {
                            calendar.set(Integer.parseInt(substring), Integer.parseInt(substring2) - 1, Integer.parseInt(substring3), Integer.parseInt(substring4), Integer.parseInt(substring5), Integer.parseInt(substring6));
                            calendar.set(14, 0);
                            hashMap.put(Long.valueOf(calendar.getTimeInMillis()), new File(F1, str));
                        } catch (Exception e2) {
                            r7.g("TD", "failed to parse " + str, e2);
                        }
                    } else {
                        r7.f("TD", "skipping bad-format backup dir " + str);
                    }
                }
            }
        }
        return hashMap;
    }

    public static int E3(tn tnVar, tn tnVar2) {
        return tnVar.getName().compareToIgnoreCase(tnVar2.getName());
    }

    public static File F1(boolean z2) {
        return dq.l1(g6.d, z2);
    }

    public static int F3(tn tnVar, tn tnVar2) {
        return Long.compare(tnVar2.d(), tnVar.d());
    }

    public static String G1(long j, long j2) {
        if (j == -1) {
            j = System.currentTimeMillis();
        }
        Calendar t = bh.t(j);
        String G = bh.G(t);
        String r = bh.r(t, true);
        Calendar t2 = bh.t(j2);
        return G + "." + r + "-" + bh.G(t2) + "." + bh.r(t2, true);
    }

    public static int G3(tn tnVar, tn tnVar2) {
        return Long.compare(tnVar.d(), tnVar2.d());
    }

    public static File H1(boolean z2) {
        return dq.l1("configs", z2);
    }

    public static int H3(wo woVar, wo woVar2) {
        return Long.compare(woVar2.d(), woVar.d());
    }

    public static void H4(tn tnVar, Set<Integer> set) {
        if (tnVar.G1()) {
            set.add(Integer.valueOf(tnVar.getIcon().T()));
        }
        for (net.dinglisch.android.taskerm.c cVar : tnVar.D0()) {
            C4(cVar, cVar.j(), set);
        }
    }

    public static int I3(wo woVar, wo woVar2) {
        return Boolean.compare(woVar2.u(), woVar.u());
    }

    public static final to J2(g gVar, Context context, boolean z2) {
        to toVar;
        Context applicationContext = context.getApplicationContext();
        int ordinal = gVar.ordinal();
        String name = Thread.currentThread().getName();
        synchronized (B[ordinal]) {
            try {
                r7.f("TD", "getStatic: " + gVar + " load: " + z2 + " - " + name);
                if (C[ordinal] == null && z2) {
                    r7.f("TD", "getStatic: new data on thread " + name);
                    C[ordinal] = new to();
                    if (Kid.b(applicationContext)) {
                        if (!C[ordinal].l4(applicationContext, "kid/data.xml")) {
                            r7.f("TD", "getStatic: kid/data.xml: load failed, return null");
                            C[ordinal] = null;
                        }
                    } else if (dq.O(applicationContext, "autobackup.xml")) {
                        r7.f("TD", "data: getStatic: null, file exists, load from file - " + name);
                        if (C[ordinal].m4(applicationContext, "autobackup.xml")) {
                            r7.f("TD", "getStatic: load success! - " + name);
                        } else {
                            r7.f("TD", "getStatic: load failed, return null - " + name);
                            C[ordinal] = null;
                        }
                    } else {
                        r7.f("TD", "data: getStatic: null: no file, return new data - " + name);
                    }
                }
                toVar = C[ordinal];
            } catch (Throwable th2) {
                throw th2;
            }
        }
        return toVar;
    }

    public static int J3(wo woVar, wo woVar2) {
        String name = woVar.getName();
        Locale locale = Locale.ROOT;
        return name.toLowerCase(locale).compareTo(woVar2.getName().toLowerCase(locale));
    }

    public static int K3(xi xiVar, xi xiVar2) {
        String name = xiVar.getName();
        Locale locale = Locale.ROOT;
        return name.toLowerCase(locale).compareTo(xiVar2.getName().toLowerCase(locale));
    }

    private String L2(Resources resources, tn tnVar) {
        String O0 = tnVar.O0(resources, false);
        if (O0.length() > 0) {
            O0 = "\n" + O0;
        }
        return (O0 + "\n") + tnVar.v1(resources, 9999, true);
    }

    public qi L3(int i) {
        qi qiVar = new qi(f2(), 1);
        qiVar.a0(new String[]{"dvi", "tv"});
        qiVar.T("tv", "6.5.11");
        qiVar.T("dvi", String.valueOf(1));
        qiVar.R("task", this.v, i);
        qiVar.R("prof", this.u, i);
        if (this.x.size() > 0) {
            qiVar.Q("proj", this.x, i);
        }
        if (this.w.size() > 0) {
            qiVar.R("scene", this.w, i);
            if (((i & 32) > 0 || (i & 2) > 0) && dq.v1()) {
                qiVar.T("dmetric", dq.t0());
            }
        }
        return qiVar;
    }

    private void M0(ri.c cVar, int i, Bundle bundle, Collection<String> collection, String str, String str2) {
        for (String str3 : vo.g(bundle)) {
            String h = ri.h(cVar, str != null ? str : ri.D(cVar, i), str3, str2);
            if (h != null) {
                collection.add(h);
            }
        }
    }

    public static to M2(tn tnVar) {
        to toVar = new to();
        toVar.B0(tnVar, -1);
        return toVar;
    }

    public java.lang.Boolean M3(boolean r13, android.content.Context r14, long r15, android.content.SharedPreferences r17, android.content.res.Resources r18, boolean r19) {
        throw new UnsupportedOperationException("Method not decompiled: net.dinglisch.android.taskerm.to.M3(boolean, android.content.Context, long, android.content.SharedPreferences, android.content.res.Resources, boolean):java.lang.Boolean");
    }

    private void M4(Set<yj> set) {
        c2 N1;
        for (yj yjVar : set) {
            if (yjVar.i() && (N1 = N1(yjVar)) != null) {
                N1.C(true);
            }
        }
    }

    public static void P3() {
        File Q2;
        File k1 = dq.k1();
        if (k1 != null) {
            File file = new File(k1, "userbackup.xml");
            if (file.isFile() && (Q2 = Q2(true)) != null) {
                file.renameTo(new File(Q2, "backup.xml"));
            }
            File file2 = new File(k1, "autobackups");
            if (file2.isDirectory()) {
                File H1 = H1(true);
                File file3 = new File(H1, "auto");
                if (file3.exists() || H1 == null || !H1.isDirectory()) {
                    return;
                }
                if (file2.renameTo(file3)) {
                    r7.f("TD", file2.toString() + " -> " + file3.toString());
                    return;
                }
                r7.G("TD", "failed: " + file2.toString() + " -> " + file3.toString());
            }
        }
    }

    public static File Q2(boolean z2) {
        return dq.l1(g6.e, z2);
    }

    private static void S0() {
        qn.a("!(%)(DJJJ!!");
    }

    public static final boolean S2() {
        return Z2(g.Passive);
    }

    private static void S4(boolean z2) {
        F = z2;
        r7.f("TD", "Debug Variable - Saving data: " + z2);
    }

    private void T0() {
        this.i = false;
    }

    private int T1() {
        while (true) {
            int i = E + 1;
            E = i;
            if (!this.u.containsKey(Integer.valueOf(i)) && !this.v.containsKey(Integer.valueOf(E))) {
                return E;
            }
        }
    }

    private static tn U1(int i) {
        return new tn(i);
    }

    public static void U4(g gVar, to toVar) {
        int ordinal = gVar.ordinal();
        synchronized (B[ordinal]) {
            r7.f("TD", "data: setStatic: " + gVar);
            C[ordinal] = toVar;
        }
    }

    private void V4(Context context) {
        SharedPreferences R0 = dq.R0(context);
        xi xiVar = new xi(xi.j(context));
        xiVar.r0(wo.b.values()[R0.getInt("pSr", g6.i.b.b)]);
        xiVar.m0(new net.dinglisch.android.taskerm.g(context.getResources(), tp.J(context, 2130969162)));
        R0.edit().remove("pSr").commit();
        x0(xiVar);
        L0(false);
    }

    private static synchronized int W1() {
        int i;
        synchronized (to.class) {
            i = D;
            D = i - 1;
        }
        return i;
    }

    private void W4(List<wo> list, List<wo> list2, List<wo> list3) {
        for (wo woVar : list) {
            if (woVar.e1()) {
                list2.add(woVar);
            } else {
                list3.add(woVar);
            }
        }
    }

    public static tn X1() {
        return Y1(null);
    }

    private void X4(List<wo> list, List<wo> list2, List<wo> list3) {
        for (wo woVar : list) {
            if (woVar.h1()) {
                list2.add(woVar);
            } else {
                list3.add(woVar);
            }
        }
    }

    public static tn Y1(Integer num) {
        tn U1 = U1(W1());
        if (num != null) {
            U1.M2(num.intValue());
        }
        return U1;
    }

    public static to Z1(Context context) {
        to toVar = new to();
        toVar.x0(new xi(xi.j(context)));
        return toVar;
    }

    public static final boolean Z2(g gVar) {
        boolean z2;
        int ordinal = gVar.ordinal();
        synchronized (B[ordinal]) {
            StringBuilder sb = new StringBuilder();
            sb.append("data: haveStatic: ");
            sb.append(gVar);
            sb.append(" ");
            sb.append(C[ordinal] != null);
            r7.f("TD", sb.toString());
            z2 = C[ordinal] != null;
        }
        return z2;
    }

    private void b1() {
        for (tn tnVar : this.v.values()) {
            if (tnVar.M1()) {
                tnVar.p0(this);
            }
        }
    }

    public static String f2() {
        return "TaskerData";
    }

    public static int g2() {
        return 1;
    }

    public static File g5(String str) {
        File b2 = ti.b();
        if (b2 == null) {
            r7.f("TD", "not writing capabilities, no storage dir");
        } else {
            File file = new File(b2, str);
            StringBuilder sb = new StringBuilder();
            sb.append("<");
            sb.append("capabilities");
            sb.append(">\n");
            on.h(sb);
            j2.o(sb);
            a1.L(sb);
            sb.append("</");
            sb.append("capabilities");
            sb.append(">");
            if (dq.C3(sb.toString(), file, false)) {
                return file;
            }
        }
        return null;
    }

    public static final to h2(Context context) {
        return i2(context, true);
    }

    public static File h5(Resources resources, String str, boolean z2) {
        File b2 = ti.b();
        if (b2 == null) {
            r7.f("TD", "not writing data def, no storage dir");
            return null;
        }
        File file = new File(b2, str);
        r7.f("TD", "write data def: " + file);
        if (file.exists() && !z2) {
            r7.f("TD", "skip, exists");
            return null;
        }
        StringBuilder sb = new StringBuilder();
        sb.append("<");
        sb.append("datadef");
        sb.append(">\n");
        qi.g0(sb);
        on.n(resources, false, sb);
        j2.u(resources, sb);
        a1.R(resources, false, sb);
        sb.append("</");
        sb.append("datadef");
        sb.append(">");
        if (dq.C3(sb.toString(), file, false)) {
            return file;
        }
        return null;
    }

    private void i1(int i) {
        tn tnVar = this.v.get(Integer.valueOf(i));
        if (tnVar == null) {
            r7.k("TD", "attempt to delete non-existent macro ID " + i);
        } else {
            if (tnVar.u()) {
                this.q.remove(tnVar.getName());
            }
            this.v.remove(Integer.valueOf(i));
            Iterator<xi> it = this.x.iterator();
            while (it.hasNext()) {
                it.next().e0(i);
            }
            K4();
        }
        r7.f("TD", "deleteTaskAux " + i + " : done");
    }

    public static final to i2(Context context, boolean z2) {
        return J2(g.Passive, context, z2);
    }

    public static final uo j2(Context context) {
        return h2(context);
    }

    private g5 j3(PackageManager packageManager, to toVar) {
        g5 g5Var = new g5();
        int c2 = toVar.c2();
        if (c2 == 0) {
            g5Var.b = 2131887809;
            g5Var.a = 2131891224;
        } else if (c2 == 1) {
            xi w = toVar.w(0);
            g5Var.c = w;
            r7.f("TD", "import project " + w.getName());
            if (W2(w.getName())) {
                g5Var.b = 2131887882;
            } else {
                toVar.P2(0);
                Set<Integer> J = w.J();
                Set<String> G = w.G();
                Set<Integer> s = w.s();
                HashMap hashMap = new HashMap();
                r7.f("TD", "project contents: " + J.size() + " tasks, " + w.v().size() + " profiles, " + w.I().size() + " scenes");
                w.f();
                int c22 = c2();
                x0(w);
                Iterator<Integer> it = J.iterator();
                while (true) {
                    if (!it.hasNext()) {
                        break;
                    }
                    int intValue = it.next().intValue();
                    r7.f("TD", "handle task import: " + intValue);
                    if (!toVar.T(intValue)) {
                        r7.G("TD", "project refers to non-existent task ID " + intValue);
                        g5Var.b = 2131887883;
                        break;
                    }
                    tn R = toVar.R(intValue);
                    int P0 = R.P0();
                    g5 m3 = m3(R, c22);
                    if (!g5Var.d(m3)) {
                        break;
                    }
                    int P02 = ((tn) m3.c).P0();
                    if (P0 != P02) {
                        hashMap.put(Integer.valueOf(P0), Integer.valueOf(P02));
                        r7.f("TD", "task ID remap: " + P0 + " -> " + P02);
                    }
                }
                if (!g5Var.a()) {
                    Iterator<Integer> it2 = s.iterator();
                    while (true) {
                        if (!it2.hasNext()) {
                            break;
                        }
                        int intValue2 = it2.next().intValue();
                        r7.f("TD", "handle profile import: " + intValue2);
                        if (!toVar.V(intValue2)) {
                            r7.G("TD", "project refers to non-existing profile ID " + intValue2);
                            g5Var.b = 2131887883;
                            break;
                        }
                        wo c3 = toVar.c(intValue2);
                        c3.z1(T1(), "impProj");
                        c3.c0();
                        c3.x();
                        c3.p1(hashMap);
                        v0(c3, c22);
                    }
                }
                if (!g5Var.a()) {
                    Iterator<String> it3 = G.iterator();
                    while (true) {
                        if (!it3.hasNext()) {
                            break;
                        }
                        String next = it3.next();
                        r7.f("TD", "handle scene import" + next);
                        if (!toVar.p(next)) {
                            r7.G("TD", "project refers to non-existent scene " + next);
                            g5Var.b = 2131887883;
                            break;
                        }
                        dk z2 = toVar.z2(next);
                        z2.a3(hashMap);
                        if (!g5Var.d(k3(z2, c22))) {
                            break;
                        }
                    }
                }
                if (g5Var.a()) {
                    r7.G("TD", "project import failed, tidy up");
                    d1(packageManager, c22, true);
                } else {
                    K4();
                }
            }
        } else {
            g5Var.b = 2131887807;
            g5Var.a = 2131891221;
        }
        return g5Var;
    }

    public static File j4(PackageManager packageManager, SharedPreferences sharedPreferences, Resources resources, String str) {
        int i = sharedPreferences.getInt("lph", 0);
        if (i > 0) {
            File F1 = F1(true);
            r7.f("TD", "auto-backups required (index period " + i + "), prepare dir");
            if (F1 == null) {
                r7.G("TD", "failed to write auto-backup data, no storage");
            } else {
                s4(resources, i);
                File file = new File(F1, str);
                if (dq.o2(file)) {
                    r7.f("TD", "created backup dir " + file);
                    return file;
                }
            }
        }
        return null;
    }

    public static i5 k1(Context context, Bundle bundle) {
        if (bundle == null) {
            return null;
        }
        qi qiVar = new qi(bundle);
        if (qiVar.H("Task")) {
            return new tn(qiVar);
        }
        if (qiVar.H("Profile")) {
            return new wo(context, qiVar, -1);
        }
        if (qiVar.H("Project")) {
            return new xi(qiVar);
        }
        return null;
    }

    private g5 k3(dk dkVar, int i) {
        g5 g5Var = new g5();
        if (p(dkVar.getName())) {
            g5Var.b = 2131887890;
            g5Var.d = dkVar.getName();
        } else {
            y0(dkVar, i);
            g5Var.c = dkVar;
        }
        return g5Var;
    }

    private g5 m3(tn tnVar, int i) {
        return n3(tnVar, i, false);
    }

    private g5 n3(tn tnVar, int i, boolean z2) {
        g5 g5Var = new g5();
        if (tnVar.u()) {
            String name = tnVar.getName();
            if (N3(name)) {
                tn N = N(name);
                if (N.d() == tnVar.d() || z2) {
                    r7.f("TD", "same creation date or asked to overwrite, overwrite existing task");
                    int P0 = N.P0();
                    tnVar.t2(P0);
                    this.v.put(Integer.valueOf(P0), tnVar);
                } else {
                    g5Var.b = 2131887808;
                    g5Var.d = name;
                    tnVar.t2(N(name).P0());
                }
                g5Var.c = tnVar;
                return g5Var;
            }
        }
        tnVar.t2(T1());
        B0(tnVar, i);
        g5Var.c = tnVar;
        return g5Var;
    }

    public static boolean r1() {
        return qn.e("!(%)(DJJJ!!", "!88***&^&^&", "PBEWithMD5And128BitAES-CBC-OpenSSL", 10);
    }

    public static void s4(Resources resources, int i) {
        Map<Long, File> E1 = E1();
        long j = i == 0 ? -1L : resources.getIntArray(2130903178)[i] * 1000;
        long currentTimeMillis = System.currentTimeMillis();
        for (Map.Entry<Long, File> entry : E1.entrySet()) {
            File value = entry.getValue();
            long longValue = currentTimeMillis - entry.getKey().longValue();
            if (longValue > j) {
                r7.f("TD", "delete backup " + value.getName() + " age " + longValue + " max " + j);
                dq.w2(value);
            }
        }
    }

    private void u0(b5 b5Var, ri.c cVar, int i, int i2, Map<String, String> map, boolean z2) {
        String w = b5Var.N(i).w();
        String F2 = ri.F(cVar, w, b5Var.N(i2).w(), "");
        boolean isEmpty = TextUtils.isEmpty(w);
        boolean isEmpty2 = TextUtils.isEmpty(F2);
        if (z2) {
            if (isEmpty2 || isEmpty) {
                map.put(w, F2);
                return;
            }
            return;
        }
        if (isEmpty2 || isEmpty) {
            return;
        }
        map.put(w, F2);
    }

    public static final to u1(Context context) {
        return J2(g.Active, context, true);
    }

    public static final uo v1(Context context) {
        return u1(context);
    }

    public static boolean v3(String str) {
        return str.startsWith("taskerprofile");
    }

    public static boolean w3(String str) {
        return str.startsWith("taskerproject");
    }

    public static void w4(g gVar, boolean z2) {
        int ordinal = gVar.ordinal();
        synchronized (B[ordinal]) {
            try {
                r7.f("TD", "data: removeStatic: " + gVar);
                C[ordinal] = null;
                if (z2) {
                    System.gc();
                }
            } catch (Throwable th2) {
                throw th2;
            }
        }
    }

    public static boolean x3() {
        return F;
    }

    private String y1(Context context, xi xiVar, int i) {
        return A1(context, v2(context.getPackageManager(), xiVar), "taskerproject", i);
    }

    public static boolean y3(String str) {
        return str.startsWith("taskershare");
    }

    private int y4(String str, String str2, String str3, tn tnVar) {
        int i = 0;
        for (net.dinglisch.android.taskerm.c cVar : tnVar.D0()) {
            for (int i2 = 0; i2 < cVar.Y(); i2++) {
                if (cVar.p0(i2) == 1 && a1.D0(cVar.j(), i2).equals(str3) && cVar.N(i2).w().equals(str)) {
                    if (str2 != null) {
                        cVar.k0(i2, str2);
                    }
                    i++;
                }
            }
        }
        return i;
    }

    public static String z1(Context context, tn tnVar, int i) {
        return A1(context, M2(tnVar), "taskertask", i);
    }

    public static boolean z3(String str) {
        return str.startsWith("https://taskernet.com/shares/") && str.contains("user=") && str.contains("id=");
    }

    private int z4(String str, String str2, String str3) {
        Iterator<tn> it = this.v.values().iterator();
        int i = 0;
        while (it.hasNext()) {
            i += y4(str, str2, str3, it.next());
        }
        return i;
    }

    public void A0(tn tnVar) {
        B0(tnVar, -1);
    }

    public to A2(dk dkVar) {
        to toVar = new to();
        toVar.y0(dkVar, -1);
        Iterator<Integer> it = dkVar.L1(false).iterator();
        while (it.hasNext()) {
            int intValue = it.next().intValue();
            if (T(intValue)) {
                toVar.A0(R(intValue));
            } else {
                r7.G("TD", "scene " + dkVar.getName() + " refs non-existent tid " + intValue);
            }
        }
        return toVar;
    }

    public void A4(c2 c2Var) {
        if (c2Var == null) {
            r7.G("TD", "resetEntityEditDate: null entity");
        } else {
            c2Var.y();
            K4();
        }
    }

    public void B0(tn tnVar, int i) {
        if (tnVar.P0() == -1) {
            tnVar.t2(T1());
        } else if (B3(tnVar.P0())) {
            tnVar.t2(T1());
        }
        int P0 = tnVar.P0();
        this.v.put(Integer.valueOf(P0), tnVar);
        if (tnVar.u()) {
            String name = tnVar.getName();
            if (this.q.containsKey(name) && this.q.get(name).intValue() != P0) {
                r7.k("TD", "addTask: task name " + name + " tID " + P0 + " conflicts with tID " + this.q.get(name));
            }
            this.q.put(tnVar.getName(), Integer.valueOf(tnVar.P0()));
            if (i >= 0) {
                this.x.get(i).e(P0);
            }
        }
        K4();
    }

    public String B2(dk dkVar, Resources resources) {
        return dkVar.I1(resources);
    }

    public boolean B4(final Context context, final SharedPreferences sharedPreferences, final Resources resources, final long j, final boolean z2, final boolean z3) {
        boolean booleanValue;
        S4(true);
        try {
            synchronized (B[g.Passive.ordinal()]) {
                booleanValue = ((Boolean) TaskerApp.q("Tasker Data savePassiveDataAndActivate", new xj.a() {
                    @Override
                    public final Object invoke() {
                        Boolean M3;
                        M3 = to.this.M3(z2, context, j, sharedPreferences, resources, z3);
                        return M3;
                    }
                })).booleanValue();
            }
            return booleanValue;
        } finally {
            S4(false);
        }
    }

    @Override
    public ArrayList<String> C() {
        ArrayList<xi> e2 = e();
        ArrayList<String> arrayList = new ArrayList<>();
        Iterator<xi> it = e2.iterator();
        while (it.hasNext()) {
            arrayList.add(it.next().getName());
        }
        return arrayList;
    }

    public String C1(Context context, int i) {
        return D1(context, i, false);
    }

    public int C2(String str) {
        Iterator<xi> it = this.x.iterator();
        int i = 0;
        while (it.hasNext()) {
            if (it.next().T(str)) {
                return i;
            }
            i++;
        }
        return -1;
    }

    public void D0(int i, int i2) {
        if (this.x.size() != 0) {
            if (i2 >= 0) {
                this.x.get(i2).e(i);
                return;
            }
            return;
        }
        r7.G("TD", "addTaskToProject: proj: " + i2 + " task: " + i + " no projects...");
    }

    public String D1(final Context context, final int i, final boolean z2) {
        return (String) TaskerApp.q("Tasker Data get XML ", new xj.a() {
            @Override
            public final Object invoke() {
                String D3;
                D3 = to.this.D3(context, i, z2);
                return D3;
            }
        });
    }

    public ArrayList<dk> D2(int i, boolean z2) {
        Collection<String> hashSet;
        ArrayList<dk> arrayList = new ArrayList<>();
        if (i == -2) {
            hashSet = this.w.keySet();
        } else if (i < 0 || i >= this.x.size()) {
            r7.G("TD", "gsip: bad project index: " + i);
            hashSet = new HashSet();
        } else {
            hashSet = this.x.get(i).I();
        }
        for (String str : hashSet) {
            if (z2 || !xl.P(str)) {
                arrayList.add(this.w.get(str));
            }
        }
        return arrayList;
    }

    public Set<String> D4(Context context, PackageManager packageManager, int i, boolean z2) {
        return L(context, packageManager, i, z2, true);
    }

    @Override
    public int E(int i) {
        Iterator<xi> it = this.x.iterator();
        int i2 = 0;
        while (it.hasNext()) {
            if (it.next().R(i)) {
                return i2;
            }
            i2++;
        }
        return -1;
    }

    public void E0(Context context) {
        for (xi xiVar : x2()) {
            if (xiVar.Q() && tp.Z(context, xiVar.getIcon())) {
                K4();
            }
        }
        Iterator<tn> it = P2(-2).iterator();
        while (it.hasNext()) {
            tn next = it.next();
            if (next.G1() && tp.Z(context, next.getIcon())) {
                K4();
            }
        }
    }

    public ArrayList<tn> E2(int i, tn.f fVar, boolean z2) {
        ArrayList<tn> F1 = fVar == tn.f.UserReverse ? com.joaomgcd.taskerm.util.x2.F1(this, i, z2) : q(i, z2);
        if (fVar == tn.f.Alpha) {
            Collections.sort(F1, new Comparator() {
                @Override
                public final int compare(Object obj, Object obj2) {
                    int E3;
                    E3 = to.E3((tn) obj, (tn) obj2);
                    return E3;
                }
            });
        } else if (fVar == tn.f.AgeNewestFirst) {
            Collections.sort(F1, new Comparator() {
                @Override
                public final int compare(Object obj, Object obj2) {
                    int F3;
                    F3 = to.F3((tn) obj, (tn) obj2);
                    return F3;
                }
            });
        } else if (fVar == tn.f.AgeOldestFirst) {
            Collections.sort(F1, new Comparator() {
                @Override
                public final int compare(Object obj, Object obj2) {
                    int G3;
                    G3 = to.G3((tn) obj, (tn) obj2);
                    return G3;
                }
            });
        }
        return F1;
    }

    public Set<String> E4(Context context, PackageManager packageManager, int i, boolean z2, boolean z3) {
        int i2;
        int i3;
        int[] iArr;
        int i4;
        int i5;
        HashSet hashSet = new HashSet();
        Iterator<tn> it = P2(i).iterator();
        while (it.hasNext()) {
            tn next = it.next();
            if (next != null) {
                next.d2(context, false, hashSet, false, z2, false, z3);
            }
        }
        Iterator<dk> it2 = D2(i, true).iterator();
        while (it2.hasNext()) {
            dk next2 = it2.next();
            if (next2 != null) {
                next2.g3(false, hashSet, false, z2);
                Iterator<Integer> it3 = next2.L1(false).iterator();
                while (it3.hasNext()) {
                    int intValue = it3.next().intValue();
                    if (T(intValue)) {
                        R(intValue).d2(context, false, hashSet, false, z2, false, z3);
                    } else {
                        r7.G("TD", "scanForProjectVariables: scene references unknown task " + intValue);
                    }
                }
            }
        }
        for (wo woVar : q2(i)) {
            int[] iArr2 = A;
            int length = iArr2.length;
            int i6 = 0;
            while (i6 < length) {
                int i7 = iArr2[i6];
                if (woVar.Z0(i7)) {
                    if (i7 == 1) {
                        ((kp) woVar.T0(i7)).x1(hashSet, false, z2);
                    } else {
                        i4 = i6;
                        i5 = length;
                        kq.y1((b5) woVar.T0(i7), false, hashSet, false, z2, false, z3);
                        i6 = i4 + 1;
                        length = i5;
                    }
                }
                i4 = i6;
                i5 = length;
                i6 = i4 + 1;
                length = i5;
            }
            int[] R0 = woVar.R0();
            int length2 = R0.length;
            int i8 = 0;
            while (i8 < length2) {
                int i9 = R0[i8];
                tn R = R(i9);
                if (R == null) {
                    r7.k("TD", "varscan: profile: " + woVar.C0() + ": bad task ID: " + i9);
                    i2 = i8;
                    i3 = length2;
                    iArr = R0;
                } else {
                    i2 = i8;
                    i3 = length2;
                    iArr = R0;
                    R.d2(context, false, hashSet, false, z2, false, z3);
                }
                i8 = i2 + 1;
                R0 = iArr;
                length2 = i3;
            }
        }
        return hashSet;
    }

    public int F0(wo woVar, String str) {
        if (TextUtils.isEmpty(str)) {
            str = null;
        }
        int z4 = woVar.u() ? z4(woVar.getName(), str, "prof") : 0;
        woVar.G(str);
        K4();
        return z4;
    }

    public java.util.List<net.dinglisch.android.taskerm.wo> F2(android.content.Context r8, net.dinglisch.android.taskerm.wo.b r9, int r10) {
        throw new UnsupportedOperationException("Method not decompiled: net.dinglisch.android.taskerm.to.F2(android.content.Context, net.dinglisch.android.taskerm.wo$b, int):java.util.List");
    }

    public Set<String> F4(Context context, Set<String> set, boolean z2, boolean z3) {
        return G4(context, set, z2, z3, false);
    }

    @Override
    public List<Integer> G(String str) {
        LinkedList linkedList = new LinkedList();
        for (wo woVar : this.u.values()) {
            if (woVar.u() && woVar.getName().equals(str)) {
                linkedList.add(Integer.valueOf(woVar.C0()));
            }
        }
        return linkedList;
    }

    public void G0(dk dkVar, String str) {
        String name = dkVar.getName();
        for (xi xiVar : this.x) {
            if (xiVar.d0(name) != -1) {
                xiVar.d(str);
            }
        }
        Iterator<tn> it = this.v.values().iterator();
        while (it.hasNext()) {
            Iterator<net.dinglisch.android.taskerm.c> it2 = it.next().D0().iterator();
            while (it2.hasNext()) {
                it2.next().h(name, str);
            }
        }
        for (dk dkVar2 : this.w.values()) {
            if (!dkVar2.getName().equals(name)) {
                dkVar2.q0(name, str);
            }
        }
        this.w.remove(name);
        dkVar.G(str);
        this.w.put(str, dkVar);
    }

    public List<wo> G2(Object[] objArr, int i) {
        if (objArr == null) {
            objArr = this.u.values().toArray();
        }
        ArrayList arrayList = new ArrayList();
        for (Object obj : objArr) {
            wo woVar = (wo) obj;
            if (woVar.Z0(i)) {
                int i2 = 0;
                while (i2 < arrayList.size() && woVar.T0(i).compareTo(((wo) arrayList.get(i2)).T0(i)) <= 0) {
                    i2++;
                }
                arrayList.add(i2, woVar);
            }
        }
        return arrayList;
    }

    public Set<String> G4(Context context, Set<String> set, boolean z2, boolean z3, boolean z4) {
        int i;
        int i2;
        int i3;
        Set<Integer> hashSet = new HashSet<>();
        HashSet hashSet2 = new HashSet();
        PackageManager packageManager = context.getPackageManager();
        Set<String> hashSet3 = !z2 ? new HashSet<>() : null;
        boolean z5 = false;
        if (Kid.b(context) && (i3 = w(0).m().i()) != -1) {
            hashSet.add(Integer.valueOf(i3));
        }
        Iterator<tn> it = this.v.values().iterator();
        while (it.hasNext()) {
            for (net.dinglisch.android.taskerm.c cVar : it.next().D0()) {
                if (a1.i1(cVar.j()) || a1.j1(cVar.j())) {
                    hashSet2.add(cVar.N(0).w());
                }
            }
        }
        for (wo woVar : this.u.values()) {
            if (woVar.h1()) {
                for (int i4 : A) {
                    if (woVar.Z0(i4)) {
                        if (i4 == 1) {
                            ((kp) woVar.T0(i4)).x1(hashSet3, z2, true);
                        } else {
                            kq.w1((b5) woVar.T0(i4), z2, hashSet3, z5, true);
                        }
                    }
                }
                int[] R0 = woVar.R0();
                int length = R0.length;
                int i5 = 0;
                while (i5 < length) {
                    tn R = R(R0[i5]);
                    if (R != null) {
                        if (R.u()) {
                            hashSet.add(Integer.valueOf(R.P0()));
                        } else {
                            i = i5;
                            i2 = length;
                            R.c2(context, z2, hashSet3, false, true, false);
                            t0(packageManager, R, hashSet);
                            i5 = i + 1;
                            length = i2;
                        }
                    }
                    i = i5;
                    i2 = length;
                    i5 = i + 1;
                    length = i2;
                }
            }
            z5 = false;
        }
        for (dk dkVar : this.w.values()) {
            if (hashSet2.contains(dkVar.getName())) {
                dkVar.g3(z2, hashSet3, false, true);
                t0(packageManager, dkVar, hashSet);
            }
        }
        if (!z3) {
            for (String str : set) {
                if (this.q.containsKey(str)) {
                    Integer num = this.q.get(str);
                    num.intValue();
                    hashSet.add(num);
                }
            }
            for (Object obj : hashSet.toArray()) {
                Integer num2 = (Integer) obj;
                if (this.v.containsKey(num2)) {
                    t0(packageManager, this.v.get(num2), hashSet);
                }
            }
        }
        for (tn tnVar : this.v.values()) {
            if ((!z3 && !hashSet.contains(Integer.valueOf(tnVar.P0()))) || !z4 || tnVar.u() || com.joaomgcd.taskerm.util.x2.f3(this, tnVar)) {
                tnVar.c2(context, z2, hashSet3, false, true, false);
            }
        }
        return hashSet3;
    }

    @Override
    public int H(int i) {
        Iterator<xi> it = this.x.iterator();
        int i2 = 0;
        while (it.hasNext()) {
            if (it.next().V(i)) {
                return i2;
            }
            i2++;
        }
        return -1;
    }

    public int H0(tn tnVar, String str, int i) {
        int i2;
        boolean u = tnVar.u();
        if (tnVar.u()) {
            String name = tnVar.getName();
            this.q.remove(name);
            i2 = z4(name, str, "m");
        } else {
            i2 = 0;
        }
        tnVar.G(str);
        if (tnVar.u()) {
            this.q.put(tnVar.getName(), Integer.valueOf(tnVar.P0()));
        }
        if (!u) {
            if (i == -1) {
                i = 0;
            }
            this.x.get(i).e(tnVar.P0());
        }
        K4();
        return i2;
    }

    public ArrayList<String> H2(ArrayList<dk> arrayList) {
        ArrayList<String> arrayList2 = new ArrayList<>();
        Iterator<dk> it = arrayList.iterator();
        while (it.hasNext()) {
            arrayList2.add(it.next().getName());
        }
        return arrayList2;
    }

    @Override
    public hk.k I(String str, String str2) {
        return this.w.get(str).b1(str2).C1();
    }

    public void I0(Context context) {
        Map<Integer, tn> map = this.v;
        if (map == null) {
            r7.k("TD", "cabscat: null tasks");
            return;
        }
        Iterator<tn> it = map.values().iterator();
        while (it.hasNext()) {
            J0(context, it.next());
        }
    }

    public ho I1(String str, int i) {
        Iterator<wo> it = G2(null, i).iterator();
        while (it.hasNext()) {
            ho T0 = it.next().T0(i);
            if (T0.D0() && T0.getName().equals(str)) {
                return T0;
            }
        }
        return null;
    }

    public ArrayList<String> I2(int i, tn.f fVar) {
        return O(K(i, fVar));
    }

    public void I4(Context context, bm bmVar, List<cm> list) {
        Iterator<wo> it;
        Resources resources = context.getResources();
        LinkedList<cm> linkedList = new LinkedList();
        Iterator<tn> it2 = this.v.values().iterator();
        while (it2.hasNext()) {
            cm e2 = it2.next().e2(resources, bmVar);
            if (e2 != null) {
                linkedList.add(e2);
            }
        }
        LinkedList linkedList2 = new LinkedList();
        Iterator<wo> it3 = this.u.values().iterator();
        while (it3.hasNext()) {
            wo next = it3.next();
            cm r1 = next.r1(context, bmVar);
            int[] R0 = next.R0();
            int length = R0.length;
            int i = 0;
            while (i < length) {
                int i2 = R0[i];
                Iterator it4 = linkedList.iterator();
                while (true) {
                    if (!it4.hasNext()) {
                        it = it3;
                        break;
                    }
                    cm cmVar = (cm) it4.next();
                    it = it3;
                    if (cmVar.d() == i2) {
                        if (r1 == null) {
                            r1 = next.u0(resources, bmVar);
                        }
                        r1.a(cmVar);
                    } else {
                        it3 = it;
                    }
                }
                i++;
                it3 = it;
            }
            Iterator<wo> it5 = it3;
            if (r1 != null) {
                linkedList2.add(r1);
            }
            it3 = it5;
        }
        LinkedList linkedList3 = new LinkedList();
        Iterator<dk> it6 = this.w.values().iterator();
        while (it6.hasNext()) {
            cm h3 = it6.next().h3(linkedList, context, bmVar);
            if (h3 != null) {
                linkedList3.add(h3);
            }
        }
        int size = this.x.size();
        if (size > 1) {
            for (int i3 = 0; i3 < size; i3++) {
                xi xiVar = this.x.get(i3);
                cm j0 = xiVar.j0(resources, bmVar);
                Iterator<Integer> it7 = xiVar.K().iterator();
                while (it7.hasNext()) {
                    int intValue = it7.next().intValue();
                    int i4 = 0;
                    while (true) {
                        if (i4 < linkedList.size()) {
                            cm cmVar2 = (cm) linkedList.get(i4);
                            if (cmVar2.d() == intValue) {
                                if (j0 == null) {
                                    j0 = xiVar.i(resources, bmVar);
                                }
                                j0.a(cmVar2);
                                linkedList.remove(i4);
                            } else {
                                i4++;
                            }
                        }
                    }
                }
                Iterator<Integer> it8 = xiVar.v().iterator();
                while (it8.hasNext()) {
                    int intValue2 = it8.next().intValue();
                    int i5 = 0;
                    while (true) {
                        if (i5 < linkedList2.size()) {
                            cm cmVar3 = (cm) linkedList2.get(i5);
                            if (cmVar3.d() == intValue2) {
                                if (j0 == null) {
                                    j0 = xiVar.i(resources, bmVar);
                                }
                                j0.a(cmVar3);
                                linkedList2.remove(i5);
                            } else {
                                i5++;
                            }
                        }
                    }
                }
                for (Object obj : xiVar.I()) {
                    int i6 = 0;
                    while (true) {
                        if (i6 < linkedList3.size()) {
                            cm cmVar4 = (cm) linkedList3.get(i6);
                            if (cmVar4.g().getName().equals(obj)) {
                                if (j0 == null) {
                                    j0 = xiVar.i(resources, bmVar);
                                }
                                j0.a(cmVar4);
                                linkedList3.remove(i6);
                            } else {
                                i6++;
                            }
                        }
                    }
                }
                if (j0 != null) {
                    list.add(j0);
                }
            }
        }
        list.addAll(linkedList2);
        for (cm cmVar5 : linkedList) {
            if (cmVar5.h().u()) {
                list.add(cmVar5);
            }
        }
        list.addAll(linkedList3);
    }

    @Override
    public boolean J(String str) {
        for (wo woVar : this.u.values()) {
            if (woVar.u() && str.equals(woVar.getName())) {
                return true;
            }
        }
        return false;
    }

    public boolean J0(Context context, tn tnVar) {
        if (tnVar == null) {
            r7.k("TD", "cabsct: null task");
            return false;
        }
        List<net.dinglisch.android.taskerm.c> D0 = tnVar.D0();
        if (D0 == null) {
            return false;
        }
        boolean z2 = false;
        for (net.dinglisch.android.taskerm.c cVar : D0) {
            int j = cVar.j();
            int H = a1.H(j);
            if (H != -1) {
                String w = cVar.N(H).w();
                String[] J = a1.J(j, H);
                int length = J.length;
                int i = 0;
                while (true) {
                    if (i >= length) {
                        break;
                    }
                    if (w.equals(J[i]) && !p(w)) {
                        y0(a1.G(context, w), 0);
                        z2 = true;
                        break;
                    }
                    i++;
                }
            }
        }
        return z2;
    }

    public List<String> J1(int i) {
        ArrayList arrayList = new ArrayList();
        for (ho hoVar : K1(i)) {
            if (hoVar.D0()) {
                String name = hoVar.getName();
                if (!arrayList.contains(name)) {
                    arrayList.add(name);
                }
            }
        }
        return arrayList;
    }

    public void J4(Set<Integer> set) {
        this.r = set;
    }

    @Override
    public ArrayList<tn> K(int i, tn.f fVar) {
        return E2(i, fVar, true);
    }

    public void K0() {
        Iterator<wo> it = this.u.values().iterator();
        LinkedList linkedList = null;
        while (true) {
            if (!it.hasNext()) {
                break;
            }
            wo next = it.next();
            for (int i = 0; i <= 1; i++) {
                if (next.c1(i)) {
                    int Q0 = next.Q0(i);
                    if (!this.v.containsKey(Integer.valueOf(Q0))) {
                        r7.G("TD", "profile " + next.C0() + " refers to missing task " + Q0 + ", correcting");
                        next.F1(i, -1);
                        K4();
                    }
                }
            }
            if (next.P0() == 0) {
                r7.G("TD", "profile " + next.C0() + " no tasks, delete");
                if (linkedList == null) {
                    linkedList = new LinkedList();
                }
                linkedList.add(Integer.valueOf(next.C0()));
            }
        }
        if (linkedList != null) {
            Iterator it2 = linkedList.iterator();
            while (it2.hasNext()) {
                int intValue = ((Integer) it2.next()).intValue();
                r7.G("TD", "delete profile " + intValue);
                c1(intValue);
            }
            K4();
        }
        for (dk dkVar : this.w.values()) {
            for (Integer num : dkVar.L1(false)) {
                int intValue2 = num.intValue();
                if (!this.v.containsKey(num)) {
                    r7.G("TD", "scene " + dkVar.getName() + " refers to missing task " + intValue2 + ", correcting");
                    dkVar.F0(intValue2);
                    K4();
                }
            }
        }
    }

    public List<ho> K1(int i) {
        ArrayList arrayList = new ArrayList();
        Iterator<wo> it = G2(null, i).iterator();
        while (it.hasNext()) {
            ho T0 = it.next().T0(i);
            if (T0.B0() == i) {
                arrayList.add(T0);
            }
        }
        return arrayList;
    }

    public tn K2(wo woVar, int i) {
        if (i < 2) {
            return R(woVar.Q0(i));
        }
        r7.k("TD", "getTaskByType: bad type: " + i);
        return null;
    }

    public void K4() {
        this.i = true;
        this.y.a();
    }

    @Override
    public Set<String> L(Context context, PackageManager packageManager, int i, boolean z2, boolean z3) {
        return this.y.c(context, i, z2, z3).getValue();
    }

    public boolean L0(boolean z2) {
        HashSet hashSet;
        Iterator<Integer> it;
        Iterator<Integer> it2;
        Iterator<String> it3;
        HashSet hashSet2;
        HashSet<String> hashSet3 = new HashSet();
        HashSet<Integer> hashSet4 = new HashSet();
        HashSet<Integer> hashSet5 = new HashSet();
        HashSet hashSet6 = new HashSet();
        HashSet hashSet7 = new HashSet();
        HashSet hashSet8 = new HashSet();
        HashSet hashSet9 = new HashSet();
        HashSet hashSet10 = new HashSet();
        HashSet hashSet11 = new HashSet();
        Iterator<xi> it4 = this.x.iterator();
        boolean z3 = false;
        while (it4.hasNext()) {
            xi next = it4.next();
            for (Integer num : next.s()) {
                Iterator<xi> it5 = it4;
                boolean z4 = z3;
                int intValue = num.intValue();
                if (hashSet4.contains(num)) {
                    StringBuilder sb = new StringBuilder();
                    hashSet2 = hashSet9;
                    sb.append("cafp: profile ID ");
                    sb.append(intValue);
                    sb.append(" reffed in multiple projects (fixed)");
                    r7.N("TD", z2, sb.toString());
                    next.c0(intValue);
                    z3 = true;
                } else {
                    hashSet2 = hashSet9;
                    hashSet4.add(num);
                    z3 = z4;
                }
                it4 = it5;
                hashSet9 = hashSet2;
            }
            HashSet hashSet12 = hashSet9;
            Iterator<xi> it6 = it4;
            Iterator<Integer> it7 = next.J().iterator();
            while (it7.hasNext()) {
                Integer next2 = it7.next();
                Iterator<Integer> it8 = it7;
                int intValue2 = next2.intValue();
                if (hashSet5.contains(next2)) {
                    r7.N("TD", z2, "cafp: task ID " + intValue2 + " reffed in multiple projects (fixed)");
                    next.e0(intValue2);
                    z3 = true;
                } else {
                    hashSet5.add(next2);
                }
                it7 = it8;
            }
            Iterator<String> it9 = next.G().iterator();
            while (it9.hasNext()) {
                String next3 = it9.next();
                if (hashSet3.contains(next3)) {
                    StringBuilder sb2 = new StringBuilder();
                    it3 = it9;
                    sb2.append("cafp: scene ");
                    sb2.append(next3);
                    sb2.append(" reffed in multiple projects (fixed)");
                    r7.N("TD", z2, sb2.toString());
                    next.d0(next3);
                    z3 = true;
                } else {
                    it3 = it9;
                    hashSet3.add(next3);
                }
                it9 = it3;
            }
            it4 = it6;
            hashSet9 = hashSet12;
        }
        HashSet hashSet13 = hashSet9;
        Iterator<Integer> it10 = this.u.keySet().iterator();
        while (it10.hasNext()) {
            Integer next4 = it10.next();
            int intValue3 = next4.intValue();
            if (hashSet4.contains(next4)) {
                it2 = it10;
            } else {
                wo woVar = this.u.get(next4);
                StringBuilder sb3 = new StringBuilder();
                it2 = it10;
                sb3.append("cafp: fixed: unfiled profile: ");
                sb3.append(woVar.C0());
                r7.N("TD", z2, sb3.toString());
                this.x.get(0).c(intValue3);
                z3 = true;
            }
            hashSet7.add(next4);
            it10 = it2;
        }
        Map<String, Integer> map = this.q;
        if (map != null) {
            Iterator<Integer> it11 = map.values().iterator();
            while (it11.hasNext()) {
                Integer next5 = it11.next();
                int intValue4 = next5.intValue();
                if (hashSet5.contains(next5)) {
                    it = it11;
                } else {
                    tn tnVar = this.v.get(next5);
                    if (tnVar != null) {
                        StringBuilder sb4 = new StringBuilder();
                        it = it11;
                        sb4.append("cafp: fixed: unfiled named task: ");
                        sb4.append(tnVar.P0());
                        r7.N("TD", z2, sb4.toString());
                        this.x.get(0).e(intValue4);
                    } else {
                        it = it11;
                    }
                    z3 = true;
                }
                hashSet8.add(next5);
                it11 = it;
            }
        }
        for (String str : this.w.keySet()) {
            if (!hashSet3.contains(str)) {
                r7.N("TD", z2, "cafp: fixed: unfiled scene: " + this.w.get(str).getName());
                this.x.get(0).d(str);
                z3 = true;
            }
            hashSet6.add(str);
        }
        for (Integer num2 : hashSet4) {
            num2.intValue();
            if (!hashSet7.contains(num2)) {
                hashSet10.add(num2);
            }
        }
        for (Integer num3 : hashSet5) {
            num3.intValue();
            if (!hashSet8.contains(num3)) {
                hashSet11.add(num3);
            }
        }
        for (String str2 : hashSet3) {
            if (hashSet6.contains(str2)) {
                hashSet = hashSet13;
            } else {
                hashSet = hashSet13;
                hashSet.add(str2);
            }
            hashSet13 = hashSet;
        }
        HashSet<String> hashSet14 = hashSet13;
        Iterator it12 = hashSet10.iterator();
        while (it12.hasNext()) {
            int intValue5 = ((Integer) it12.next()).intValue();
            Iterator<xi> it13 = this.x.iterator();
            while (it13.hasNext()) {
                it13.next().c0(intValue5);
            }
            r7.N("TD", z2, "cafp: fixed: unknown project profile(s): " + intValue5);
            z3 = true;
        }
        Iterator it14 = hashSet11.iterator();
        while (it14.hasNext()) {
            int intValue6 = ((Integer) it14.next()).intValue();
            for (xi xiVar : this.x) {
                xiVar.e0(intValue6);
                r7.G("TD", "remove task ID " + intValue6 + " from project " + xiVar.getName() + " remaining " + xiVar.p());
            }
            r7.N("TD", z2, "cafp: fixed: unknown project task(s): " + intValue6);
            z3 = true;
        }
        for (String str3 : hashSet14) {
            Iterator<xi> it15 = this.x.iterator();
            while (it15.hasNext()) {
                it15.next().d0(str3);
            }
            r7.N("TD", z2, "cafp: fixed: unknown project scene(s): " + str3);
            z3 = true;
        }
        if (z3) {
            K4();
        }
        return true ^ z3;
    }

    public String L1(Context context, pe.g gVar) {
        Resources resources = context.getResources();
        StringBuffer stringBuffer = new StringBuffer();
        for (Integer num : dq.h3(this.u.keySet())) {
            stringBuffer.append(m2(this.u.get(num), context, false, gVar));
            stringBuffer.append("\n\n");
        }
        Iterator<dk> it = a(-2, dk.i.Alpha, true).iterator();
        while (it.hasNext()) {
            stringBuffer.append(B2(it.next(), resources));
            stringBuffer.append('\n');
        }
        for (Integer num2 : dq.h3(this.v.keySet())) {
            stringBuffer.append(N2(context, this.v.get(num2), resources, gVar));
            stringBuffer.append('\n');
        }
        return stringBuffer.toString();
    }

    public void L4(Set<Integer> set) {
        this.s = set;
    }

    public List<wo> M1() {
        ArrayList arrayList = new ArrayList();
        for (wo woVar : this.u.values()) {
            if (woVar.h1()) {
                arrayList.add(woVar);
            }
        }
        return arrayList;
    }

    @Override
    public tn N(String str) {
        Integer num = this.q.get(str);
        if (num != null) {
            return this.v.get(num);
        }
        return null;
    }

    public void N0() {
        HashSet hashSet = new HashSet();
        for (wo woVar : this.u.values()) {
            if (woVar.j0() && !woVar.h1()) {
                hashSet.add(Integer.valueOf(woVar.C0()));
            }
        }
        Iterator it = hashSet.iterator();
        while (it.hasNext()) {
            c1(((Integer) it.next()).intValue());
        }
    }

    public c2 N1(yj yjVar) {
        int i = f.a[yjVar.f().ordinal()];
        if (i == 1) {
            return yjVar.j() ? c(yjVar.b()) : k2(yjVar.c());
        }
        if (i == 2) {
            return yjVar.j() ? R(yjVar.b()) : N(yjVar.c());
        }
        if (i == 3) {
            return z2(yjVar.c());
        }
        r7.k("TD", "getEntity: bad type: " + yjVar.f());
        return null;
    }

    public String N2(Context context, tn tnVar, Resources resources, pe.g gVar) {
        StringBuilder sb = new StringBuilder();
        sb.append(O2(resources, tnVar, -1));
        tnVar.a(context, sb);
        sb.append(L2(resources, tnVar));
        return tnVar.w(context, sb.toString(), gVar);
    }

    public boolean N3(String str) {
        return this.q.containsKey(str);
    }

    public void N4(int i, net.dinglisch.android.taskerm.g gVar) {
        this.x.get(i).m0(gVar);
        K4();
    }

    @Override
    public ArrayList<String> O(ArrayList<tn> arrayList) {
        ArrayList<String> arrayList2 = new ArrayList<>();
        Iterator<tn> it = arrayList.iterator();
        while (it.hasNext()) {
            arrayList2.add(it.next().getName());
        }
        return arrayList2;
    }

    public void O0(PackageManager packageManager, c2.a... aVarArr) {
        for (c2.a aVar : aVarArr) {
            int i = f.b[aVar.ordinal()];
            if (i == 1) {
                Iterator<wo> it = this.u.values().iterator();
                while (it.hasNext()) {
                    it.next().a0(packageManager, this);
                }
            } else if (i == 2) {
                Iterator<tn> it2 = this.v.values().iterator();
                while (it2.hasNext()) {
                    it2.next().i0(packageManager, this);
                }
            } else if (i == 3) {
                Iterator<dk> it3 = this.w.values().iterator();
                while (it3.hasNext()) {
                    it3.next().r0(packageManager, this);
                }
            }
        }
    }

    public int O1(PackageManager packageManager, String str) {
        String d2;
        int e2;
        HashSet hashSet = null;
        if (p(str)) {
            for (yj yjVar : z2(str).h(packageManager)) {
                if (yjVar.f() == yj.b.Task && (e2 = yjVar.e(this)) != -1) {
                    if (hashSet == null) {
                        hashSet = new HashSet();
                    }
                    hashSet.add(Integer.valueOf(e2));
                }
            }
        }
        int i = 0;
        for (tn tnVar : this.v.values()) {
            int P0 = tnVar.P0();
            if (hashSet == null || !hashSet.contains(Integer.valueOf(P0))) {
                for (yj yjVar2 : tnVar.h(packageManager)) {
                    if (yjVar2.k() && (d2 = yjVar2.d()) != null && d2.equals(str)) {
                        i++;
                    }
                }
            }
        }
        return i;
    }

    public String O2(Resources resources, tn tnVar, int i) {
        String name = tnVar.u() ? tnVar.getName() : vh.h(resources, 2131891124, new Object[0]);
        String string = resources.getString(2131891257);
        if (i != -1) {
            string = tn.z1(resources, i) + " " + string;
        }
        return string + ": " + name;
    }

    public void O3(tn tnVar) {
        tn tnVar2 = this.v.get(Integer.valueOf(tnVar.P0()));
        if (tnVar2 != null && tnVar2.u()) {
            if (this.q.containsKey(tnVar2.getName())) {
                this.q.remove(tnVar2.getName());
            } else {
                r7.G("TD", "mergeMacro: old macro has name but is not in aliases");
            }
        }
        r7.f("TD", "mergeMacro: do add: " + tnVar.Z0());
        B0(tnVar, -1);
    }

    public void O4(int i, String str) {
        this.x.get(i).q0(str);
        K4();
    }

    public void P0(String str) {
        Q0(true, "sub: " + str);
    }

    public final Map<String, Integer> P1() {
        return this.q;
    }

    public ArrayList<tn> P2(int i) {
        Collection<Integer> collection;
        ArrayList<tn> arrayList = new ArrayList<>();
        if (i == -2) {
            collection = this.v.keySet();
        } else if (i < this.x.size()) {
            collection = this.x.get(i).K();
        } else {
            r7.k("TD", "getTasksInProject: req index " + i + ", no projects " + this.x.size());
            collection = null;
        }
        if (collection != null) {
            for (Integer num : collection) {
                num.intValue();
                arrayList.add(this.v.get(num));
            }
        }
        return arrayList;
    }

    public void P4(int i, wo.b bVar) {
        List<xi> list = this.x;
        if (list == null) {
            return;
        }
        try {
            list.get(i).r0(bVar);
        } catch (Throwable th2) {
            r7.l("TD", "setProjectProfileSort", th2);
        }
        K4();
    }

    @Override
    public void Q(Context context, Collection<String> collection, int i, Integer num) {
        xi xiVar;
        kg.w0 M;
        if (i < 0) {
            return;
        }
        try {
            xiVar = w(i);
        } catch (Throwable unused) {
            xiVar = null;
        }
        if (xiVar == null || (M = xiVar.M()) == null) {
            return;
        }
        String g2 = vh.g(context, 2131891224, new Object[0]);
        if (num != null) {
            g2 = g2 + " (" + vh.g(context, num.intValue(), new Object[0]) + ")";
        }
        M.u(context, collection, g2);
    }

    public void Q0(boolean z2, String str) {
        if (z2) {
            V0();
        }
        this.u.clear();
        this.v.clear();
        this.r.clear();
        this.s.clear();
        this.t.clear();
        this.w.clear();
        this.x.clear();
        this.q.clear();
        K4();
    }

    public Set<Integer> Q1() {
        return this.v.keySet();
    }

    public void Q3(int i, int i2, int i3) {
        this.x.get(i2).Z(i, i3);
        K4();
    }

    public void Q4(int i, dk.i iVar) {
        try {
            this.x.get(i).t0(iVar);
            K4();
        } catch (Throwable th2) {
            r7.l("TD", "setProjectSceneSort", th2);
        }
    }

    @Override
    public tn R(int i) {
        if (this.v.containsKey(Integer.valueOf(i))) {
            return this.v.get(Integer.valueOf(i));
        }
        r7.G("TD", "getMacroByID: non-existent ID " + i);
        return null;
    }

    public void R0() {
        for (wo woVar : q2(-2)) {
            woVar.b0();
            woVar.s1(false);
        }
    }

    public HashMap<String, List<String>> R1(Context context, Set<String> set, boolean z2) {
        return S1(context, set, z2, false);
    }

    public boolean R2() {
        return t1(381, true).size() > 0;
    }

    public void R3(int i, int i2) {
        int E2 = E(i);
        if (E2 == i2) {
            return;
        }
        u4(E2, i);
        w0(i, i2);
    }

    public void R4(int i, tn.f fVar) {
        this.x.get(i).u0(fVar);
        K4();
    }

    public HashMap<String, List<String>> S1(Context context, Set<String> set, boolean z2, boolean z3) {
        int i;
        HashMap<String, List<String>> hashMap = new HashMap<>();
        Settings.H1(context, hashMap);
        HashSet hashSet = new HashSet();
        HashSet hashSet2 = new HashSet();
        PackageManager packageManager = context.getPackageManager();
        if (Kid.b(context) && (i = w(0).m().i()) != -1) {
            hashSet.add(Integer.valueOf(i));
        }
        Iterator<tn> it = this.v.values().iterator();
        while (it.hasNext()) {
            for (net.dinglisch.android.taskerm.c cVar : it.next().D0()) {
                if (a1.i1(cVar.j()) || a1.j1(cVar.j())) {
                    hashSet2.add(cVar.N(0).w());
                }
            }
        }
        for (wo woVar : this.u.values()) {
            if (woVar.h1()) {
                for (int i2 = 0; i2 < woVar.I0(); i2++) {
                    woVar.S0(i2).x0(context, hashMap);
                }
                for (int i3 : woVar.R0()) {
                    tn R = R(i3);
                    if (R != null) {
                        if (R.u()) {
                            hashSet.add(Integer.valueOf(R.P0()));
                        } else {
                            R.A(context, this, hashMap);
                            t0(packageManager, R, hashSet);
                        }
                    }
                }
            }
        }
        for (dk dkVar : this.w.values()) {
            if (hashSet2.contains(dkVar.getName())) {
                t0(packageManager, dkVar, hashSet);
            }
        }
        for (String str : set) {
            if (this.q.containsKey(str)) {
                Integer num = this.q.get(str);
                num.intValue();
                hashSet.add(num);
            }
        }
        for (Object obj : hashSet.toArray()) {
            Integer num2 = (Integer) obj;
            if (this.v.containsKey(num2)) {
                t0(packageManager, this.v.get(num2), hashSet);
            }
        }
        for (tn tnVar : this.v.values()) {
            if (z2 || hashSet.contains(Integer.valueOf(tnVar.P0()))) {
                tnVar.A(context, this, hashMap);
            }
        }
        for (String str2 : G4(context, set, false, true, z3)) {
            if (kq.S0(str2)) {
                kq.n0(context, hashMap, kq.H0(str2));
            }
        }
        return hashMap;
    }

    public void S3(int i, int i2) {
        r7.f("TD", "moveProject: " + i + " -> " + i2);
        this.x.add(i2, this.x.remove(i));
        K4();
    }

    @Override
    public boolean T(int i) {
        return this.v.containsKey(Integer.valueOf(i));
    }

    public boolean T2(int i) {
        return K1(i).size() > 0;
    }

    public void T3(String str, int i, int i2) {
        this.x.get(i).a0(str, i2);
        K4();
    }

    public void T4(Set<Integer> set) {
        this.t = set;
    }

    @Override
    public qi U(final int i) {
        return (qi) TaskerApp.q("pack Tasker Data", new xj.a() {
            @Override
            public final Object invoke() {
                qi L3;
                L3 = to.this.L3(i);
                return L3;
            }
        });
    }

    public void U0() {
        Iterator<wo> it = this.u.values().iterator();
        while (it.hasNext()) {
            it.next().C(false);
        }
        Iterator<tn> it2 = this.v.values().iterator();
        while (it2.hasNext()) {
            it2.next().C(false);
        }
        Iterator<dk> it3 = this.w.values().iterator();
        while (it3.hasNext()) {
            it3.next().C(false);
        }
    }

    public boolean U2(int i) {
        return this.s.contains(Integer.valueOf(i));
    }

    public void U3(String str, int i) {
        int C2 = C2(str);
        if (C2 == i) {
            return;
        }
        v4(C2, str);
        z0(str, i);
    }

    @Override
    public boolean V(int i) {
        return this.u.containsKey(Integer.valueOf(i));
    }

    public void V0() {
        for (wo woVar : this.u.values()) {
            woVar.k0();
            woVar.i0();
        }
    }

    public wo V1(Context context) {
        return new wo(context, T1());
    }

    public boolean V2() {
        for (tn tnVar : this.v.values()) {
            if (tnVar.u() && tnVar.q()) {
                return true;
            }
        }
        Iterator<wo> it = this.u.values().iterator();
        while (true) {
            if (!it.hasNext()) {
                return false;
            }
            wo next = it.next();
            if (next.q()) {
                for (int i : next.R0()) {
                    if (R(i).u()) {
                        return true;
                    }
                }
            }
        }
    }

    public void V3(int i, int i2, int i3) {
        this.x.get(i2).b0(i, i3);
        K4();
    }

    @Override
    public ArrayList<String> W(int i, dk.i iVar, boolean z2) {
        return H2(a(i, iVar, z2));
    }

    public wo W0(wo woVar, int i) {
        wo X0 = X0(woVar, false);
        for (int i2 = 0; i2 < 8; i2++) {
            if (i2 != i && X0.Z0(i2)) {
                X0.h0(i2);
            }
        }
        X0.d0();
        return X0;
    }

    public boolean W2(String str) {
        return k4(str) != -1;
    }

    public void W3(int i, int i2) {
        int H = H(i);
        if (H == i2) {
            return;
        }
        x4(H, i);
        D0(i, i2);
    }

    @Override
    public boolean X(String str) {
        dk z2 = z2(str);
        return z2 != null && z2.p0();
    }

    public wo X0(wo woVar, boolean z2) {
        tn R;
        wo woVar2 = new wo(woVar, T1());
        woVar2.A1(woVar.j1());
        woVar2.C1(woVar.M0());
        if (z2) {
            for (int i = 0; i < 2; i++) {
                if (woVar2.c1(i) && (R = R(woVar2.Q0(i))) != null && !R.u()) {
                    tn r0 = R.r0();
                    r0.t2(T1());
                    woVar2.F1(i, r0.P0());
                    A0(r0);
                }
            }
        } else {
            woVar2.F1(0, -1);
            woVar2.F1(1, -1);
        }
        v0(woVar2, E(woVar.C0()));
        return woVar2;
    }

    public boolean X2(int i, hk.k kVar) {
        Iterator<dk> it = D2(i, true).iterator();
        while (it.hasNext()) {
            if (it.next().k2(kVar)) {
                return true;
            }
        }
        return false;
    }

    public boolean X3() {
        Iterator<net.dinglisch.android.taskerm.c> it = t1(314, true).iterator();
        while (it.hasNext()) {
            if (com.joaomgcd.taskerm.action.input.a.N(it.next())) {
                return true;
            }
        }
        return false;
    }

    @Override
    public boolean Y(String str) {
        if (p(str)) {
            return z2(str).r();
        }
        return false;
    }

    public void Y0() {
        for (wo woVar : this.u.values()) {
            if (woVar.q() || woVar.p()) {
                woVar.c0();
            }
        }
    }

    public boolean Y2(int i) {
        return this.t.contains(Integer.valueOf(i));
    }

    public boolean Y3() {
        return s3(2094);
    }

    public boolean Y4(tn tnVar) {
        return tnVar.u() && H(tnVar.P0()) == -1;
    }

    @Override
    public boolean Z(String str) {
        return this.q.containsKey(str);
    }

    public void Z0(int i) {
        for (wo woVar : q2(i)) {
            if (woVar != null && !woVar.f1()) {
                woVar.c0();
                K4();
            }
        }
    }

    public boolean Z3() {
        return q3(390);
    }

    public boolean Z4(int i) {
        for (wo woVar : this.u.values()) {
            if (woVar.q() && (woVar.Q0(0) == i || woVar.Q0(1) == i)) {
                return true;
            }
        }
        return false;
    }

    @Override
    public ArrayList<dk> a(int i, dk.i iVar, boolean z2) {
        ArrayList<dk> D2 = D2(i, z2);
        if (iVar == dk.i.Alpha) {
            Collections.sort(D2, new c());
        } else if (iVar == dk.i.AgeNewestFirst) {
            Collections.sort(D2, new d());
        } else if (iVar == dk.i.AgeOldestFirst) {
            Collections.sort(D2, new e());
        }
        return D2;
    }

    @Override
    public net.dinglisch.android.taskerm.g a0(String str) {
        if (Z(str)) {
            return N(str).getIcon().q();
        }
        return null;
    }

    public boolean a1(String str, int i) {
        return I1(str, i) != null;
    }

    public int a2() {
        return this.q.size();
    }

    public boolean a3(int i) {
        Iterator<wo> it = this.u.values().iterator();
        while (it.hasNext()) {
            if (it.next().Z0(i)) {
                return true;
            }
        }
        return false;
    }

    public boolean a4() {
        return q3(351);
    }

    public String a5(Context context, boolean z2) {
        return D1(context, 52, z2);
    }

    @Override
    public boolean b(String str, String str2, boolean z2) {
        dk z22 = z2(str);
        if (z22 == null) {
            return false;
        }
        if (!z2) {
            return z22.j2(str2);
        }
        List<hk> e1 = z22.e1(str2);
        return e1 != null && e1.size() > 0;
    }

    @Override
    public boolean b0(int i) {
        wo c2 = c(i);
        if (c2 == null) {
            return false;
        }
        boolean q = c2.q();
        return !q ? w(E(i)).X() : q;
    }

    public int b2() {
        return this.u.size();
    }

    public boolean b3() {
        Iterator<Integer> it = a1.G0().iterator();
        while (it.hasNext()) {
            if (q3(it.next().intValue())) {
                return true;
            }
        }
        return false;
    }

    public boolean b4() {
        return q3(394);
    }

    public boolean b5(int i) {
        xi w = w(i);
        w.p0(!w.X());
        K4();
        return w.X();
    }

    @Override
    public wo c(int i) {
        if (!this.u.containsKey(Integer.valueOf(i))) {
            r7.G("TD", "no profile ID: " + i);
        }
        return this.u.get(Integer.valueOf(i));
    }

    @Override
    public dk c0(String str) {
        if (this.w.containsKey(str)) {
            return this.w.get(str).B0();
        }
        r7.k("TD", "getSceneCopy: unknown scene: " + str);
        return null;
    }

    public void c1(int i) {
        wo woVar = this.u.get(Integer.valueOf(i));
        if (woVar == null) {
            r7.G("TD", "deleteProfile: unknown ID " + i);
            return;
        }
        woVar.k0();
        woVar.i0();
        for (int i2 : woVar.R0()) {
            tn R = R(i2);
            if (R == null) {
                r7.G("TD", "deleteProfile: ignoring reference to unknown task ID " + i2);
            } else if (!R.u()) {
                i1(i2);
            }
        }
        this.u.remove(Integer.valueOf(i));
        Iterator<xi> it = this.x.iterator();
        while (it.hasNext()) {
            it.next().c0(i);
        }
        K4();
    }

    public int c2() {
        return this.x.size();
    }

    public g5 c3(Context context, Uri uri, int i) throws FileNotFoundException {
        String uri2 = uri.toString();
        return e3(context, i, uri2.endsWith(".tsk.xml"), uri2.endsWith(".prf.xml"), uri2.endsWith(".prj.xml"), com.joaomgcd.taskerm.util.g8.g0(context.getContentResolver().openInputStream(uri)), true);
    }

    public boolean c4() {
        return q3(328);
    }

    public void c5(ho hoVar) {
        ho T0;
        String name = hoVar.getName();
        for (wo woVar : this.u.values()) {
            if (woVar.Z0(hoVar.B0()) && (T0 = woVar.T0(hoVar.B0())) != hoVar && T0.D0() && T0.getName().equals(name)) {
                woVar.Y(hoVar.t0());
            }
        }
    }

    @Override
    public boolean d(int i, int i2, String str) {
        for (net.dinglisch.android.taskerm.c cVar : t1(i, false)) {
            if (cVar.Y() > i2 && cVar.p0(i2) == 1 && cVar.N(i2).w().equals(str)) {
                return true;
            }
        }
        return false;
    }

    @Override
    public List<Integer> d0(int i) {
        ArrayList arrayList = new ArrayList();
        for (wo woVar : this.u.values()) {
            int[] R0 = woVar.R0();
            int length = R0.length;
            int i2 = 0;
            while (true) {
                if (i2 >= length) {
                    break;
                }
                if (R0[i2] == i) {
                    arrayList.add(Integer.valueOf(woVar.C0()));
                    break;
                }
                i2++;
            }
        }
        return arrayList;
    }

    public void d1(PackageManager packageManager, int i, boolean z2) {
        r7.f("TD", "delete project: " + i);
        HashSet hashSet = new HashSet();
        if (z2) {
            for (Integer num : this.x.get(i).K()) {
                Iterator<Integer> it = d0(num.intValue()).iterator();
                while (it.hasNext()) {
                    if (E(it.next().intValue()) != i) {
                        hashSet.add(num);
                    }
                }
            }
        }
        xi remove = this.x.remove(i);
        xi xiVar = this.x.get(0);
        Iterator<Integer> it2 = remove.v().iterator();
        while (it2.hasNext()) {
            int intValue = it2.next().intValue();
            if (z2) {
                c1(intValue);
            } else {
                xiVar.c(intValue);
            }
        }
        for (Integer num2 : remove.K()) {
            int intValue2 = num2.intValue();
            if (!z2 || hashSet.contains(num2)) {
                xiVar.e(intValue2);
            } else {
                g1(intValue2);
            }
        }
        for (String str : remove.I()) {
            if (z2) {
                f1(packageManager, str);
            } else {
                xiVar.d(str);
            }
        }
        K4();
    }

    public int d2() {
        return this.w.size();
    }

    public g5 d3(Context context, String str, int i) {
        byte[] bArr;
        synchronized (B[g.Active.ordinal()]) {
            try {
                boolean A3 = A3(str);
                boolean v3 = v3(str);
                boolean w3 = w3(str);
                if (!A3 && !v3 && !w3) {
                    g5 g5Var = new g5();
                    g5Var.b = 2131887730;
                    r7.f("TD", "Can't import data " + str);
                    return g5Var;
                }
                try {
                    bArr = Base64.decode(str.replace("taskertask", "").replace("taskerprofile", "").replace("taskerproject", "").substring(3), 0);
                } catch (IllegalArgumentException e2) {
                    r7.k("TD", e2.getMessage());
                    bArr = null;
                }
                if (bArr != null) {
                    return e3(context, i, A3, v3, w3, jr.b(bArr), true);
                }
                g5 g5Var2 = new g5();
                g5Var2.b = 2131887730;
                return g5Var2;
            } catch (Throwable th2) {
                throw th2;
            }
        }
    }

    public boolean d4() {
        return g4() || X2(0, hk.k.MAP);
    }

    public boolean d5() {
        return s3(2097);
    }

    @Override
    public ArrayList<xi> e() {
        ArrayList<xi> arrayList = new ArrayList<>();
        for (xi xiVar : this.x) {
            if (xiVar.u()) {
                arrayList.add(xiVar);
            }
        }
        Collections.sort(arrayList, new Comparator() {
            @Override
            public final int compare(Object obj, Object obj2) {
                int K3;
                K3 = to.K3((xi) obj, (xi) obj2);
                return K3;
            }
        });
        return arrayList;
    }

    public boolean e1(PackageManager packageManager, String str, boolean z2) {
        for (int i = 0; i < this.x.size(); i++) {
            if (str.equals(this.x.get(i).getName())) {
                d1(packageManager, i, z2);
                return true;
            }
        }
        return false;
    }

    public int e2() {
        return this.v.size();
    }

    public g5 e3(Context context, int i, boolean z2, boolean z3, boolean z4, String str, boolean z5) {
        if (!z2 && !z3 && !z4) {
            g5 g5Var = new g5();
            g5Var.b = 2131887730;
            r7.f("TD", "Can't import data: not supported");
            return g5Var;
        }
        if (z2) {
            return p3(context, str, i, z5);
        }
        to toVar = new to();
        toVar.q1(context, "fromurl", str, false, true);
        if (!z3) {
            return j3(context.getPackageManager(), toVar);
        }
        Set<Integer> n2 = toVar.n2();
        if (n2.size() != 0) {
            return g3(toVar, n2.iterator().next().intValue(), i);
        }
        throw new RuntimeException("Missing event type");
    }

    public boolean e4() {
        return q3(366);
    }

    public boolean e5(Context context, boolean z2) {
        if (z2) {
            return true;
        }
        Set<String> F4 = F4(context, new HashSet(), false, true);
        if (F4 != null) {
            return F4.contains("%CLIP");
        }
        r7.f("TD", "usesClipboardVariable Can't check variables, return true");
        return true;
    }

    @Override
    public void f(Set<Integer> set) {
        for (xi xiVar : this.x) {
            if (xiVar.Q()) {
                set.add(Integer.valueOf(xiVar.getIcon().T()));
            }
        }
        Iterator<tn> it = this.v.values().iterator();
        while (it.hasNext()) {
            H4(it.next(), set);
        }
        for (dk dkVar : this.w.values()) {
            for (int i = 0; i < dkVar.t1(); i++) {
                C4(dkVar.a1(i), -1, set);
            }
            cl B1 = dkVar.B1(false);
            if (B1 != null) {
                C4(B1, -1, set);
            }
        }
    }

    public void f1(PackageManager packageManager, String str) {
        dk remove = this.w.remove(str);
        if (remove == null) {
            r7.k("TD", "deleteScene: unknown scene " + str);
        } else {
            Iterator<xi> it = this.x.iterator();
            while (it.hasNext()) {
                it.next().d0(str);
            }
            Iterator<Integer> it2 = remove.L1(true).iterator();
            while (it2.hasNext()) {
                int intValue = it2.next().intValue();
                if (T(intValue) && !R(intValue).u()) {
                    g1(intValue);
                }
            }
        }
        K4();
    }

    public g5 f3(Context context, String str, int i) throws FileNotFoundException {
        boolean contains = str.contains("Project");
        boolean z2 = str.contains("Profile") && !contains;
        return e3(context, i, (!str.contains("Task") || z2 || contains) ? false : true, z2, contains, str, true);
    }

    public boolean f4() {
        return U2(2076) || q3(330);
    }

    public boolean f5() {
        return com.joaomgcd.taskerm.util.x2.q3(this, 402);
    }

    @Override
    public ArrayList<net.dinglisch.android.taskerm.g> g(ArrayList<tn> arrayList) {
        ArrayList<net.dinglisch.android.taskerm.g> arrayList2 = new ArrayList<>();
        Iterator<tn> it = arrayList.iterator();
        while (it.hasNext()) {
            arrayList2.add(it.next().getIcon());
        }
        return arrayList2;
    }

    public void g1(int i) {
        r7.f("TD", "delete task: " + i);
        Iterator<wo> it = this.u.values().iterator();
        while (it.hasNext()) {
            it.next().m0(i);
        }
        for (dk dkVar : this.w.values()) {
            r7.f("TD", "scene: " + dkVar.getName() + " delete task refs by id: " + i);
            dkVar.F0(i);
        }
        i1(i);
    }

    public net.dinglisch.android.taskerm.g5 g3(net.dinglisch.android.taskerm.to r6, int r7, int r8) {
        throw new UnsupportedOperationException("Method not decompiled: net.dinglisch.android.taskerm.to.g3(net.dinglisch.android.taskerm.to, int, int):net.dinglisch.android.taskerm.g5");
    }

    public boolean g4() {
        return q3(368);
    }

    @Override
    public boolean h(String str) {
        return this.w.get(str).n2();
    }

    public void h1(Context context, wo woVar, int i) {
        int Q0 = woVar.Q0(i);
        woVar.n0(i);
        if (!this.v.get(Integer.valueOf(Q0)).u() && r2(Q0) == 0) {
            i1(Q0);
        }
        if (woVar.i1(context, com.joaomgcd.taskerm.util.x2.t(this, context, woVar, null, "deleteTaskAtProfile")) && i == 0 && woVar.c1(1)) {
            woVar.F1(0, woVar.n0(1));
        }
    }

    public g5 h3(Context context, File file, int i) {
        Context applicationContext = context.getApplicationContext();
        g5 g5Var = new g5();
        to toVar = new to();
        if (file == null) {
            r7.G("TD", "importProfile: null file path");
            g5Var.b = 2131887728;
            return g5Var;
        }
        if (!file.exists()) {
            r7.G("TD", "importProfile: path doesn't exist: " + file);
            g5Var.b = 2131887728;
            return g5Var;
        }
        if (!toVar.n4(applicationContext, file.getParentFile(), file.getName(), true, true)) {
            g5Var.b = 2131887728;
            return g5Var;
        }
        int b2 = toVar.b2();
        if (b2 == 0) {
            g5Var.b = 2131887809;
            g5Var.a = 2131891221;
            return g5Var;
        }
        if (b2 == 1) {
            return g3(toVar, toVar.n2().iterator().next().intValue(), i);
        }
        g5Var.b = 2131887807;
        g5Var.a = 2131891222;
        return g5Var;
    }

    public boolean h4() {
        return g4() || e4();
    }

    @Override
    public boolean i(yj yjVar) {
        return N1(yjVar) != null;
    }

    public g5 i3(Context context, PackageManager packageManager, File file) {
        g5 g5Var = new g5();
        to toVar = new to();
        r7.f("TD", "read import data");
        if (file == null) {
            r7.G("TD", "importProject: null file path");
            g5Var.b = 2131887728;
            return g5Var;
        }
        if (file.exists()) {
            if (toVar.n4(context, file.getParentFile(), file.getName(), true, true)) {
                return j3(packageManager, toVar);
            }
            g5Var.b = 2131887728;
            return g5Var;
        }
        r7.G("TD", "importProject: path doesn't exist: " + file);
        g5Var.b = 2131887728;
        return g5Var;
    }

    public boolean i4() {
        return r3(421, 333);
    }

    public java.lang.String i5(android.content.Context r5, java.lang.String r6, java.lang.Boolean r7) {
        throw new UnsupportedOperationException("Method not decompiled: net.dinglisch.android.taskerm.to.i5(android.content.Context, java.lang.String, java.lang.Boolean):java.lang.String");
    }

    @Override
    public ArrayList<wo> j() {
        ArrayList<wo> arrayList = new ArrayList<>();
        for (wo woVar : this.u.values()) {
            if (woVar.u()) {
                arrayList.add(woVar);
            }
        }
        Collections.sort(arrayList, new Comparator() {
            @Override
            public final int compare(Object obj, Object obj2) {
                int J3;
                J3 = to.J3((wo) obj, (wo) obj2);
                return J3;
            }
        });
        return arrayList;
    }

    public boolean j1(Context context, File file, String str, boolean z2) {
        return k5(context, file, str, 52, z2);
    }

    public boolean j5(Context context, File file, String str, int i) {
        return k5(context, file, str, i, false);
    }

    @Override
    public void k(PackageManager packageManager) {
        for (xi xiVar : this.x) {
            if (xiVar.X()) {
                M4(xiVar.o(packageManager, this));
            }
        }
        for (wo woVar : this.u.values()) {
            if (woVar.q()) {
                M4(woVar.i(packageManager, this));
            }
        }
        for (tn tnVar : this.v.values()) {
            if (tnVar.q()) {
                M4(tnVar.i(packageManager, this));
            }
        }
        for (dk dkVar : this.w.values()) {
            if (dkVar.q()) {
                M4(dkVar.i(packageManager, this));
            }
        }
    }

    public wo k2(String str) {
        for (wo woVar : this.u.values()) {
            if (woVar.u() && woVar.getName().equals(str)) {
                return woVar;
            }
        }
        return null;
    }

    public int k4(String str) {
        Iterator<xi> it = this.x.iterator();
        int i = 0;
        while (it.hasNext()) {
            if (it.next().getName().equals(str)) {
                return i;
            }
            i++;
        }
        return -1;
    }

    public boolean k5(Context context, File file, String str, int i, boolean z2) {
        File file2;
        jf.d a2 = jf.a.a(context, file);
        if (!a2.Z()) {
            a2.X(context, true);
        }
        boolean z3 = false;
        if (a2.Z()) {
            File file3 = new File(file, str);
            if (h4.c0(context, file3, true)) {
                File u = com.joaomgcd.taskerm.util.g8.u(context, str);
                u.getParentFile();
                file3 = u;
                file2 = file3;
            } else {
                file2 = null;
            }
            synchronized (z) {
                String D1 = D1(context, i, z2);
                boolean C3 = D1 == null ? false : dq.C3(D1, file3, false);
                if (file2 == null || !jf.a.a(context, file3).Z()) {
                    z3 = C3;
                } else {
                    try {
                        com.joaomgcd.taskerm.util.g8.e(context, file3, file2);
                        z3 = C3;
                    } catch (Exception e2) {
                        r7.l("TD", "writeSDAbsDir", e2);
                    }
                    com.joaomgcd.taskerm.util.g8.l(context, str);
                }
            }
        }
        return z3;
    }

    @Override
    public String l(int i) {
        if (T(i)) {
            return R(i).k();
        }
        return null;
    }

    public boolean l1(Context context, String str, String str2, boolean z2) {
        String f0 = com.joaomgcd.taskerm.util.g8.f0(com.joaomgcd.taskerm.util.g8.u(context, str2));
        if (f0 == null) {
            return false;
        }
        return z2 ? com.joaomgcd.taskerm.util.g8.l(context, str2) : o1(context, str, f0);
    }

    public to l2(wo woVar) {
        to toVar = new to();
        for (int i : woVar.R0()) {
            toVar.B0(R(i), -1);
        }
        toVar.v0(woVar, -1);
        return toVar;
    }

    public g5 l3(Context context, File file, int i) {
        Context applicationContext = context.getApplicationContext();
        g5 g5Var = new g5();
        to toVar = new to();
        if (!file.exists()) {
            r7.G("TD", "importSceneFromFile: path doesn't exist: " + file);
            g5Var.b = 2131887728;
        } else if (toVar.n4(applicationContext, file.getParentFile(), file.getName(), true, true)) {
            int d2 = toVar.d2();
            if (d2 == 0) {
                g5Var.b = 2131887809;
                g5Var.a = 2131891237;
            } else if (d2 == 1) {
                dk dkVar = toVar.a(-2, dk.i.User, true).get(0);
                String name = dkVar.getName();
                if (name == null) {
                    g5Var.b = 2131887810;
                    g5Var.a = 2131891237;
                } else if (p(name)) {
                    g5Var.b = 2131887808;
                    g5Var.d = name;
                } else {
                    LinkedList linkedList = new LinkedList();
                    HashMap hashMap = null;
                    for (Integer num : dkVar.L1(true)) {
                        int intValue = num.intValue();
                        if (!dk.C2(intValue)) {
                            if (toVar.T(intValue)) {
                                tn R = toVar.R(intValue);
                                r7.f("TD", "try task import: " + intValue);
                                g5 m3 = m3(R, i);
                                if (m3.a()) {
                                    r7.f("TD", "task err");
                                    g5Var.d(m3);
                                    Iterator it = linkedList.iterator();
                                    while (it.hasNext()) {
                                        g1(((Integer) it.next()).intValue());
                                    }
                                } else {
                                    int P0 = R.P0();
                                    if (P0 != intValue) {
                                        if (hashMap == null) {
                                            hashMap = new HashMap();
                                        }
                                        r7.f("TD", "remapped task ID: " + intValue + " -> " + P0);
                                        hashMap.put(num, Integer.valueOf(P0));
                                    }
                                    linkedList.add(Integer.valueOf(P0));
                                }
                            } else {
                                g5Var.b = 2131887889;
                            }
                        }
                    }
                    if (!g5Var.a()) {
                        if (hashMap != null) {
                            dkVar.a3(hashMap);
                        }
                        y0(dkVar, i);
                        g5Var.c = dkVar;
                    }
                }
            } else {
                g5Var.b = 2131887807;
                g5Var.a = 2131891237;
            }
        } else {
            g5Var.b = 2131887731;
        }
        return g5Var;
    }

    public boolean l4(Context context, String str) {
        boolean z2;
        qi qiVar;
        Context applicationContext = context.getApplicationContext();
        synchronized (z) {
            z2 = false;
            Q0(false, "readAsset");
            try {
                qiVar = new qi(applicationContext.getAssets().open(str));
            } catch (Exception e2) {
                r7.l("TD", "readAsset", e2);
                qiVar = null;
            }
            if (qiVar == null) {
                r7.k("TD", "readAsset: null packed object");
            } else if (qiVar.f()) {
                r7.k("TD", "readAsset: packed xml string error");
            } else {
                qiVar.b0(8);
                m1(applicationContext, qiVar, false);
                T0();
                z2 = true;
            }
        }
        return z2;
    }

    @Override
    public cl.c m(String str) {
        return z2(str).k1();
    }

    public boolean m1(Context context, qi qiVar, boolean z2) {
        return n1(context, qiVar, z2, false);
    }

    public String m2(wo woVar, Context context, boolean z2, pe.g gVar) {
        tn K2;
        Resources resources = context.getResources();
        StringBuilder sb = new StringBuilder();
        String name = woVar.u() ? woVar.getName() : vh.h(resources, 2131891124, new Object[0]);
        sb.append(vh.h(resources, 2131891221, new Object[0]));
        sb.append(": ");
        sb.append(name);
        woVar.a(context, sb);
        String B0 = woVar.B0();
        if (B0.length() > 0) {
            sb.append("\n");
            sb.append(resources.getString(2131891241));
            sb.append(": ");
            sb.append(B0);
        }
        kg.w0.A(sb, woVar);
        sb.append("\n");
        sb.append(woVar.v0(context, false, true, true));
        sb.append("\n\n");
        for (int i = 0; i < 2; i++) {
            if (woVar.c1(i) && (K2 = K2(woVar, i)) != null) {
                sb.append("\n\n");
                sb.append(O2(resources, K2, i));
                if (z2) {
                    sb.append(L2(resources, K2));
                }
            }
        }
        return woVar.w(context, sb.toString(), gVar);
    }

    public boolean m4(Context context, String str) {
        boolean z2;
        qi qiVar;
        Context applicationContext = context.getApplicationContext();
        synchronized (z) {
            z2 = false;
            Q0(false, "readDevice");
            try {
                qiVar = new qi(applicationContext.openFileInput(str));
            } catch (Exception e2) {
                r7.l("TD", "readDevice", e2);
                qiVar = null;
            }
            if (qiVar == null) {
                r7.k("TD", "readDevice: null packed object");
            } else if (qiVar.f()) {
                r7.k("TD", "readDevice: packed xml string error");
            } else {
                r7.f("TD", "readDevice");
                m1(applicationContext, qiVar, false);
                T0();
                z2 = true;
            }
        }
        return z2;
    }

    @Override
    public int n(String str) {
        if (Z(str)) {
            return N(str).P0();
        }
        return -1;
    }

    public boolean n1(Context context, final qi qiVar, final boolean z2, final boolean z3) {
        final Context applicationContext = context.getApplicationContext();
        return ((Boolean) TaskerApp.q("unpack Tasker Data", new xj.a() {
            @Override
            public final Object invoke() {
                Boolean C3;
                C3 = to.this.C3(qiVar, z2, applicationContext, z3);
                return C3;
            }
        })).booleanValue();
    }

    public Set<Integer> n2() {
        return this.u.keySet();
    }

    public boolean n4(Context context, File file, String str, boolean z2, boolean z3) {
        return o4(context, file, str, z2, z3, false);
    }

    @Override
    public List<String> o(String str, int i) {
        return this.w.get(str).G1(i);
    }

    public boolean o1(Context context, String str, String str2) {
        return p1(context, str, str2, false);
    }

    public List<Integer> o2(int i) {
        if (i < this.x.size() && i >= 0) {
            return this.x.get(i).v();
        }
        r7.G("TD", "getPIDSInProject: bad index: " + i + " size " + this.x.size());
        return new ArrayList();
    }

    public g5 o3(Context context, File file, int i) {
        g5 g5Var = new g5();
        String X = dq.X(file);
        if (X != null) {
            return p3(context, X, i, false);
        }
        g5Var.b = 2131887732;
        return g5Var;
    }

    public boolean o4(Context context, File file, String str, boolean z2, boolean z3, boolean z4) {
        boolean z5;
        Context applicationContext = context.getApplicationContext();
        synchronized (z) {
            boolean z6 = true;
            z5 = false;
            try {
                if (file == null) {
                    r7.k("TD", "readSD: null dir");
                    if (!z2) {
                    }
                    z6 = false;
                } else {
                    jf.d a2 = jf.a.a(applicationContext, new File(file, str));
                    if (a2.Z()) {
                        Q0(true, "readSD");
                        K4();
                        qi qiVar = new qi(a2);
                        if (qiVar.f()) {
                            r7.k("TD", "readSD: packed xml string error");
                        } else {
                            try {
                                try {
                                    qiVar.b0(8);
                                    n1(applicationContext, qiVar, z3, z4);
                                } finally {
                                    S0();
                                }
                            } catch (Exception e2) {
                                r7.l("TD", "readSD", e2);
                                S0();
                            }
                        }
                        z6 = false;
                    } else if (z2) {
                        r7.k("TD", "readSD: file doesn't exist: " + a2);
                        z6 = false;
                    }
                }
                z5 = z6;
            } catch (Exception e3) {
                r7.l("TD", "readSD: failed:", e3);
            } finally {
            }
        }
        return z5;
    }

    @Override
    public boolean p(String str) {
        return this.w.containsKey(str);
    }

    public boolean p1(Context context, String str, String str2, boolean z2) {
        return q1(context, str, str2, z2, false);
    }

    public List<wo> p2(String str) {
        LinkedList linkedList = null;
        for (wo woVar : this.u.values()) {
            if (woVar.u() && woVar.getName().equals(str)) {
                if (linkedList == null) {
                    linkedList = new LinkedList();
                }
                linkedList.add(woVar);
            }
        }
        return linkedList;
    }

    public g5 p3(Context context, String str, int i, boolean z2) {
        tn tnVar;
        g5 g5Var = new g5();
        Context applicationContext = context.getApplicationContext();
        qi qiVar = new qi(str);
        if (qiVar.f()) {
            g5Var.b = 2131887730;
            return g5Var;
        }
        String u = qiVar.u();
        tn tnVar2 = null;
        if (u == null) {
            r7.G("TD", "no object class");
            g5Var.b = 2131887730;
        } else if (u.equals("Task")) {
            try {
                tnVar = new tn(qiVar);
            } catch (Exception e2) {
                e = e2;
            }
            try {
                if (tnVar.M1()) {
                    tnVar.p0(this);
                }
                tnVar2 = tnVar;
            } catch (Exception e3) {
                e = e3;
                tnVar2 = tnVar;
                r7.k("TD", e.toString());
                r7.l("TD", "importTaskFromFile", e);
                if (g5Var.a()) {
                }
                g5Var.b = 2131887731;
                return g5Var;
            }
        } else if (qiVar.u().equals("TaskerData")) {
            to toVar = new to();
            qiVar.b0(8);
            toVar.m1(applicationContext, qiVar, true);
            int e22 = toVar.e2();
            if (e22 == 0) {
                g5Var.b = 2131887809;
                g5Var.a = 2131891257;
            } else if (e22 == 1) {
                tnVar2 = toVar.R(toVar.Q1().iterator().next().intValue());
            } else {
                g5Var.b = 2131887807;
                g5Var.a = 2131891257;
            }
        } else {
            g5Var.b = 2131887731;
        }
        if (!g5Var.a() || tnVar2 == null) {
            g5Var.b = 2131887731;
            return g5Var;
        }
        if (tnVar2.u()) {
            return n3(tnVar2, i, z2);
        }
        g5Var.b = 2131887810;
        g5Var.a = 2131891257;
        return g5Var;
    }

    public void p4() {
        this.r.clear();
        Iterator<tn> it = this.v.values().iterator();
        while (it.hasNext()) {
            C0(it.next(), this.r);
        }
        Iterator<dk> it2 = this.w.values().iterator();
        while (it2.hasNext()) {
            Iterator<hk> it3 = it2.next().f1(hk.k.LIST).iterator();
            while (it3.hasNext()) {
                for (k7 k7Var : it3.next().t0().s4()) {
                    if (k7Var.l()) {
                        this.r.add(Integer.valueOf(k7Var.d().j()));
                    }
                }
            }
        }
    }

    @Override
    public ArrayList<tn> q(int i, boolean z2) {
        Collection<Integer> K;
        ArrayList<tn> arrayList = new ArrayList<>();
        if (i == -2) {
            K = this.q.values();
        } else {
            if (i >= this.x.size()) {
                r7.k("TD", "getNamedTasks: bad project index: " + i + " num " + this.x.size());
                return arrayList;
            }
            K = this.x.get(i).K();
        }
        for (Integer num : K) {
            num.intValue();
            tn tnVar = this.v.get(num);
            if (tnVar != null && tnVar.u() && (z2 || !tnVar.q())) {
                arrayList.add(tnVar);
            }
        }
        return arrayList;
    }

    public boolean q1(Context context, String str, String str2, boolean z2, boolean z3) {
        Q0(true, "fromXMLString");
        qi qiVar = new qi(str2);
        if (!qiVar.f()) {
            n1(context, qiVar, z3, z2);
            return true;
        }
        r7.k("TD", "fromXMLString: " + str + ": packed xml string error");
        return false;
    }

    public List<wo> q2(int i) {
        ArrayList arrayList = new ArrayList();
        if (i == -2) {
            for (wo woVar : this.u.values()) {
                if (woVar != null) {
                    arrayList.add(woVar);
                }
            }
        } else {
            Iterator<Integer> it = o2(i).iterator();
            while (it.hasNext()) {
                wo c2 = c(it.next().intValue());
                if (c2 != null) {
                    arrayList.add(c2);
                }
            }
        }
        return arrayList;
    }

    public boolean q3(int i) {
        return this.r.contains(Integer.valueOf(i));
    }

    public void q4(boolean z2) {
        Collection<wo> values;
        this.r.clear();
        Map<Integer, wo> map = this.u;
        if (map != null && (values = map.values()) != null) {
            for (wo woVar : values) {
                if (z2 || woVar.h1()) {
                    for (int i : woVar.R0()) {
                        tn R = R(i);
                        if (R == null) {
                            r7.G("TD", "rpla: unknown task ID " + i);
                        } else {
                            C0(R, this.r);
                        }
                    }
                }
            }
        }
        r7.f("TD", "recalcPLAS done");
    }

    @Override
    public ArrayList<String> r() {
        ArrayList<wo> j = j();
        ArrayList<String> arrayList = new ArrayList<>();
        Iterator<wo> it = j.iterator();
        while (it.hasNext()) {
            arrayList.add(it.next().getName());
        }
        return arrayList;
    }

    public void r0(c2 c2Var, int i) {
        int i2 = f.b[c2Var.f().ordinal()];
        if (i2 == 1) {
            v0((wo) c2Var, i);
            return;
        }
        if (i2 == 2) {
            B0((tn) c2Var, i);
            return;
        }
        if (i2 == 3) {
            y0((dk) c2Var, i);
            return;
        }
        r7.k("TD", "addEntity: bad type: " + c2Var.f());
    }

    public int r2(int i) {
        return d0(i).size();
    }

    public boolean r3(int... iArr) {
        for (int i : iArr) {
            if (q3(i)) {
                return true;
            }
        }
        return false;
    }

    public to r4(Context context) {
        to toVar = new to();
        toVar.m1(context, U(0), false);
        L4(toVar.s);
        T4(toVar.t);
        J4(toVar.r);
        return this;
    }

    @Override
    public String s(int i) {
        wo woVar = this.u.get(Integer.valueOf(i));
        if (woVar != null) {
            return woVar.getName();
        }
        return null;
    }

    public void s0(Context context, Set<String> set) {
        List<net.dinglisch.android.taskerm.c> t1 = t1(365, true);
        if (t1.size() == 0) {
            return;
        }
        Iterator<net.dinglisch.android.taskerm.c> it = t1.iterator();
        while (it.hasNext()) {
            String[] O = com.joaomgcd.taskerm.action.tasker.c.O(context, it.next());
            if (O != null) {
                set.addAll(Arrays.asList(O));
            }
        }
    }

    public Set<Integer> s1() {
        return this.r;
    }

    public xi s2(int i, String str) {
        if (i < this.x.size()) {
            return this.x.get(i);
        }
        r7.G("TD", "getProject: " + str + ": bad index " + i + " size: " + this.x.size());
        return null;
    }

    public boolean s3(int i) {
        return this.s.contains(Integer.valueOf(i));
    }

    public void t0(PackageManager packageManager, c2 c2Var, Set<Integer> set) {
        int e2;
        if (c2Var != null) {
            for (yj yjVar : c2Var.h(packageManager)) {
                if (yjVar.f() == yj.b.Task && (e2 = yjVar.e(this)) != -1) {
                    set.add(Integer.valueOf(e2));
                }
            }
        }
    }

    public List<net.dinglisch.android.taskerm.c> t1(int i, boolean z2) {
        ArrayList arrayList = new ArrayList();
        if (!z2 || q3(i)) {
            Iterator<tn> it = P2(-2).iterator();
            while (it.hasNext()) {
                for (net.dinglisch.android.taskerm.c cVar : it.next().D0()) {
                    if (cVar.j() == i) {
                        arrayList.add(cVar);
                    }
                }
            }
        }
        return arrayList;
    }

    public xi t2(String str) {
        for (xi xiVar : this.x) {
            if (xiVar.getName().equals(str)) {
                return xiVar;
            }
        }
        return null;
    }

    public void t3(Context context, boolean z2) {
        if (c2() == 0) {
            V4(context);
        } else {
            if (!z2 || L0(true)) {
                return;
            }
            r7.G("TD", "initProjects: project integrity failure");
        }
    }

    public void t4() {
        HashSet hashSet = new HashSet();
        Iterator<wo> it = this.u.values().iterator();
        while (true) {
            if (!it.hasNext()) {
                break;
            }
            for (int i : it.next().R0()) {
                tn R = R(i);
                if (R != null && !R.u()) {
                    hashSet.add(Integer.valueOf(i));
                }
            }
        }
        Iterator<dk> it2 = this.w.values().iterator();
        while (it2.hasNext()) {
            for (Integer num : it2.next().L1(false)) {
                tn R2 = R(num.intValue());
                if (R2 != null && !R2.u()) {
                    hashSet.add(num);
                }
            }
        }
        ArrayList arrayList = null;
        for (tn tnVar : this.v.values()) {
            if (!tnVar.u() && !hashSet.contains(Integer.valueOf(tnVar.P0()))) {
                if (arrayList == null) {
                    arrayList = new ArrayList();
                }
                arrayList.add(Integer.valueOf(tnVar.P0()));
            }
        }
        if (arrayList != null) {
            Iterator it3 = arrayList.iterator();
            while (it3.hasNext()) {
                int intValue = ((Integer) it3.next()).intValue();
                r7.f("TD", "removing orphan anonymous task " + intValue);
                g1(intValue);
            }
        }
    }

    public int u2(int i) {
        return this.x.get(i).k();
    }

    public boolean u3() {
        return this.i;
    }

    public void u4(int i, int i2) {
        if (i >= 0) {
            this.x.get(i).c0(i2);
            K4();
        }
    }

    @Override
    public ArrayList<String> v() {
        return I2(-2, tn.f.Alpha);
    }

    public void v0(wo woVar, int i) {
        xi xiVar;
        if (woVar == null) {
            r7.k("TD", "addProfile: called with null profile, project " + i);
            return;
        }
        int C0 = woVar.C0();
        this.u.put(Integer.valueOf(C0), woVar);
        if (i >= 0 && this.x.size() > 0) {
            try {
                xiVar = this.x.get(i);
            } catch (Throwable unused) {
                xiVar = null;
            }
            if (xiVar == null) {
                r7.k("TD", "addProfile: null project index " + i + " no projects " + c2());
            } else {
                xiVar.c(C0);
            }
        }
        K4();
    }

    public to v2(PackageManager packageManager, xi xiVar) {
        to toVar = new to();
        xi xiVar2 = new xi(xiVar.U(2));
        xiVar2.f();
        toVar.x0(xiVar2);
        for (yj yjVar : xiVar.o(packageManager, this)) {
            if (yjVar.i() && i(yjVar)) {
                toVar.r0(N1(yjVar), 0);
                if (yjVar.f() == yj.b.Task && yjVar.j()) {
                    toVar.D0(yjVar.b(), 0);
                }
            }
        }
        return toVar;
    }

    public void v4(int i, String str) {
        if (i >= 0) {
            this.x.get(i).d0(str);
            K4();
        }
    }

    @Override
    public xi w(int i) {
        return this.x.get(i);
    }

    public void w0(int i, int i2) {
        if (i2 >= 0) {
            this.x.get(i2).c(i);
            K4();
        }
    }

    public ArrayList<tn> w1() {
        return K(-2, tn.f.Alpha);
    }

    public Integer w2(String str) {
        Iterator<xi> it = this.x.iterator();
        int i = 0;
        while (it.hasNext()) {
            if (it.next().getName().equals(str)) {
                return Integer.valueOf(i);
            }
            i++;
        }
        return null;
    }

    @Override
    public void x(Context context, int i, HashMap<String, String> hashMap) {
        for (tn tnVar : this.v.values()) {
            if (tnVar.P0() != i) {
                tnVar.e0(context, -1, false, hashMap);
            }
        }
    }

    public void x0(xi xiVar) {
        this.x.add(xiVar);
        K4();
    }

    public String x1(Context context, i5 i5Var, int i) {
        if (i5Var instanceof tn) {
            return z1(context, (tn) i5Var, i);
        }
        if (i5Var instanceof wo) {
            return B1(context, (wo) i5Var, i);
        }
        if (i5Var instanceof xi) {
            return y1(context, (xi) i5Var, i);
        }
        throw new RuntimeException("Can't get URL of " + i5Var.getClass().getName());
    }

    public final List<xi> x2() {
        return this.x;
    }

    public void x4(int i, int i2) {
        if (i >= 0) {
            this.x.get(i).e0(i2);
            K4();
        }
    }

    @Override
    public void y(Context context, int i, int i2, Collection<String> collection) {
        List<Integer> linkedList;
        if (i == -1 || B3(i)) {
            linkedList = new LinkedList<>();
            Iterator<wo> it = q2(i2).iterator();
            while (true) {
                if (!it.hasNext()) {
                    break;
                }
                wo next = it.next();
                if (next.P0() == 0) {
                    linkedList.add(Integer.valueOf(next.C0()));
                    break;
                }
            }
        } else {
            linkedList = d0(i);
        }
        Iterator<Integer> it2 = linkedList.iterator();
        while (it2.hasNext()) {
            wo c2 = c(it2.next().intValue());
            if (c2 != null) {
                com.joaomgcd.taskerm.util.x2.r(this, context, collection, c2, null);
                for (int i3 = 4; i3 < 6; i3++) {
                    if (c2.Z0(i3)) {
                        pn pnVar = (pn) c2.T0(i3);
                        pnVar.j();
                        vg.e v1 = pnVar.v1();
                        if (on.O(pnVar.j()) || v1 != null) {
                            M0(ri.c.Condition, pnVar.j(), pnVar.a(0).x(), collection, v1 != null ? v1.m() : null, null);
                        }
                    }
                }
                if (c2.Z0(7)) {
                    k2 k2Var = (k2) c2.T0(7);
                    int j = k2Var.j();
                    ze.b e1 = k2Var.e1();
                    if (j2.X(j) || e1 != null) {
                        M0(ri.c.Event, j, k2Var.a(0).x(), collection, e1 != null ? e1.m() : null, null);
                    } else {
                        com.joaomgcd.taskerm.inputoutput.a R1 = com.joaomgcd.taskerm.util.x2.R1(k2Var, context);
                        R1.add((com.joaomgcd.taskerm.inputoutput.a) new uf.e(null, "evtprm", com.joaomgcd.taskerm.util.x2.Q4(2131887746, context, new Object[0]), com.joaomgcd.taskerm.util.x2.Q4(2131887747, context, new Object[0]), true));
                        Iterator<TTaskerVariable> it3 = R1.iterator();
                        while (it3.hasNext()) {
                            collection.add(ri.h(ri.c.Event, k2Var.K(), ((uf.e) it3.next()).toString(), null));
                        }
                    }
                }
            }
        }
    }

    public void y0(dk dkVar, int i) {
        this.w.put(dkVar.getName(), dkVar);
        if (i >= 0) {
            this.x.get(i).d(dkVar.getName());
        }
        K4();
    }

    public HashMap<String, String> y2(PackageManager packageManager, boolean z2) {
        HashMap<String, String> hashMap = new HashMap<>();
        Iterator<tn> it = this.v.values().iterator();
        while (it.hasNext()) {
            for (b5 b5Var : it.next().D0()) {
                if (a1.f1(b5Var.j())) {
                    u0(b5Var, ri.c.Action, 1, 2, hashMap, z2);
                }
            }
        }
        for (wo woVar : this.u.values()) {
            for (int i = 0; i < woVar.I0(); i++) {
                ho S0 = woVar.S0(i);
                int B0 = S0.B0();
                if (B0 >= 4 && B0 <= 6) {
                    b5 b5Var2 = (pn) S0;
                    if (on.O(b5Var2.j())) {
                        u0(b5Var2, ri.c.Condition, 1, 2, hashMap, z2);
                    }
                } else if (B0 == 7) {
                    b5 b5Var3 = (k2) S0;
                    if (j2.X(b5Var3.j())) {
                        u0(b5Var3, ri.c.Event, 1, 2, hashMap, z2);
                    }
                }
            }
        }
        return hashMap;
    }

    @Override
    public String z(int i) {
        return this.x.get(i).getName();
    }

    public void z0(String str, int i) {
        if (i >= 0) {
            this.x.get(i).d(str);
            K4();
        }
    }

    public dk z2(String str) {
        return this.w.get(str);
    }
}