blunden / SPayToGPay

A helper app to remap the Samsung Pay button shortcut on the GW4 to Google Pay on watches shipping without Samsung Pay
Apache License 2.0
43 stars 0 forks source link

SPayToGpay stopped working after WearOS 4 (OneUI 5) update. #5

Closed 4k3or3et closed 1 year ago

4k3or3et commented 1 year ago

Hi there,

My Galaxy Watch 4 Classic just got update to Wear OS 5. Unfortunatelly SPayToGpay stopped working after update. I have tried to install app again but logner press of a button does not invoke Google Wallet. Is there any chance developer would spend some time trying to fix the issue on Wear OS 5? I am happy to test just in case.

Thanks anyway :-)

blunden commented 1 year ago

Yeah, I've heard that but I am unable to debug the app myself since I'm in a region where my app can't be installed.

I need a logcat log from slightly before, during and after the button shortcut is attempted to have any chance of tracking down the issue.

Is that something you are able to get me?

4k3or3et commented 1 year ago

I can definitely try. Can you let me know how to perform logcat?

blunden commented 1 year ago

This guide shows you how to set up ADB:

https://droidwin.com/how-to-set-up-and-enable-adb-debugging-in-galaxy-watch-4/

Once that's done and you've connected to the watch as described there, try running "adb logcat".

If you see a bunch of text filling up your terminal, press CTRL+C to cancel it. Then:

  1. Run "adb logcat > /sdcard/log.txt" to write it to a file.

  2. Try triggering the Samsung Pay button shortcut a few times.

  3. Press CTRL+C

  4. Run "adb pull /sdcard/log.txt ." (note the period at the end) to copy the log file from the watch to the directory your terminal is currently pointing at.

  5. Send me that file to support [at] blunden.se.

4k3or3et commented 1 year ago

I think i have it :-)

I have sent you the logcat log file on the mail which you specified above.

I have invoked Samsung Pay button (long press) 5 times during capturing the log with couple of second pause between each press and hold. If there is anything wrong with that log or you need anything else please let me know, i am happy to cooperate with you to get that issue possibly fixed.

Thanks a million for taking time to look into this matter. I truly appreciate that especially that for you that app is of no use.

blunden commented 1 year ago

Thanks! I have received it.

It might be a fiew days until I have a chance to look at it.

mk89pwnz commented 1 year ago

Looking forward for this to work again :)

blunden commented 1 year ago

I make no promises. 🙂

VNRARA commented 1 year ago

@blunden you need the new name of the Samsung pay app right?

blunden commented 1 year ago

I would expect the package name to remain the same. The activity name might have changed though, I suppose.

I'll pull the apk from my watch once the update has finished installing.

blunden commented 1 year ago

I made some blind changes here based on the manifest of the new Samsung Pay app:

https://www.mediafire.com/file/vdy4u4uijmlvekv/SPayToGPay-v1.3-wearos-4.0-test.apk/file

It includes a number of new activity-aliases as well as a broadcast receiver that looked potentially interesting.

This is completely untested of course. Make sure to reboot the watch after installing.

VNRARA commented 1 year ago

No dice. Didn't work :(

blunden commented 1 year ago

Hmm, ok.

This line in the log seems potentially interesting:

W ContextImpl: Calling a method in the system process without a qualified user: android.app.ContextImpl.sendBroadcast:1194 com.android.server.policy.PhoneWindowManagerExt.sendBroadcastSamsungPay:1439 com.android.server.policy.PhoneWindowManagerExt.stemPrimaryLongPress:1418 com.android.server.policy.PhoneWindowManager.stemPrimaryLongPress:1743 com.android.server.policy.PhoneWindowManager.-$$Nest$mstemPrimaryLongPress:0

That's why I implemented the receiver that I thought it refers to (based solely on the name). I haven't bothered to decompile PhoneWindowManagerExt to see what the sendBroadcastSamsungPay method actually does yet. I guess I'll need to do that at some point.

VNRARA commented 1 year ago

If I may be so bold: What did you change? I have the project open in Android Studio, but I'm a noob xD

blunden commented 1 year ago

This is the manifest from the latest test APK:

https://gist.github.com/blunden/4404f2a6593b582d16b6dcb908f8b7be

I also implemented a simple WalletLaunchReceiver.

blunden commented 1 year ago

It seems they didn't bother to obfuscate the PhoneWindowManagerExt class in /system/framework/services.jar:

https://pastebin.com/00L6cnJu

@VNRARA Can you check the logcat log for "SPayToGPayWalletLaunchReceiver" when performing the shortcut? I'm curious if it gets called at all.

VNRARA commented 1 year ago

With the v1.3 app correct? Also I noticed that : android.intent.category.INFO => android.intent.category.LAUNCHER

blunden commented 1 year ago

Yes, with the v1.3 test app above. :)

VNRARA commented 1 year ago

huh...

09-13 01:18:40.035 15189 15189 E SPayToGPayWalletLaunchReceiver: Failed to start Google Pay activity 09-13 01:18:40.035 15189 15189 W System.err: android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?

Running the v1.2 activity command via adb did work tho..

blunden commented 1 year ago

@VNRARA Thanks! Try the APK below and provide me the log output from when it fails. The same search you used last time should work.

https://www.mediafire.com/file/ephii59atj6zxhm/SPayToGPay-v1.3-wearos-4.0-test-2.apk/file

I'm a little concerned that Android will prevent it from launching the Google Pay app due to the limitations imposed in Android 10. Samsung's app has a special permission to launch apps from the background that can't be granted to my app. I suppose it might be possible to abuse the SYSTEM_ALERT_WINDOW permission, but I don't know if there is a UI for granting that on Wear OS, or if it can be granted with "pm grant".

https://developer.android.com/guide/components/activities/background-starts

VNRARA commented 1 year ago

I'm not sure. Am I supposed to look for SPayToGPayWalletLaunchReceiver ? Cause that isn't showing.

blunden commented 1 year ago

Yes, I would've expected it to print a line about receiving the broadcast when you press the button shortcut. It doesn't anymore?

Did you reboot the watch (unless that wasn't needed last time)?

VNRARA commented 1 year ago

I rebooted twice for good measure after installing the SPayToGPay-v1.3-wearos-4.0-test-2.apk via adblink2

logv132_2.txt

We can do some more testing tomorrow. GTG sleep. EU/AMS timezone here

What if you make the app pretty and abuse this:

"The app has an activity in the back stack of an existing task on the Recents screen."

blunden commented 1 year ago

Perhaps you could uninstall and then reinstall the SPayToGPay-v1.3-wearos-4.0-test-2.apk again? Maybe the system just stopped sending the broadcasts to it for some reason.

Clearly, your last log snippet showed that it was being called (but threw an exception later when trying to launch the Google Pay app without FLAG_ACTIVITY_NEW_TASK). All I changed was to add that flag to the intent before calling context.startActivity(activityIntent). Even if that call to startActivity failed, I would've expected to see some other exception and a log line saying "SPayToGPayWalletLaunchReceiver: onReceive(): com.samsung.android.wearable.sysui.action.CHECK_AND_LAUNCH_WALLET" before that.

blunden commented 1 year ago

You could also try what I mentioned above with this new APK instead (after you grant it the permission needed):

https://www.mediafire.com/file/58tkfl0bv7sz5gt/SPayToGPay-v1.3-wearos-4.0-test-3.apk/file

To grant the permission, run the following command:

adb shell pm grant com.samsung.android.samsungpay.gear android.permission.SYSTEM_ALERT_WINDOW

tomskra commented 1 year ago

I just tried SPayToGPay-v1.3-wearos-4.0-test-3.apk with granted SYSTEM_ALERT_WINDOW permission command and it's working !! 👍

blunden commented 1 year ago

Awesome! I'll push the code and upload an official APK. Apart from removing an extra line of debug logging, it should be functionally the same though.

Thank you all for providing me the necessary logs and testing. :)

blunden commented 1 year ago

Fixed in version 1.3 available under Releases.

mk89pwnz commented 1 year ago

Thanks a lot... also I needed some googling to figure it out, you need latest adb on your pc to first pair the watch then connect to it, it's not that simple like before and to use PowerShell instead of cmd, but now everything is working :)

blunden commented 1 year ago

@mk89pwnz Yes, that pairing process was new to me too. 😄 Surprisingly, it wasn't as well documented as I expected it to be.

VNRARA commented 1 year ago

@blunden srry for being late to the party today. Will install later too.

FYI: The mediafire link is dead.

VNRARA commented 1 year ago

NB: may not work immediately after boot.

@blunden it's a bit groggy after boot: it doesn't come as snappy as it used to.

blunden commented 1 year ago

But it doesn't require you to grant the permission again?

I don't think there is much I can do about that.

VNRARA commented 1 year ago

No worries. It was more of a nota bene for other users.

blunden commented 1 year ago

@VNRARA But the performance goes back to normal a while after boot?

VNRARA commented 1 year ago

Yeah, it seems back to normal after.

4k3or3et commented 1 year ago

@blunden, Thanks a million for sorting this out. Works fine :-)

I have noticed massive improvement in comparison to version 1.2. On 1.2 you could open Google Wallet using Samsung Pay button only when you were on watch face screen. If you had and app opened or were in setting you had to go to face watch screen and then you could open Google Wallet using Samsung Pay button. On version 1.3 no matter what you have on the screen at the moment, pressing Samsung Pay button always opens Google wallet. Not sure if that is thanks to adb permission command which you have now execute after installation or @blunden changed the code but this is actually great feature to have! Thanks again!

blunden commented 1 year ago

@4k3or3et My understanding is that it is a result of changes made by Samsung. I won't claim any credit for it, but I'm happy that people see an improvement in functionality. 😀

To me, it's mostly about solving problems and enjoying building PoCs that end up working for people. In this case, the target audience is definitely the smallest of any of my modded apps etc. but it's still fulfilling. 🙂