Cloonix
Cloonix

Reputation: 113

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

Upvotes: 1

Views: 1663

Answers (5)

Helium100
Helium100

Reputation: 1



It's a old topic, but still very current issue, if like me you ended up here few days ago and getting stuck with lineageOS API changes, and golly-gosh-where-can-I-find-profile-UUID??, you may take advantages of the tasker's tasks here: GitHub

With them you should be able to set profile with UUID string (as long as tasker got the appropriate permissions) + get the UUID string currently in use by the system.

I precise that this work hugely take source on Samara Jinnah initial work on the subject.

Upvotes: 0

OrenRysn
OrenRysn

Reputation: 36

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.

Upvotes: 2

Cloonix
Cloonix

Reputation: 113

For those who want to use Lineage OS profiles within tasker (Android 7) you need the following task. Attention: Commands A1 and A4 disable/enable SELinux. The used variable %Newprofile equals the name of the Lineage profile (eg. "4G"). I set the variable within another task.

A1: Run Shell [ Command:setenforce 0 Timeout (Seconds):0 Use Root:On Store Output In: Store Errors In: Store Result In: ] 
A2: Java Function [ Return:proman Class Or Object:cyanogenmod.app.ProfileManager Function:getInstance {cyanogenmod.app.ProfileManager} (Context) Param:CONTEXT Param: Param: Param: Param: Param: Param: ] 
A3: Java Function [ Return: Class Or Object:proman Function:setActiveProfile {} (String) Param:%Newprofile Param: Param: Param: Param: Param: Param: ] 
A4: Run Shell [ Command:setenforce 1 Timeout (Seconds):0 Use Root:On Store Output In: Store Errors In: Store Result In: ] 

Upvotes: 0

wowo
wowo

Reputation: 1

You can disable SELinux right before the Function and re-enable it right after it in Tasker.

I guess I want to accomplish the same thing you are trying to do, but I can't make it work. Could you be so kind and post all the values for the fields in Tasker to create the proman object? I seem to be missing something.

Upvotes: 0

Cloonix
Cloonix

Reputation: 113

Sometimes by asking a question, the answer comes up.

SELinux is the reason that my method is not working. Temporarily set SELinux to "permissive" (setenforce 0) and everything is fine.

So i guess there is no workaround other than disabling SELinux (which i do not want).

Upvotes: 0

Related Questions