appium/appium-android-driver

ACCESS_MOCK_LOCATION

rompic opened this issue · 13 comments

When I try to set a mock location on an emulator (Nexus_5_API_22) the appium settings is killed and I get the following info in the emulator log:

06-10 13:17:03.080: E/AndroidRuntime(7966): FATAL EXCEPTION: main
06-10 13:17:03.080: E/AndroidRuntime(7966): Process: io.appium.settings, PID: 7966
06-10 13:17:03.080: E/AndroidRuntime(7966): java.lang.RuntimeException: Unable to start service io.appium.settings.LocationService@21c91729 with Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=io.appium.settings/.LocationService (has extras) }: java.lang.SecurityException: Requires ACCESS_MOCK_LOCATION secure setting
06-10 13:17:03.080: E/AndroidRuntime(7966):     at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2911)
06-10 13:17:03.080: E/AndroidRuntime(7966):     at android.app.ActivityThread.access$2100(ActivityThread.java:151)
06-10 13:17:03.080: E/AndroidRuntime(7966):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1401)
06-10 13:17:03.080: E/AndroidRuntime(7966):     at android.os.Handler.dispatchMessage(Handler.java:102)
06-10 13:17:03.080: E/AndroidRuntime(7966):     at android.os.Looper.loop(Looper.java:135)
06-10 13:17:03.080: E/AndroidRuntime(7966):     at android.app.ActivityThread.main(ActivityThread.java:5254)
06-10 13:17:03.080: E/AndroidRuntime(7966):     at java.lang.reflect.Method.invoke(Native Method)
06-10 13:17:03.080: E/AndroidRuntime(7966):     at java.lang.reflect.Method.invoke(Method.java:372)
06-10 13:17:03.080: E/AndroidRuntime(7966):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
06-10 13:17:03.080: E/AndroidRuntime(7966):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
06-10 13:17:03.080: E/AndroidRuntime(7966): Caused by: java.lang.SecurityException: Requires ACCESS_MOCK_LOCATION secure setting
06-10 13:17:03.080: E/AndroidRuntime(7966):     at android.os.Parcel.readException(Parcel.java:1546)
06-10 13:17:03.080: E/AndroidRuntime(7966):     at android.os.Parcel.readException(Parcel.java:1499)
06-10 13:17:03.080: E/AndroidRuntime(7966):     at android.location.ILocationManager$Stub$Proxy.addTestProvider(ILocationManager.java:1054)
06-10 13:17:03.080: E/AndroidRuntime(7966):     at android.location.LocationManager.addTestProvider(LocationManager.java:1216)
06-10 13:17:03.080: E/AndroidRuntime(7966):     at io.appium.settings.MockLocationProvider.pushLocation(MockLocationProvider.java:20)
06-10 13:17:03.080: E/AndroidRuntime(7966):     at io.appium.settings.LocationService.onStartCommand(LocationService.java:25)
06-10 13:17:03.080: E/AndroidRuntime(7966):     at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2894)
06-10 13:17:03.080: E/AndroidRuntime(7966):     ... 9 more

I'm running appium 1.5.3 on MacOSX 10.11.5
any hints?

Can you please try the same in API Level 21 or lesser than 22 and update us?

can do (again).. guess it is the same as appium/java-client#407

on API level 21 I get:
06-10 14:09:13.599: W/ActivityManager(1484): Unable to start service Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=io.appium.settings/.LocationService (has extras) } U=0: not found

in the android log

may that's also why it doesn't work on API level 21

The app has mock location access on (see https://github.com/appium/io.appium.settings/blob/master/AndroidManifest.xml#L32). Not sure why it is failing.

i just noticed that allow mock locations is not enabled by default in the api level 22 nexus 5 emulators (with google api).
it works after activating this setting.

however no luck with api level 21.

i can start the service via adb shell on api level 22 but not on 21

am startservice -e longitude 1 -e latitude 2 io.appium.settings/.LocationService
Starting service: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=io.appium.settings/.LocationServiceam (has extras) }
Error: Not found; no service started.

i manually uninstalled the appium settings app from the emulator and it seems that a newer version was installed by appium now. it now also works on api level 21.

However Appium should propably check the version.
06-10 15:38:16.747: W/PackageManager(1484): Attempt to re-install io.appium.settings without first uninstalling.

the problem could be that https://github.com/appium/io.appium.settings/blob/master/AndroidManifest.xml#L32 still has version 1.0 ?

maybe this should be true otherwise?

await adb.install(settingsApkPath, false);

for completeness: setting locations also works on Api 23 after sleecting the app in the developer settings to allow setting mock locations.

Issue moved to appium/appium #7404 via ZenHub