Search code examples
javaandroidcyanogenmodtasker

LineageOS: Tasker Java Function "setActiveProfile(java.lang.String)"


i'm trying to set a LineageOS system profile by a tasker task. I found some examples for CM13 but i can't get it work on LineagesOS. I'm not much into Java.

What have i done so far...

  1. Created a Tasker task "Java Function": proman = cyanogenmod.app.ProfileManager.getInstance{cyanogenmod.app.ProfileManager} (Context)

  2. Second "Java Function": proman.setActiveProfile( %Newprofile )

  3. Value of %Newprofile = "4G"

But i get the following error in my tasker log:

> 11.30.17/E Java Function:  -> 
> 11.30.17/JU analyse: target: proman expected: null
> 11.30.17/JU target: analyse done: proman: class: cyanogenmod.app.ProfileManager  obj: cyanogenmod.app.ProfileManager@1f3308e partWithoutMods: null static: false const false casted: false
> 11.30.17/JU analyse: returnval: java.lang.Void expected: null
> 11.30.17/JU returnval: analyse done: java.lang.Void: class: java.lang.Void  obj: null partWithoutMods: null static: true const false casted: false
> 11.30.17/JU initClass: class: java.lang.Void  obj: null partWithoutMods: java.lang.Void static: true const false casted: false
> 11.30.17/JU initClass: retnovar: init with array handling -> class java.lang.Void
> 11.30.17/JU initClass: class: cyanogenmod.app.ProfileManager  obj: cyanogenmod.app.ProfileManager@1f3308e partWithoutMods: proman static: false const false casted: false
> 11.30.17/JU initclass: target: use object class: cyanogenmod.app.ProfileManager
> 11.30.17/JU analyse: param0: %Newprofile expected: class java.lang.String
> 11.30.17/Variables doreplresult: |%Newprofile| -> |4G|
> 11.30.17/JU param0: analyse done: %Newprofile: class: java.lang.String  obj: 4G partWithoutMods: null static: false const true casted: false
> 11.30.17/E param 0 class: class java.lang.String
> 11.30.17/E targetClass: class cyanogenmod.app.ProfileManager
> 11.30.17/E object: cyanogenmod.app.ProfileManager@1f3308e
> 11.30.17/E method: public void cyanogenmod.app.ProfileManager.setActiveProfile(java.lang.String)
> 11.30.17/E arg0 class java.lang.String value 4G
> 11.30.17/E Java Function: java.lang.reflect.InvocationTargetException
> 11.30.17/ Caused by: java.lang.NullPointerException: Attempt to invoke interface method 'boolean cyanogenmod.app.IProfileManager.setActiveProfileByName(java.lang.String)' on a null object reference
> 11.30.17/ cyanogenmod.app.ProfileManager.setActiveProfile(Unknown Source)
> 11.30.17/ java.lang.reflect.Method.invoke(Native Method)
> 11.30.17/ net.dinglisch.android.taskerm.ExecuteService.c(Unknown Source)
> 11.30.17/ net.dinglisch.android.taskerm.ExecuteService.a(Unknown Source)
> 11.30.17/ net.dinglisch.android.taskerm.ExecuteService.a(Unknown Source)
> 11.30.17/ net.dinglisch.android.taskerm.fd.run(Unknown Source)
> 11.30.17/E result: stop task (error)
> 11.30.17/E Error: 1
> 11.30.17/MacroEdit action finished exeID 1 action no 1 code 664 status: Err next 1

Can anyone give ma a hint to narrow down my error? I guess something is wrong with the creation of the object "proman".

Thanks.

EDIT: Source of the Class - https://github.com/LineageOS/cm_platform_sdk/blob/cm-14.1/sdk/src/java/cyanogenmod/app/ProfileManager.java


Solution

  • I know this is an older post, but I stumbled on this post while doing some research to verify if the API names have changed since the spinoff of LineageOS from the original CM source, and wanted to provide what I hope is some useful information.

    A permissive SELinux is not required to set a system profile on LineageOS with Tasker. I have a Tasker profile that I've had since CM12 or CM13 that still works on LineageOS, and my SELinux status is currently Enforcing.

    LineageOS, Android v7.1.2

    Attached are screenshots showing the Java logic, and I'll include the full XML of the task below.

    Setting System Profile in LineageOS with Tasker

    <TaskerData sr="" dvi="1" tv="5.0u2m">
        <Task sr="task9">
            <cdate>1420510419053</cdate>
            <edate>1501266948615</edate>
            <id>9</id>
            <nme>Set CM Profile</nme>
            <pri>100</pri>
            <Action sr="act0" ve="7">
                <code>547</code>
                <Str sr="arg0" ve="3">%profile</Str>
                <Str sr="arg1" ve="3">%par1</Str>
                <Int sr="arg2" val="0"/>
                <Int sr="arg3" val="0"/>
                <Int sr="arg4" val="0"/>
            </Action>
            <Action sr="act1" ve="7">
                <code>664</code>
                <Str sr="arg0" ve="3">ps</Str>
                <Str sr="arg1" ve="3">cyanogenmod.app.ProfileManager</Str>
                <Str sr="arg2" ve="3">getService {cyanogenmod.app.IProfileManager} ()</Str>
                <Str sr="arg3" ve="3">profile</Str>
                <Str sr="arg4" ve="3"/>
                <Str sr="arg5" ve="3"/>
                <Str sr="arg6" ve="3"/>
                <Str sr="arg7" ve="3"/>
                <Str sr="arg8" ve="3"/>
                <Str sr="arg9" ve="3"/>
            </Action>
            <Action sr="act2" ve="7">
                <code>664</code>
                <Str sr="arg0" ve="3">%returnValue</Str>
                <Str sr="arg1" ve="3">ps</Str>
                <Str sr="arg2" ve="3">setActiveProfileByName {boolean} (String)</Str>
                <Str sr="arg3" ve="3">%profile</Str>
                <Str sr="arg4" ve="3"/>
                <Str sr="arg5" ve="3"/>
                <Str sr="arg6" ve="3"/>
                <Str sr="arg7" ve="3"/>
                <Str sr="arg8" ve="3"/>
                <Str sr="arg9" ve="3"/>
            </Action>
            <Img sr="icn" ve="2">
                <nme>hl_aaa_ext_barcode_1</nme>
            </Img>
        </Task>
    </TaskerData>
    

    Note: this is a generic Task that takes the name of a Profile and tries to set the System Profile to the profile matching the incoming parameter. This requires other tasks that send a specific string to this task.

    The final screenshot of the link above shows using another task and passing the name of the profile you wish to set.