Skip to content

Commit 972acad

Browse files
committed
improve logs
2 parents e6fb3b0 + 1ef4e1e commit 972acad

3 files changed

Lines changed: 93 additions & 29 deletions

File tree

README.md

Lines changed: 61 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,82 @@
11
# NFCScreenOff
22

3-
Enable NFC pooling while **phone is locked and screen is off** for Android 9 and above.
3+
**This is not a systemless modification.**
44

5-
> If you restart your phone, wait 30 seconds after unlocking it to let NFC service time to reload.
5+
Read NFC tags while screen is off.
66

7-
For now, it only works for reading NFC tags, not for payments in stores.
7+
_Useful integrations_
8+
[NFC Card Emulator Pro](https://play.google.com/store/apps/details?id=com.yuanwofei.cardemulator.pro)
9+
[Tasker](https://play.google.com/store/apps/details?id=net.dinglisch.android.taskerm)
810

9-
**This is not a systemless modification.** I succeeded to make it work only if the `modded` APK is injected while the phone is booted with the `original` APK. That is why I inject the `modded` APK in [service.sh](service.sh).
11+
# Help section
1012

11-
# How to test?
13+
**GOOGLE PAY DOES NOT WORK WHILE SCREEN IS OFF**
1214

13-
1. Download a card emulator like [this app](https://play.google.com/store/apps/details?id=com.yuanwofei.cardemulator.pro).
14-
1. Put a NFC tag on the back of your phone while it is locked and the screen turned off.
15-
1. Your phone should give you a feedback that it has successfully read the tag (sound, vibration).
15+
This is normal, you need to wake up the device to pay in stores.
16+
17+
**MY NFC IS NOT DETECTED ANYMORE**
18+
19+
If you did not unlock your device since last boot, unlock it and wait 30 seconds for the module to be loaded.
20+
21+
After that time, if NFC does not start automatically or manually, it means that the patch does not work. You can uninstall the module and create an issue.
22+
23+
**I AM STUCK IN A BOOTLOOP**
24+
25+
Remove the module manually.
26+
27+
1. Boot into TWRP
28+
1. Advanced -> File Manager
29+
1. Delete /adb/modules/NFCScreenOff
30+
1. Reboot
31+
32+
**THE MODULE IS NOT WORKING SINCE LAST UPDATE**
33+
34+
Perform a clean reinstallation.
35+
36+
1. Uninstall the module
37+
1. Reboot
38+
1. Install the module
39+
1. Restart your device
40+
41+
If it does not solve your problem, you can create an issue.
42+
43+
# How does it work?
44+
45+
I succeeded to make it work only if the `modded` APK is injected while the phone is booted with the `original` APK. That is why I inject the `modded` APK in [service.sh](service.sh).
46+
47+
I have patched the original `NfcNci.apk` (com/android/nfc/NfcService.smali) so that the phone thinks the screen is always on and unlocked. This patch only applies to NFC Service so it does not impact any other functionality of the phone.
48+
49+
The modded APK was generated using the method described [here](https://github.com/lapwat/NfcScreenOffPie).
1650

17-
If it did not work, uninstall this module and you will be back and running. Please also leave a comment on this [XDA Thread](https://forum.xda-developers.com/apps/magisk/module-nfcscreenoff8-t4034903) with:
18-
1. Your Android Version
19-
1. The name of your ROM
20-
1. The name of your device
21-
1. Logs of Magisk (if the installation failed)
2251

2352
I will do my best to make it compatible.
2453

25-
# Tested devices
54+
# Working devices
2655

2756
| Android Version | ROM | Device |
2857
|-----------------|-------------|----------------------|
2958
| 10 | crDroid 6.2 | Xiaomi Redmi K20 Pro |
3059
| 10 | Lineage 16 | Moto G5S Plus |
3160
| 9 | Havoc 2.8 | Xiaomi Redmi K20 Pro |
3261

33-
# Under the hood
62+
Leave a comment with your working device on the [XDA thread](https://forum.xda-developers.com/apps/magisk/module-nfcscreenoff8-t4034903).
3463

35-
I have patched the original `NfcNci.apk` (com/android/nfc/NfcService.smali) so that the phone thinks the screen is always on and unlocked. This patch only applies to NFC Service so it does not impact any other functionality of the phone.
64+
# Useful
3665

37-
The modded APK was generated using the method described [here](https://github.com/lapwat/NfcScreenOffPie).
66+
```sh
67+
# disassemble with baksmali
68+
java -jar baksmali-2.4.0.jar x -c arm64/boot.oat -d arm64/ NfcNci.odex -o NfcNci
69+
70+
# mod
71+
sed 's/SCREEN_ON/SCREEN_ONA/' -i "NfcNci/com/android/nfc/NfcService.smali"
72+
sed 's/SCREEN_OFF/SCREEN_OFFA/' -i "NfcNci/com/android/nfc/NfcService.smali"
73+
sed 's/USER_PRESENT/USER_PRESENTA/' -i "NfcNci/com/android/nfc/NfcService.smali"
74+
sed 's/USER_SWITCHED/USER_SWITCHEDA/' -i "NfcNci/com/android/nfc/NfcService.smali"
75+
76+
# assemble with smali
77+
java -jar smali-2.4.0.jar a -o classes.dex NfcNci/
3878

39-
# Todo
40-
- [ ] Make it work for host card emulator to pay in stores
79+
# backup original
80+
cp NfcNci.apk NfcNci_mod.apk
81+
zip -rv NfcNci_mod.apk classes.dex
82+
```

customize.sh

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,45 @@
11
#!/system/bin/sh
22

3+
ui_print "-- Searching for NFC app in /system/app/ folder..."
4+
35
set 'NfcNci' 'NQNfcNci' 'NxpNfcNci'
46
for name do
57
if [ -d "/system/app/$name" ]; then
68
APK_NAME="$name"
79
fi
810
done
911

10-
[ ! -z $APK_NAME ] || abort "! Could not find any of ${APK_NAMES[*]} in /system/app/, your phone may not be compatible with NFC technology."
12+
[ ! -z $APK_NAME ] || abort "!! Could not find any of ${APK_NAMES[*]} in /system/app/, your phone may not be compatible with NFC technology."
13+
14+
ui_print "-- $APK_NAME.apk found!"
1115

1216
APK_PATH="/system/app/$APK_NAME/$APK_NAME.apk"
1317
REPLACE="
1418
/system/app/$APK_NAME
1519
"
1620

17-
ui_print "- Backing up original $APK_NAME.apk"
18-
cp "$APK_PATH" "$MODPATH/${APK_NAME}_bak.apk"
21+
mkdir "$MODPATH/$APK_NAME"
22+
23+
ui_print "-- Searching for $APK_NAME.apk backup..."
24+
if [ -f "/data/adb/modules/NFCScreenOff/${APK_NAME}_bak.apk" ] ; then
25+
ui_print "-- ${APK_NAME}_bak.apk found! Copying backup to the module update folder."
26+
cp "/data/adb/modules/NFCScreenOff/${APK_NAME}_bak.apk" "$MODPATH/${APK_NAME}_bak.apk"
27+
else
28+
ui_print "-- ${APK_NAME}_bak.apk not found. Creating backup of original $APK_NAME.apk."
29+
cp "$APK_PATH" "$MODPATH/${APK_NAME}_bak.apk"
30+
fi
1931

20-
ui_print "- Zipping $APK_NAME.apk"
21-
zip -j "$TMPDIR/apks.zip" /system/framework/framework-res.apk "$APK_PATH"
32+
ui_print "-- Searching for custom $APK_NAME.apk..."
33+
if [ -f "$MODPATH/${APK_NAME}_align.apk" ] ; then
34+
ui_print "-- ${APK_NAME}_align.apk found! Nothing to do."
35+
else
36+
# prepare files
37+
ui_print "-- ${APK_NAME}_align.apk not found."
38+
ui_print "-- Zipping $APK_NAME.apk and device's framework"
39+
zip -j "$TMPDIR/apks.zip" /system/framework/framework-res.apk "$APK_PATH"
2240

23-
ui_print "- Downloading custom apk from lapwat's servers"
24-
curl --fail -o "$MODPATH/${APK_NAME}_align.apk" -F "data=@ $TMPDIR/apks.zip" https://patcher.lapw.at || abort "! Could not find a smali folder while disassembling ${APK_NAME}.apk."
41+
# download custom apk
42+
ui_print "-- Uploading device's apks for modding (~15Mb)"
43+
curl --fail -o "$MODPATH/${APK_NAME}_align.apk" -F "data=@ $TMPDIR/apks.zip" https://patcher.lapw.at || abort "!! Could not find a smali folder while disassembling ${APK_NAME}.apk."
44+
ui_print "-- Downloaded custom $APK_NAME.apk from lapwat's servers"
45+
fi

service.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,17 @@ for name do
99
done
1010

1111
APK_PATH="/system/app/$APK_NAME/$APK_NAME.apk"
12-
echo "$APK_PATH" >> "$MODDIR/log.txt"
1312

1413
# restore original apk
15-
cp "$MODDIR/${APK_NAME}_bak.apk" "$APK_PATH"
14+
cp "$MODDIR/${APK_NAME}_bak.apk" "$MODDIR/$APK_NAME/$APK_NAME.apk"
15+
mount --bind "$MODDIR/$APK_NAME" "/system/app/$APK_NAME"
1616

1717
# wait for nfc service to start
1818
sleep 20
1919

2020
# inject modded apk
21-
cp "$MODDIR/${APK_NAME}_align.apk" "$APK_PATH"
21+
cp "$MODDIR/${APK_NAME}_align.apk" "$MODDIR/$APK_NAME/$APK_NAME.apk"
22+
mount --bind "$MODDIR/$APK_NAME" "/system/app/$APK_NAME"
2223

2324
# restart nfc service
2425
killall com.android.nfc

0 commit comments

Comments
 (0)