导航菜单

页面标题

页面副标题

Tasker v6.5.11 - ControlsProviderServiceTasker.java 源代码

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

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


package com.joaomgcd.taskerm.controlsprovider;

import android.app.PendingIntent;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.drawable.Icon;
import android.service.controls.Control;
import android.service.controls.ControlsProviderService;
import android.service.controls.actions.ControlAction;
import android.service.controls.templates.ControlButton;
import android.service.controls.templates.ControlTemplate;
import android.service.controls.templates.RangeTemplate;
import android.util.Log;
import androidx.annotation.Keep;
import com.joaomgcd.taskerm.action.input.PowerMenuActionType;
import com.joaomgcd.taskerm.action.input.StoredPowerMenuAction;
import com.joaomgcd.taskerm.action.input.StoredPowerMenuActions;
import com.joaomgcd.taskerm.action.input.b3;
import com.joaomgcd.taskerm.action.input.c3;
import com.joaomgcd.taskerm.action.input.l2;
import com.joaomgcd.taskerm.action.input.o2;
import com.joaomgcd.taskerm.action.input.p2;
import com.joaomgcd.taskerm.action.input.s;
import com.joaomgcd.taskerm.action.input.s2;
import com.joaomgcd.taskerm.action.input.t2;
import com.joaomgcd.taskerm.action.input.u2;
import com.joaomgcd.taskerm.action.input.v2;
import com.joaomgcd.taskerm.action.input.w2;
import com.joaomgcd.taskerm.action.input.y2;
import com.joaomgcd.taskerm.controlsprovider.ControlsProviderServiceTasker;
import com.joaomgcd.taskerm.rx.EventBusRxSubscription;
import com.joaomgcd.taskerm.util.ActivitySecondaryApp;
import com.joaomgcd.taskerm.util.ExtensionsContextKt;
import com.joaomgcd.taskerm.util.k8;
import com.joaomgcd.taskerm.util.x2;
import hk.o;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.Flow;
import java.util.function.Consumer;
import ji.r;
import lj.e0;
import net.dinglisch.android.taskerm.ExecuteService;
import net.dinglisch.android.taskerm.tn;
import net.dinglisch.android.taskerm.to;
import pg.w0;
import xj.l;
import yj.p;
import yj.q;

public final class ControlsProviderServiceTasker extends ControlsProviderService {
    private final lj.j i = lj.k.b(new f());
    private final lj.j q = lj.k.b(j.i);
    private final lj.j r = lj.k.b(k.i);
    private final lj.j s = lj.k.b(g.i);
    private Flow.Subscriber<? super Control> t;

    public class a {
        public static final int[] a;

        static {
            int[] iArr = new int[PowerMenuActionType.values().length];
            try {
                iArr[PowerMenuActionType.Button.ordinal()] = 1;
            } catch (NoSuchFieldError unused) {
            }
            try {
                iArr[PowerMenuActionType.Toggle.ordinal()] = 2;
            } catch (NoSuchFieldError unused2) {
            }
            try {
                iArr[PowerMenuActionType.Range.ordinal()] = 3;
            } catch (NoSuchFieldError unused3) {
            }
            try {
                iArr[PowerMenuActionType.ToggleRange.ordinal()] = 4;
            } catch (NoSuchFieldError unused4) {
            }
            try {
                iArr[PowerMenuActionType.NoAction.ordinal()] = 5;
            } catch (NoSuchFieldError unused5) {
            }
            a = iArr;
        }
    }

    static final class b extends q implements xj.a<RangeTemplate> {
        final String i;
        final ControlsProviderServiceTasker q;

        b(String str, ControlsProviderServiceTasker controlsProviderServiceTasker) {
            super(0);
            this.i = str;
            this.q = controlsProviderServiceTasker;
        }

        public final RangeTemplate invoke() {
            p2.a();
            String str = this.i;
            return o2.a(str, 0.0f, 100.0f, this.q.p(str), 1.0f, null);
        }
    }

    static final class c extends q implements xj.a<Bitmap> {
        final tn i;
        final ControlsProviderServiceTasker q;

        c(tn tnVar, ControlsProviderServiceTasker controlsProviderServiceTasker) {
            super(0);
            this.i = tnVar;
            this.q = controlsProviderServiceTasker;
        }

        public final Bitmap invoke() {
            net.dinglisch.android.taskerm.g icon = this.i.getIcon();
            if (icon != null) {
                return icon.y(this.q.i(), 50, 50, "ControlsProviderServiceTasker");
            }
            return null;
        }
    }

    static final class d extends q implements xj.a<e0> {
        final List<String> q;
        final Flow.Subscriber<? super Control> r;

        static final class a extends q implements xj.a<Control> {
            final StoredPowerMenuActions i;
            final String q;
            final ControlsProviderServiceTasker r;

            a(StoredPowerMenuActions storedPowerMenuActions, String str, ControlsProviderServiceTasker controlsProviderServiceTasker) {
                super(0);
                this.i = storedPowerMenuActions;
                this.q = str;
                this.r = controlsProviderServiceTasker;
            }

            public final Control invoke() {
                r control$default;
                StoredPowerMenuAction byId = this.i.byId(this.q);
                if (byId == null || (control$default = StoredPowerMenuAction.getControl$default(byId, this.r.i(), false, 2, null)) == null) {
                    return null;
                }
                return s2.a(control$default.f());
            }
        }

        public static final class b implements Flow.Subscription {
            b() {
            }

            @Override
            public void cancel() {
                Log.d("ControlTest", "cancel");
            }

            @Override
            public void request(long j) {
                Log.d("ControlTest", "request " + j);
            }
        }

        d(List<String> list, Flow.Subscriber<? super Control> subscriber) {
            super(0);
            this.q = list;
            this.r = subscriber;
        }

        public final void a() {
            StoredPowerMenuActions e = s.e(ControlsProviderServiceTasker.this);
            List<String> list = this.q;
            ControlsProviderServiceTasker controlsProviderServiceTasker = ControlsProviderServiceTasker.this;
            Flow.Subscriber<? super Control> subscriber = this.r;
            for (String str : list) {
                Control k = controlsProviderServiceTasker.k(str);
                if (k == null) {
                    k = s2.a(x2.U4((l) null, new a(e, str, controlsProviderServiceTasker), 1, (Object) null));
                }
                if (k != null) {
                    subscriber.onSubscribe(re.k.a(new b()));
                    subscriber.onNext(k);
                }
            }
            ef.i.a(ControlsProviderServiceTasker.this, false);
        }

        public Object invoke() {
            a();
            return e0.a;
        }
    }

    static final class e extends q implements xj.a<e0> {
        final Flow.Subscriber<? super Control> q;

        static final class a extends q implements xj.a<Control> {
            final StoredPowerMenuAction i;
            final ControlsProviderServiceTasker q;

            a(StoredPowerMenuAction storedPowerMenuAction, ControlsProviderServiceTasker controlsProviderServiceTasker) {
                super(0);
                this.i = storedPowerMenuAction;
                this.q = controlsProviderServiceTasker;
            }

            public final Control invoke() {
                return s2.a(this.i.getControl(this.q.i(), true).f());
            }
        }

        static final class b extends q implements l<tn, Control> {
            final ControlsProviderServiceTasker i;

            b(ControlsProviderServiceTasker controlsProviderServiceTasker) {
                super(1);
                this.i = controlsProviderServiceTasker;
            }

            public final Control invoke(tn tnVar) {
                return this.i.j(tnVar);
            }
        }

        e(Flow.Subscriber<? super Control> subscriber) {
            super(0);
            this.q = subscriber;
        }

        public final void a() {
            StoredPowerMenuActions e = s.e(ControlsProviderServiceTasker.this);
            Flow.Subscriber<? super Control> subscriber = this.q;
            ControlsProviderServiceTasker controlsProviderServiceTasker = ControlsProviderServiceTasker.this;
            Iterator<StoredPowerMenuAction> it = e.iterator();
            while (it.hasNext()) {
                Control a2 = s2.a(x2.U4((l) null, new a(it.next(), controlsProviderServiceTasker), 1, (Object) null));
                if (a2 != null) {
                    subscriber.onNext(a2);
                }
            }
            ArrayList w1 = to.u1(ControlsProviderServiceTasker.this.i()).w1();
            p.h(w1, "getAllAlphabeticallySortedNamedTasks(...)");
            gk.h u = gk.k.u(kotlin.collections.r.V(w1), new b(ControlsProviderServiceTasker.this));
            Flow.Subscriber<? super Control> subscriber2 = this.q;
            Iterator it2 = u.iterator();
            while (it2.hasNext()) {
                subscriber2.onNext(s2.a(it2.next()));
            }
            this.q.onComplete();
            ef.i.a(ControlsProviderServiceTasker.this, true);
        }

        public Object invoke() {
            a();
            return e0.a;
        }
    }

    static final class f extends q implements xj.a<Icon> {
        f() {
            super(0);
        }

        public final Icon invoke() {
            Icon createWithResource;
            createWithResource = Icon.createWithResource(ControlsProviderServiceTasker.this.i(), 2131689473);
            p.h(createWithResource, "createWithResource(...)");
            return createWithResource;
        }
    }

    static final class g extends q implements xj.a<mi.a> {
        public static final g i = new g();

        g() {
            super(0);
        }

        public final mi.a invoke() {
            return new mi.a();
        }
    }

    static final class h extends q implements xj.a<e0> {
        public static final h i = new h();

        h() {
            super(0);
        }

        public final void a() {
        }

        public Object invoke() {
            a();
            return e0.a;
        }
    }

    static final class i extends q implements l<Control, e0> {
        i() {
            super(1);
        }

        public final void a(Control control) {
            p.i(control, "it");
            Flow.Subscriber<? super Control> t = ControlsProviderServiceTasker.this.t();
            if (t != null) {
                t.onNext(control);
            }
        }

        public Object invoke(Object obj) {
            a(s2.a(obj));
            return e0.a;
        }
    }

    static final class j extends q implements xj.a<HashMap<String, Float>> {
        public static final j i = new j();

        j() {
            super(0);
        }

        public final HashMap<String, Float> invoke() {
            return new HashMap<>();
        }
    }

    static final class k extends q implements xj.a<HashMap<String, Boolean>> {
        public static final k i = new k();

        k() {
            super(0);
        }

        public final HashMap<String, Boolean> invoke() {
            return new HashMap<>();
        }
    }

    private final void A(String str, float f2) {
        v().put(str, Float.valueOf(f2));
    }

    private final void B(String str, boolean z) {
        w().put(str, Boolean.valueOf(z));
    }

    public static final void g(ControlsProviderServiceTasker controlsProviderServiceTasker, List list, Flow.Subscriber subscriber) {
        p.i(controlsProviderServiceTasker, "this$0");
        p.i(list, "$controlIds");
        controlsProviderServiceTasker.t = subscriber;
        w0.m0(controlsProviderServiceTasker.new d(list, subscriber));
    }

    public static final void h(ControlsProviderServiceTasker controlsProviderServiceTasker, Flow.Subscriber subscriber) {
        p.i(controlsProviderServiceTasker, "this$0");
        w0.m0(controlsProviderServiceTasker.new e(subscriber));
    }

    public final ControlsProviderServiceTasker i() {
        return this;
    }

    public final Control j(tn tnVar) {
        String m;
        String o;
        ControlTemplate a2;
        Control build;
        if (tnVar == null || (m = m(tnVar)) == null || (o = o(tnVar)) == null) {
            return null;
        }
        HashSet hashSet = new HashSet();
        tnVar.c2(this, false, hashSet, true, false, false);
        boolean contains = hashSet.contains(tn.h1(1));
        boolean contains2 = hashSet.contains(tn.h1(2));
        Intent intent = new Intent(i(), (Class<?>) ActivitySecondaryApp.class);
        c3.a();
        Control.StatefulBuilder a3 = b3.a(m, PendingIntent.getActivity(i(), 0, intent, k8.g(268435456, intent)));
        a3.setTitle(o);
        a3.setSubtitle("Trigger " + o);
        a3.setDeviceType(-1);
        a3.setControlId(m);
        a3.setStatus(1);
        a3.setCustomIcon(l(tnVar));
        if (contains || contains2) {
            u2.a();
            ControlButton a4 = t2.a(q(m), "id");
            b bVar = new b(m, this);
            if (contains && contains2) {
                y2.a();
                a2 = l2.a(v2.a(m, a4, re.h.a(bVar.invoke())));
            } else {
                a2 = contains ? l2.a(w2.a(o, a4)) : l2.a(bVar.invoke());
            }
        } else {
            a2 = l2.a(com.joaomgcd.taskerm.action.input.x2.a(o));
        }
        a3.setControlTemplate(a2);
        build = a3.build();
        return build;
    }

    public final Control k(String str) {
        tn u = u(str);
        if (u != null) {
            return j(u);
        }
        return null;
    }

    private final Icon l(tn tnVar) {
        Icon createWithBitmap;
        if (tnVar == null) {
            return r();
        }
        if (!tnVar.G1()) {
            return r();
        }
        Bitmap bitmap = (Bitmap) x2.U4((l) null, new c(tnVar, this), 1, (Object) null);
        if (bitmap == null) {
            return r();
        }
        createWithBitmap = Icon.createWithBitmap(bitmap);
        p.h(createWithBitmap, "createWithBitmap(...)");
        return createWithBitmap;
    }

    private final String m(tn tnVar) {
        String o = o(tnVar);
        if (o == null) {
            return null;
        }
        return "supertaskcontrolyeahbaby" + o;
    }

    private final String n(String str) {
        return o.q0(str, "supertaskcontrolyeahbaby");
    }

    private final String o(tn tnVar) {
        if (tnVar != null && tnVar.u()) {
            return tnVar.getName();
        }
        return null;
    }

    public final float p(String str) {
        Float f2 = v().get(str);
        if (f2 == null) {
            f2 = Float.valueOf(0.0f);
        }
        return f2.floatValue();
    }

    private final boolean q(String str) {
        Boolean bool = w().get(str);
        if (bool == null) {
            bool = Boolean.FALSE;
        }
        return bool.booleanValue();
    }

    private final Icon r() {
        return androidx.core.app.l.a(this.i.getValue());
    }

    private final mi.a s() {
        return (mi.a) this.s.getValue();
    }

    private final tn u(String str) {
        return to.u1(i()).N(n(str));
    }

    private final HashMap<String, Float> v() {
        return (HashMap) this.q.getValue();
    }

    private final HashMap<String, Boolean> w() {
        return (HashMap) this.r.getValue();
    }

    private final void x(String str, ControlAction controlAction, Consumer<Integer> consumer) {
        String commandPrefix;
        Boolean active;
        Float rangeCurrent;
        float newValue;
        boolean newState;
        StoredPowerMenuAction byId = s.e(this).byId(str);
        if (byId == null || (commandPrefix = byId.getCommandPrefix()) == null) {
            return;
        }
        PowerMenuActionType type = byId.getType();
        if (re.a.a(controlAction)) {
            newState = re.b.a(controlAction).getNewState();
            active = Boolean.valueOf(newState);
        } else {
            active = byId.getActive();
        }
        if (re.d.a(controlAction)) {
            newValue = re.e.a(controlAction).getNewValue();
            rangeCurrent = Float.valueOf(newValue);
        } else {
            rangeCurrent = byId.getRangeCurrent();
        }
        String y = y(type, commandPrefix, active, rangeCurrent, controlAction);
        if (y == null || y.length() == 0) {
            j1.i.a(consumer, 2);
            return;
        }
        if (type != PowerMenuActionType.Button) {
            j1.i.a(consumer, 1);
        } else {
            j1.i.a(consumer, 1);
        }
        ExtensionsContextKt.C3(this, y, (String) null, 2, (Object) null);
    }

    private static final String y(PowerMenuActionType powerMenuActionType, String str, Boolean bool, Float f2, ControlAction controlAction) {
        String str2;
        int i2 = a.a[powerMenuActionType.ordinal()];
        if (i2 == 1) {
            return str;
        }
        if (i2 == 2) {
            if (bool == null) {
                return str;
            }
            return str + "=:=" + bool;
        }
        if (i2 == 3) {
            if (f2 == null) {
                return str;
            }
            return str + "=:=" + f2;
        }
        if (i2 != 4) {
            if (i2 == 5) {
                return null;
            }
            throw new lj.o();
        }
        if (bool != null) {
            str = str + "=:=" + bool;
        }
        if (f2 != null) {
            str = str + "=:=" + f2;
        }
        if (re.a.a(controlAction)) {
            str2 = str + "=:=toggle";
        } else {
            if (!re.d.a(controlAction)) {
                return str;
            }
            str2 = str + "=:=range";
        }
        return str2;
    }

    private final boolean z(String str, ControlAction controlAction, Consumer<Integer> consumer) {
        boolean q;
        float p;
        Flow.Subscriber<? super Control> subscriber;
        if (k(str) == null) {
            return false;
        }
        if (re.a.a(controlAction)) {
            q = re.b.a(controlAction).getNewState();
            B(str, q);
        } else {
            q = q(str);
        }
        String valueOf = String.valueOf(q);
        if (re.d.a(controlAction)) {
            p = re.e.a(controlAction).getNewValue();
            A(str, p);
        } else {
            p = p(str);
        }
        ExecuteService.u7(this, n(str), valueOf, String.valueOf(ak.a.d(p)), "powermenu");
        j1.i.a(consumer, 1);
        Control k2 = k(str);
        if (k2 != null && (subscriber = this.t) != null) {
            subscriber.onNext(k2);
        }
        return true;
    }

    @Override
    public Flow.Publisher<Control> createPublisherFor(final List<String> list) {
        p.i(list, "controlIds");
        return new Flow.Publisher() {
            @Override
            public final void subscribe(Flow.Subscriber subscriber) {
                ControlsProviderServiceTasker.g(ControlsProviderServiceTasker.this, list, subscriber);
            }
        };
    }

    @Override
    public Flow.Publisher<Control> createPublisherForAllAvailable() {
        return new Flow.Publisher() {
            @Override
            public final void subscribe(Flow.Subscriber subscriber) {
                ControlsProviderServiceTasker.h(ControlsProviderServiceTasker.this, subscriber);
            }
        };
    }

    @Override
    public void onCreate() {
        super.onCreate();
        s().c(w0.B1(pg.d.k(this), this, h.i));
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        pg.d.l(this);
        s().d();
    }

    @EventBusRxSubscription
    @Keep
    public final void onStoredPowerMenuAction(StoredPowerMenuAction storedPowerMenuAction) {
        p.i(storedPowerMenuAction, "action");
        s().c(w0.F1(StoredPowerMenuAction.getControl$default(storedPowerMenuAction, this, false, 2, null), this, new i()));
    }

    @Override
    public void performControlAction(String str, ControlAction controlAction, Consumer<Integer> consumer) {
        p.i(str, "controlId");
        p.i(controlAction, "action");
        p.i(consumer, "consumer");
        if (z(str, controlAction, consumer)) {
            return;
        }
        x(str, controlAction, consumer);
    }

    public final Flow.Subscriber<? super Control> t() {
        return this.t;
    }
}