Change mock location app with Automagic

Post your questions and help other users.

Moderator: Martin

Post Reply
ewill
Posts: 67
Joined: 20 Jul 2015 16:42

Change mock location app with Automagic

Post by ewill » 12 Mar 2018 23:52

Is there a way to switch/change my mock location app with Automagic. I searched through the system settings, but didn't find any that specifies the app to be used. I also searched but didn't find a command that I could run. I have root access.

Thanks in advance for the assistance.

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Re: Change mock location app with Automagic

Post by Desmanto » 13 Mar 2018 10:40

What app do you use? FakeGPS? Do the app support automation through intent? Usually those changes are done via action Start Activity, Start Service or Send Broadcast. Automagic has example in Start Service, using Fake GPS Location Spoofer.
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

ewill
Posts: 67
Joined: 20 Jul 2015 16:42

Re: Change mock location app with Automagic

Post by ewill » 13 Mar 2018 11:46

Thank you for the assistance. I have fakegps working (using the examples that I found) and can start and stop it using Automagic.

The issue is that the gps in my phone is not too good. I am experimenting with a bluetooth gps unit.

There is another app that I can also start/stop using broadcasts that I have set up in automagic.

The issue is that the mock gps location needs to be set to the app (either fake gps or the bluetooth gps app) that I want to use. I am trying to see if there is any way I can switch the setting of the mock gps application with automagic.

Hopefully I have provided a more clear explanation of the question.

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Re: Change mock location app with Automagic

Post by Desmanto » 13 Mar 2018 15:55

There is no selection which mock app to use in android. I never try two or more mock app at the same time, can't predict what will happen then.

If that bluetooth gps unit also use start/stop service, then just make sure only one of them is running at one time.

So if you want to switch to fakegps : stop bluetooth gps unit and start fakegps service
If you want to switch to bluetooth gps unit : stop fakegps and start bluetooth gps unit.

That ensure only one app is mocking the location at one time.
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

ewill
Posts: 67
Joined: 20 Jul 2015 16:42

Re: Change mock location app with Automagic

Post by ewill » 13 Mar 2018 19:59

Thanks for the assistance. For my phone, I must select a single app (in developer options) to be used for mock locations. The setting is called "Select mock location app". Therefore in addition to starting/stopping the app, I need to change the setting in developer options to the app I am going to use (either the fake gps app or the bluetooth receiver app). I was hoping to be able to change that setting with automagic.

Perhaps that isn't possible....

Thanks for the help.

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Re: Change mock location app with Automagic

Post by Desmanto » 14 Mar 2018 13:01

Sorry, I am too lazy to google yesterday. I check again in Bliss Nougat 7.1, there is the option. Android MM 6.0+ will have that additional setting and I am still using LP 5.1 :(

Try to check If you have that option to set the value in Set System Setting. Set first your mock app to fakegps. Then use
action : Set System Setting
Category : Secure
Name : tap the ellipsis and find "mock". If you can find the packaganame of fakegps, then you can use this.

However, AFAI-Research, there is no setting database to set the mock app. So you have only last resort of using Control UI to do it, but you will have some UI distraction. Use Launch app, Choose 'Setting', and class name find the 'Developer', to launch developer options. You probably need several scroll to reach the mock app selection.

Control UI require accessibility and draw over other app permission, make sure you have granted it.
- Open Control UI, use the "Show Overlay Control" and it will popup INFO and CLOSE (and GESTURE if you are using Nougat above).
- Leave the Control UI open, press home and Go to the developer option.
- Tap the INFO to show the element and tap on one of the element from the list. Try to see if there is option to select something start with scrollForwardById().
- Tap that to copy to clipboard. If there is no element with that name, press back and try to tap another one until you get it.
- Go back to automagic and paste that to the Control UI. Save and close.
- Try to execute the flow, it should open developer option and scroll forward once.
- When I test this in Bliss, opening the developer option has some delay (probably the animation), so I have to add sleep(200) before the script to make sure it works.

Now check that after the scroll, do you see the "Select mock location app option"? If no, you need to copy that scrollForward script and paste it again, so it scroll twice. Put sleep(200) in between to make sure the script works properly.

- If yes, as I tested in the bliss, then back to Automagic and open the same Control UI and Show Overlay control again.
- Execute the flow again, to land exactly at the place where you can see the option.
-Tap the INFO and tap that "Select mock location app", choose the one with click("Select mock location app").
- Press back to hide the green layout and tap that "Select mock location app" so you can see the choice of your two apps.
- Tap the INFO again and tap the Fake GPS one, choose the click("Fake GPS") or whatever the exact name of the app.
- Press back and go back to automagic Control UI, past the script.
- Try it out, you should see the it scrolled and automatically click the select mock and tap the Fake GPS.
- If you confirm it is working properly, you can try to reduce the sleep to lower value, so the script execute faster. You need to experiment with this, or you can see my index, at "How much sleep I need". Usually 200 is fine for most devices.
- Additionally, you can add another back button at the end of the script, so it automatically exit from the setting after it has done its job.

The full script when I test it in Bliss :

Code: Select all

sleep(200);
scrollForwardById("android:id/title");
sleep(200);
click("Select mock location app");
sleep(200);
click("Fake GPS");
sleep(200);
back();
I plan to make to a complete tutorial on how to use Control UI. But there are so many things to cover. I simply know how to use it intuitively, but still too awkward to explain it in wording, as you can see in this post (means I haven't fully understand it). Making video tutorial is not my style. I should make use of my screenshot flow to document it then. It will be this weekend target.
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

ewill
Posts: 67
Joined: 20 Jul 2015 16:42

Re: Change mock location app with Automagic

Post by ewill » 14 Mar 2018 14:25

Thank you very much for the very detailed response.

I had searched the settings (including secure) and didn't see any way to change the mock application. Thanks for checking again and confirming that I wasn't missing anything.

I was hoping that there was going to be another alternative besides Control UI, but apparently there isn't. Thank you very much for providing such a detailed description of how I could use Control UI for this.

Again, I appreciate all of the help.

ewill
Posts: 67
Joined: 20 Jul 2015 16:42

Re: Change mock location app with Automagic

Post by ewill » 05 Apr 2018 01:22

I think I found the setting!

For Android 6.0+:

Allowing app for mock locaiton

adb shell appops set <PACKAGE> android:mock_location allow
Removing app for mock location

adb shell appops set <PACKAGE> android:mock_location deny
Checking if app is set for mock location

adb shell appops get <PACKAGE> android:mock_location

For shell script, just remove the "adb shell"

Also, it seems that when switching between locations, have to set the prior one to "deny", then the new one to "allow" - it didn't seem to work reliably without that. I wish that part was a bit easier, but this is a breakthrough for me.

Found https://stackoverflow.com/questions/404 ... p-from-adb

Any further tips or information would be welcome.

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Re: Change mock location app with Automagic

Post by Desmanto » 05 Apr 2018 06:24

That seems to be the best solution. Just deny all other app and allow only the one you need. Don't worry about too many line of command, as long as it achieve your purpose. Of course optimize it as we can. (that seems to be the best solution already).
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

ewill
Posts: 67
Joined: 20 Jul 2015 16:42

Re: Change mock location app with Automagic

Post by ewill » 05 Apr 2018 14:41

A little more tweaking and I think I am done. I created the following script:

current=$(appops query-op android:mock_location allow)
appops set $current android:mock_location deny
appops set $1 android:mock_location allow

Save the script to storage. call it with the name of the app that you want to use for mock locations. It will get the name of the current app that mock location is set to, disable it, and set the mock location to the app named on the command line.

For example, if the script is named "mockchg", executing mockchg com.lexa.fakegps (execute root command) will change the mock location to the app named fakegps.

This now does exactly what I want.

Post Reply