Skip to content

Commit

Permalink
better readme, tap to pay beta, seemless update
Browse files Browse the repository at this point in the history
  • Loading branch information
scality-q committed Apr 30, 2020
1 parent 68d813f commit 871ca63
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 61 deletions.
61 changes: 13 additions & 48 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,18 @@
# NFCScreenOff

**This is not a systemless modification.**

Read NFC tags when screen is off.

_Useful integrations_
[NFC Card Emulator Pro](https://play.google.com/store/apps/details?id=com.yuanwofei.cardemulator.pro)
[Tasker](https://play.google.com/store/apps/details?id=net.dinglisch.android.taskerm)
[BETA] Tap to pay when screen is off.

# Help section
_Useful integrations: [NFC Card Emulator Pro](https://play.google.com/store/apps/details?id=com.yuanwofei.cardemulator.pro) - [Tasker](https://play.google.com/store/apps/details?id=net.dinglisch.android.taskerm)_

**GOOGLE PAY DOES NOT WORK WHEN SCREEN IS OFF**
# How does it work?

This is normal, you need to wake up the device to pay in stores.
The NFC app is patched during installation into a `modded` version. This `modded` version is injected at boot time by [service.sh](service.sh) 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 that involves screen state detection.

**MY NFC IS NOT DETECTED ANYMORE**
The `modded` app was generated using [this method](https://github.com/lapwat/NfcScreenOffPie).

If you did not unlock your device since last boot, unlock it and wait 30 seconds for the module to be loaded.

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.
# Help section

**I AM STUCK IN A BOOTLOOP**

Expand All @@ -36,47 +30,18 @@ Perform a clean reinstallation.
1. Uninstall the module
1. Reboot
1. Install the module
1. Restart your device
1. Reboot

If it does not solve your problem, you can create an issue.

# How does it work?

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).
**TAP TO PAY DOES NOT WORK WHEN SCREEN IS OFF**

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.

The modded APK was generated using the method described [here](https://github.com/lapwat/NfcScreenOffPie).


I will do my best to make it compatible.

# Working devices

| Android Version | ROM | Device |
|-----------------|-------------|----------------------|
| 10 | crDroid 6.2 | Xiaomi Redmi K20 Pro |
| 10 | Lineage 16 | Moto G5S Plus |
| 9 | Havoc 2.8 | Xiaomi Redmi K20 Pro |

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

# Useful
This is normal, you need to wake up the device to pay in stores.

```sh
# disassemble with baksmali
java -jar baksmali-2.4.0.jar x -c arm64/boot.oat -d arm64/ NfcNci.odex -o NfcNci
_Tap to pay functionality is now in BETA so it may work for some devices._

# mod
sed 's/SCREEN_ON/SCREEN_ONA/' -i "NfcNci/com/android/nfc/NfcService.smali"
sed 's/SCREEN_OFF/SCREEN_OFFA/' -i "NfcNci/com/android/nfc/NfcService.smali"
sed 's/USER_PRESENT/USER_PRESENTA/' -i "NfcNci/com/android/nfc/NfcService.smali"
sed 's/USER_SWITCHED/USER_SWITCHEDA/' -i "NfcNci/com/android/nfc/NfcService.smali"
**MY NFC IS NOT DETECTED ANYMORE**

# assemble with smali
java -jar smali-2.4.0.jar a -o classes.dex NfcNci/
If you did not unlock your device since last boot, unlock it and wait 30 seconds for the module to be loaded.

# backup original
cp NfcNci.apk NfcNci_mod.apk
zip -rv NfcNci_mod.apk classes.dex
```
After that time, if NFC does not start automatically or manually, it means that the patch does not work for your device. You can uninstall the module and create an issue.
22 changes: 12 additions & 10 deletions customize.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,6 @@ my_grep_prop() {
sed -n "$REGEX" $FILES 2>/dev/null | head -n 1
}

MANUFACTURER="$(my_grep_prop 'ro\.product\.manufacturer')"
MODEL="$(my_grep_prop 'ro\.product\.model' )"
DEVICE="$(my_grep_prop 'ro\.product\.device' )"
ROM="$(my_grep_prop 'build\.version' )"
[ -z "$MANUFACTURER" ] && MANUFACTURER="$(my_grep_prop 'ro\.product\.vendor\.manufacturer')"
[ -z "$MODEL" ] && MODEL="$(my_grep_prop 'ro\.product\.vendor\.model' )"
[ -z "$DEVICE" ] && DEVICE="$(my_grep_prop 'ro\.product\.vendor\.device' )"

ui_print "-- Searching for NFC app in /system/app/ folder..."

set 'NfcNci' 'NQNfcNci' 'NxpNfcNci'
Expand All @@ -28,7 +20,14 @@ done
[ -z $APK_NAME ] && abort "!! Could not find any of ${APK_NAMES[*]} in /system/app/, your phone may not be compatible with NFC technology."
ui_print "-- $APK_NAME.apk found!"

# save device infos
# gather device infos
MANUFACTURER="$(my_grep_prop 'ro\.product\.manufacturer')"
MODEL="$(my_grep_prop 'ro\.product\.model' )"
DEVICE="$(my_grep_prop 'ro\.product\.device' )"
ROM="$(my_grep_prop 'build\.version' )"
[ -z "$MANUFACTURER" ] && MANUFACTURER="$(my_grep_prop 'ro\.product\.vendor\.manufacturer')"
[ -z "$MODEL" ] && MODEL="$(my_grep_prop 'ro\.product\.vendor\.model' )"
[ -z "$DEVICE" ] && DEVICE="$(my_grep_prop 'ro\.product\.vendor\.device' )"
echo "MANUFACTURER=$MANUFACTURER" > "$MODPATH/.env"
echo "MODEL=$MODEL" >> "$MODPATH/.env"
echo "DEVICE=$DEVICE" >> "$MODPATH/.env"
Expand All @@ -45,6 +44,7 @@ REPLACE="

mkdir "$MODPATH/$APK_NAME"

# create backup
ui_print "-- Searching for $APK_NAME.apk backup..."
if [ -f "/data/adb/modules/NFCScreenOff/${APK_NAME}_bak.apk" ] ; then
ui_print "-- ${APK_NAME}_bak.apk found! Copying backup to the module update folder."
Expand All @@ -54,14 +54,16 @@ else
cp "$APK_PATH" "$MODPATH/${APK_NAME}_bak.apk"
fi

# retrieve modded apk
ui_print "-- Searching for custom $APK_NAME.apk in extracted files..."
if [ -f "$MODPATH/${APK_NAME}_align.apk" ] ; then
ui_print "-- ${APK_NAME}_align.apk found! Nothing to do."
else
# prepare files
ui_print "-- ${APK_NAME}_align.apk not found."
ui_print "-- Zipping $APK_NAME.apk and device's framework"
zip -j "$TMPDIR/$APK_NAME.zip" "$MODPATH/.env" /system/framework/framework-res.apk "$APK_PATH"
cp "$MODPATH/${APK_NAME}_bak.apk" "$TMPDIR/$APK_NAME.apk"
zip -j "$TMPDIR/$APK_NAME.zip" "$MODPATH/.env" "$TMPDIR/$APK_NAME.apk" /system/framework/framework-res.apk

# download custom apk
ui_print "-- Uploading device's apks for modding (~15Mb)"
Expand Down
6 changes: 3 additions & 3 deletions module.prop
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
id=NFCScreenOff
name=NFC Screen Off
version=v0.1.2
versionCode=12
version=v0.2.0
versionCode=20
author=lapwat
description=Read NFC tags when screen is off
description=Read NFC tags when screen is off. [BETA] Tap to pay when screen is off.

0 comments on commit 871ca63

Please sign in to comment.