Sending intents from Java

251 views
Skip to first unread message

Sergey Khorev

unread,
Dec 31, 2014, 1:27:49 PM12/31/14
to tas...@googlegroups.com

Hi,

I'm playing with calling Java from Tasker, so far it looks fairly convenient to use but I stumbled upon a permissionning issue when trying to send an intent. I know that Tasker has built-in functionality for this but perhaps this problem is not intent-specific. Moreover the same should have been solved in Tasker somehow. Any ideas?

Here is the code:

J (5)
A1: Java Function [ Return:i Class Or Object:Intent Function:new
{Intent} () Param:"nl.mpcjanssen.simpletask.START_WITH_FILTER" Param: Param: Param: Param: ] 
A2: Java Function [ Return: Class Or Object:i Function:setAction
{Intent} (String) Param:"nl.mpcjanssen.simpletask.START_WITH_FILTER" Param: Param: Param: Param: ] 
A3: Java Function [ Return: Class Or Object:i Function:putExtra
{Intent} (String, String) Param:"SORTS" Param:"+!completed" Param: Param: Param: ] 
A4: Java Function [ Return: Class Or Object:i Function:addCategory
{Intent} (String) Param:"android.intent.category.DEFAULT" Param: Param: Param: Param: ] 
A5: [X] Java Function [ Return:(ActivityManager)am Class Or Object:CONTEXT Function:getSystemService
{Object} (String) Param:"activity" Param: Param: Param: Param: ] 
A6: [X] Java Function [ Return: Class Or Object:am Function:switchUser
{boolean} (int) Param:-2 Param: Param: Param: Param: ] 
A7: Java Function [ Return: Class Or Object:CONTEXT Function:startActivity
{} (Intent) Param:i Param: Param: Param: Param: ] 

In logcat I can see the following:

12-31 19:24:01.076  1236  1404 I InputReader: Touch event's action is 0x1 (deviceType=0) [pCnt=1, s=] when=3221957244000
12-31 19:24:01.076  1236  1403 I InputDispatcher: Delivering touch to: action: 0x1, toolType: 1
12-31 19:24:01.076  1236  2752 W ActivityManager: Permission Denial: get/set setting for user asks to run as user -2 but is calling from user 0; this requires android.permission.INTERACT_ACROSS_USERS_FULL
12-31 19:24:01.086  1236  2752 E DatabaseUtils: Writing exception to parcel
12-31 19:24:01.086  1236  2752 E DatabaseUtils: java.lang.SecurityException: Permission Denial: get/set setting for user asks to run as user -2 but is calling from user 0; this requires android.permission.INTERACT_ACROSS_USERS_FULL|
12-31 19:24:01.086  1236  2752 E DatabaseUtils:  at com.android.server.am.ActivityManagerService.handleIncomingUser(ActivityManagerService.java:15031)
12-31 19:24:01.086  1236  2752 E DatabaseUtils:  at android.app.ActivityManager.handleIncomingUser(ActivityManager.java:2492)
12-31 19:24:01.086  1236  2752 E DatabaseUtils:  at com.android.providers.settings.SettingsProvider.call(SettingsProvider.java:688)
12-31 19:24:01.086  1236  2752 E DatabaseUtils:  at android.content.ContentProvider$Transport.call(ContentProvider.java:325)
12-31 19:24:01.086  1236  2752 E DatabaseUtils:  at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:275)
12-31 19:24:01.086  1236  2752 E DatabaseUtils:  at android.os.Binder.execTransact(Binder.java:404)
12-31 19:24:01.086  1236  2752 E DatabaseUtils:  at dalvik.system.NativeStart.run(Native Method)
12-31 19:24:01.166  6755 18099 W Tasker  : 19.24.01#E: warning: Java Function: java.lang.reflect.InvocationTargetException


If I uncomment A5 and A6 (there I tried to mimic the `am' utility) I get:

12-31 19:09:01.261  1236  1404 I InputReader: Touch event's action is 0x1 (deviceType=0) [pCnt=1, s=] when=2716818084000
12-31 19:09:01.261  1236  1403 I InputDispatcher: Delivering touch to: action: 0x1, toolType: 1
12-31 19:09:01.271  1236  2754 E DatabaseUtils: Writing exception to parcel
12-31 19:09:01.271  1236  2754 E DatabaseUtils: java.lang.SecurityException: Permission Denial: get/set setting for user asks to run as user -2 but is calling from user 0; this requires android.permission.INTERACT_ACROSS_USERS_FULL
12-31 19:09:01.271  1236  2754 E DatabaseUtils:  at com.android.server.am.ActivityManagerService.handleIncomingUser(ActivityManagerService.java:15031)
12-31 19:09:01.271  1236  2754 E DatabaseUtils:  at android.app.ActivityManager.handleIncomingUser(ActivityManager.java:2492)
12-31 19:09:01.271  1236  2754 E DatabaseUtils:  at com.android.providers.settings.SettingsProvider.call(SettingsProvider.java:688)
12-31 19:09:01.271  1236  2754 E DatabaseUtils:  at android.content.ContentProvider$Transport.call(ContentProvider.java:325)
12-31 19:09:01.271  1236  2754 E DatabaseUtils:  at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:275)
12-31 19:09:01.271  1236  2754 E DatabaseUtils:  at android.os.Binder.execTransact(Binder.java:404)
12-31 19:09:01.271  1236  2754 E DatabaseUtils:  at dalvik.system.NativeStart.run(Native Method)
12-31 19:09:01.271  1236  2754 W ActivityManager: Permission Denial: get/set setting for user asks to run as user -2 but is calling from user 0; this requires android.permission.INTERACT_ACROSS_USERS_FULL
12-31 19:09:01.341   159   159 D simal   : had not finish
12-31 19:09:01.341  1471  1471 D STATUSBAR-NetworkController: onSignalStrengthsChanged signalStrength=SignalStrength: 23 0 -120 -160 -120 0 -1 99 2147483647 2147483647 2147483647 2147483647 2147483647 gsm|lte 0x0 level=4
12-31 19:09:01.351  6755 16006 W Tasker  : 19.09.01#E: warning: Java Function: java.lang.reflect.InvocationTargetException
12-31 19:09:01.351  1236  2752 W ActivityManager: Permission Denial: switchUser() from pid=6755, uid=10385 requires android.permission.INTERACT_ACROSS_USERS_FULL
12-31 19:09:03.333   159   159 D simal   : had not finish

Pent

unread,
Jan 1, 2015, 4:09:08 AM1/1/15
to tas...@googlegroups.com

 I know that Tasker has built-in functionality for this but perhaps this problem is not intent-specific. Moreover the same should have been solved in Tasker somehow. Any ideas?


If I remember right,  android.permission.INTERACT_ACROSS_USERS_FULL is only granted to system apps.

Pent

Sergey Khorev

unread,
Jan 8, 2015, 6:45:30 AM1/8/15
to tas...@googlegroups.com
On Thursday, January 1, 2015 12:09:08 PM UTC+3, Pent wrote:

 I know that Tasker has built-in functionality for this but perhaps this problem is not intent-specific. Moreover the same should have been solved in Tasker somehow. Any ideas?


If I remember right,  android.permission.INTERACT_ACROSS_USERS_FULL is only granted to system apps.


 Yes, google says it's granted only to system apps. I am wondering why Tasker does not get the same error when sending intents. Does it use some other context?

Pent

unread,
Jan 8, 2015, 7:23:32 AM1/8/15
to tas...@googlegroups.com



 Yes, google says it's granted only to system apps. I am wondering why Tasker does not get the same error when sending intents.

Tasker doesn't have any function to set user.

Pent

Sergey Khorev

unread,
Jan 8, 2015, 11:34:47 AM1/8/15
to tas...@googlegroups.com

 Yes, google says it's granted only to system apps. I am wondering why Tasker does not get the same error when sending intents.

Tasker doesn't have any function to set user.

I see, Tasker does not set user. Then the questions is why action below works? Does it have anything to do with context used in my Java calls or something like that? Essentially both should do the same thing.

A1: Send Intent [ Action:nl.mpcjanssen.simpletask.START_WITH_FILTER Cat:Default Mime Type: Data: Extra:SORTS:+!completed Extra: Package: Class: Target:Activity ] 

Pent

unread,
Jan 8, 2015, 11:54:53 AM1/8/15
to tas...@googlegroups.com


I see, Tasker does not set user. Then the questions is why action below works? Does it have anything to do with context used in my Java calls or something like that? Essentially both should do the same thing.

A1: Send Intent [ Action:nl.mpcjanssen.simpletask.START_WITH_FILTER Cat:Default Mime Type: Data: Extra:SORTS:+!completed Extra: Package: Class: Target:Activity ] 

Sorry, I don't understand why it wouldn't since it's apparently an intent to a 3rd Party app ?

Pent

Sergey Khorev

unread,
Jan 8, 2015, 1:29:26 PM1/8/15
to tas...@googlegroups.com
I see, Tasker does not set user. Then the questions is why action below works? Does it have anything to do with context used in my Java calls or something like that? Essentially both should do the same thing.

A1: Send Intent [ Action:nl.mpcjanssen.simpletask.START_WITH_FILTER Cat:Default Mime Type: Data: Extra:SORTS:+!completed Extra: Package: Class: Target:Activity ] 

Sorry, I don't understand why it wouldn't since it's apparently an intent to a 3rd Party app ?

Agreed. And I am puzzled why presumably identical Java code doesn't work with Permission denial error:

A1: Java Function [ Return:i Class Or Object:Intent Function:new
{Intent} () Param:"nl.mpcjanssen.simpletask.START_WITH_FILTER" Param: Param: Param: Param: ] 
A2: Java Function [ Return: Class Or Object:i Function:setAction
{Intent} (String) Param:"nl.mpcjanssen.simpletask.START_WITH_FILTER" Param: Param: Param: Param: ] 
A3: Java Function [ Return: Class Or Object:i Function:putExtra
{Intent} (String, String) Param:"SORTS" Param:"+!completed" Param: Param: Param: ] 
A4: Java Function [ Return: Class Or Object:i Function:addCategory
{Intent} (String) Param:"android.intent.category.DEFAULT" Param: Param: Param: Param: ] 
A5: Java Function [ Return: Class Or Object:CONTEXT Function:startActivity

Pent

unread,
Jan 8, 2015, 2:44:32 PM1/8/15
to tas...@googlegroups.com
I had assumed the permission denial was coming from the switchUser call at A6.

Pent

Pent

unread,
Jan 8, 2015, 2:45:17 PM1/8/15
to tas...@googlegroups.com

I had assumed the permission denial was coming from the switchUser call at A6.

In fact I'm sure of it, since -2 is the parameter and mention in the error.

Pent

Sergey Khorev

unread,
Jan 9, 2015, 1:18:25 AM1/9/15
to tas...@googlegroups.com

I had assumed the permission denial was coming from the switchUser call at A6.

In fact I'm sure of it, since -2 is the parameter and mention in the error.

It seems my original report caused some confusion. I attempted to switch users after I got that permission denial error. As you can see below, -2 appears even for simple startActivity call i.e.
for action
A1: Java Function [ Return:i Class Or Object:Intent Function:new
{Intent} () Param:"nl.mpcjanssen.simpletask.START_WITH_FILTER" Param: Param: Param: Param: ] 
A2: Java Function [ Return: Class Or Object:i Function:setAction
{Intent} (String) Param:"nl.mpcjanssen.simpletask.START_WITH_FILTER" Param: Param: Param: Param: ] 
A3: Java Function [ Return: Class Or Object:i Function:putExtra
{Intent} (String, String) Param:"SORTS" Param:"+!completed" Param: Param: Param: ] 
A4: Java Function [ Return: Class Or Object:i Function:addCategory
{Intent} (String) Param:"android.intent.category.DEFAULT" Param: Param: Param: Param: ] 
A5: Java Function [ Return: Class Or Object:CONTEXT Function:startActivity
{} (Intent) Param:i Param: Param: Param: Param: ] 

I can see the following in logcat:
01-09 09:04:05.801  1235  1401 I InputDispatcher: Delivering touch to: action: 0x1, toolType: 1
01-09 09:04:05.811  1235  2892 E DatabaseUtils: Writing exception to parcel
01-09 09:04:05.811  1235  2892 E DatabaseUtils: java.lang.SecurityException: Permission Denial: get/set setting for user asks to run as user -2 but is calling from user 0; this requires android.permission.INTERACT_ACROSS_USERS_FULL
01-09 09:04:05.811  1235  2892 E DatabaseUtils: at com.android.server.am.ActivityManagerService.handleIncomingUser(ActivityManagerService.java:15031)
01-09 09:04:05.811  1235  2892 E DatabaseUtils: at android.app.ActivityManager.handleIncomingUser(ActivityManager.java:2492)
01-09 09:04:05.811  1235  2892 E DatabaseUtils: at com.android.providers.settings.SettingsProvider.call(SettingsProvider.java:688)
01-09 09:04:05.811  1235  2892 E DatabaseUtils: at android.content.ContentProvider$Transport.call(ContentProvider.java:325)
01-09 09:04:05.811  1235  2892 E DatabaseUtils: at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:275)
01-09 09:04:05.811  1235  2892 E DatabaseUtils: at android.os.Binder.execTransact(Binder.java:404)
01-09 09:04:05.811  1235  2892 E DatabaseUtils: at dalvik.system.NativeStart.run(Native Method)
01-09 09:04:05.811  1235  2892 W ActivityManager: Permission Denial: get/set setting for user asks to run as user -2 but is calling from user 0; this requires android.permission.INTERACT_ACROSS_USERS_FULL
01-09 09:04:05.911  6837 27645 W Tasker  : 09.04.05#E: warning: Java Function: java.lang.reflect.InvocationTargetException

Pent

unread,
Jan 9, 2015, 2:31:28 AM1/9/15
to tas...@googlegroups.com


It seems my original report caused some confusion. I attempted to switch users after I got that permission denial error. As you can see below, -2 appears even for simple startActivity call i.e.
for action

OK, then presumably whatever is receiving the intent is attempting to switch user.

Pent

Pent

unread,
Jan 9, 2015, 2:40:06 AM1/9/15
to tas...@googlegroups.com
Ah, I finally get it. You are asking why one way of sending the intent doesn't do that :-)

Maybe it's due to some flags Tasker automatically adds to the intent:

        intent.addFlags( Intent.FLAG_ACTIVITY_NEW_TASK );
        intent.addFlags( Intent.FLAG_FROM_BACKGROUND);
        intent.addFlags( Intent.FLAG_ACTIVITY_SINGLE_TOP );   
   
        if ( excludeFromRecentsList )
            intent.addFlags( Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS );

The first two are compulsory because it's a service which is sending the intent.

Pent

Sergey Khorev

unread,
Jan 9, 2015, 6:43:42 AM1/9/15
to tas...@googlegroups.com
Ah, I finally get it. You are asking why one way of sending the intent doesn't do that :-)

Maybe it's due to some flags Tasker automatically adds to the intent:
...

The first two are compulsory because it's a service which is sending the intent.


Many thanks, that solved my problem and the activity is starting just fine :) Btw is it possible to access static fields like android.content.Intent.FLAG_ACTIVITY_NEW_TASK from Tasker?

David Wang

unread,
Jan 9, 2015, 6:57:25 AM1/9/15
to tas...@googlegroups.com
Btw is it possible to access static fields like android.content.Intent.FLAG_ACTIVITY_NEW_TASK from Tasker?

You can use the reflection characteristic of JAVA at present. See my previous post here.

Hope it helps.

Pent

unread,
Jan 9, 2015, 7:16:57 AM1/9/15
to tas...@googlegroups.com


Btw is it possible to access static fields like android.content.Intent.FLAG_ACTIVITY_NEW_TASK from Tasker?

You can use the reflection characteristic of JAVA at present. See my previous post here.

... and I hope to add the capability for Tasker 4.7.

Pent

David Wang

unread,
Jan 9, 2015, 7:32:05 AM1/9/15
to tas...@googlegroups.com
... and I hope to add the capability for Tasker 4.7.

Can't wait for it. :-) 
Reply all
Reply to author
Forward
0 new messages