mcastillof / FakeTraveler

Fake where your phone is located (Mock location for Android).
GNU General Public License v3.0
356 stars 79 forks source link

Android 13 - Crashes on start #56

Open TimoGoetze opened 1 year ago

TimoGoetze commented 1 year ago

Describe the bug A clear and concise description of what the bug is.

Information:

To Reproduce Steps to reproduce the behavior:

  1. Go to '...' Choose location and press start. then it crashes.
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior A clear and concise description of what you expected to happen.

works and doesnt crash

type: crash
osVersion: google/oriole/oriole:13/TP1A.220624.021/2022083000:user/release-keys
package: cl.coders.faketraveler:7
process: cl.coders.faketraveler

java.lang.IllegalStateException
    at android.os.Parcel.createExceptionOrNull(Parcel.java:3020)
    at android.os.Parcel.createException(Parcel.java:2996)
    at android.os.Parcel.readException(Parcel.java:2979)
    at android.os.Parcel.readException(Parcel.java:2921)
    at android.location.ILocationManager$Stub$Proxy.addTestProvider(ILocationManager.java:2154)
    at android.location.LocationManager.addTestProvider(LocationManager.java:2113)
    at android.location.LocationManager.addTestProvider(LocationManager.java:2088)
    at android.location.LocationManager.addTestProvider(LocationManager.java:2062)
    at cl.coders.faketraveler.MockLocationProvider.<init>(MockLocationProvider.java:28)
    at cl.coders.faketraveler.MainActivity.applyLocation(MainActivity.java:257)
    at cl.coders.faketraveler.MainActivity$1.onClick(MainActivity.java:81)
    at android.view.View.performClick(View.java:7506)
    at android.view.View.performClickInternal(View.java:7483)
    at android.view.View.-$$Nest$mperformClickInternal(Unknown Source:0)
    at android.view.View$PerformClick.run(View.java:29335)
    at android.os.Handler.handleCallback(Handler.java:942)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loopOnce(Looper.java:201)
    at android.os.Looper.loop(Looper.java:288)
    at android.app.ActivityThread.main(ActivityThread.java:7904)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
    at com.android.internal.os.ExecInit.main(ExecInit.java:49)
    at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
    at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:355)
Caused by: android.os.RemoteException: Remote stack trace:
    at com.android.internal.util.Preconditions.checkState(Preconditions.java:215)
    at com.android.internal.util.Preconditions.checkState(Preconditions.java:200)
    at com.android.server.location.LocationManagerService.addLocationProviderManager(LocationManagerService.java:350)
    at com.android.server.location.LocationManagerService.getOrAddLocationProviderManager(LocationManagerService.java:342)
    at com.android.server.location.LocationManagerService.addTestProvider(LocationManagerService.java:1314)

Screenshots If applicable, add screenshots to help explain your problem.

Logcat If the app is crashing, a logcat of the error could be very helpful.

Additional context Add any other context about the problem here.

steel-steven-87 commented 1 year ago

Can confirm this stopped working for me after upgrading to Android 13.

Idcrafter commented 1 year ago

I can't even start it on my redmi note 10 with custom lineage os but it runs on my pixel 6 pro that runs on calyx os, both android phone versions are Android 13

schklom commented 1 year ago

FYI, a similar issue got fixed at https://github.com/warren-bank/Android-Mock-Location/issues/14 for my Pixel 6a with GrapheneOS. The code workaround is dumb, but it works for me. Maybe it works here too?

warren-bank commented 1 year ago

Hi, all. To quickly summarize the "dumb" workaround (as it's now affectionately known) mentioned by @schklom ...

Also, I should probably mention.. with regard to the question of why an IllegalStateException is being thrown.. Daniel Micay, the founder and lead developer of GrapheneOS, offered a bit of a warning.. though not an explanation, he did say that he doesn't believe this is limited to the Pixel.. that there's nothing special about its hardware to cause this.. but rather, that it happens to be one of only a few devices that runs bleeding-edge AOSP code.. and in time, once device makers catch up, and update the version of Android 13 that's running on their products.. this issue will (most likely) be far more common.

mcastillof commented 1 year ago

@TimoGoetze I have made the change that @warren-bank is proposing. Can you test if this APK is working for you?

warren-bank commented 1 year ago

@mcastillof I'd offer to test your build myself, but I'm in the same boat. I don't have a device new enough to reproduce or test this bug. Consequently, I'm also not sure what the effect of this workaround actually is. It's either:

  1. try once.. fail. try again.. succeed
  2. foreach of N retry attempts: try.. fail. silently ignore particular location provider.

I suppose that either option is better than a fatal error.. crash.

mcastillof commented 1 year ago

@warren-bank I wonder if a Pixel 6 device with Android 13 (arm64-v8a or x86) emulated using Android Studio could be useful to test the behavior.

warren-bank commented 1 year ago

I don't know. Also, and this is just a personal quirk.. with a dash of laziness sprinkled on top, but I only test on a few real devices. That said, the issue didn't occur when tested on a Galaxy S5 w/ LineageOS 20 (Android 13.0).

I was actually wondering whether android-x86 had a nighly release to test in VirtualBox, but the project hasn't been active in quite a long time.

Bliss OS is also some variation of Android x86, but its releases are based on versions of AOSP that are nowhere near new enough.

mcastillof commented 1 year ago

I went ahead and tried a Pixel 6 pro with Android 13 (arm64-v8a) in Android Emulator within Android Studio. My host machine has an x86_64 architecture.

./emulator @Pixel_6_Pro_API_33
INFO    | Android emulator version 32.1.12.0 (build_id 9751036) (CL:N/A)
INFO    | Found systemPath /home/user/workspace/android/Android/Sdk/system-images/android-33/google_apis/arm64-v8a/
PANIC: Avd's CPU Architecture 'arm64' is not supported by the QEMU2 emulator on x86_64 host.

I will try an x86_64 image now. Hope it works this time.

warren-bank commented 1 year ago

Yeah, definitely let me know the outcome. The x86_64 image will run.. dunno whether the bug will occur. Curious to find out.

I'm actually reading this.. and am tempted to try the same methodology to run the newest Pixel factory image.. which we know is problematic. Though, now that you mention it, the OP might have been unable to run his image because he was also using an arm64 image.

mcastillof commented 1 year ago

Now I'm a bit confused. I only use LineageOS, and I'm not used to that Android/Pixel stuff. The images found in Pixel factory image aren't the same as the images that can be downloaded with in Android Emulator in Android Studio?

Pixel phones come with a different Android version? What's the name of the ROM?

warren-bank commented 1 year ago

since I don't use it.. I'm not an expert.. but my understanding of the emulator that comes with Android Studio is that is uses the qemu emulator and the AVD (android virtual device) images that it downloads directly from google are very much like a factory image.. in that it's a zip file containing individual images for each partition.

as to which version.. or how old the images are.. I'm not sure.. does the AVD manager provide details about each image? ..it's not in front of me at the moment.

for example, this is a link to an old image

mcastillof commented 1 year ago

It booted now (x86_64 image)

image

AVD manager only seems to say that it is an API 33:

Properties
avd.ini.displayname              Pixel 6 Pro API 33 2
avd.ini.encoding                 UTF-8
AvdId                            Pixel_6_Pro_API_33_2
disk.dataPartition.size          2G
fastboot.chosenSnapshotFile
fastboot.forceChosenSnapshotBoot no
fastboot.forceColdBoot           no
fastboot.forceFastBoot           yes
hw.accelerometer                 yes
hw.arc                           false
hw.audioInput                    yes
hw.battery                       yes
hw.camera.back                   virtualscene
hw.camera.front                  emulated
hw.cpu.ncore                     2
hw.device.hash2                  MD5:a8abfd3536f3d35e4ba2041a7b99f40e
hw.device.manufacturer           Google
hw.device.name                   pixel_6_pro
hw.dPad                          no
hw.gps                           yes
hw.gpu.enabled                   yes
hw.gpu.mode                      auto
hw.initialOrientation            Portrait
hw.keyboard                      yes
hw.lcd.density                   560
hw.lcd.height                    3120
hw.lcd.width                     1440
hw.mainKeys                      no
hw.ramSize                       1536
hw.sdCard                        yes
hw.sensors.orientation           yes
hw.sensors.proximity             yes
hw.trackBall                     no
image.androidVersion.api         33
image.sysdir.1                   system-images/android-33/google_apis/x86_64/
PlayStore.enabled                false
runtime.network.latency          none
runtime.network.speed            full
showDeviceFrame                  yes
skin.dynamic                     yes
tag.display                      Google APIs
tag.id                           google_apis
vm.heapSize                      384
mcastillof commented 1 year ago

In the followin image, I downloaded Tiramisu (number 1 red), It showed me the url of the download, but I can't get access to it now, If I try to download the number 2 red, it show this link https://dl.google.com/android/repository/sys-img/google_apis/x86_64-UpsideDownCake_r03.zip

image

warren-bank commented 1 year ago

hmm.. I googled the build number.. but it didn't pull anything up.

going by the date of the last security update.. it should be pretty recent.

what happens when you run the last stable release of your app (that users are seeing this issue)?

mcastillof commented 1 year ago

Your fix seems to work fine, as I don't see that it crashes. I will try now without your fix.

warren-bank commented 1 year ago

the response for the URL of that system image includes the header:

last-modified: Wed, 12 Apr 2023 16:15:00 GMT

..but that can't be right

warren-bank commented 1 year ago

pins and needles.. :smiley:

Pay for the whole seat, but you'll only need.. the edge!

mcastillof commented 1 year ago

I couldn't reproduce the problem with the old code.

And new problem arises in FakeTraveler when using Android 13,

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: cl.coders.faketraveler, PID: 11990
    java.lang.IllegalArgumentException: cl.coders.faketraveler: Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent.
    Strongly consider using FLAG_IMMUTABLE, only use FLAG_MUTABLE if some functionality depends on the PendingIntent being mutable, e.g. if it needs to be used with inline replies or bubbles.
        at android.app.PendingIntent.checkFlags(PendingIntent.java:401)
        at android.app.PendingIntent.getBroadcastAsUser(PendingIntent.java:671)
        at android.app.PendingIntent.getBroadcast(PendingIntent.java:658)
        at cl.coders.faketraveler.MainActivity.setAlarm(MainActivity.java:318)
        at cl.coders.faketraveler.MainActivity.applyLocation(MainActivity.java:270)
        at cl.coders.faketraveler.MainActivity$1.onClick(MainActivity.java:81)
        at android.view.View.performClick(View.java:7506)
        at android.view.View.performClickInternal(View.java:7483)
        at android.view.View.-$$Nest$mperformClickInternal(Unknown Source:0)
        at android.view.View$PerformClick.run(View.java:29334)
        at android.os.Handler.handleCallback(Handler.java:942)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loopOnce(Looper.java:201)
        at android.os.Looper.loop(Looper.java:288)
        at android.app.ActivityThread.main(ActivityThread.java:7872)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
D/EGL_emulation: app_time_stats: avg=75.43ms min=4.31ms max=727.74ms count=13
I/Process: Sending signal. PID: 11990 SIG: 9

which is solved by changing this line to

    pendingIntent = PendingIntent.getBroadcast(context, SCHEDULE_REQUEST_CODE, serviceIntent, PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_IMMUTABLE);

I believe that your code already address this FLAG_IMMUTABLE or FLAG_MUTABLE exception.

So, we are the begging again. We need a tester which had the problem.

warren-bank commented 1 year ago

Yeah.. there was an issue about that (missing PendingIntent flag) error in one of my apps a few months ago.. and I pushed an update across all of them at the same time. Easy enough to fix.. just annoying how every new version of Android breaks user space and requires updates to keep existing functionality working.. big pet peeve.

Anyway, as you said.. shame that the emulator wasn't any help. But, huge thanks for bothering to test it! Would've been really nice to run this error through the debugger and be able to determine whether this workaround is actually fixing initialization of the provider.. or simply catching the exception and allowing the app to ignore that it failed.

update: I just learned something new.. about the push toward running generic system images. I don't think I have a phone that supports this.. and even if I did, it still looks too risky to try installing an update manually.. but it's great to see.. because it's so very much needed.. and clearly the future for Android updatability. Links: 1, 2, 3, 4, and 5. Related links: 1, 2, and 3.

mcastillof commented 1 year ago

Yeah.. there was an issue about that (missing PendingIntent flag) error in one of my apps a few months ago.. and I pushed an update across all of them at the same time. Easy enough to fix.. just annoying how every new version of Android breaks user space and requires updates to keep existing functionality working.. big pet peeve.

I think the same.

Anyway, as you said.. shame that the emulator wasn't any help. But, huge thanks for bothering to test it! Would've been really nice to run this error through the debugger and be able to determine whether this workaround is actually fixing initialization of the provider.. or simply catching the exception and allowing the app to ignore that it failed.

We had to give it a try to the emulator.

Have a good day/night @warren-bank warren-bank :)

mcastillof commented 1 year ago

If somebody is still having this issue with FakeTraveler v1.9.1, which was released a few days ago in F-Droid, then please try if this APK is working for you and report it here.

TimoGoetze commented 1 year ago

Tried the one from F-Droid. First just did not work. Then Crashed again. I cannot try from coders.cl.

`` type: crash osVersion: google/oriole/oriole:13/TQ2A.230405.003.E1/2023041100:user/release-keys package: cl.coders.faketraveler:9 process: cl.coders.faketraveler processUptime: 4501 + 192 ms

java.lang.IllegalStateException at android.os.Parcel.createExceptionOrNull(Parcel.java:3029) at android.os.Parcel.createException(Parcel.java:3005) at android.os.Parcel.readException(Parcel.java:2981) at android.os.Parcel.readException(Parcel.java:2923) at android.location.ILocationManager$Stub$Proxy.addTestProvider(ILocationManager.java:2169) at android.location.LocationManager.addTestProvider(LocationManager.java:2131) at android.location.LocationManager.addTestProvider(LocationManager.java:2106) at android.location.LocationManager.addTestProvider(LocationManager.java:2080) at cl.coders.faketraveler.MockLocationProvider.(MockLocationProvider.java:28) at cl.coders.faketraveler.MainActivity.applyLocation(MainActivity.java:257) at cl.coders.faketraveler.MainActivity$1.onClick(MainActivity.java:81) at android.view.View.performClick(View.java:7506) at android.view.View.performClickInternal(View.java:7483) at android.view.View.-$$Nest$mperformClickInternal(Unknown Source:0) at android.view.View$PerformClick.run(View.java:29357) at android.os.Handler.handleCallback(Handler.java:942) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loopOnce(Looper.java:201) at android.os.Looper.loop(Looper.java:288) at android.app.ActivityThread.main(ActivityThread.java:7891) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548) at com.android.internal.os.ExecInit.main(ExecInit.java:49) at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method) at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:355) Caused by: android.os.RemoteException: Remote stack trace: at com.android.internal.util.Preconditions.checkState(Preconditions.java:215) at com.android.internal.util.Preconditions.checkState(Preconditions.java:200) at com.android.server.location.LocationManagerService.addLocationProviderManager(LocationManagerService.java:350) at com.android.server.location.LocationManagerService.getOrAddLocationProviderManager(LocationManagerService.java:342) at com.android.server.location.LocationManagerService.addTestProvider(LocationManagerService.java:1319)

TimoGoetze commented 1 year ago

pixel 6. latest updates.

mcastillof commented 1 year ago

Hello @TimoGoetze

Tried the one from F-Droid. First just did not work. Then Crashed again. I cannot try from coders.cl.

Did you experienced any problem with the download of the APK from c.coders.cl server?

I test the download and it worked without any problem. if you prefer I can upload the test APK here in Github.

mcastillof commented 1 year ago

@TimoGoetze I have pushed this beta release to F-Droid. It should be available soon in F-Droid's app. As this is a beta release, you will have to manually install it from the versions dropdown.

If you don't want to wait, you can download an unsigned apk built automatically by GitLab CI at the bottom of the Merge Request.

Please, test the app and come back with feedback.

UnlimitedCookies commented 6 months ago

@mcastillof It seems the build failed at F-Droid. Does this version also fix the missing FLAG_IMMUTABLE vor FLAG_MUTABLE for the PendingIntent ? (https://paste.crdroid.net/V6KHeN)

warren-bank commented 6 months ago

@UnlimitedCookies the FLAG_IMMUTABLE flag is included in master and the most recent tag: v1.9.2-beta,
but not in the most recent stable release: v1.9.1

@mcastillof fwiw, although it probably isn't necessary, I like to make the inclusion of this flag conditional.. for example:

serviceIntent = new Intent(context, ApplyMockBroadcastReceiver.class);

int flags = PendingIntent.FLAG_CANCEL_CURRENT;
if (Build.VERSION.SDK_INT >= 23)
  flags |= PendingIntent.FLAG_IMMUTABLE;

pendingIntent = PendingIntent.getBroadcast(context, SCHEDULE_REQUEST_CODE, serviceIntent, flags);
mnalis commented 5 months ago

@TimoGoetze I have pushed this beta release to F-Droid. It should be available soon in F-Droid's app. As this is a beta release, you will have to manually install it from the versions dropdown.

As noted, unfortunately F-droid build of v1.9.2-beta seemed to fail, and thus it is not available at f-droid at all.

If you don't want to wait, you can download an unsigned apk built automatically by GitLab CI at the bottom of the Merge Request.

Unfortunately, that .apk no longer seem available. I guess it is only kept for some short period of time. Also, I was hoping to find pre-release APK on this Github repo, but no such luck.

I've ended up forking and having GitHub compile it for me. It wasn't easy as usual, though, as Android CI GitHub workflow was failing. I've managed to make it work (by updating workflow, using not-recommended workaround of setting targetSdkVersion back to 30 and disabling lint.)

Luckily, the resulting .apk worked! (although, for Google Play release, the real culprit of that compilation error should be found and fixed).

Please, test the app and come back with feedback.

I've tested the latest master 1878d70baf6792c507283176cc5aa39c3620b843 on Android 13 (Samsung Galaxy S23+) and it no longer crashes there and works just fine! (if others want to try too, the .apk built by GitHub) should be available for next 90 days.

Can we have an release of 1.9.2 please, so regular f-droid.org users can benefit too?

mcastillof commented 5 months ago

Sorry I haven't had the time to take care of FakeTraveler. I will work on the project this days to be sure it works on f-droid..