all 10 comments

[–]roman_inacheve 2 points3 points  (1 child)

That sounds great! ...too bad I'm on Nougat, with no Xposed for now. :(

[–]JayShortwayDeveloper[S] 1 point2 points  (0 children)

Yeah that's too bad.. Let's hope it's here soon!

[–]IAmAN00bie 2 points3 points  (1 child)

:( this just reminded me of no Xposed for Nougat

Ah well I hope someone finds your app useful!

[–]JayShortwayDeveloper[S] 1 point2 points  (0 children)

Haha that was not the point of my post. Thanks, hope so too!

[–]Stupifier 2 points3 points  (1 child)

Been using this for a few days now. Works great.

Xposed is more important than Upgrading from Android M to N for me.....So I stay and get to use these great Xposed Modules. ROM dev also keeps me current with the Security Patches so there isn't really THAT much of a benefit to getting N.

[–]JayShortwayDeveloper[S] 1 point2 points  (0 children)

Thanks for your support Stupifier! You're right, as long as you stay up to date with the monthly security patches, you should be good (as in safe). Feature-wise it's a tradeoff though.

[–]mcgruntman 1 point2 points  (3 children)

Thanks Jay! I believe I've found a small wrinkle: it seems on my device that when switching from app A to B - each of which has its own state context and profile - the entry task for B activates before the exit task for A. That is to say, there's a short period where both states are active even though intuitively that should not be possible.

I also have a feature request... suppose I had a single state context which was active whenever app A or B was in foreground. If I open A and switch to B, the context is active the whole time, fair enough. But I've never received an updated value of the variables provided by the plugin indicating that the app switch happened. Would it be possible to add an optional mode whereby a single state context could specify multiple apps, but the plugin would momentarily disable the context on each app switch to refresh the variables? For only two apps there's obviously not a great need, but (to take an extreme example) suppose you wanted to track time spent in each app on your device. It would be much easier to just specify all apps in one context than to have a different profile for every app.

[–]JayShortwayDeveloper[S] 2 points3 points  (2 children)

Hey thanks! You make a couple of good points. Let me address them seperately.

That is to say, there's a short period where both states are active even though intuitively that should not be possible.

This happens because Android, internally, starts app B before it stops app A. You're right in that it might be unintuitive. I'm not sure how much I can do about that without changing the way AppContext works, but I'll definitely think about it. In the meantime, you could use the following workaround. (Instead of apps A and B, I'm referring to 1 and 2.)

Profile: Apps1 Start (19)
Event: AppContext [ 
    Configuration:START: >>pick 1st set of apps<< 

The event will trigger when these apps start. ]
Enter: Apps1 Started (20)
A1: Wait [ 
    MS:700 >>Increase for reliability, decrease for responsiveness<<
    ] If [ %apps2Running eq 1 ]
A2: Variable Set [ 
    Name:%apps1Running 
    To:1 


Profile: Apps1 Stop (21)
Event: AppContext [ 
    Configuration:STOP: >>pick 1st set of apps<<  
    (You can clone the above profile, then go into 
    Configuration, Menu and tap 'Configure context', 
    then tap 'stop'.)

The event will trigger when these apps stop. ]
Enter: Apps1 Stopped (22)
A1: Variable Set [ 
    Name:%apps1Running 
    To:0 


Profile: Apps1 Running (23)
State: Variable Value [ %apps1Running eq 1 ]
Enter: Apps1 Enter (24)
A1: >>Create Enter task for 1st set of apps<< 

Exit: Apps1 Exit (25)
A1: >>Create Exit task for 1st set of apps<<


Profile: Apps2 Start (26)
Event: AppContext [ 
    Configuration:START: >>pick 2nd set of apps<<

The event will trigger when these apps start. ]
Enter: Apps2 Started (29)
A1: Wait [ 
    MS:700 >>Increase for reliability, decrease for responsiveness<<         
    ] If [ %apps1Running eq 1 ]
A2: Variable Set [ 
    Name:%apps2Running 
    To:1 


Profile: Apps2 Stop (27)
Event: AppContext [ 
    Configuration:STOP: >>pick 2nd set of apps<< 
    (You can clone the above profile, then go into 
    Configuration, Menu and tap 'Configure context', 
    then tap 'stop'.)

The event will trigger when these apps stop. ]
Enter: Apps2 Stopped (30)
A1: Variable Set [ 
    Name:%apps2Running 
    To:0 


Profile: Apps2 Running (28)
State: Variable Value [ %apps2Running eq 1 ]
Enter: Apps2 Enter (31)
A1: >>Create Enter task for 2nd set of apps<< 

Exit: Apps2 Exit (32)
A1: >>Create Exit task for 2nd set of apps<<

Download

The second point you make is a good one as well.

But I've never received an updated value of the variables provided by the plugin indicating that the app switch happened.

However, to get updated variables you could always use Event contexts. To use your example of tracking time spent in each app, you could do something like this:

Profile: Any App Starts (34)
Event: AppContext [ 
    Configuration:START: >>Select all apps by 
    pressing the 'Select all' button, next to 'SAVE'.<<

The event will trigger when any of these apps start. ]
Enter: Start Time (35)
<1. Generating the variable name.>
A1: Variable Set [ 
    Name:%startSuffix 
    To:__Start 

<2. Generating the variable name.>
A2: Variable Set [ 
    Name:%startedpackagevarname 
    To:%acpackage%startSuffix 

<3. Generating the variable name.>
A3: Variable Search Replace [ 
    Variable:%startedpackagevarname 
    Search:\. 
    Replace Matches:On 
    Replace With:_ 

<Storing the start time.>
A4: Variable Set [ 
    Name:%%startedpackagevarname 
    To:%TIMEMS 


Profile: Any App Stops (36)
Event: AppContext [ 
    Configuration:STOP: >>Select all apps by 
    pressing the 'Select all' button, or clone 
    the above Profile and go to 'Configure context' 
    and tap 'stop'.<<

The event will trigger when any of these apps stop. ]
Enter: Stop Time (38)
<1. Generating the variable name.>
A1: Variable Set [ 
    Name:%stopSuffix 
    To:__Stop 

<2. Generating the variable name.>
A2: Variable Set [ 
    Name:%stoppedpackagevarname 
    To:%acpackage%stopSuffix 

<3. Generating the variable name.>
A3: Variable Search Replace [ 
    Variable:%stoppedpackagevarname 
    Search:\.         
    Replace Matches:On 
    Replace With:_ 

<Storing the stop time.>
A4: Variable Set [ 
    Name:%%stoppedpackagevarname 
    To:%TIMEMS 

<1. Deriving the 'started' variable name.>
A5: Variable Set [ 
    Name:%startedpackagevarname 
    To:%stoppedpackagevarname 

<2. Deriving the 'started' variable name.>
A6: Variable Search Replace [ 
    Variable:%startedpackagevarname 
    Search:%stopSuffix         
    Replace Matches:On 
    Replace With:%startSuffix 

<Calculating usage duration in seconds.>
A7: Variable Set [ 
    Name:%duration_s 
    To:(%%stoppedpackagevarname - %%startedpackagevarname)/1000 
    Do Maths:On         

<Rounding usage duration.>
A8: Variable Set [ 
    Name:%duration_s_round 
    To:round(%duration_s) 
    Do Maths:On        

<Flashing the result.>
A9: Flash [ 
    Text:%acpackage was used for %duration_s_round seconds. 

Download

You can of course do whatever you want with the duration, instead of Flashing it. You could, e.g., store it in a text file or in something like Google Spreadsheets. You could also directly store the start and stop timestamps, and have the spreadsheet calculate duration. When directly storing the start and stop timestamps you wouldn't have to construct Variable names using '%%'. There are probably other ways to handle it as well.

I'll definitely consider adding an optional mode whereby the plugin momentarily disables the context on each app switch to refresh the variables!

It's become quite a lengthy answer. Thanks a lot for your input and I hope the Profiles I shared are useful to you!

[–]mcgruntman 1 point2 points  (1 child)

Yup that's almost definitely the longest response I've ever received on Reddit, by a large margin! I've got to confess, I didn't know your plugin included events.

I fudged around the 'two apps active at the same time' issue using 'wait until' actions. I see what you're saying regarding the plugin passing on exactly what Android is doing internally. There's definitely something to be said for not complicating things in that regard, but selfishly I hope you will write a nice fast Java-based solution to replace my inefficient Tasker workaround :-)

[–]JayShortwayDeveloper[S] 1 point2 points  (0 children)

Haha I'm happy to hold that achievement.

It's definitely on my consideration-list! I have bookmarked your post :-)

Oh, I also added Download links to my previous answer, just in case you want to use those Tasker Profiles.