Start a Service from Tasker (Component Intent, system app)

4,704 views
Skip to first unread message

joeviocoe

unread,
Oct 19, 2011, 10:57:59 PM10/19/11
to Tasker
I am trying to run the following:

Task > Add > misc > Component Intent
Class: com.cyanogenmod.cmparts.services.RenderFXService
Package: com.cyanogenmod.cmparts
Cat: None
Data:
Extra:
Target: Service

and I get:
"Component Intent: permission denied by Android"

This is a rooted HTC device running Cyanogenmod 7.1.1 (stable Mod)

CMParts is a system app/package that supplies most of the unique
settings of this ROM. It is a system level app. Which is why I think
I am getting this error. I am fairly new to Action and Component
Intents, but I have had some success with using parsed
AndroidManifest.xml files to find the intents for apps such as
Handcent SMS (quick compose - component,activity), Car Locator (set
location widget - action,receiver).

This is a portion of the AndroidManifest.xml file for CMParts:

C:\Users\Joeviocoe\Downloads\x_Android\apktool>aapt dump xmltree C:
\Users\Joeviocoe\Downloads\x_Android\apktool\com.cyan
ogenmod.cmparts-bb0eee3345b1f90ff44ea77fc3cc31fd.apk
AndroidManifest.xml
N: android=http://schemas.android.com/apk/res/android
E: manifest (line=2)
A: android:sharedUserId(0x0101000b)="android.uid.system" (Raw:
"android.uid.system")
A: android:versionCode(0x0101021b)=(type 0x10)0xa
A: android:versionName(0x0101021c)="2.3.7" (Raw: "2.3.7")
A: package="com.cyanogenmod.cmparts" (Raw:
"com.cyanogenmod.cmparts")
E: uses-sdk (line=5)
A: android:minSdkVersion(0x0101020c)=(type 0x10)0x8
A: android:targetSdkVersion(0x01010270)=(type 0x10)0xa
E: uses-permission (line=6)
A:
android:name(0x01010003)="android.permission.WRITE_SETTINGS" (Raw:
"android.permission.WRITE_SETTINGS")
E: uses-permission (line=7)
A:
android:name(0x01010003)="android.permission.WRITE_SECURE_SETTINGS" (Raw:
"android.permission.WRITE_SECURE_SETT
INGS")
E: uses-permission (line=8)
A:
android:name(0x01010003)="android.permission.WRITE_EXTERNAL_STORAGE" (Raw:
"android.permission.WRITE_EXTERNAL_S
TORAGE")
E: uses-permission (line=9)
A:
android:name(0x01010003)="android.permission.READ_EXTERNAL_STORAGE" (Raw:
"android.permission.READ_EXTERNAL_STO
RAGE")
E: uses-permission (line=10)
A:
android:name(0x01010003)="android.permission.HARDWARE_TEST" (Raw:
"android.permission.HARDWARE_TEST")
E: uses-permission (line=11)
A:
android:name(0x01010003)="android.permission.MODIFY_AUDIO_SETTINGS" (Raw:
"android.permission.MODIFY_AUDIO_SETT
INGS")
E: application (line=13)
A: android:label(0x01010001)=@0x7f090000
A: android:icon(0x01010002)=@0x7f020005

..................... *bunch of other stuff
here* ......................

E: intent-filter (line=305)
E: action (line=306)
A:
android:name(0x01010003)="android.intent.action.MAIN" (Raw:
"android.intent.action.MAIN")
E: receiver (line=310)
A: android:label(0x01010001)=@0x7f090169
A:
android:name(0x01010003)=".provider.RenderFXWidgetProvider" (Raw:
".provider.RenderFXWidgetProvider")
E: intent-filter (line=311)
E: action (line=312)
A:
android:name(0x01010003)="android.appwidget.action.APPWIDGET_UPDATE" (Raw:
"android.appwidget.action.APPW
IDGET_UPDATE")
E: meta-data (line=314)
A:
android:name(0x01010003)="android.appwidget.provider" (Raw:
"android.appwidget.provider")
A: android:resource(0x01010025)=@0x7f040001
E: service (line=318)
A: android:name(0x01010003)=".services.RenderFXService" (Raw:
".services.RenderFXService")
A: android:enabled(0x0101000e)=(type 0x12)0xffffffff
E: service (line=319)
A: android:name(0x01010003)=".services.BatteryService" (Raw:
".services.BatteryService")
A: android:enabled(0x0101000e)=(type 0x12)0xffffffff


I am pretty confident I filled out the Component Intent correctly,
since I have "trial n error"ed a bunch of other ways and this was the
only one that gave any response (the error message of, "Component
Intent: permission denied by Android"

===============

Since this is a system service, I would need root privilege I think.
Is there any possible way to run Component Intent as Root? If not, is
there any way to use Python or Shell script to start this particular
service?

Thank you.

Pent

unread,
Oct 20, 2011, 3:51:41 AM10/20/11
to Tasker

> Since this is a system service, I would need root privilege I think.

Won't necessarily help. Whoever calls the API, the API says: 'have I
given this user the Android permission XXX'. It doesn't say 'is this
user allowed to do this' ?

More likely is that you would need Tasker installed in the system
directory /system/app (which would then get assigned special
privileges within Android).

I 'officially' don't recommend it for security reasons though: if
Tasker is compromised it can do virtually anything with your phone.

Pent

Matthieu Berthomé

unread,
Oct 20, 2011, 3:57:34 AM10/20/11
to tas...@googlegroups.com
With a rooted shell command
am
will query the activity manager, and launch activites. Try it with the appropriate input ;)

Pent

unread,
Oct 20, 2011, 4:53:56 AM10/20/11
to Tasker
I only know the API stuff :-)

Pent

Matthieu Berthomé

unread,
Oct 20, 2011, 5:16:24 AM10/20/11
to tas...@googlegroups.com
I see ;-)
Anyway, if you want to propose a component intent or action intent action with root possibility in the Tasker, UI.you could try invoking in Tasker source code a rooted shell with the command am. I don't think there's a huge demand for that, if in need the Tasker user can always invoke a rooted shell to do that.
Matthieu.

Joeviocoe Gmail

unread,
Oct 20, 2011, 7:03:45 AM10/20/11
to tas...@googlegroups.com

What would be the compete syntax to to run a component intent from a shell script?

Matthieu Berthomé

unread,
Oct 20, 2011, 7:11:01 AM10/20/11
to tas...@googlegroups.com
try running am with no parameters in a terminal or via ADB. There is a syntax help
Something like
"am start <INTENT>" to start an activity
"am service <INTENT>" to start a service (what you need, I think)
"am broadcast <INTENT>" to broadcast an intent
the syntax to define the intent with am is explained when you type "am" only in a terminal. It might be difficult to add more complex data types, but for simple intents it's doable.


Joeviocoe Gmail

unread,
Oct 20, 2011, 7:23:03 AM10/20/11
to tas...@googlegroups.com

You wouldn't by chance have an example of a working 'am' command.  I need something to compare.  I am trying different strings, and the only thing it says is, "Bad component name".
An example of a working 'am startservice' and the corresponding Tasker action would be perfect.

Joeviocoe Gmail

unread,
Oct 20, 2011, 7:31:04 AM10/20/11
to tas...@googlegroups.com
"am startservice -n com.cyanogenmod.cmparts/com.cyanogenmod.cmparts.services.RenderFXService"

WORKS!  Although the color is not what I want, I think I need to add some data string.

And returns:
"Starting service: Intent { cmp=com.cyanogenmod.cmparts/.services.RenderFXService }"

Now, the question is, how do I stop a service???

Matthieu Berthomé

unread,
Oct 20, 2011, 7:39:58 AM10/20/11
to tas...@googlegroups.com
Glad it worked. I was trying it on my phone and you beat me to it :-)
you don't need to worry about stopping the service. In Android world, everything is always running, pretty much. Which does not mean everything is always consuming power. The service should be well behaved, do its thing, stay in memory if needed, and be disposed by android if unused. But it might be dependent on an activity doing a stopserive() though, it depends. You can probably find the com.cyanogenmod.cmparts source code somewhere (where you got the android Manifest I'd say) and get an info on if this service needs stopping (probably not).
to add appropriatte data and cahnge color, look up the source code to know what to include

Joeviocoe Gmail

unread,
Oct 20, 2011, 7:48:12 AM10/20/11
to tas...@googlegroups.com
Thanks for your help.
 In this case, it is important to stop the service when I need to.. since this is a Screen Render Color modification,  As long as the service is running, the screen has a Red (or right now, a soft red) tint!  

I can either use the widget, 
or 
settings>application>running services>Cyanogenmod Settings> *under RenderFXService*, STOP
otherwise, the screen stays tinted.

Is there anyway to see into the code for that widget?  I know it uses:
    android:name(0x01010003)=".provider.RenderFXWidgetProvider" (Raw:".provider.RenderFXWidgetProvider")
 to send it to the "place widget on home screen menu"

BossMan

unread,
Oct 20, 2011, 7:52:51 AM10/20/11
to tas...@googlegroups.com

Is there anyway to see into the code for that widget?  I know it uses:
    android:name(0x01010003)=".provider.RenderFXWidgetProvider" (Raw:".provider.RenderFXWidgetProvider")
 to send it to the "place widget on home screen menu"

Matthieu Berthomé

unread,
Oct 20, 2011, 8:04:46 AM10/20/11
to tas...@googlegroups.com
The source code for RenderFXservice is here https://github.com/CyanogenMod/android_packages_apps_CMParts/blob/gingerbread/src/com/cyanogenmod/cmparts/services/RenderFXService.java
https://github.com/CyanogenMod/android_packages_apps_CMParts/blob/gingerbread/src/com/cyanogenmod/cmparts/provider/RenderFXWidgetProvider.java is the code for the widget
Extracted info:

The extra for the color is widget_render_effect, an integer. Use -e widget_render_effect N, where N is an integer (try to see the results).
The service does not stop itself. But There's nothing "running" inside AFAIK. It just calls something in the CM system and then does nothing.
You might want to call a service in the RenderFXWidgetProvider instead of the RenderFXService. Look up the onReceive for the widgetprovider, maybe you'll get some nice inside info :-)


Joeviocoe Gmail

unread,
Oct 20, 2011, 8:06:48 AM10/20/11
to tas...@googlegroups.com
Awesome, there is a lot in there.  And I've never taken apart source code before.  So I would need some time to figure all this out.  



public class RenderFXService extends Service {

public static final String MSG_TAG = "RenderFXService";
    private Notification mNotification;

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
if (intent != null) {
writeRenderEffect(intent.getIntExtra("widget_render_effect", 1));

That '1' at the end corresponds to a default of the 3700K night mode (that soft red).  I thing it should be 10 (full RED)



+        case 10:
+            views.setTextViewText(R.id.ind, context.getResources().getString(R.string.widget_render_effect_red));
             break;

But I have NO IDEA how to put this setting into that 'am startservice' or 'am start' (for activities), or Tasker.

If I could figure that out, I might have a way to turn the effect off, without killing the service explicitly

Matthieu Berthomé

unread,
Oct 20, 2011, 8:10:26 AM10/20/11
to tas...@googlegroups.com
am startservice -n com.cyanogenmod.cmparts/com.cyanogenmod.cmparts.services.RenderFXService -e widget_render_effect N
to change the render effect. I'm currently digging in SurfaceFlinger to find the correct values for N ;-)
The 1 is the default value if the extra is not included, you're right. And 1 is soft red. But I tried some others, I'm still stuck with soft red ;-)

Matthieu Berthomé

unread,
Oct 20, 2011, 8:29:59 AM10/20/11
to tas...@googlegroups.com

Matthieu Berthomé

unread,
Oct 20, 2011, 8:33:23 AM10/20/11
to tas...@googlegroups.com
According to this
https://github.com/drakaz/gaosp_frameworks_base/blob/gaosp-froyo/libs/surfaceflinger/LayerBase.cpp
It should be 1 for red, 2 for terminal, etc. It doesn't seem to work. Maybe this has been changed in CM ?

Matthieu Berthomé

unread,
Oct 20, 2011, 9:21:22 AM10/20/11
to tas...@googlegroups.com
Got it.
The syntax is
am startservice -n com.cyanogenmod.cmparts/com.cyanogenmod.cmparts.services.RenderFXService --ei widget_render_effect N
Where N is an integer in this list:
#define RENDER_EFFECT_NIGHT 1
#define RENDER_EFFECT_TERMINAL 2
#define RENDER_EFFECT_BLUE 3
#define RENDER_EFFECT_AMBER 4
#define RENDER_EFFECT_SALMON 5
#define RENDER_EFFECT_FUSCIA 6
#define RENDER_EFFECT_N1_CALIBRATED_N 7
#define RENDER_EFFECT_N1_CALIBRATED_R 8
#define RENDER_EFFECT_N1_CALIBRATED_C 9
#define RENDER_EFFECT_RED 10
If you want to "go back to normal", use N=7.

Well, that was fun.
Use that shell line in a root shell in an action in Tasker, and voilà, you got a tasker-controlled Render Effect. Cool!

Joeviocoe Gmail

unread,
Oct 20, 2011, 10:40:44 AM10/20/11
to tas...@googlegroups.com

THAT WORKS PERFECT.  I put that into Tasker, misc, shell command, run as root.  No component intent task needed.

Thank you again!

Reply all
Reply to author
Forward
0 new messages