Page 1 of 1

custom volume stream type

Posted: 09 Jun 2017 21:53
by kovlaszlo
Dear Martin,

I found Automagic as I was looking for an automation app which is able to use GPS speed as trigger. How your speed trigger is defined is ingenious :) When later I was checking all the other features of your app, and read through you site (just more or less), it has become clear that your app is much better than the competitors! I tried Tasker and Macrodroid before. Until now I was using Trigger on my phone, but I am going to throw it away.

Coming to the point, I have quite a special problem. I have an Android head unit in my car, which uses a relatively new hardware (8 core processor, 2GB RAM, with Android 6). I wanted to use Automagic to define speed-dependent volume control on the device. Not a complicated flow: with GPS speed trigger, when speed is increased over the limit, action is “Set audio stream volume”, add one. The speed, where I raise volume, less the threshold, is the speed where in the opposite direction (lower volume) I set the trigger. 6x2 flows would do the job for me.

Now comes the problem: the head unit is not using any of the standard stream types! I tried all stream types available in your volume control action, none of them worked. I tried then your very useful “Set system setting” action. Amongst the available options I identified the bloody custom stream type, that they are using: it is called “av_volume”. As a test, I fixed a high value for this setting. As the speed was reached, Automagic changed the volume in the setting. I think you know already what comes now: since I am not using the API, the changed setting took effect only after a restart of the unit. But, set this aside for a moment, just go on thinking. The complete flow would be: speed trigger as written above --> “Init variable system setting” for “av_volume” --> +1 to the variable --> “Set system setting” according to the variable current value.

Coming back now to the API issue: the way out would be screen off and on. In practice: I set screen time out to 1sec --> wait 1sec --> screen on. What I would see in my car: the screen of my stereo turns off for a visible period of time, then turns back on, in the same time the volume changes. This is not nice: looks rather a bug, not a feature (despite that it is Linux, not Microsoft :D )

Conclusion, and my request / question: do you see a chance to adjust the “Set audio volume” action, so that the not standard “av_volume” stream type becomes a selectable option? Or, do you maybe have an idea, how I could solve the problem?

Re: custom volume stream type

Posted: 11 Jun 2017 19:44
by Martin
Hi,

Glad you like Automagic :-)

This stream might be special to your device/ROM so I'm not yet sure if I can add the stream type in general and if the stream can be adjusted at all with the official API.
Could you please make following test:
1. Create a new empty action Script
2. Paste following code into the script:

Code: Select all

audioManager=callJavaMethod(getContext(), "android.content.Context", "getSystemService(java.lang.String)", "audio");
callJavaMethod(audioManager, "android.media.AudioManager", "setStreamVolume(int, int, int)", 4, 2, 5);
The three number (4, 2, 5) have the following meaning:
4: adjust stream number 4 (Alarm)
2: set the volume to level 2
5: show a popup and play a sound

While still editing the action, you can use menu->Execute to see if the above code properly works and adjusts the alarm volume.
You can now change the stream type in the script from 4 to any other value like 7, 8, 9, 10, 11 etc. When the script fails with an error, it could mean that you are using a stream type that's too high.

Can you identify the stream type that changes the desired volume?

Regards,
Martin

Re: custom volume stream type

Posted: 12 Jun 2017 21:36
by kovlaszlo
Hi,

Thank you very much for the support! I tried from 0 to 10. Unfortunately none of the stream types is the one I need :( I got the error message at 10, did not go further

Best regards,
Laszlo

Re: custom volume stream type

Posted: 14 Jun 2017 19:30
by Martin
Thanks for testing.

It means that the ROM likely uses a different API to change the volume which is something I can not directly support in Automagic. Maybe the API even uses permissions that are not available to Automagic.

You could try the following steps to find and call the Java method directly. Unfortunately it's quite complicated:
Paste the following line in an action Script:

Code: Select all

audioManager=callJavaMethod(getContext(), "android.content.Context", "getSystemService(java.lang.String)", "audio");
1. Place the cursor on a new line and use button Function->Call Java Method
2. Click the [...]-button of the Object field and select audioManager (the class name field should be populated automatically)
3. Use the [...]-button of the method signature field and browse through the list of methods to see if there's a method that sounds like it changes the right audio level. The method likely start with adjust... or set..

Maybe the ROM also uses a totally different method that is not part of the AudioManager to change this volume.

Regards,
Martin

Re: custom volume stream type

Posted: 25 Jun 2017 12:46
by kovlaszlo
Thanks for your support!

I have tried what you proposed. After checking all methods that I found suspicious, and not finding any which solved my problem, I got an idea for a different approach, than simple try and error. I compared the list of methods given by the device with the list available on android developer site, and tried to understand the meaning of each and every method, which was not mentioned on the developer site. By this way I found an interesting method, called "reloadAudioSettings". I have also found a description with google, which told that "This method is called by Settings backup agent when audio settings are restored and causes the AudioService to read and apply restored settings". I thought this may force the system in my case to apply the settings that I changed via your setSystemSetting action. The fact that this did not change the volume tells me that your idea is most probably right, and the ROM must be using a completely different method. I did not stop at this point, though. Applying your proposal, I tried to find the method I need in the complete list of methods in the device, but i found nothing useful with "volume" or "vol". At the moment I have no idea, what keyword I should use, or how to step further.

I think you helped me already more than I could expect, but if you have any idea, please share it with me!

Best regards,
Laszlo