ComeetChat v1.866866806590版本的 MD5 值为:4a7461802cd62adce19de75377dd7ca7

以下内容为反编译后的 fy.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.backup.GenericActionBackupToGoogleDriveWhenConnectedAndCharging;
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.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import net.danlew.android.joda.R;
import net.dinglisch.android.taskerm.ai;
import net.dinglisch.android.taskerm.bh;
import net.dinglisch.android.taskerm.dh;
import net.dinglisch.android.taskerm.di;
import net.dinglisch.android.taskerm.dr;
import net.dinglisch.android.taskerm.dt;
import net.dinglisch.android.taskerm.du;
import net.dinglisch.android.taskerm.ek;
import net.dinglisch.android.taskerm.ft;
import net.dinglisch.android.taskerm.gb;

public class fy implements dg, fz {
    private boolean g = false;
    private Map<String, Integer> h = new HashMap();
    private Set<Integer> i = new HashSet();
    private Set<Integer> j = new HashSet();
    private Set<Integer> k = new HashSet();
    private Map<Integer, gb> l = new ConcurrentHashMap();
    private Map<Integer, ft> m = new ConcurrentHashMap();
    private Map<String, dt> n = new HashMap();
    private List<dm> o = new ArrayList();

    private static final Object f13382b = new Object();

    private static final int[] f13383c = {4, 5, 6, 7, 1};

    public static Object[] f13381a = {new Object(), new Object()};

    private static fy[] f13384d = new fy[a.values().length];

    private static int f13385e = -2;

    private static int f13386f = 1;

    public enum a {
        Active,
        Passive
    }

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

    public static int b() {
        return 1;
    }

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

    public static fy a(Context context) {
        fy fyVar = new fy();
        fyVar.a(new dm(dm.a(context)));
        return fyVar;
    }

    public static final fz b(Context context) {
        return d(context);
    }

    public static final fz c(Context context) {
        return e(context);
    }

    public static final fy a(Context context, boolean z) {
        return a(a.Passive, context, z);
    }

    public static final fy d(Context context) {
        return a(a.Passive, context, true);
    }

    public static final fy e(Context context) {
        return a(a.Active, context, true);
    }

    public static final boolean c() {
        return a(a.Passive);
    }

    public static final boolean a(a aVar) {
        boolean z;
        int ordinal = aVar.ordinal();
        synchronized (f13381a[ordinal]) {
            StringBuilder sb = new StringBuilder();
            sb.append("data: haveStatic: ");
            sb.append(aVar);
            sb.append(" ");
            sb.append(f13384d[ordinal] != null);
            bo.b("TD", sb.toString());
            z = f13384d[ordinal] != null;
        }
        return z;
    }

    public static final fy a(a aVar, Context context, boolean z) {
        fy fyVar;
        Context applicationContext = context.getApplicationContext();
        int ordinal = aVar.ordinal();
        String name = Thread.currentThread().getName();
        synchronized (f13381a[ordinal]) {
            bo.b("TD", "getStatic: " + aVar + " load: " + z + " - " + name);
            if (f13384d[ordinal] == null && z) {
                bo.b("TD", "getStatic: new data on thread " + name);
                f13384d[ordinal] = new fy();
                if (Kid.a(applicationContext)) {
                    if (!f13384d[ordinal].a(applicationContext, "kid/data.xml")) {
                        bo.b("TD", "getStatic: kid/data.xml: load failed, return null");
                        f13384d[ordinal] = null;
                    }
                } else if (gs.b(applicationContext, "autobackup.xml")) {
                    bo.b("TD", "data: getStatic: null, file exists, load from file - " + name);
                    if (!f13384d[ordinal].b(applicationContext, "autobackup.xml")) {
                        bo.b("TD", "getStatic: load failed, return null - " + name);
                        f13384d[ordinal] = null;
                    } else {
                        bo.b("TD", "getStatic: load success! - " + name);
                    }
                } else {
                    bo.b("TD", "data: getStatic: null: no file, return new data - " + name);
                }
            }
            fyVar = f13384d[ordinal];
        }
        return fyVar;
    }

    public static void a(a aVar, fy fyVar) {
        int ordinal = aVar.ordinal();
        synchronized (f13381a[ordinal]) {
            bo.b("TD", "data: setStatic: " + aVar);
            f13384d[ordinal] = fyVar;
        }
    }

    public static void a(a aVar, boolean z) {
        int ordinal = aVar.ordinal();
        synchronized (f13381a[ordinal]) {
            bo.b("TD", "data: removeStatic: " + aVar);
            f13384d[ordinal] = null;
            if (z) {
                System.gc();
            }
        }
    }

    public static ft d() {
        return H(W());
    }

    private static ft H(int i) {
        return new ft(i);
    }

    private static synchronized int W() {
        int i;
        synchronized (fy.class) {
            f13385e--;
            i = f13385e + 1;
        }
        return i;
    }

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

    private static void X() {
        fq.b("!(%)(DJJJ!!");
    }

    public static File a(String str) {
        File a2 = dk.a();
        if (a2 == null) {
            bo.b("TD", "not writing capabilities, no storage dir");
        } else {
            File file = new File(a2, str);
            StringBuilder sb = new StringBuilder();
            sb.append("<");
            sb.append("capabilities");
            sb.append(">\n");
            fo.a(sb);
            an.a(sb);
            n.a(sb);
            sb.append("</");
            sb.append("capabilities");
            sb.append(">");
            if (gs.a(sb.toString(), file, false)) {
                return file;
            }
        }
        return null;
    }

    public static File a(Resources resources, String str, boolean z) {
        File a2 = dk.a();
        if (a2 == null) {
            bo.b("TD", "not writing data def, no storage dir");
            return null;
        }
        File file = new File(a2, str);
        bo.b("TD", "write data def: " + file);
        if (!file.exists() || z) {
            StringBuilder sb = new StringBuilder();
            sb.append("<");
            sb.append("datadef");
            sb.append(">\n");
            dh.a(sb);
            fo.a(resources, false, sb);
            an.a(resources, sb);
            n.a(resources, false, sb);
            sb.append("</");
            sb.append("datadef");
            sb.append(">");
            if (gs.a(sb.toString(), file, false)) {
                return file;
            }
            return null;
        }
        bo.b("TD", "skip, exists");
        return null;
    }

    public static File a(PackageManager packageManager, SharedPreferences sharedPreferences, Resources resources, String str) {
        int i = sharedPreferences.getInt("lph", 0);
        if (i > 0) {
            File b2 = b(true);
            bo.b("TD", "auto-backups required (index period " + i + "), prepare dir");
            if (b2 == null) {
                bo.d("TD", "failed to write auto-backup data, no storage");
            } else {
                a(resources, i);
                File file = new File(b2, str);
                if (gs.e(file)) {
                    bo.b("TD", "created backup dir " + file);
                    return file;
                }
            }
        }
        return null;
    }

    public static void a(Resources resources, int i) {
        Map<Long, File> f2 = f();
        long j = i == 0 ? -1L : resources.getIntArray(R.array.update_check_secs)[i] * 1000;
        long currentTimeMillis = System.currentTimeMillis();
        for (Map.Entry<Long, File> entry : f2.entrySet()) {
            File value = entry.getValue();
            long longValue = currentTimeMillis - entry.getKey().longValue();
            if (longValue > j) {
                bo.b("TD", "delete backup " + value.getName() + " age " + longValue + " max " + j);
                gs.h(value);
            }
        }
    }

    public static Map<Long, File> f() {
        File b2 = b(false);
        HashMap hashMap = new HashMap();
        if (b2 != null) {
            String[] list = b2.list();
            if (!gs.a((Object[]) 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(b2, str));
                        } catch (Exception e2) {
                            bo.a("TD", "failed to parse " + str, (Throwable) e2);
                        }
                    } else {
                        bo.b("TD", "skipping bad-format backup dir " + str);
                    }
                }
            }
        }
        return hashMap;
    }

    public static String a(long j, long j2) {
        if (j == -1) {
            j = System.currentTimeMillis();
        }
        Calendar c2 = cb.c(j);
        String c3 = cb.c(c2);
        String a2 = cb.a(c2, true);
        Calendar c4 = cb.c(j2);
        return c3 + "." + a2 + "-" + cb.c(c4) + "." + cb.a(c4, true);
    }

    public static File a(boolean z) {
        return gs.c(bh.f12208e, z);
    }

    public static File b(boolean z) {
        return gs.c(bh.f12207d, z);
    }

    public static File c(boolean z) {
        return gs.c("configs", z);
    }

    public static void g() {
        File a2;
        File k = gs.k();
        if (k != null) {
            File file = new File(k, "userbackup.xml");
            if (file.isFile() && (a2 = a(true)) != null) {
                file.renameTo(new File(a2, "backup.xml"));
            }
            File file2 = new File(k, "autobackups");
            if (file2.isDirectory()) {
                File c2 = c(true);
                File file3 = new File(c2, "auto");
                if (file3.exists() || c2 == null || !c2.isDirectory()) {
                    return;
                }
                if (file2.renameTo(file3)) {
                    bo.b("TD", file2.toString() + " -> " + file3.toString());
                    return;
                }
                bo.d("TD", "failed: " + file2.toString() + " -> " + file3.toString());
            }
        }
    }

    public static void a(ft ftVar, Set<Integer> set) {
        if (ftVar.z()) {
            set.add(Integer.valueOf(ftVar.f().x()));
        }
        for (c cVar : ftVar.A()) {
            a(cVar, cVar.i(), set);
        }
    }

    private static void a(av avVar, int i, Set<Integer> set) {
        for (int i2 = 0; i2 < avVar.h(); i2++) {
            if (avVar.m(i2) == 4) {
                set.add(Integer.valueOf(avVar.e(i2).x()));
            } else if (i != -1 && avVar.m(i2) == 1 && n.f(i, i2) == "col") {
                j j = avVar.j(i2);
                if (j.g()) {
                    String c2 = j.c();
                    if (cd.a(c2)) {
                        set.add(Integer.valueOf(cd.c(c2)));
                    }
                }
            }
        }
    }

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

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

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

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

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

    public static az a(Context context, Bundle bundle) {
        if (bundle == null) {
            return null;
        }
        dh dhVar = new dh(bundle);
        if (dhVar.m("Task")) {
            return new ft(dhVar);
        }
        if (dhVar.m("Profile")) {
            return new gb(context, dhVar, -1);
        }
        if (dhVar.m("Project")) {
            return new dm(dhVar);
        }
        return null;
    }

    public void g(String str) {
        a(true, "sub: " + str);
    }

    @Override
    public ArrayList<String> h() {
        ArrayList<String> arrayList = new ArrayList<>();
        for (gb gbVar : this.l.values()) {
            if (gbVar.n()) {
                arrayList.add(gbVar.m());
            }
        }
        Collections.sort(arrayList);
        return arrayList;
    }

    @Override
    public boolean c(int i) {
        gb k = k(i);
        if (k == null) {
            return false;
        }
        boolean h = k.h();
        return !h ? z(t(i)).A() : h;
    }

    public void i() {
        for (gb gbVar : this.l.values()) {
            if (gbVar.h() || gbVar.g()) {
                gbVar.ab();
            }
        }
    }

    @Override
    public List<Integer> h(String str) {
        LinkedList linkedList = new LinkedList();
        for (gb gbVar : this.l.values()) {
            if (gbVar.n() && gbVar.m().equals(str)) {
                linkedList.add(Integer.valueOf(gbVar.K()));
            }
        }
        return linkedList;
    }

    public void d(int i) {
        for (gb gbVar : B(i)) {
            if (gbVar != null && !gbVar.P()) {
                gbVar.ab();
                t();
            }
        }
    }

    public boolean j() {
        for (ft ftVar : this.m.values()) {
            if (ftVar.n() && ftVar.h()) {
                return true;
            }
        }
        Iterator<gb> it = this.l.values().iterator();
        while (true) {
            if (!it.hasNext()) {
                return false;
            }
            gb next = it.next();
            if (next.h()) {
                for (int i : next.ac()) {
                    if (j(i).n()) {
                        return true;
                    }
                }
            }
        }
    }

    @Override
    public ft i(String str) {
        Integer num = this.h.get(str);
        if (num != null) {
            return this.m.get(num);
        }
        return null;
    }

    public Set<Integer> k() {
        return this.i;
    }

    public void l() {
        this.i.clear();
        Iterator<ft> it = this.m.values().iterator();
        while (it.hasNext()) {
            b(it.next(), this.i);
        }
        Iterator<dt> it2 = this.n.values().iterator();
        while (it2.hasNext()) {
            Iterator<du> it3 = it2.next().c(du.e.LIST).iterator();
            while (it3.hasNext()) {
                for (bm bmVar : it3.next().an().aF()) {
                    if (bmVar.f()) {
                        this.i.add(Integer.valueOf(bmVar.k().i()));
                    }
                }
            }
        }
    }

    public void d(boolean z) {
        Collection<gb> values;
        this.i.clear();
        if (this.l != null && (values = this.l.values()) != null) {
            for (gb gbVar : values) {
                if (z || gbVar.S()) {
                    for (int i : gbVar.ac()) {
                        ft j = j(i);
                        if (j == null) {
                            bo.d("TD", "rpla: unknown task ID " + i);
                        } else {
                            b(j, this.i);
                        }
                    }
                }
            }
        }
        bo.b("TD", "recalcPLAS done");
    }

    private void b(ft ftVar, Set<Integer> set) {
        for (c cVar : ftVar.A()) {
            set.add(Integer.valueOf(cVar.i()));
            if (cVar.v()) {
                for (bm bmVar : cVar.w()) {
                    if (bmVar.f()) {
                        set.add(Integer.valueOf(bmVar.k().i()));
                    }
                }
            }
        }
    }

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

    public boolean f(int i) {
        return this.j.contains(Integer.valueOf(i));
    }

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

    public boolean g(int i) {
        return this.j.contains(Integer.valueOf(i));
    }

    public void a(Set<Integer> set) {
        this.j = set;
    }

    public void b(Set<Integer> set) {
        this.k = set;
    }

    public void c(Set<Integer> set) {
        this.i = set;
    }

    public boolean h(int i) {
        return this.k.contains(Integer.valueOf(i));
    }

    @Override
    public boolean a(int i, int i2, String str) {
        for (c cVar : a(i, false)) {
            if (cVar.h() > i2 && cVar.m(i2) == 1 && cVar.j(i2).c().equals(str)) {
                return true;
            }
        }
        return false;
    }

    public List<c> a(int i, boolean z) {
        ArrayList arrayList = new ArrayList();
        if (!z || e(i)) {
            Iterator<ft> it = r(-2).iterator();
            while (it.hasNext()) {
                for (c cVar : it.next().A()) {
                    if (cVar.i() == i) {
                        arrayList.add(cVar);
                    }
                }
            }
        }
        return arrayList;
    }

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

    @Override
    public Set<String> a(Context context, PackageManager packageManager, int i, boolean z, boolean z2) {
        int i2;
        int i3;
        int i4;
        HashSet hashSet = new HashSet();
        Iterator<ft> it = r(i).iterator();
        while (it.hasNext()) {
            ft next = it.next();
            if (next != null) {
                next.a(context, false, hashSet, false, z, false, z2);
            }
        }
        Iterator<dt> it2 = b(i, true).iterator();
        while (it2.hasNext()) {
            dt next2 = it2.next();
            if (next2 != null) {
                next2.a(false, (Set<String>) hashSet, false, z);
                Iterator<Integer> it3 = next2.e(false).iterator();
                while (it3.hasNext()) {
                    int intValue = it3.next().intValue();
                    if (i(intValue)) {
                        j(intValue).a(context, false, hashSet, false, z, false, z2);
                    } else {
                        bo.d("TD", "scanForProjectVariables: scene references unknown task " + intValue);
                    }
                }
            }
        }
        for (gb gbVar : B(i)) {
            int[] iArr = f13383c;
            int length = iArr.length;
            int i5 = 0;
            while (i5 < length) {
                int i6 = iArr[i5];
                if (gbVar.j(i6)) {
                    if (i6 == 1) {
                        ((gh) gbVar.l(i6)).a((Set<String>) hashSet, false, z);
                    } else {
                        i4 = i5;
                        gx.a((av) gbVar.l(i6), false, (Set<String>) hashSet, false, z, false, z2);
                        i5 = i4 + 1;
                    }
                }
                i4 = i5;
                i5 = i4 + 1;
            }
            int[] ac = gbVar.ac();
            int length2 = ac.length;
            int i7 = 0;
            while (i7 < length2) {
                int i8 = ac[i7];
                ft j = j(i8);
                if (j == null) {
                    bo.c("TD", "varscan: profile: " + gbVar.K() + ": bad task ID: " + i8);
                    i2 = i7;
                    i3 = length2;
                } else {
                    i2 = i7;
                    i3 = length2;
                    j.a(context, false, hashSet, false, z, false, z2);
                }
                i7 = i2 + 1;
                length2 = i3;
            }
        }
        return hashSet;
    }

    @Override
    public void a(Context context, Collection<String> collection, int i, Integer num) {
        dm dmVar;
        com.joaomgcd.taskerm.profile.k b2;
        if (i < 0) {
            return;
        }
        try {
            dmVar = z(i);
        } catch (Throwable unused) {
            dmVar = null;
        }
        if (dmVar == null || (b2 = dmVar.b()) == null) {
            return;
        }
        String a2 = ct.a(context, R.string.word_project, new Object[0]);
        if (num != null) {
            a2 = a2 + " (" + ct.a(context, num.intValue(), new Object[0]) + ")";
        }
        b2.a(context, collection, a2);
    }

    public Set<String> a(Context context, Set<String> set, boolean z, boolean z2) {
        return a(context, set, z, z2, false);
    }

    public Set<String> a(Context context, Set<String> set, boolean z, boolean z2, boolean z3) {
        int i;
        int i2;
        int[] iArr;
        int l;
        Set<Integer> hashSet = new HashSet<>();
        HashSet hashSet2 = new HashSet();
        PackageManager packageManager = context.getPackageManager();
        Set<String> hashSet3 = !z ? new HashSet<>() : null;
        boolean z4 = false;
        if (Kid.a(context) && (l = z(0).C().l()) != -1) {
            hashSet.add(Integer.valueOf(l));
        }
        Iterator<ft> it = this.m.values().iterator();
        while (it.hasNext()) {
            for (c cVar : it.next().A()) {
                if (n.N(cVar.i()) || n.O(cVar.i())) {
                    hashSet2.add(cVar.j(0).c());
                }
            }
        }
        for (gb gbVar : this.l.values()) {
            if (gbVar.S()) {
                for (int i3 : f13383c) {
                    if (gbVar.j(i3)) {
                        if (i3 == 1) {
                            ((gh) gbVar.l(i3)).a(hashSet3, z, true);
                        } else {
                            gx.a((av) gbVar.l(i3), z, hashSet3, z4, true);
                        }
                    }
                }
                int[] ac = gbVar.ac();
                int length = ac.length;
                int i4 = 0;
                while (i4 < length) {
                    ft j = j(ac[i4]);
                    if (j != null) {
                        if (j.n()) {
                            hashSet.add(Integer.valueOf(j.G()));
                        } else {
                            i = i4;
                            i2 = length;
                            iArr = ac;
                            j.a(context, z, hashSet3, false, true, false);
                            a(packageManager, j, hashSet);
                            i4 = i + 1;
                            length = i2;
                            ac = iArr;
                        }
                    }
                    i = i4;
                    i2 = length;
                    iArr = ac;
                    i4 = i + 1;
                    length = i2;
                    ac = iArr;
                }
            }
            z4 = false;
        }
        for (dt dtVar : this.n.values()) {
            if (hashSet2.contains(dtVar.m())) {
                dtVar.a(z, hashSet3, false, true);
                a(packageManager, dtVar, hashSet);
            }
        }
        if (!z2) {
            for (String str : set) {
                if (this.h.containsKey(str)) {
                    hashSet.add(Integer.valueOf(this.h.get(str).intValue()));
                }
            }
            for (Object obj : hashSet.toArray()) {
                Integer num = (Integer) obj;
                if (this.m.containsKey(num)) {
                    a(packageManager, this.m.get(num), hashSet);
                }
            }
        }
        for (ft ftVar : this.m.values()) {
            if ((!z2 && !hashSet.contains(Integer.valueOf(ftVar.G()))) || !z3 || ftVar.n() || com.joaomgcd.taskerm.util.an.b(this, ftVar)) {
                ftVar.a(context, z, hashSet3, false, true, false);
            }
        }
        return hashSet3;
    }

    public void a(PackageManager packageManager, ai aiVar, Set<Integer> set) {
        int a2;
        if (aiVar != null) {
            for (dr drVar : aiVar.a(packageManager)) {
                if (drVar.b() == dr.a.Task && (a2 = drVar.a(this)) != -1) {
                    set.add(Integer.valueOf(a2));
                }
            }
        }
    }

    public void m() {
        for (gb gbVar : this.l.values()) {
            gbVar.X();
            gbVar.Y();
        }
    }

    public void a(boolean z, String str) {
        if (z) {
            m();
        }
        this.l.clear();
        this.m.clear();
        this.i.clear();
        this.j.clear();
        this.k.clear();
        this.n.clear();
        this.o.clear();
        this.h.clear();
        t();
    }

    @Override
    public boolean j(String str) {
        return this.h.containsKey(str);
    }

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

    @Override
    public ft j(int i) {
        if (this.m.containsKey(Integer.valueOf(i))) {
            return this.m.get(Integer.valueOf(i));
        }
        bo.d("TD", "getMacroByID: non-existent ID " + i);
        return null;
    }

    public ay a(Context context, File file, int i) {
        Context applicationContext = context.getApplicationContext();
        ay ayVar = new ay();
        fy fyVar = new fy();
        if (!file.exists()) {
            bo.d("TD", "importSceneFromFile: path doesn't exist: " + file);
            ayVar.f12148b = R.string.err_profile_import_failed_read_data;
        } else if (fyVar.a(applicationContext, file.getParentFile(), file.getName(), true, true)) {
            int r = fyVar.r();
            if (r == 0) {
                ayVar.f12148b = R.string.f_import_no_enities;
                ayVar.f12147a = R.string.word_scene;
            } else if (r == 1) {
                dt dtVar = fyVar.b(-2, dt.f.User, true).get(0);
                String m = dtVar.m();
                if (m == null) {
                    ayVar.f12148b = R.string.f_import_no_name;
                    ayVar.f12147a = R.string.word_scene;
                } else if (t(m)) {
                    ayVar.f12148b = R.string.f_import_name_exists;
                    ayVar.f12150d = m;
                } else {
                    HashMap hashMap = null;
                    LinkedList linkedList = new LinkedList();
                    Iterator<Integer> it = dtVar.e(true).iterator();
                    while (it.hasNext()) {
                        int intValue = it.next().intValue();
                        if (!dt.b(intValue)) {
                            if (fyVar.i(intValue)) {
                                ft j = fyVar.j(intValue);
                                bo.b("TD", "try task import: " + intValue);
                                ay b2 = b(j, i);
                                if (b2.a()) {
                                    bo.b("TD", "task err");
                                    ayVar.a(b2);
                                    Iterator it2 = linkedList.iterator();
                                    while (it2.hasNext()) {
                                        o(((Integer) it2.next()).intValue());
                                    }
                                } else {
                                    int G = j.G();
                                    if (G != intValue) {
                                        if (hashMap == null) {
                                            hashMap = new HashMap();
                                        }
                                        bo.b("TD", "remapped task ID: " + intValue + " -> " + G);
                                        hashMap.put(Integer.valueOf(intValue), Integer.valueOf(G));
                                    }
                                    linkedList.add(Integer.valueOf(G));
                                }
                            } else {
                                ayVar.f12148b = R.string.f_scene_import_bad_task;
                            }
                        }
                    }
                    if (!ayVar.a()) {
                        if (hashMap != null) {
                            dtVar.a(hashMap);
                        }
                        a(dtVar, i);
                        ayVar.f12149c = dtVar;
                    }
                }
            } else {
                ayVar.f12148b = R.string.f_import_more_than_one;
                ayVar.f12147a = R.string.word_scene;
            }
        } else {
            ayVar.f12148b = R.string.err_task_import_bad_packed_data;
        }
        return ayVar;
    }

    private ay b(dt dtVar, int i) {
        ay ayVar = new ay();
        if (t(dtVar.m())) {
            ayVar.f12148b = R.string.f_scene_import_name_exists;
            ayVar.f12150d = dtVar.m();
        } else {
            a(dtVar, i);
            ayVar.f12149c = dtVar;
        }
        return ayVar;
    }

    public int n() {
        return this.m.size();
    }

    public int o() {
        return this.h.size();
    }

    private ay b(ft ftVar, int i) {
        return a(ftVar, i, false);
    }

    private ay a(ft ftVar, int i, boolean z) {
        ay ayVar = new ay();
        boolean z2 = true;
        if (ftVar.n()) {
            String m = ftVar.m();
            if (n(m)) {
                ft i2 = i(m);
                if (i2.j() == ftVar.j() || z) {
                    bo.b("TD", "same creation date or asked to overwrite, overwrite existing task");
                    int G = i2.G();
                    ftVar.e(G);
                    this.m.put(Integer.valueOf(G), ftVar);
                } else {
                    ayVar.f12148b = R.string.f_import_name_exists;
                    ayVar.f12150d = m;
                    ftVar.e(i(m).G());
                }
                z2 = false;
            }
        }
        if (z2) {
            ftVar.e(aa());
            a(ftVar, i);
        }
        ayVar.f12149c = ftVar;
        return ayVar;
    }

    public void a(ft ftVar) {
        a(ftVar, -1);
    }

    public void a(ft ftVar, int i) {
        if (ftVar.G() == -1) {
            ftVar.e(aa());
        } else if (b(ftVar.G())) {
            ftVar.e(aa());
        }
        int G = ftVar.G();
        this.m.put(Integer.valueOf(G), ftVar);
        if (ftVar.n()) {
            String m = ftVar.m();
            if (this.h.containsKey(m) && this.h.get(m).intValue() != G) {
                bo.c("TD", "addTask: task name " + m + " tID " + G + " conflicts with tID " + this.h.get(m));
            }
            this.h.put(ftVar.m(), Integer.valueOf(ftVar.G()));
            if (i >= 0) {
                this.o.get(i).d(G);
            }
        }
        t();
    }

    public Set<Integer> p() {
        return this.l.keySet();
    }

    public Set<Integer> q() {
        return this.m.keySet();
    }

    public ay b(Context context, File file, int i) {
        ay ayVar = new ay();
        String a2 = gs.a(file);
        if (a2 == null) {
            ayVar.f12148b = R.string.err_task_import_read_file;
            return ayVar;
        }
        return a(context, a2, i, false);
    }

    public ay a(Context context, String str, int i, boolean z) {
        ft ftVar;
        ay ayVar = new ay();
        Context applicationContext = context.getApplicationContext();
        dh dhVar = new dh(str);
        if (dhVar.b()) {
            ayVar.f12148b = R.string.err_task_import_bad_data;
            return ayVar;
        }
        ft ftVar2 = null;
        String e2 = dhVar.e();
        if (e2 == null) {
            bo.d("TD", "no object class");
            ayVar.f12148b = R.string.err_task_import_bad_data;
        } else {
            if (e2.equals("Task")) {
                try {
                    ftVar = new ft(dhVar);
                    try {
                        if (ftVar.y()) {
                            ftVar.a(this);
                        }
                    } catch (Exception e3) {
                        ftVar2 = ftVar;
                        e = e3;
                        bo.c("TD", e.toString());
                        bo.b("TD", "importTaskFromFile", e);
                        if (ayVar.a()) {
                        }
                        ayVar.f12148b = R.string.err_task_import_bad_packed_data;
                        return ayVar;
                    }
                } catch (Exception e4) {
                    e = e4;
                }
            } else if (dhVar.e().equals("TaskerData")) {
                fy fyVar = new fy();
                dhVar.a(8);
                try {
                    fyVar.a(applicationContext, dhVar, true);
                    int n = fyVar.n();
                    if (n == 0) {
                        ayVar.f12148b = R.string.f_import_no_enities;
                        ayVar.f12147a = R.string.word_task;
                    } else if (n == 1) {
                        ftVar = fyVar.j(fyVar.q().iterator().next().intValue());
                    } else {
                        ayVar.f12148b = R.string.f_import_more_than_one;
                        ayVar.f12147a = R.string.word_task;
                    }
                    ftVar = null;
                } catch (dh.b e5) {
                    ayVar.f12148b = R.string.f_err_object_version;
                    ayVar.f12147a = e5.f12708c;
                }
            } else {
                ayVar.f12148b = R.string.err_task_import_bad_packed_data;
            }
            ftVar2 = ftVar;
        }
        if (ayVar.a() && ftVar2 != null) {
            if (!ftVar2.n()) {
                ayVar.f12148b = R.string.f_import_no_name;
                ayVar.f12147a = R.string.word_task;
                return ayVar;
            }
            return a(ftVar2, i, z);
        }
        ayVar.f12148b = R.string.err_task_import_bad_packed_data;
        return ayVar;
    }

    public ay c(Context context, File file, int i) {
        Context applicationContext = context.getApplicationContext();
        ay ayVar = new ay();
        fy fyVar = new fy();
        if (file == null) {
            bo.d("TD", "importProfile: null file path");
            ayVar.f12148b = R.string.err_profile_import_failed_read_data;
            return ayVar;
        }
        if (!file.exists()) {
            bo.d("TD", "importProfile: path doesn't exist: " + file);
            ayVar.f12148b = R.string.err_profile_import_failed_read_data;
            return ayVar;
        }
        if (fyVar.a(applicationContext, file.getParentFile(), file.getName(), true, true)) {
            int y = fyVar.y();
            if (y == 0) {
                ayVar.f12148b = R.string.f_import_no_enities;
                ayVar.f12147a = R.string.word_profile;
                return ayVar;
            }
            if (y == 1) {
                return a(fyVar, fyVar.p().iterator().next().intValue(), i);
            }
            ayVar.f12148b = R.string.f_import_more_than_one;
            ayVar.f12147a = R.string.word_profiles;
            return ayVar;
        }
        ayVar.f12148b = R.string.err_profile_import_failed_read_data;
        return ayVar;
    }

    public int r() {
        return this.n.size();
    }

    public ay a(fy fyVar, int i, int i2) {
        int G;
        ay ayVar = new ay();
        gb k = fyVar.k(i);
        if (k == null) {
            bo.c("TD", "importProfile: null profile id " + i);
            ayVar.f12148b = R.string.err_profile_import_bad_profile;
        } else if (k.M() == 0) {
            bo.c("TD", "importProfile: no tasks pid " + i);
            ayVar.f12148b = R.string.f_import_no_enities;
            ayVar.f12147a = R.string.word_task;
        } else {
            for (int i3 = 0; i3 < 2; i3++) {
                if (k.k(i3)) {
                    ft j = fyVar.j(k.n(i3));
                    if (j == null) {
                        ayVar.f12148b = R.string.err_profile_import_bad_task;
                    } else {
                        ay b2 = b(j, i2);
                        if (b2.a()) {
                            ayVar.a(b2);
                        } else {
                            G = ((ft) b2.f12149c).G();
                            if (ayVar.f12148b != -1) {
                                k.a(i3, G);
                            }
                        }
                    }
                    G = -1;
                    if (ayVar.f12148b != -1) {
                    }
                }
            }
            if (ayVar.f12148b == -1) {
                k.a(aa(), "impProf");
                k.ab();
                k.k();
                a(k, i2);
                ayVar.f12149c = k;
            }
        }
        return ayVar;
    }

    public void a(gb gbVar, int i) {
        if (gbVar == null) {
            bo.c("TD", "addProfile: called with null profile, project " + i);
            return;
        }
        int K = gbVar.K();
        this.l.put(Integer.valueOf(K), gbVar);
        if (i >= 0 && this.o.size() > 0) {
            dm dmVar = null;
            try {
                dmVar = this.o.get(i);
            } catch (Throwable unused) {
            }
            if (dmVar == null) {
                bo.c("TD", "addProfile: null project index " + i + " no projects " + A());
            } else {
                dmVar.e(K);
            }
        }
        t();
    }

    @Override
    public gb k(int i) {
        if (!this.l.containsKey(Integer.valueOf(i))) {
            bo.d("TD", "no profile ID: " + i);
        }
        return this.l.get(Integer.valueOf(i));
    }

    public List<gb> k(String str) {
        LinkedList linkedList = null;
        for (gb gbVar : this.l.values()) {
            if (gbVar.n() && gbVar.m().equals(str)) {
                if (linkedList == null) {
                    linkedList = new LinkedList();
                }
                linkedList.add(gbVar);
            }
        }
        return linkedList;
    }

    public gb l(String str) {
        for (gb gbVar : this.l.values()) {
            if (gbVar.n() && gbVar.m().equals(str)) {
                return gbVar;
            }
        }
        return null;
    }

    @Override
    public boolean m(String str) {
        for (gb gbVar : this.l.values()) {
            if (gbVar.n() && str.equals(gbVar.m())) {
                return true;
            }
        }
        return false;
    }

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

    private void I(int i) {
        ft ftVar = this.m.get(Integer.valueOf(i));
        if (ftVar == null) {
            bo.c("TD", "attempt to delete non-existent macro ID " + i);
        } else {
            if (ftVar.n()) {
                this.h.remove(ftVar.m());
            }
            this.m.remove(Integer.valueOf(i));
            Iterator<dm> it = this.o.iterator();
            while (it.hasNext()) {
                it.next().c(i);
            }
            t();
        }
        bo.b("TD", "deleteTaskAux " + i + " : done");
    }

    public void a(Context context, gb gbVar, int i) {
        int n = gbVar.n(i);
        gbVar.e(i);
        if (!this.m.get(Integer.valueOf(n)).n() && n(n) == 0) {
            I(n);
        }
        if (gbVar.a(context, com.joaomgcd.taskerm.util.an.a(this, context, gbVar, (Bundle) null, "deleteTaskAtProfile")) && i == 0 && gbVar.k(1)) {
            gbVar.a(0, gbVar.e(1));
        }
    }

    public int a(PackageManager packageManager, String str) {
        String g;
        int a2;
        HashSet hashSet = null;
        if (t(str)) {
            for (dr drVar : u(str).a(packageManager)) {
                if (drVar.b() == dr.a.Task && (a2 = drVar.a(this)) != -1) {
                    if (hashSet == null) {
                        hashSet = new HashSet();
                    }
                    hashSet.add(Integer.valueOf(a2));
                }
            }
        }
        int i = 0;
        for (ft ftVar : this.m.values()) {
            int G = ftVar.G();
            if (hashSet == null || !hashSet.contains(Integer.valueOf(G))) {
                for (dr drVar2 : ftVar.a(packageManager)) {
                    if (drVar2.f() && (g = drVar2.g()) != null && g.equals(str)) {
                        i++;
                    }
                }
            }
        }
        return i;
    }

    @Override
    public void a(Context context, int i, int i2, Collection<String> collection) {
        List<Integer> linkedList;
        if (i == -1 || b(i)) {
            linkedList = new LinkedList<>();
            Iterator<gb> it = B(i2).iterator();
            while (true) {
                if (!it.hasNext()) {
                    break;
                }
                gb next = it.next();
                if (next.M() == 0) {
                    linkedList.add(Integer.valueOf(next.K()));
                    break;
                }
            }
        } else {
            linkedList = m(i);
        }
        Iterator<Integer> it2 = linkedList.iterator();
        while (it2.hasNext()) {
            gb k = k(it2.next().intValue());
            if (k != null) {
                com.joaomgcd.taskerm.util.an.a(this, context, collection, k, (Integer) null);
                for (int i3 = 4; i3 < 6; i3++) {
                    if (k.j(i3)) {
                        fp fpVar = (fp) k.l(i3);
                        fpVar.i();
                        com.joaomgcd.taskerm.state.e f2 = fpVar.f();
                        if (fo.b(fpVar.i()) || f2 != null) {
                            a(di.a.Condition, fpVar.i(), fpVar.i(0).c(), collection, f2 != null ? f2.k() : null);
                        }
                    }
                }
                if (k.j(7)) {
                    ao aoVar = (ao) k.l(7);
                    int i4 = aoVar.i();
                    com.joaomgcd.taskerm.event.b a2 = aoVar.a();
                    if (an.q(i4) || a2 != null) {
                        a(di.a.Event, i4, aoVar.i(0).c(), collection, a2 != null ? a2.k() : null);
                    } else {
                        com.joaomgcd.taskerm.inputoutput.j a3 = com.joaomgcd.taskerm.util.an.a(aoVar, context);
                        a3.add((com.joaomgcd.taskerm.inputoutput.j) new com.joaomgcd.taskerm.inputoutput.f((String) null, "evtprm", com.joaomgcd.taskerm.util.an.a(R.string.event_parameters, context, new Object[0]), com.joaomgcd.taskerm.util.an.a(R.string.event_parameters_description, context, new Object[0]), true));
                        Iterator it3 = a3.iterator();
                        while (it3.hasNext()) {
                            collection.add(di.b(di.a.Event, aoVar.m(), ((com.joaomgcd.taskerm.inputoutput.f) it3.next()).toString()));
                        }
                    }
                }
            }
        }
    }

    private void a(di.a aVar, int i, Bundle bundle, Collection<String> collection, String str) {
        for (String str2 : ga.a(bundle)) {
            String b2 = di.b(aVar, str != null ? str : di.b(aVar, i), str2);
            if (b2 != null) {
                collection.add(b2);
            }
        }
    }

    @Override
    public List<Integer> m(int i) {
        ArrayList arrayList = new ArrayList();
        for (gb gbVar : this.l.values()) {
            int[] ac = gbVar.ac();
            int length = ac.length;
            int i2 = 0;
            while (true) {
                if (i2 >= length) {
                    break;
                }
                if (ac[i2] == i) {
                    arrayList.add(Integer.valueOf(gbVar.K()));
                    break;
                }
                i2++;
            }
        }
        return arrayList;
    }

    public int n(int i) {
        return m(i).size();
    }

    public void o(int i) {
        bo.b("TD", "delete task: " + i);
        Iterator<gb> it = this.l.values().iterator();
        while (it.hasNext()) {
            it.next().f(i);
        }
        for (dt dtVar : this.n.values()) {
            bo.b("TD", "scene: " + dtVar.m() + " delete task refs by id: " + i);
            dtVar.n(i);
        }
        I(i);
    }

    public void p(int i) {
        gb gbVar = this.l.get(Integer.valueOf(i));
        if (gbVar == null) {
            bo.d("TD", "deleteProfile: unknown ID " + i);
            return;
        }
        gbVar.X();
        gbVar.Y();
        for (int i2 : gbVar.ac()) {
            ft j = j(i2);
            if (j == null) {
                bo.d("TD", "deleteProfile: ignoring reference to unknown task ID " + i2);
            } else if (!j.n()) {
                I(i2);
            }
        }
        this.l.remove(Integer.valueOf(i));
        Iterator<dm> it = this.o.iterator();
        while (it.hasNext()) {
            it.next().b(i);
        }
        t();
    }

    public gb f(Context context) {
        return new gb(context, aa());
    }

    public boolean s() {
        return this.g;
    }

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

    public fx b(String str, int i) {
        Iterator<gb> it = a((Object[]) null, i).iterator();
        while (it.hasNext()) {
            fx l = it.next().l(i);
            if (l.w() && l.n().equals(str)) {
                return l;
            }
        }
        return null;
    }

    public boolean n(String str) {
        return this.h.containsKey(str);
    }

    public void b(ft ftVar) {
        ft ftVar2 = this.m.get(Integer.valueOf(ftVar.G()));
        if (ftVar2 != null && ftVar2.n()) {
            if (this.h.containsKey(ftVar2.m())) {
                this.h.remove(ftVar2.m());
            } else {
                bo.d("TD", "mergeMacro: old macro has name but is not in aliases");
            }
        }
        bo.b("TD", "mergeMacro: do add: " + ftVar.ah());
        a(ftVar, -1);
    }

    public boolean a(Context context, File file, String str, boolean z) {
        return a(context, file, str, 52, z);
    }

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

    public boolean a(Context context, File file, String str, int i, boolean z) {
        File file2;
        com.joaomgcd.taskerm.j.d a2 = com.joaomgcd.taskerm.j.a.a(context, file);
        if (!a2.k()) {
            a2.a(context, true);
        }
        boolean z2 = false;
        if (a2.k()) {
            File file3 = new File(file, str);
            if (at.a(context, file3, true)) {
                file2 = com.joaomgcd.taskerm.util.dq.a(context, str);
                file2.getParentFile();
            } else {
                file3 = null;
                file2 = file3;
            }
            synchronized (f13382b) {
                String a3 = a(context, i, z);
                boolean a4 = a3 == null ? false : gs.a(a3, file2, false);
                if (file3 != null && com.joaomgcd.taskerm.j.a.a(context, file2).k()) {
                    try {
                        com.joaomgcd.taskerm.util.dq.a(context, file2, file3);
                    } catch (Exception e2) {
                        bo.b("TD", "writeSDAbsDir", e2);
                        a4 = false;
                    }
                    com.joaomgcd.taskerm.util.dq.b(context, str);
                }
                z2 = a4;
            }
        }
        return z2;
    }

    private String a(Context context, fy fyVar, String str, int i) {
        return str + "://" + Base64.encodeToString(hi.a(fyVar.a(context, i)), 2);
    }

    public String a(Context context, az azVar, int i) {
        if (azVar instanceof ft) {
            return a(context, (ft) azVar, i);
        }
        if (azVar instanceof gb) {
            return b(context, (gb) azVar, i);
        }
        if (azVar instanceof dm) {
            return a(context, (dm) azVar, i);
        }
        throw new RuntimeException("Can't get URL of " + azVar.getClass().getName());
    }

    private String a(Context context, ft ftVar, int i) {
        return a(context, c(ftVar), "taskertask", i);
    }

    private String b(Context context, gb gbVar, int i) {
        return a(context, a(gbVar), "taskerprofile", i);
    }

    private String a(Context context, dm dmVar, int i) {
        return a(context, a(context.getPackageManager(), dmVar), "taskerproject", i);
    }

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

    public ay a(Context context, String str, int i) {
        byte[] bArr;
        synchronized (f13381a[a.Active.ordinal()]) {
            boolean d2 = d(str);
            boolean e2 = e(str);
            boolean f2 = f(str);
            if (!d2 && !e2 && !f2) {
                ay ayVar = new ay();
                ayVar.f12148b = R.string.err_task_import_bad_data;
                bo.b("TD", "Can't import data " + str);
                return ayVar;
            }
            try {
                bArr = Base64.decode(str.replace("taskertask", "").replace("taskerprofile", "").replace("taskerproject", "").substring(3), 0);
            } catch (IllegalArgumentException e3) {
                bo.c("TD", e3.getMessage());
                bArr = null;
            }
            if (bArr == null) {
                ay ayVar2 = new ay();
                ayVar2.f12148b = R.string.err_task_import_bad_data;
                return ayVar2;
            }
            return a(context, i, d2, e2, f2, hi.a(bArr), true);
        }
    }

    public ay a(Context context, int i, boolean z, boolean z2, boolean z3, String str, boolean z4) {
        if (!z && !z2 && !z3) {
            ay ayVar = new ay();
            ayVar.f12148b = R.string.err_task_import_bad_data;
            bo.b("TD", "Can't import data: not supported");
            return ayVar;
        }
        if (z) {
            return a(context, str, i, z4);
        }
        fy fyVar = new fy();
        fyVar.a(context, "fromurl", str, false, true);
        if (z2) {
            Set<Integer> p = fyVar.p();
            if (p.size() == 0) {
                throw new RuntimeException("Missing event type");
            }
            return a(fyVar, p.iterator().next().intValue(), i);
        }
        return a(context.getPackageManager(), fyVar);
    }

    public String b(Context context, boolean z) {
        return a(context, 52, z);
    }

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

    public String a(Context context, int i, boolean z) {
        dh dhVar;
        try {
            try {
                int i2 = (com.joaomgcd.taskerm.settings.ai.j(context) ? 65 : 1) | i;
                dhVar = a(i2);
                if (z) {
                    try {
                        dhVar.a("vars", com.joaomgcd.taskerm.util.al.ax(context), i2);
                        dhVar.a("prefs", com.joaomgcd.taskerm.util.al.ay(context), i2);
                    } catch (Exception e2) {
                        e = e2;
                        bo.b("TD", "getAsXMLString", e);
                    }
                }
            } catch (Exception e3) {
                e = e3;
                dhVar = null;
            }
        } finally {
            if ((i & 4) > 0) {
                X();
            }
        }
    }

    public String a(Context context, String str, Boolean bool) {
        String str2;
        String str3;
        Context applicationContext = context.getApplicationContext();
        synchronized (f13382b) {
            str2 = null;
            if ("https://tasker.joaoapps.com/cgi-bin/nph-validate.cgi".contains("://tasker.j") && (this.g || bool.booleanValue())) {
                try {
                    str3 = a(com.joaomgcd.taskerm.settings.ai.j(applicationContext) ? 64 : 0).b(0);
                } catch (OutOfMemoryError unused) {
                    bo.d("TD", "writeDevice: oom");
                    str3 = null;
                }
                if (str3 != null) {
                    if (gs.a(applicationContext, str3, str, 0)) {
                        Y();
                    }
                }
                str2 = str3;
            }
        }
        return str2;
    }

    private void Y() {
        this.g = false;
    }

    public boolean a(Context context, File file, String str, boolean z, boolean z2) {
        return a(context, file, str, z, z2, false);
    }

    public boolean a(Context context, File file, String str, boolean z, boolean z2, boolean z3) {
        boolean z4;
        Context applicationContext = context.getApplicationContext();
        synchronized (f13382b) {
            z4 = false;
            try {
            } catch (Exception e2) {
                bo.b("TD", "readSD: failed:", e2);
            } finally {
            }
            if (file == null) {
                bo.c("TD", "readSD: null dir");
                if (!z) {
                }
            } else {
                com.joaomgcd.taskerm.j.d a2 = com.joaomgcd.taskerm.j.a.a(applicationContext, new File(file, str));
                if (a2.k()) {
                    a(true, "readSD");
                    t();
                    dh dhVar = new dh(a2);
                    if (dhVar.b()) {
                        bo.c("TD", "readSD: packed xml string error");
                    } else {
                        try {
                            try {
                                dhVar.a(8);
                                a(applicationContext, dhVar, z2, z3);
                            } finally {
                                X();
                            }
                        } catch (Exception e3) {
                            bo.b("TD", "readSD", e3);
                            X();
                        }
                    }
                } else if (z) {
                    bo.c("TD", "readSD: file doesn't exist: " + a2);
                }
            }
            z4 = true;
        }
        return z4;
    }

    public boolean a(Context context, String str) {
        boolean z;
        Context applicationContext = context.getApplicationContext();
        synchronized (f13382b) {
            z = false;
            a(false, "readAsset");
            dh dhVar = null;
            try {
                dhVar = new dh(applicationContext.getAssets().open(str));
            } catch (Exception e2) {
                bo.b("TD", "readAsset", e2);
            }
            if (dhVar == null) {
                bo.c("TD", "readAsset: null packed object");
            } else if (dhVar.b()) {
                bo.c("TD", "readAsset: packed xml string error");
            } else {
                dhVar.a(8);
                a(applicationContext, dhVar, false);
                z = true;
                Y();
            }
        }
        return z;
    }

    public boolean b(Context context, String str) {
        boolean z;
        Context applicationContext = context.getApplicationContext();
        synchronized (f13382b) {
            z = false;
            a(false, "readDevice");
            dh dhVar = null;
            try {
                dhVar = new dh(applicationContext.openFileInput(str));
            } catch (Exception e2) {
                bo.b("TD", "readDevice", e2);
            }
            if (dhVar == null) {
                bo.c("TD", "readDevice: null packed object");
            } else if (dhVar.b()) {
                bo.c("TD", "readDevice: packed xml string error");
            } else {
                bo.b("TD", "readDevice");
                a(applicationContext, dhVar, false);
                z = true;
                Y();
            }
        }
        return z;
    }

    public boolean a(Context context, String str, String str2, boolean z) {
        String d2 = com.joaomgcd.taskerm.util.dq.d(com.joaomgcd.taskerm.util.dq.a(context, str2));
        if (d2 == null) {
            return false;
        }
        return z ? com.joaomgcd.taskerm.util.dq.b(context, str2) : a(context, str, d2);
    }

    public boolean a(Context context, String str, String str2) {
        return b(context, str, str2, false);
    }

    public boolean b(Context context, String str, String str2, boolean z) {
        return a(context, str, str2, z, false);
    }

    public boolean a(Context context, String str, String str2, boolean z, boolean z2) {
        a(true, "fromXMLString");
        dh dhVar = new dh(str2);
        if (dhVar.b()) {
            bo.c("TD", "fromXMLString: " + str + ": packed xml string error");
        } else {
            try {
                a(context, dhVar, z2, z);
                return true;
            } catch (dh.b e2) {
                bo.c("TD", "fromXMLString: " + e2);
            }
        }
        return false;
    }

    private void Z() {
        for (ft ftVar : this.m.values()) {
            if (ftVar.y()) {
                ftVar.a(this);
            }
        }
    }

    public boolean a(Context context, dh dhVar, boolean z) {
        return a(context, dhVar, z, false);
    }

    public boolean a(Context context, dh dhVar, boolean z, boolean z2) {
        String str;
        SharedPreferences.Editor editor;
        dh q;
        int i;
        Context applicationContext = context.getApplicationContext();
        dhVar.j("dvi");
        dhVar.j("tv");
        dhVar.j("nid");
        if (dhVar.c("dmetric")) {
            String k = dhVar.k("dmetric");
            dhVar.j("dmetric");
            str = k;
        } else {
            str = null;
        }
        boolean z3 = false;
        int i2 = 0;
        while (true) {
            String a2 = dh.a("proj", i2);
            if (!dhVar.c(a2)) {
                break;
            }
            try {
                dm dmVar = new dm(dhVar.q(a2));
                this.o.add(dmVar);
                bo.b("TD", "added project: " + dmVar.m());
            } catch (dh.a e2) {
                bo.d("TD", "unpack project failure: " + e2.toString());
                z3 = true;
            }
            dhVar.j(a2);
            i2++;
        }
        bo.b("TD", "fpo: found " + this.o.size() + " projects");
        Set<String> d2 = dhVar.d();
        dh.a(d2);
        Iterator<String> it = d2.iterator();
        SharedPreferences.Editor edit = gs.g(applicationContext).edit();
        HashMap hashMap = null;
        boolean z4 = false;
        boolean z5 = false;
        int i3 = 9999;
        while (it.hasNext()) {
            try {
                q = dhVar.q(it.next());
            } catch (dh.a e3) {
                e = e3;
            }
            if (q.m("Task")) {
                ft ftVar = new ft(q);
                a(ftVar, -1);
                if (ftVar.y()) {
                    z5 = true;
                }
            } else if (q.m("Profile")) {
                if (z) {
                    HashMap hashMap2 = hashMap == null ? new HashMap() : hashMap;
                    try {
                        hashMap2.put(Integer.valueOf(q.f(bf.EXTRA_ID)), Integer.valueOf(i3));
                        hashMap = hashMap2;
                    } catch (dh.a e4) {
                        e = e4;
                        hashMap = hashMap2;
                        editor = edit;
                        bo.d("TD", "unpack object: " + e.toString());
                        edit = editor;
                        z3 = true;
                    }
                }
                if (z) {
                    int i4 = i3;
                    i3++;
                    i = i4;
                } else {
                    i = -1;
                }
                gb gbVar = new gb(applicationContext, q, i);
                if (gbVar.I() > 0) {
                    a(gbVar, -1);
                    for (int i5 = 0; i5 < gbVar.H(); i5++) {
                        int i6 = gbVar.i(i5);
                        if (i6 == 7) {
                            this.j.add(Integer.valueOf(((ao) gbVar.d(i5)).i()));
                        } else if (i6 == 4 || i6 == 5 || i6 == 6) {
                            this.k.add(Integer.valueOf(((fp) gbVar.d(i5)).i()));
                        }
                    }
                } else {
                    bo.d("TD", "dropping profile with no valid contexts: " + gbVar.x());
                    z3 = true;
                }
            } else if (q.m("Scene")) {
                a(new dt(q), -1);
            } else {
                if (z2 && q.m("Variable")) {
                    gu guVar = new gu(applicationContext, q);
                    editor = edit;
                    try {
                        gx.a(applicationContext, guVar.m(), guVar.u(), false, (Bundle) null, "TD");
                    } catch (dh.a e5) {
                        e = e5;
                        bo.d("TD", "unpack object: " + e.toString());
                        edit = editor;
                        z3 = true;
                    }
                } else {
                    editor = edit;
                    if (z2 && q.m("Setting")) {
                        new com.joaomgcd.taskerm.settings.l(applicationContext, q).a(editor);
                        z4 = true;
                    } else {
                        bo.d("TD", "unpack: bad object class: " + q.e());
                        z3 = true;
                    }
                }
                edit = editor;
            }
            editor = edit;
            edit = editor;
        }
        SharedPreferences.Editor editor2 = edit;
        if (z4) {
            editor2.commit();
        }
        if (z && hashMap != null) {
            for (dm dmVar2 : this.o) {
                for (Map.Entry entry : hashMap.entrySet()) {
                    dmVar2.a(((Integer) entry.getKey()).intValue(), ((Integer) entry.getValue()).intValue());
                }
            }
        }
        if (z5) {
            Z();
        }
        C();
        if (str != null && r() > 0) {
            String[] split = str.split(",");
            if (split != null && split.length == 2) {
                if (!gs.a()) {
                    gs.c(applicationContext);
                }
                if (gs.a()) {
                    float parseFloat = Float.parseFloat(split[0]);
                    float parseFloat2 = Float.parseFloat(split[1]);
                    Iterator<dt> it2 = this.n.values().iterator();
                    while (it2.hasNext()) {
                        it2.next().a("TD", parseFloat, parseFloat2, gs.d(), gs.e(), false);
                    }
                } else {
                    bo.d("TD", "have no display metrics for this device");
                }
            } else {
                bo.d("TD", "bad base metric spec: " + str);
            }
        }
        Y();
        return z3;
    }

    public void t() {
        this.g = true;
    }

    @Override
    public dh a(int i) {
        dh dhVar = new dh(a(), 1);
        dhVar.a(new String[]{"dvi", "tv"});
        dhVar.c("tv", "6.1.32");
        dhVar.c("dvi", String.valueOf(1));
        dhVar.a("task", this.m, i);
        dhVar.a("prof", this.l, i);
        if (this.o.size() > 0) {
            dhVar.a("proj", this.o, i);
        }
        if (this.n.size() > 0) {
            dhVar.a("scene", this.n, i);
            if (((i & 32) > 0 || (i & 2) > 0) && gs.a()) {
                dhVar.c("dmetric", gs.f());
            }
        }
        return dhVar;
    }

    public List<gb> a(final Context context, gb.b bVar, int i) {
        List<gb> list;
        List<gb> B = B(i);
        List<gb> list2 = null;
        Comparator<gb> comparator = (bVar == gb.b.EnabledAlpha || bVar == gb.b.ActiveAlpha || bVar == gb.b.Alpha) ? new Comparator<gb>() {
            @Override
            public int compare(gb gbVar, gb gbVar2) {
                return (gbVar.n() ? gbVar.m() : gbVar.b(context, true, false, false)).compareToIgnoreCase(gbVar2.n() ? gbVar2.m() : gbVar2.b(context, true, false, false));
            }
        } : null;
        if (bVar != gb.b.User) {
            if (bVar == gb.b.Alpha) {
                Collections.sort(B, comparator);
            } else {
                if (bVar == gb.b.EnabledAlpha) {
                    List<gb> arrayList = new ArrayList<>();
                    List<gb> arrayList2 = new ArrayList<>();
                    a(B, arrayList, arrayList2);
                    Collections.sort(arrayList, comparator);
                    Collections.sort(arrayList2, comparator);
                    arrayList.addAll(arrayList2);
                    return arrayList;
                }
                if (bVar == gb.b.ActiveAlpha) {
                    List<gb> arrayList3 = new ArrayList<>();
                    List<gb> arrayList4 = new ArrayList<>();
                    b(B, arrayList3, arrayList4);
                    Collections.sort(arrayList3, comparator);
                    Collections.sort(arrayList4, comparator);
                    arrayList3.addAll(arrayList4);
                    return arrayList3;
                }
                if (bVar == gb.b.AgeNewestFirst) {
                    Collections.sort(B, new Comparator() {
                        @Override
                        public final int compare(Object obj, Object obj2) {
                            int b2;
                            b2 = fy.b((gb) obj, (gb) obj2);
                            return b2;
                        }
                    });
                } else if (bVar == gb.b.Named) {
                    Collections.sort(B, new Comparator() {
                        @Override
                        public final int compare(Object obj, Object obj2) {
                            int a2;
                            a2 = fy.a((gb) obj, (gb) obj2);
                            return a2;
                        }
                    });
                } else if (bVar == gb.b.AgeOldestFirst) {
                    Collections.sort(B, new Comparator<gb>() {
                        @Override
                        public int compare(gb gbVar, gb gbVar2) {
                            return Long.compare(gbVar.j(), gbVar2.j());
                        }
                    });
                } else {
                    if (bVar == gb.b.ActiveContext) {
                        list = new ArrayList<>();
                        list2 = new ArrayList<>();
                        b(B, list, list2);
                    } else if (bVar == gb.b.EnabledContext) {
                        list = new ArrayList<>();
                        list2 = new ArrayList<>();
                        a(B, list, list2);
                    } else {
                        list = B;
                    }
                    B = new ArrayList<>();
                    int i2 = 0;
                    while (i2 < 2) {
                        List<gb> list3 = i2 == 0 ? list : list2;
                        if (list3 != null) {
                            for (int i3 = 0; i3 < 8; i3++) {
                                for (gb gbVar : a(list3.toArray(), i3)) {
                                    if (!B.contains(gbVar)) {
                                        B.add(gbVar);
                                    }
                                }
                            }
                        }
                        i2++;
                    }
                }
            }
        }
        return B;
    }

    public static int b(gb gbVar, gb gbVar2) {
        return Long.compare(gbVar2.j(), gbVar.j());
    }

    public static int a(gb gbVar, gb gbVar2) {
        return Boolean.compare(gbVar2.n(), gbVar.n());
    }

    private void a(List<gb> list, List<gb> list2, List<gb> list3) {
        for (gb gbVar : list) {
            if (gbVar.S()) {
                list2.add(gbVar);
            } else {
                list3.add(gbVar);
            }
        }
    }

    private void b(List<gb> list, List<gb> list2, List<gb> list3) {
        for (gb gbVar : list) {
            if (gbVar.F()) {
                list2.add(gbVar);
            } else {
                list3.add(gbVar);
            }
        }
    }

    public List<gb> a(Object[] objArr, int i) {
        if (objArr == null) {
            objArr = this.l.values().toArray();
        }
        ArrayList arrayList = new ArrayList();
        for (Object obj : objArr) {
            gb gbVar = (gb) obj;
            if (gbVar.j(i)) {
                int i2 = 0;
                while (i2 < arrayList.size() && gbVar.l(i).compareTo(((gb) arrayList.get(i2)).l(i)) <= 0) {
                    i2++;
                }
                arrayList.add(i2, gbVar);
            }
        }
        return arrayList;
    }

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

    public boolean q(int i) {
        Iterator<gb> it = this.l.values().iterator();
        while (it.hasNext()) {
            if (it.next().j(i)) {
                return true;
            }
        }
        return false;
    }

    public void v() {
        HashSet hashSet = new HashSet();
        for (gb gbVar : this.l.values()) {
            if (gbVar.C() && !gbVar.S()) {
                hashSet.add(Integer.valueOf(gbVar.K()));
            }
        }
        Iterator it = hashSet.iterator();
        while (it.hasNext()) {
            p(((Integer) it.next()).intValue());
        }
    }

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

    @Override
    public ArrayList<g> b(ArrayList<ft> arrayList) {
        ArrayList<g> arrayList2 = new ArrayList<>();
        Iterator<ft> it = arrayList.iterator();
        while (it.hasNext()) {
            arrayList2.add(it.next().f());
        }
        return arrayList2;
    }

    @Override
    public ArrayList<String> w() {
        return a(-2, ft.c.Alpha);
    }

    public ArrayList<String> a(int i, ft.c cVar) {
        return a(b(i, cVar));
    }

    public ArrayList<ft> r(int i) {
        Collection collection;
        ArrayList<ft> arrayList = new ArrayList<>();
        if (i == -2) {
            collection = this.m.keySet();
        } else if (i < this.o.size()) {
            collection = this.o.get(i).q();
        } else {
            bo.c("TD", "getTasksInProject: req index " + i + ", no projects " + this.o.size());
            collection = null;
        }
        if (collection != null) {
            Iterator it = collection.iterator();
            while (it.hasNext()) {
                arrayList.add(this.m.get(Integer.valueOf(((Integer) it.next()).intValue())));
            }
        }
        return arrayList;
    }

    @Override
    public ArrayList<ft> s(int i) {
        Collection<Integer> q;
        ArrayList<ft> arrayList = new ArrayList<>();
        if (i == -2) {
            q = this.h.values();
        } else {
            if (i >= this.o.size()) {
                bo.c("TD", "getNamedTasks: bad project index: " + i + " num " + this.o.size());
                return arrayList;
            }
            q = this.o.get(i).q();
        }
        Iterator<Integer> it = q.iterator();
        while (it.hasNext()) {
            ft ftVar = this.m.get(Integer.valueOf(it.next().intValue()));
            if (ftVar != null && ftVar.n()) {
                arrayList.add(ftVar);
            }
        }
        return arrayList;
    }

    @Override
    public ArrayList<ft> b(int i, ft.c cVar) {
        ArrayList<ft> s = s(i);
        if (cVar == ft.c.Alpha) {
            Collections.sort(s, new Comparator() {
                @Override
                public final int compare(Object obj, Object obj2) {
                    int c2;
                    c2 = fy.c((ft) obj, (ft) obj2);
                    return c2;
                }
            });
        } else if (cVar == ft.c.AgeNewestFirst) {
            Collections.sort(s, new Comparator() {
                @Override
                public final int compare(Object obj, Object obj2) {
                    int b2;
                    b2 = fy.b((ft) obj, (ft) obj2);
                    return b2;
                }
            });
        } else if (cVar == ft.c.AgeOldestFirst) {
            Collections.sort(s, new Comparator() {
                @Override
                public final int compare(Object obj, Object obj2) {
                    int a2;
                    a2 = fy.a((ft) obj, (ft) obj2);
                    return a2;
                }
            });
        }
        return s;
    }

    public static int c(ft ftVar, ft ftVar2) {
        return ftVar.m().compareToIgnoreCase(ftVar2.m());
    }

    public static int b(ft ftVar, ft ftVar2) {
        return Long.compare(ftVar2.j(), ftVar.j());
    }

    public static int a(ft ftVar, ft ftVar2) {
        return Long.compare(ftVar.j(), ftVar2.j());
    }

    public ArrayList<ft> x() {
        return b(-2, ft.c.Alpha);
    }

    public ArrayList<String> c(ArrayList<dt> arrayList) {
        ArrayList<String> arrayList2 = new ArrayList<>();
        Iterator<dt> it = arrayList.iterator();
        while (it.hasNext()) {
            arrayList2.add(it.next().m());
        }
        return arrayList2;
    }

    @Override
    public ArrayList<String> a(int i, dt.f fVar, boolean z) {
        return c(b(i, fVar, z));
    }

    public ArrayList<dt> b(int i, boolean z) {
        Collection<String> hashSet;
        ArrayList<dt> arrayList = new ArrayList<>();
        if (i == -2) {
            hashSet = this.n.keySet();
        } else if (i >= 0 && i < this.o.size()) {
            hashSet = this.o.get(i).r();
        } else {
            bo.d("TD", "gsip: bad project index: " + i);
            hashSet = new HashSet();
        }
        for (String str : hashSet) {
            if (z || !ex.c(str)) {
                arrayList.add(this.n.get(str));
            }
        }
        return arrayList;
    }

    public ArrayList<dt> b(int i, dt.f fVar, boolean z) {
        ArrayList<dt> b2 = b(i, z);
        if (fVar == dt.f.Alpha) {
            Collections.sort(b2, new Comparator<dt>() {
                @Override
                public int compare(dt dtVar, dt dtVar2) {
                    return dtVar.m().compareToIgnoreCase(dtVar2.m());
                }
            });
        } else if (fVar == dt.f.AgeNewestFirst) {
            Collections.sort(b2, new Comparator<dt>() {
                @Override
                public int compare(dt dtVar, dt dtVar2) {
                    return Long.compare(dtVar2.j(), dtVar.j());
                }
            });
        } else if (fVar == dt.f.AgeOldestFirst) {
            Collections.sort(b2, new Comparator<dt>() {
                @Override
                public int compare(dt dtVar, dt dtVar2) {
                    return Long.compare(dtVar.j(), dtVar2.j());
                }
            });
        }
        return b2;
    }

    public ft b(gb gbVar, int i) {
        if (i >= 2) {
            bo.c("TD", "getTaskByType: bad type: " + i);
            return null;
        }
        return j(gbVar.n(i));
    }

    public gb a(gb gbVar, boolean z) {
        ft j;
        gb gbVar2 = new gb(gbVar, aa());
        gbVar2.j(gbVar.T());
        gbVar2.p(gbVar.R());
        if (z) {
            for (int i = 0; i < 2; i++) {
                if (gbVar2.k(i) && (j = j(gbVar2.n(i))) != null && !j.n()) {
                    ft af = j.af();
                    af.e(aa());
                    gbVar2.a(i, af.G());
                    a(af);
                }
            }
        } else {
            gbVar2.a(0, -1);
            gbVar2.a(1, -1);
        }
        a(gbVar2, t(gbVar.K()));
        return gbVar2;
    }

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

    @Override
    public int u(int i) {
        Iterator<dm> it = this.o.iterator();
        int i2 = 0;
        while (it.hasNext()) {
            if (it.next().h(i)) {
                return i2;
            }
            i2++;
        }
        return -1;
    }

    public int o(String str) {
        Iterator<dm> it = this.o.iterator();
        int i = 0;
        while (it.hasNext()) {
            if (it.next().e(str)) {
                return i;
            }
            i++;
        }
        return -1;
    }

    public gb c(gb gbVar, int i) {
        gb a2 = a(gbVar, false);
        for (int i2 = 0; i2 < 8; i2++) {
            if (i2 != i && a2.j(i2)) {
                a2.h(i2);
            }
        }
        a2.J();
        return a2;
    }

    public int y() {
        return this.l.size();
    }

    public int a(gb gbVar, String str) {
        if (TextUtils.isEmpty(str)) {
            str = null;
        }
        int a2 = gbVar.n() ? a(gbVar.m(), str, "prof") : 0;
        gbVar.a(str);
        t();
        return a2;
    }

    public int a(ft ftVar, String str, int i) {
        int i2;
        boolean n = ftVar.n();
        if (ftVar.n()) {
            String m = ftVar.m();
            this.h.remove(m);
            i2 = a(m, str, "m");
        } else {
            i2 = 0;
        }
        ftVar.a(str);
        if (ftVar.n()) {
            this.h.put(ftVar.m(), Integer.valueOf(ftVar.G()));
        }
        if (!n) {
            if (i == -1) {
                i = 0;
            }
            this.o.get(i).d(ftVar.G());
        }
        t();
        return i2;
    }

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

    private int a(String str, String str2, String str3, ft ftVar) {
        int i = 0;
        for (c cVar : ftVar.A()) {
            int i2 = i;
            for (int i3 = 0; i3 < cVar.h(); i3++) {
                if (cVar.m(i3) == 1 && n.f(cVar.i(), i3).equals(str3) && cVar.j(i3).c().equals(str)) {
                    if (str2 != null) {
                        cVar.b(i3, str2);
                    }
                    i2++;
                }
            }
            i = i2;
        }
        return i;
    }

    public void a(fx fxVar) {
        fx l;
        String n = fxVar.n();
        for (gb gbVar : this.l.values()) {
            if (gbVar.j(fxVar.z()) && (l = gbVar.l(fxVar.z())) != fxVar && l.w() && l.n().equals(n)) {
                gbVar.a(fxVar.p());
            }
        }
    }

    public List<gb> z() {
        ArrayList arrayList = new ArrayList();
        for (gb gbVar : this.l.values()) {
            if (gbVar.S()) {
                arrayList.add(gbVar);
            }
        }
        return arrayList;
    }

    private int aa() {
        while (true) {
            f13386f++;
            if (!this.l.containsKey(Integer.valueOf(f13386f)) && !this.m.containsKey(Integer.valueOf(f13386f))) {
                return f13386f;
            }
        }
    }

    public String a(gb gbVar, Context context, boolean z, com.joaomgcd.taskerm.f.g gVar) {
        ft b2;
        Resources resources = context.getResources();
        StringBuilder sb = new StringBuilder();
        String m = gbVar.n() ? gbVar.m() : ct.b(resources, R.string.word_anon_short, new Object[0]);
        sb.append(ct.b(resources, R.string.word_profile, new Object[0]));
        sb.append(": ");
        sb.append(m);
        String aa = gbVar.aa();
        if (aa.length() > 0) {
            sb.append("\n");
            sb.append(resources.getString(R.string.word_settings));
            sb.append(": ");
            sb.append(aa);
        }
        sb.append("\n");
        sb.append(gbVar.b(context, false, true, true));
        sb.append("\n\n");
        for (int i = 0; i < 2; i++) {
            if (gbVar.k(i) && (b2 = b(gbVar, i)) != null) {
                sb.append("\n\n");
                sb.append(a(resources, b2, i));
                if (z) {
                    sb.append(a(resources, b2));
                }
            }
        }
        return gbVar.a(context, sb.toString(), gVar);
    }

    public String a(Context context, ft ftVar, Resources resources, com.joaomgcd.taskerm.f.g gVar) {
        return ftVar.a(context, a(resources, ftVar, -1) + a(resources, ftVar), gVar);
    }

    @Override
    public du.e a(String str, String str2) {
        return this.n.get(str).j(str2).t();
    }

    @Override
    public List<String> c(String str, int i) {
        return this.n.get(str).m(i);
    }

    public String a(dt dtVar, Resources resources) {
        return dtVar.e(resources);
    }

    private String a(Resources resources, ft ftVar) {
        String a2 = ftVar.a(resources, false);
        if (a2.length() > 0) {
            a2 = "\n" + a2;
        }
        return (a2 + "\n") + ftVar.a(resources, 9999, true);
    }

    public String a(Resources resources, ft ftVar, int i) {
        String m = ftVar.n() ? ftVar.m() : ct.b(resources, R.string.word_anon_short, new Object[0]);
        String string = resources.getString(R.string.word_task);
        if (i != -1) {
            string = ft.a(resources, i) + " " + string;
        }
        return string + ": " + m;
    }

    public String a(Context context, com.joaomgcd.taskerm.f.g gVar) {
        Resources resources = context.getResources();
        StringBuffer stringBuffer = new StringBuffer();
        for (Integer num : gs.a(this.l.keySet())) {
            stringBuffer.append(a(this.l.get(num), context, false, gVar));
            stringBuffer.append("\n\n");
        }
        Iterator<dt> it = b(-2, dt.f.Alpha, true).iterator();
        while (it.hasNext()) {
            stringBuffer.append(a(it.next(), resources));
            stringBuffer.append('\n');
        }
        for (Integer num2 : gs.a(this.m.keySet())) {
            stringBuffer.append(a(context, this.m.get(num2), resources, gVar));
            stringBuffer.append('\n');
        }
        return stringBuffer.toString();
    }

    public fy g(Context context) {
        fy fyVar = new fy();
        fyVar.a(context, a(0), false);
        a(fyVar.j);
        b(fyVar.k);
        c(fyVar.i);
        return this;
    }

    public boolean a(Context context, SharedPreferences sharedPreferences, Resources resources, long j, boolean z, boolean z2) {
        boolean z3;
        boolean z4;
        synchronized (f13381a[a.Passive.ordinal()]) {
            synchronized (f13382b) {
                z3 = false;
                try {
                } catch (OutOfMemoryError unused) {
                    gs.d(context, R.string.oom, new Object[0]);
                    bo.d("TD", "spdaa: oom");
                }
                if (!this.g && !z) {
                    z4 = false;
                    if (a(context, "autobackup.xml", Boolean.valueOf(z)) != null) {
                        if (z4) {
                            gs.c(context, R.string.warn_write_datafile, new Object[0]);
                            if (z3) {
                                synchronized (f13381a[a.Active.ordinal()]) {
                                    bo.b("TD", "this -> active");
                                    a(a.Active, this);
                                    if (z2) {
                                        bo.b("TD", "remove passive");
                                        a(a.Passive, true);
                                    }
                                    com.joaomgcd.taskerm.profile.i.a(context);
                                    com.joaomgcd.taskerm.action.d.b();
                                }
                            }
                        }
                    } else if (j != -1) {
                        if (Settings.j(context)) {
                            new GenericActionBackupToGoogleDriveWhenConnectedAndCharging().runDontTrackProgress(context);
                        }
                        MyBackupAgent.a(context);
                        String a2 = a(j, System.currentTimeMillis());
                        File a3 = a(context.getPackageManager(), sharedPreferences, resources, a2);
                        if (a3 != null) {
                            File file = new File(a3, "userbackup.xml");
                            if (a(context, new File(b(true), a2), "userbackup.xml", 36, com.joaomgcd.taskerm.settings.ai.c(context))) {
                                bo.b("TD", "auto-backup made to " + file);
                            } else {
                                bo.d("TD", "failed to make auto-backup to " + file);
                            }
                        }
                    }
                    z3 = true;
                    if (z3) {
                    }
                }
                z4 = true;
                if (a(context, "autobackup.xml", Boolean.valueOf(z)) != null) {
                }
                z3 = true;
                if (z3) {
                }
            }
        }
        return z3;
    }

    public boolean v(int i) {
        for (gb gbVar : this.l.values()) {
            if (gbVar.h() && (gbVar.n(0) == i || gbVar.n(1) == i)) {
                return true;
            }
        }
        return false;
    }

    public List<fx> w(int i) {
        ArrayList arrayList = new ArrayList();
        Iterator<gb> it = a((Object[]) null, i).iterator();
        while (it.hasNext()) {
            fx l = it.next().l(i);
            if (l.z() == i) {
                arrayList.add(l);
            }
        }
        return arrayList;
    }

    public List<String> x(int i) {
        ArrayList arrayList = new ArrayList();
        for (fx fxVar : w(i)) {
            if (fxVar.w()) {
                String n = fxVar.n();
                if (!arrayList.contains(n)) {
                    arrayList.add(n);
                }
            }
        }
        return arrayList;
    }

    public int A() {
        return this.o.size();
    }

    public dm p(String str) {
        for (dm dmVar : this.o) {
            if (dmVar.m().equals(str)) {
                return dmVar;
            }
        }
        return null;
    }

    public Integer q(String str) {
        Iterator<dm> it = this.o.iterator();
        int i = 0;
        while (it.hasNext()) {
            if (it.next().m().equals(str)) {
                return Integer.valueOf(i);
            }
            i++;
        }
        return null;
    }

    @Override
    public String y(int i) {
        return this.o.get(i).m();
    }

    @Override
    public dm z(int i) {
        return this.o.get(i);
    }

    public dm a(int i, String str) {
        if (i >= this.o.size()) {
            bo.d("TD", "getProject: " + str + ": bad index " + i + " size: " + this.o.size());
            return null;
        }
        return this.o.get(i);
    }

    public final List<dm> B() {
        return this.o;
    }

    public void a(int i, g gVar) {
        this.o.get(i).a(gVar);
        t();
    }

    public void b(int i, String str) {
        this.o.get(i).a(str);
        t();
    }

    public void a(int i, gb.b bVar) {
        List<dm> list = this.o;
        if (list == null) {
            return;
        }
        try {
            list.get(i).a(bVar);
        } catch (Throwable th) {
            bo.b("TD", "setProjectProfileSort", th);
        }
        t();
    }

    public void c(int i, ft.c cVar) {
        this.o.get(i).a(cVar);
        t();
    }

    public void a(int i, dt.f fVar) {
        try {
            this.o.get(i).a(fVar);
            t();
        } catch (Throwable th) {
            bo.b("TD", "setProjectSceneSort", th);
        }
    }

    public void a(int i, int i2) {
        bo.b("TD", "moveProject: " + i + " -> " + i2);
        this.o.add(i2, this.o.remove(i));
        t();
    }

    public boolean a(PackageManager packageManager, String str, boolean z) {
        for (int i = 0; i < this.o.size(); i++) {
            if (str.equals(this.o.get(i).m())) {
                a(packageManager, i, z);
                return true;
            }
        }
        return false;
    }

    public void a(PackageManager packageManager, int i, boolean z) {
        bo.b("TD", "delete project: " + i);
        HashSet hashSet = new HashSet();
        if (z) {
            Iterator<Integer> it = this.o.get(i).q().iterator();
            while (it.hasNext()) {
                int intValue = it.next().intValue();
                Iterator<Integer> it2 = m(intValue).iterator();
                while (it2.hasNext()) {
                    if (t(it2.next().intValue()) != i) {
                        hashSet.add(Integer.valueOf(intValue));
                    }
                }
            }
        }
        dm remove = this.o.remove(i);
        dm dmVar = this.o.get(0);
        Iterator<Integer> it3 = remove.p().iterator();
        while (it3.hasNext()) {
            int intValue2 = it3.next().intValue();
            if (z) {
                p(intValue2);
            } else {
                dmVar.e(intValue2);
            }
        }
        Iterator<Integer> it4 = remove.q().iterator();
        while (it4.hasNext()) {
            int intValue3 = it4.next().intValue();
            if (z && !hashSet.contains(Integer.valueOf(intValue3))) {
                o(intValue3);
            } else {
                dmVar.d(intValue3);
            }
        }
        for (String str : remove.r()) {
            if (z) {
                b(packageManager, str);
            } else {
                dmVar.c(str);
            }
        }
        t();
    }

    public void a(dm dmVar) {
        this.o.add(dmVar);
        t();
    }

    public ay a(Context context, PackageManager packageManager, File file) {
        ay ayVar = new ay();
        fy fyVar = new fy();
        bo.b("TD", "read import data");
        if (file == null) {
            bo.d("TD", "importProject: null file path");
            ayVar.f12148b = R.string.err_profile_import_failed_read_data;
            return ayVar;
        }
        if (!file.exists()) {
            bo.d("TD", "importProject: path doesn't exist: " + file);
            ayVar.f12148b = R.string.err_profile_import_failed_read_data;
            return ayVar;
        }
        if (fyVar.a(context, file.getParentFile(), file.getName(), true, true)) {
            return a(packageManager, fyVar);
        }
        ayVar.f12148b = R.string.err_profile_import_failed_read_data;
        return ayVar;
    }

    private ay a(PackageManager packageManager, fy fyVar) {
        ay ayVar = new ay();
        int A = fyVar.A();
        if (A == 0) {
            ayVar.f12148b = R.string.f_import_no_enities;
            ayVar.f12147a = R.string.word_profile;
        } else if (A == 1) {
            dm z = fyVar.z(0);
            ayVar.f12149c = z;
            bo.b("TD", "import project " + z.m());
            if (!r(z.m())) {
                fyVar.r(0);
                Set<Integer> v = z.v();
                Set<String> x = z.x();
                Set<Integer> w = z.w();
                HashMap hashMap = new HashMap();
                bo.b("TD", "project contents: " + v.size() + " tasks, " + z.p().size() + " profiles, " + z.r().size() + " scenes");
                z.u();
                int A2 = A();
                a(z);
                Iterator<Integer> it = v.iterator();
                while (true) {
                    if (!it.hasNext()) {
                        break;
                    }
                    int intValue = it.next().intValue();
                    bo.b("TD", "handle task import: " + intValue);
                    if (fyVar.i(intValue)) {
                        ft j = fyVar.j(intValue);
                        int G = j.G();
                        ay b2 = b(j, A2);
                        if (!ayVar.a(b2)) {
                            break;
                        }
                        int G2 = ((ft) b2.f12149c).G();
                        if (G != G2) {
                            hashMap.put(Integer.valueOf(G), Integer.valueOf(G2));
                            bo.b("TD", "task ID remap: " + G + " -> " + G2);
                        }
                    } else {
                        bo.d("TD", "project refers to non-existent task ID " + intValue);
                        ayVar.f12148b = R.string.f_project_import_data_error;
                        break;
                    }
                }
                if (!ayVar.a()) {
                    Iterator<Integer> it2 = w.iterator();
                    while (true) {
                        if (!it2.hasNext()) {
                            break;
                        }
                        int intValue2 = it2.next().intValue();
                        bo.b("TD", "handle profile import: " + intValue2);
                        if (fyVar.l(intValue2)) {
                            gb k = fyVar.k(intValue2);
                            k.a(aa(), "impProj");
                            k.ab();
                            k.k();
                            k.a(hashMap);
                            a(k, A2);
                        } else {
                            bo.d("TD", "project refers to non-existing profile ID " + intValue2);
                            ayVar.f12148b = R.string.f_project_import_data_error;
                            break;
                        }
                    }
                }
                if (!ayVar.a()) {
                    Iterator<String> it3 = x.iterator();
                    while (true) {
                        if (!it3.hasNext()) {
                            break;
                        }
                        String next = it3.next();
                        bo.b("TD", "handle scene import" + next);
                        if (fyVar.t(next)) {
                            dt u = fyVar.u(next);
                            u.a(hashMap);
                            if (!ayVar.a(b(u, A2))) {
                                break;
                            }
                        } else {
                            bo.d("TD", "project refers to non-existent scene " + next);
                            ayVar.f12148b = R.string.f_project_import_data_error;
                            break;
                        }
                    }
                }
                if (ayVar.a()) {
                    bo.d("TD", "project import failed, tidy up");
                    a(packageManager, A2, true);
                } else {
                    t();
                }
            } else {
                ayVar.f12148b = R.string.f_project_already_exists;
            }
        } else {
            ayVar.f12148b = R.string.f_import_more_than_one;
            ayVar.f12147a = R.string.word_profile;
        }
        return ayVar;
    }

    public void b(int i, int i2) {
        if (this.o.size() != 0) {
            if (i2 >= 0) {
                this.o.get(i2).d(i);
                return;
            }
            return;
        }
        bo.d("TD", "addTaskToProject: proj: " + i2 + " task: " + i + " no projects...");
    }

    public void c(int i, int i2) {
        if (i2 >= 0) {
            this.o.get(i2).e(i);
            t();
        }
    }

    public void d(String str, int i) {
        if (i >= 0) {
            this.o.get(i).c(str);
            t();
        }
    }

    public void a(int i, int i2, int i3) {
        this.o.get(i2).b(i, i3);
        t();
    }

    public void b(int i, int i2, int i3) {
        this.o.get(i2).c(i, i3);
        t();
    }

    public void a(String str, int i, int i2) {
        this.o.get(i).a(str, i2);
        t();
    }

    public void d(int i, int i2) {
        if (i >= 0) {
            this.o.get(i).b(i2);
            t();
        }
    }

    public void e(int i, int i2) {
        if (i >= 0) {
            this.o.get(i).c(i2);
            t();
        }
    }

    public void c(int i, String str) {
        if (i >= 0) {
            this.o.get(i).b(str);
            t();
        }
    }

    public List<Integer> A(int i) {
        if (i < this.o.size() && i >= 0) {
            return this.o.get(i).p();
        }
        bo.d("TD", "getPIDSInProject: bad index: " + i + " size " + this.o.size());
        return new ArrayList();
    }

    public List<gb> B(int i) {
        ArrayList arrayList = new ArrayList();
        if (i == -2) {
            for (gb gbVar : this.l.values()) {
                if (gbVar != null) {
                    arrayList.add(gbVar);
                }
            }
        } else {
            Iterator<Integer> it = A(i).iterator();
            while (it.hasNext()) {
                gb k = k(it.next().intValue());
                if (k != null) {
                    arrayList.add(k);
                }
            }
        }
        return arrayList;
    }

    public boolean r(String str) {
        return s(str) != -1;
    }

    public int s(String str) {
        Iterator<dm> it = this.o.iterator();
        int i = 0;
        while (it.hasNext()) {
            if (it.next().m().equals(str)) {
                return i;
            }
            i++;
        }
        return -1;
    }

    @Override
    public boolean t(String str) {
        return this.n.containsKey(str);
    }

    public dt u(String str) {
        return this.n.get(str);
    }

    public void b(PackageManager packageManager, String str) {
        dt remove = this.n.remove(str);
        if (remove == null) {
            bo.c("TD", "deleteScene: unknown scene " + str);
        } else {
            Iterator<dm> it = this.o.iterator();
            while (it.hasNext()) {
                it.next().b(str);
            }
            Iterator<Integer> it2 = remove.e(true).iterator();
            while (it2.hasNext()) {
                int intValue = it2.next().intValue();
                if (i(intValue) && !j(intValue).n()) {
                    o(intValue);
                }
            }
        }
        t();
    }

    public void a(dt dtVar, int i) {
        this.n.put(dtVar.m(), dtVar);
        if (i >= 0) {
            this.o.get(i).c(dtVar.m());
        }
        t();
    }

    public void C() {
        Iterator<gb> it = this.l.values().iterator();
        LinkedList linkedList = null;
        while (true) {
            if (!it.hasNext()) {
                break;
            }
            gb next = it.next();
            for (int i = 0; i <= 1; i++) {
                if (next.k(i)) {
                    int n = next.n(i);
                    if (!this.m.containsKey(Integer.valueOf(n))) {
                        bo.d("TD", "profile " + next.K() + " refers to missing task " + n + ", correcting");
                        next.a(i, -1);
                        t();
                    }
                }
            }
            if (next.M() == 0) {
                bo.d("TD", "profile " + next.K() + " no tasks, delete");
                if (linkedList == null) {
                    linkedList = new LinkedList();
                }
                linkedList.add(Integer.valueOf(next.K()));
            }
        }
        if (linkedList != null) {
            Iterator it2 = linkedList.iterator();
            while (it2.hasNext()) {
                int intValue = ((Integer) it2.next()).intValue();
                bo.d("TD", "delete profile " + intValue);
                p(intValue);
            }
            t();
        }
        for (dt dtVar : this.n.values()) {
            Iterator<Integer> it3 = dtVar.e(false).iterator();
            while (it3.hasNext()) {
                int intValue2 = it3.next().intValue();
                if (!this.m.containsKey(Integer.valueOf(intValue2))) {
                    bo.d("TD", "scene " + dtVar.m() + " refers to missing task " + intValue2 + ", correcting");
                    dtVar.n(intValue2);
                    t();
                }
            }
        }
    }

    public boolean e(boolean z) {
        boolean z2;
        Iterator<String> it;
        Iterator<Integer> it2;
        Iterator<Integer> it3;
        Iterator<String> it4;
        Iterator<Integer> it5;
        Iterator<dm> it6;
        HashSet<String> hashSet = new HashSet();
        HashSet hashSet2 = new HashSet();
        HashSet hashSet3 = new HashSet();
        HashSet hashSet4 = new HashSet();
        HashSet hashSet5 = new HashSet();
        HashSet hashSet6 = new HashSet();
        HashSet<String> hashSet7 = new HashSet();
        HashSet hashSet8 = new HashSet();
        HashSet hashSet9 = new HashSet();
        Iterator<dm> it7 = this.o.iterator();
        boolean z3 = false;
        while (it7.hasNext()) {
            dm next = it7.next();
            Iterator<Integer> it8 = next.w().iterator();
            while (it8.hasNext()) {
                int intValue = it8.next().intValue();
                if (hashSet2.contains(Integer.valueOf(intValue))) {
                    StringBuilder sb = new StringBuilder();
                    it6 = it7;
                    sb.append("cafp: profile ID ");
                    sb.append(intValue);
                    sb.append(" reffed in multiple projects (fixed)");
                    bo.a("TD", z, sb.toString());
                    next.b(intValue);
                    z3 = true;
                } else {
                    it6 = it7;
                    hashSet2.add(Integer.valueOf(intValue));
                }
                it7 = it6;
            }
            Iterator<dm> it9 = it7;
            Iterator<Integer> it10 = next.v().iterator();
            boolean z4 = z3;
            while (it10.hasNext()) {
                int intValue2 = it10.next().intValue();
                if (hashSet3.contains(Integer.valueOf(intValue2))) {
                    StringBuilder sb2 = new StringBuilder();
                    it5 = it10;
                    sb2.append("cafp: task ID ");
                    sb2.append(intValue2);
                    sb2.append(" reffed in multiple projects (fixed)");
                    bo.a("TD", z, sb2.toString());
                    next.c(intValue2);
                    z4 = true;
                } else {
                    it5 = it10;
                    hashSet3.add(Integer.valueOf(intValue2));
                }
                it10 = it5;
            }
            Iterator<String> it11 = next.x().iterator();
            z3 = z4;
            while (it11.hasNext()) {
                String next2 = it11.next();
                if (hashSet.contains(next2)) {
                    StringBuilder sb3 = new StringBuilder();
                    it4 = it11;
                    sb3.append("cafp: scene ");
                    sb3.append(next2);
                    sb3.append(" reffed in multiple projects (fixed)");
                    bo.a("TD", z, sb3.toString());
                    next.b(next2);
                    z3 = true;
                } else {
                    it4 = it11;
                    hashSet.add(next2);
                }
                it11 = it4;
            }
            it7 = it9;
        }
        Iterator<Integer> it12 = this.l.keySet().iterator();
        while (it12.hasNext()) {
            int intValue3 = it12.next().intValue();
            if (hashSet2.contains(Integer.valueOf(intValue3))) {
                it3 = it12;
            } else {
                gb gbVar = this.l.get(Integer.valueOf(intValue3));
                StringBuilder sb4 = new StringBuilder();
                it3 = it12;
                sb4.append("cafp: fixed: unfiled profile: ");
                sb4.append(gbVar.K());
                bo.a("TD", z, sb4.toString());
                this.o.get(0).e(intValue3);
                z3 = true;
            }
            hashSet5.add(Integer.valueOf(intValue3));
            it12 = it3;
        }
        Map<String, Integer> map = this.h;
        if (map != null) {
            Iterator<Integer> it13 = map.values().iterator();
            z2 = z3;
            while (it13.hasNext()) {
                int intValue4 = it13.next().intValue();
                if (hashSet3.contains(Integer.valueOf(intValue4))) {
                    it2 = it13;
                } else {
                    ft ftVar = this.m.get(Integer.valueOf(intValue4));
                    if (ftVar != null) {
                        StringBuilder sb5 = new StringBuilder();
                        it2 = it13;
                        sb5.append("cafp: fixed: unfiled named task: ");
                        sb5.append(ftVar.G());
                        bo.a("TD", z, sb5.toString());
                        this.o.get(0).d(intValue4);
                    } else {
                        it2 = it13;
                    }
                    z2 = true;
                }
                hashSet6.add(Integer.valueOf(intValue4));
                it13 = it2;
            }
        } else {
            z2 = z3;
        }
        Iterator<String> it14 = this.n.keySet().iterator();
        while (it14.hasNext()) {
            String next3 = it14.next();
            if (hashSet.contains(next3)) {
                it = it14;
            } else {
                dt dtVar = this.n.get(next3);
                StringBuilder sb6 = new StringBuilder();
                it = it14;
                sb6.append("cafp: fixed: unfiled scene: ");
                sb6.append(dtVar.m());
                bo.a("TD", z, sb6.toString());
                this.o.get(0).c(next3);
                z2 = true;
            }
            hashSet4.add(next3);
            it14 = it;
        }
        Iterator it15 = hashSet2.iterator();
        while (it15.hasNext()) {
            int intValue5 = ((Integer) it15.next()).intValue();
            if (!hashSet5.contains(Integer.valueOf(intValue5))) {
                hashSet8.add(Integer.valueOf(intValue5));
            }
        }
        Iterator it16 = hashSet3.iterator();
        while (it16.hasNext()) {
            int intValue6 = ((Integer) it16.next()).intValue();
            if (!hashSet6.contains(Integer.valueOf(intValue6))) {
                hashSet9.add(Integer.valueOf(intValue6));
            }
        }
        for (String str : hashSet) {
            if (!hashSet4.contains(str)) {
                hashSet7.add(str);
            }
        }
        Iterator it17 = hashSet8.iterator();
        while (it17.hasNext()) {
            int intValue7 = ((Integer) it17.next()).intValue();
            Iterator<dm> it18 = this.o.iterator();
            while (it18.hasNext()) {
                it18.next().b(intValue7);
            }
            bo.a("TD", z, "cafp: fixed: unknown project profile(s): " + intValue7);
            z2 = true;
        }
        Iterator it19 = hashSet9.iterator();
        while (it19.hasNext()) {
            int intValue8 = ((Integer) it19.next()).intValue();
            for (dm dmVar : this.o) {
                dmVar.c(intValue8);
                bo.d("TD", "remove task ID " + intValue8 + " from project " + dmVar.m() + " remaining " + dmVar.D());
            }
            bo.a("TD", z, "cafp: fixed: unknown project task(s): " + intValue8);
            z2 = true;
        }
        for (String str2 : hashSet7) {
            Iterator<dm> it20 = this.o.iterator();
            while (it20.hasNext()) {
                it20.next().b(str2);
            }
            bo.a("TD", z, "cafp: fixed: unknown project scene(s): " + str2);
            z2 = true;
        }
        if (z2) {
            t();
        }
        return true ^ z2;
    }

    public void c(Context context, boolean z) {
        if (A() == 0) {
            j(context);
        } else {
            if (!z || e(true)) {
                return;
            }
            bo.d("TD", "initProjects: project integrity failure");
        }
    }

    private void j(Context context) {
        SharedPreferences g = gs.g(context);
        dm dmVar = new dm(dm.a(context));
        dmVar.a(gb.b.values()[g.getInt("pSr", bh.j.b.f12232b)]);
        dmVar.a(new g(context.getResources(), go.c(context, R.attr.iconBaseProject)));
        g.edit().remove("pSr").commit();
        a(dmVar);
        e(false);
    }

    public fy a(gb gbVar) {
        fy fyVar = new fy();
        for (int i : gbVar.ac()) {
            fyVar.a(j(i), -1);
        }
        fyVar.a(gbVar, -1);
        return fyVar;
    }

    public fy c(ft ftVar) {
        fy fyVar = new fy();
        fyVar.a(ftVar, -1);
        return fyVar;
    }

    public fy a(dt dtVar) {
        fy fyVar = new fy();
        fyVar.a(dtVar, -1);
        Iterator<Integer> it = dtVar.e(false).iterator();
        while (it.hasNext()) {
            int intValue = it.next().intValue();
            if (i(intValue)) {
                fyVar.a(j(intValue));
            } else {
                bo.d("TD", "scene " + dtVar.m() + " refs non-existent tid " + intValue);
            }
        }
        return fyVar;
    }

    public fy a(PackageManager packageManager, dm dmVar) {
        fy fyVar = new fy();
        dm dmVar2 = new dm(dmVar.a(2));
        dmVar2.u();
        fyVar.a(dmVar2);
        for (dr drVar : dmVar.a(packageManager, this)) {
            if (drVar.e() && a(drVar)) {
                fyVar.a(b(drVar), 0);
                if (drVar.b() == dr.a.Task && drVar.a()) {
                    fyVar.b(drVar.d(), 0);
                }
            }
        }
        return fyVar;
    }

    public void a(dt dtVar, String str) {
        String m = dtVar.m();
        for (dm dmVar : this.o) {
            if (dmVar.b(m) != -1) {
                dmVar.c(str);
            }
        }
        Iterator<ft> it = this.m.values().iterator();
        while (it.hasNext()) {
            Iterator<c> it2 = it.next().A().iterator();
            while (it2.hasNext()) {
                it2.next().a(m, str);
            }
        }
        for (dt dtVar2 : this.n.values()) {
            if (!dtVar2.m().equals(m)) {
                dtVar2.d(m, str);
            }
        }
        this.n.remove(m);
        dtVar.a(str);
        this.n.put(str, dtVar);
    }

    @Override
    public boolean a(dr drVar) {
        return b(drVar) != null;
    }

    public ai b(dr drVar) {
        switch (drVar.b()) {
            case Profile:
                return drVar.a() ? k(drVar.d()) : l(drVar.c());
            case Task:
                return drVar.a() ? j(drVar.d()) : i(drVar.c());
            case Scene:
                return u(drVar.c());
            default:
                bo.c("TD", "getEntity: bad type: " + drVar.b());
                return null;
        }
    }

    public void a(ai aiVar, int i) {
        switch (aiVar.d()) {
            case Profile:
                a((gb) aiVar, i);
                return;
            case Task:
                a((ft) aiVar, i);
                return;
            case Scene:
                a((dt) aiVar, i);
                return;
            default:
                bo.c("TD", "addEntity: bad type: " + aiVar.d());
                return;
        }
    }

    public boolean d(ft ftVar) {
        return ftVar.n() && u(ftVar.G()) == -1;
    }

    public void a(ai aiVar) {
        if (aiVar == null) {
            bo.d("TD", "resetEntityEditDate: null entity");
        } else {
            aiVar.p();
            t();
        }
    }

    public void D() {
        Iterator<gb> it = this.l.values().iterator();
        while (it.hasNext()) {
            it.next().a(false);
        }
        Iterator<ft> it2 = this.m.values().iterator();
        while (it2.hasNext()) {
            it2.next().a(false);
        }
        Iterator<dt> it3 = this.n.values().iterator();
        while (it3.hasNext()) {
            it3.next().a(false);
        }
    }

    @Override
    public void a(PackageManager packageManager) {
        for (dm dmVar : this.o) {
            if (dmVar.A()) {
                e(dmVar.a(packageManager, this));
            }
        }
        for (gb gbVar : this.l.values()) {
            if (gbVar.h()) {
                e(gbVar.a(packageManager, this));
            }
        }
        for (ft ftVar : this.m.values()) {
            if (ftVar.h()) {
                e(ftVar.a(packageManager, this));
            }
        }
        for (dt dtVar : this.n.values()) {
            if (dtVar.h()) {
                e(dtVar.a(packageManager, this));
            }
        }
    }

    private void e(Set<dr> set) {
        ai b2;
        for (dr drVar : set) {
            if (drVar.e() && (b2 = b(drVar)) != null) {
                b2.a(true);
            }
        }
    }

    public void a(PackageManager packageManager, ai.a... aVarArr) {
        int length = aVarArr.length;
        for (int i = 0; i < length; i++) {
            switch (aVarArr[i]) {
                case Profile:
                    Iterator<gb> it = this.l.values().iterator();
                    while (it.hasNext()) {
                        it.next().a(packageManager, (fz) this);
                    }
                    break;
                case Task:
                    Iterator<ft> it2 = this.m.values().iterator();
                    while (it2.hasNext()) {
                        it2.next().a(packageManager, (fz) this);
                    }
                    break;
                case Scene:
                    Iterator<dt> it3 = this.n.values().iterator();
                    while (it3.hasNext()) {
                        it3.next().a(packageManager, (fz) this);
                    }
                    break;
            }
        }
    }

    @Override
    public boolean v(String str) {
        dt u = u(str);
        return u != null && u.ag();
    }

    public boolean a(int i, du.e eVar) {
        Iterator<dt> it = b(i, true).iterator();
        while (it.hasNext()) {
            if (it.next().b(eVar)) {
                return true;
            }
        }
        return false;
    }

    @Override
    public boolean a(String str, String str2, boolean z) {
        dt u = u(str);
        if (u == null) {
            return false;
        }
        if (z) {
            List<du> i = u.i(str2);
            return i != null && i.size() > 0;
        }
        return u.k(str2);
    }

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

    public boolean C(int i) {
        dm z = z(i);
        z.a(!z.A());
        t();
        return z.A();
    }

    @Override
    public boolean x(String str) {
        if (t(str)) {
            return u(str).i();
        }
        return false;
    }

    @Override
    public dt y(String str) {
        if (this.n.containsKey(str)) {
            return this.n.get(str).B();
        }
        bo.c("TD", "getSceneCopy: unknown scene: " + str);
        return null;
    }

    @Override
    public g z(String str) {
        if (j(str)) {
            return i(str).f().u();
        }
        return null;
    }

    public int D(int i) {
        return this.o.get(i).h();
    }

    public void h(Context context) {
        if (this.m == null) {
            bo.c("TD", "cabscat: null tasks");
            return;
        }
        Iterator<ft> it = this.m.values().iterator();
        while (it.hasNext()) {
            a(context, it.next());
        }
    }

    public boolean a(Context context, ft ftVar) {
        if (ftVar == null) {
            bo.c("TD", "cabsct: null task");
            return false;
        }
        List<c> A = ftVar.A();
        if (A == null) {
            return false;
        }
        boolean z = false;
        for (c cVar : A) {
            int i = cVar.i();
            int P = n.P(i);
            if (P != -1) {
                String c2 = cVar.j(P).c();
                String[] v = n.v(i, P);
                int length = v.length;
                int i2 = 0;
                while (true) {
                    if (i2 >= length) {
                        break;
                    }
                    if (c2.equals(v[i2]) && !t(c2)) {
                        a(n.a(context, c2), 0);
                        z = true;
                        break;
                    }
                    i2++;
                }
            }
        }
        return z;
    }

    public void E() {
        HashSet hashSet = new HashSet();
        Iterator<gb> it = this.l.values().iterator();
        while (true) {
            if (!it.hasNext()) {
                break;
            }
            for (int i : it.next().ac()) {
                ft j = j(i);
                if (j != null && !j.n()) {
                    hashSet.add(Integer.valueOf(i));
                }
            }
        }
        Iterator<dt> it2 = this.n.values().iterator();
        while (it2.hasNext()) {
            Iterator<Integer> it3 = it2.next().e(false).iterator();
            while (it3.hasNext()) {
                int intValue = it3.next().intValue();
                ft j2 = j(intValue);
                if (j2 != null && !j2.n()) {
                    hashSet.add(Integer.valueOf(intValue));
                }
            }
        }
        ArrayList arrayList = null;
        for (ft ftVar : this.m.values()) {
            if (!ftVar.n() && !hashSet.contains(Integer.valueOf(ftVar.G()))) {
                if (arrayList == null) {
                    arrayList = new ArrayList();
                }
                arrayList.add(Integer.valueOf(ftVar.G()));
            }
        }
        if (arrayList != null) {
            Iterator it4 = arrayList.iterator();
            while (it4.hasNext()) {
                int intValue2 = ((Integer) it4.next()).intValue();
                bo.b("TD", "removing orphan anonymous task " + intValue2);
                o(intValue2);
            }
        }
    }

    @Override
    public String E(int i) {
        if (i(i)) {
            return j(i).l();
        }
        return null;
    }

    @Override
    public int A(String str) {
        if (j(str)) {
            return i(str).G();
        }
        return -1;
    }

    public boolean F(int i) {
        return w(i).size() > 0;
    }

    public HashMap<String, String> a(PackageManager packageManager, boolean z) {
        HashMap<String, String> hashMap = new HashMap<>();
        Iterator<ft> it = this.m.values().iterator();
        while (it.hasNext()) {
            for (av avVar : it.next().A()) {
                if (n.s(avVar.i())) {
                    a(avVar, di.a.Action, 1, 2, hashMap, z);
                }
            }
        }
        for (gb gbVar : this.l.values()) {
            for (int i = 0; i < gbVar.H(); i++) {
                fx d2 = gbVar.d(i);
                int z2 = d2.z();
                if (z2 >= 4 && z2 <= 6) {
                    av avVar2 = (fp) d2;
                    if (fo.b(avVar2.i())) {
                        a(avVar2, di.a.Condition, 1, 2, hashMap, z);
                    }
                } else if (z2 == 7) {
                    av avVar3 = (ao) d2;
                    if (an.q(avVar3.i())) {
                        a(avVar3, di.a.Event, 1, 2, hashMap, z);
                    }
                }
            }
        }
        return hashMap;
    }

    private void a(av avVar, di.a aVar, int i, int i2, Map<String, String> map, boolean z) {
        String c2 = avVar.j(i).c();
        String a2 = di.a(aVar, c2, avVar.j(i2).c(), "");
        boolean isEmpty = TextUtils.isEmpty(c2);
        boolean isEmpty2 = TextUtils.isEmpty(a2);
        if (z) {
            if (isEmpty2 || isEmpty) {
                map.put(c2, a2);
                return;
            }
            return;
        }
        if (isEmpty2 || isEmpty) {
            return;
        }
        map.put(c2, a2);
    }

    public boolean F() {
        Iterator<Integer> it = n.m().iterator();
        while (it.hasNext()) {
            if (e(it.next().intValue())) {
                return true;
            }
        }
        return false;
    }

    @Override
    public String G(int i) {
        gb gbVar = this.l.get(Integer.valueOf(i));
        if (gbVar != null) {
            return gbVar.m();
        }
        return null;
    }

    public void a(Context context, fb fbVar, List<fc> list) {
        Iterator<gb> it;
        Resources resources = context.getResources();
        LinkedList<fc> linkedList = new LinkedList();
        Iterator<ft> it2 = this.m.values().iterator();
        while (it2.hasNext()) {
            fc a2 = it2.next().a(resources, fbVar);
            if (a2 != null) {
                linkedList.add(a2);
            }
        }
        LinkedList linkedList2 = new LinkedList();
        Iterator<gb> it3 = this.l.values().iterator();
        while (it3.hasNext()) {
            gb next = it3.next();
            fc a3 = next.a(context, fbVar);
            int[] ac = next.ac();
            int length = ac.length;
            int i = 0;
            while (i < length) {
                int i2 = ac[i];
                Iterator it4 = linkedList.iterator();
                while (true) {
                    if (!it4.hasNext()) {
                        it = it3;
                        break;
                    }
                    fc fcVar = (fc) it4.next();
                    it = it3;
                    if (fcVar.i() == i2) {
                        if (a3 == null) {
                            a3 = next.a(resources, fbVar);
                        }
                        a3.b(fcVar);
                    } else {
                        it3 = it;
                    }
                }
                i++;
                it3 = it;
            }
            Iterator<gb> it5 = it3;
            if (a3 != null) {
                linkedList2.add(a3);
            }
            it3 = it5;
        }
        LinkedList linkedList3 = new LinkedList();
        Iterator<dt> it6 = this.n.values().iterator();
        while (it6.hasNext()) {
            fc a4 = it6.next().a(linkedList, context, fbVar);
            if (a4 != null) {
                linkedList3.add(a4);
            }
        }
        int size = this.o.size();
        if (size > 1) {
            for (int i3 = 0; i3 < size; i3++) {
                dm dmVar = this.o.get(i3);
                fc a5 = dmVar.a(resources, fbVar);
                Iterator<Integer> it7 = dmVar.q().iterator();
                while (it7.hasNext()) {
                    int intValue = it7.next().intValue();
                    int i4 = 0;
                    while (true) {
                        if (i4 < linkedList.size()) {
                            fc fcVar2 = (fc) linkedList.get(i4);
                            if (fcVar2.i() == intValue) {
                                if (a5 == null) {
                                    a5 = dmVar.b(resources, fbVar);
                                }
                                a5.b(fcVar2);
                                linkedList.remove(i4);
                            } else {
                                i4++;
                            }
                        }
                    }
                }
                Iterator<Integer> it8 = dmVar.p().iterator();
                while (it8.hasNext()) {
                    int intValue2 = it8.next().intValue();
                    int i5 = 0;
                    while (true) {
                        if (i5 < linkedList2.size()) {
                            fc fcVar3 = (fc) linkedList2.get(i5);
                            if (fcVar3.i() == intValue2) {
                                if (a5 == null) {
                                    a5 = dmVar.b(resources, fbVar);
                                }
                                a5.b(fcVar3);
                                linkedList2.remove(i5);
                            } else {
                                i5++;
                            }
                        }
                    }
                }
                for (Object obj : dmVar.r()) {
                    int i6 = 0;
                    while (true) {
                        if (i6 < linkedList3.size()) {
                            fc fcVar4 = (fc) linkedList3.get(i6);
                            if (fcVar4.h().m().equals(obj)) {
                                if (a5 == null) {
                                    a5 = dmVar.b(resources, fbVar);
                                }
                                a5.b(fcVar4);
                                linkedList3.remove(i6);
                            } else {
                                i6++;
                            }
                        }
                    }
                }
                if (a5 != null) {
                    list.add(a5);
                }
            }
        }
        list.addAll(linkedList2);
        for (fc fcVar5 : linkedList) {
            if (fcVar5.f().n()) {
                list.add(fcVar5);
            }
        }
        list.addAll(linkedList3);
    }

    @Override
    public ek.c B(String str) {
        return u(str).ax();
    }

    @Override
    public void a(Context context, int i, HashMap<String, String> hashMap) {
        for (ft ftVar : this.m.values()) {
            if (ftVar.G() != i) {
                ftVar.a(context, -1, false, hashMap);
            }
        }
    }

    public void G() {
        for (gb gbVar : B(-2)) {
            gbVar.G();
            gbVar.h(false);
        }
    }

    public HashMap<String, List<String>> a(Context context, Set<String> set, boolean z) {
        return b(context, set, z, false);
    }

    public HashMap<String, List<String>> b(Context context, Set<String> set, boolean z, boolean z2) {
        int l;
        HashMap<String, List<String>> hashMap = new HashMap<>();
        Settings.a(context, hashMap);
        HashSet hashSet = new HashSet();
        HashSet hashSet2 = new HashSet();
        PackageManager packageManager = context.getPackageManager();
        if (Kid.a(context) && (l = z(0).C().l()) != -1) {
            hashSet.add(Integer.valueOf(l));
        }
        Iterator<ft> it = this.m.values().iterator();
        while (it.hasNext()) {
            for (c cVar : it.next().A()) {
                if (n.N(cVar.i()) || n.O(cVar.i())) {
                    hashSet2.add(cVar.j(0).c());
                }
            }
        }
        for (gb gbVar : this.l.values()) {
            if (gbVar.S()) {
                for (int i = 0; i < gbVar.H(); i++) {
                    gbVar.d(i).a(context, hashMap);
                }
                for (int i2 : gbVar.ac()) {
                    ft j = j(i2);
                    if (j != null) {
                        if (j.n()) {
                            hashSet.add(Integer.valueOf(j.G()));
                        } else {
                            j.a(context, this, hashMap);
                            a(packageManager, j, hashSet);
                        }
                    }
                }
            }
        }
        for (dt dtVar : this.n.values()) {
            if (hashSet2.contains(dtVar.m())) {
                a(packageManager, dtVar, hashSet);
            }
        }
        for (String str : set) {
            if (this.h.containsKey(str)) {
                hashSet.add(Integer.valueOf(this.h.get(str).intValue()));
            }
        }
        for (Object obj : hashSet.toArray()) {
            Integer num = (Integer) obj;
            if (this.m.containsKey(num)) {
                a(packageManager, this.m.get(num), hashSet);
            }
        }
        for (ft ftVar : this.m.values()) {
            if (z || hashSet.contains(Integer.valueOf(ftVar.G()))) {
                ftVar.a(context, this, hashMap);
            }
        }
        for (String str2 : a(context, set, false, true, z2)) {
            if (gx.b(str2)) {
                gx.a(context, hashMap, gx.i(str2));
            }
        }
        return hashMap;
    }

    public boolean H() {
        return com.joaomgcd.taskerm.util.an.a(this, 402);
    }

    public boolean I() {
        return f(2097);
    }

    public boolean d(Context context, boolean z) {
        if (z) {
            return true;
        }
        Set<String> a2 = a(context, (Set<String>) new HashSet(), false, true);
        if (a2 == null) {
            bo.b("TD", "usesClipboardVariable Can't check variables, return true");
            return true;
        }
        return a2.contains("%CLIP");
    }

    @Override
    public void d(Set<Integer> set) {
        for (dm dmVar : this.o) {
            if (dmVar.i()) {
                set.add(Integer.valueOf(dmVar.n().x()));
            }
        }
        Iterator<ft> it = this.m.values().iterator();
        while (it.hasNext()) {
            a(it.next(), set);
        }
        for (dt dtVar : this.n.values()) {
            for (int i = 0; i < dtVar.w(); i++) {
                a(dtVar.c(i), -1, set);
            }
            ek g = dtVar.g(false);
            if (g != null) {
                a(g, -1, set);
            }
        }
    }

    public void i(Context context) {
        for (dm dmVar : B()) {
            if (dmVar.i() && go.a(context, dmVar.n())) {
                t();
            }
        }
        Iterator<ft> it = r(-2).iterator();
        while (it.hasNext()) {
            ft next = it.next();
            if (next.z() && go.a(context, next.f())) {
                t();
            }
        }
    }

    public boolean J() {
        return g(2076) || e(330);
    }

    public boolean K() {
        return e(328);
    }

    public boolean L() {
        return f(2094);
    }

    public boolean M() {
        return e(351);
    }

    public boolean N() {
        return e(368);
    }

    public boolean O() {
        return e(390);
    }

    public boolean P() {
        return a(421, 333);
    }

    public boolean Q() {
        return e(394);
    }

    public boolean R() {
        return e(366);
    }

    public boolean S() {
        return N() || a(0, du.e.MAP);
    }

    public boolean T() {
        return N() || R();
    }

    public void a(Context context, Set<String> set) {
        List<c> a2 = a(365, true);
        if (a2.size() == 0) {
            return;
        }
        Iterator<c> it = a2.iterator();
        while (it.hasNext()) {
            String[] a3 = com.joaomgcd.taskerm.action.d.c.a(context, it.next());
            if (a3 != null) {
                set.addAll(Arrays.asList(a3));
            }
        }
    }

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

    public boolean V() {
        return a(381, true).size() > 0;
    }
}