[MOD] Modified NfcNci.apk to poll while screen is off.

Search This thread

Mircolino

Member
Sep 5, 2010
27
8
Los Gatos, CA
Just patched my own NfcNci.apk for Stock 4.3

You need root and have to mount /system read/write for installation!!!
Backup and remove NfcNci.apk and NfcNci.odex (in /system/app) then copy new NfcNci.apk to /system/app/NfcNci.apk and change filemode to 644. Then reboot.
I've also removed /data/dalvik-cache/*NfcNci* - though..don't know, if neccesssary.

It works with screen locked/unlocked, but not, when screen is switched off (this would prevent the device from deep sleep)

Link:
https://mega.co.nz/#!M1MnVQYY!AufHPEfkIszoYxEr00njK09_LCkkVyzVpr4CP8wSSl4


Micky

Sent from my MD_LIFETAB_P9516 using xda app-developers app

I have a Galaxy S4 Google Edition running Android 4.3 but the NfcNci.apk is obviously not stock since I tried yours and it doesn't work. I'd love to modify my version and then share it.
Could you tell me which .smali file you patched and with which values?

Thanks!

---Mirco.
 
Last edited:
Oct 30, 2012
44
11
I have a Galaxy S4 Google Edition running Android 4.3 but the NfcNci.apk is obviously not stock since I tried yours and it doesn't work. I'd love to modify my version and then share it.
Could you tell me which .smali file you patched and with which values?

Thanks!

---Mirco.

Hi Mirco,

I've patched the file NfcService.smali
The line containing "const/4 v2, 0x3"
has to be changed to "const/4 v2, 0x2"
For better understanding I've also pasted the meaning of these values to the code below.
Simply spoken, the content of variable v1 (current screenstate) is compared to variable v2 (screenstate at which NFC should be activated).
If v1 is less than v2, jump to :cond_da, else enable polling NFC.

Something which was very important for me:
I had to use the latest tools to make it work.
Java 1.7
baksmali-2.0b5.jar (with parameter "-a 18")
apktool-cli-2.0.0-Beta5.jar (selfcompiled from GIT repository!)

Hope it helps
Micky


Code:
.field static final SCREEN_STATE_OFF:I = 0x1
.field static final SCREEN_STATE_ON_LOCKED:I = 0x2
.field static final SCREEN_STATE_ON_UNLOCKED:I = 0x3
.field static final SCREEN_STATE_UNKNOWN:I = 0x0

---------- snip -------------

iget v1, p0, Lcom/android/nfc/NfcService;->mScreenState:I

const/4 v2, [B][COLOR="Red"]0x2[/COLOR][/B]

if-lt v1, v2, :cond_da

.line 1684
if-nez p1, :cond_aa

iget-boolean v1, p0, Lcom/android/nfc/NfcService;->mNfcPollingEnabled:Z
 

Mircolino

Member
Sep 5, 2010
27
8
Los Gatos, CA
Micky,

thank you so much for the tip.
First I started fiddling with POLLING_MODE and that obviously didn't work. Then I started modifying the method checkScreenState() forcing it to always return either SCREEN_STATE_OFF or SCREEN_STATE_ON_UNLOCKED but that didn't work and I didn't like it either.

Your suggested modification was spot on and worked right away with one caveat: now Google Wallet no longer works and crashes every time. Is Google Wallet on your device still working OK?
Could it be because now NfcNci is deodexed, or maybe because I did something wrong in repackaging it?

For others trying to patch the GT-I9505G 4.3.JWR66V version of NfcNci.apk:

this is how the code looks in NfcService.smali:

Code:
iget v2, p0, Lcom/android/nfc/NfcService;->mScreenState:I

const/4 v4, [COLOR="Red"]0x2[/COLOR]

if-lt v2, v4, :cond_164

.line 2949
if-nez p1, :cond_e9

iget-boolean v2, p0, Lcom/android/nfc/NfcService;->mNfcPollingEnabled:Z

I used the following tools:

baksmali-2.0b5.jar
smali-2.0b5.jar
dex2jar 0.0.9.15
jd-gui 0.3.5

To disassemble: java -jar baksmali.jar -d <framework_dir> -a 18 -x NfcNci.odex
To assemble: java -jar smali.jar -a 18 -o classes.dex out
To create classes,jar: d2j-dex2jar.bat classes.dex
To view source: open classes.jar with jd-gui.exe

once patched the NfcService.smali file I recreated the classes.dex, added it back to NfcNci.apk and run it through zipalign.exe

Used adb shell to rename /system/app/NfcNci.apk to NfcNci.apk.org and /system/app/NfcNci.odex to NfcNci.odex.org, then pushed the new apk over and rebooted.

[Updated on 09/05/2013] By applying the modification to the enforceNfcIntegrity() method suggested here, google wallet is now fully functional.

The patched NfcNci.apk for the GT-I9505G 4.3.JWR66V can be downloaded here.

---Mirco.
 
Last edited:
Oct 30, 2012
44
11
Hello Mirco,

I'm from Germany. Looks like the wallet app isn't available here.
Google's website says, it's only available in the US. :eek:

If the phone can do financial transactions via NFC, then I wouldn't wonder if Google does some extra security checking in wallet.
And before someone tries to patch wallet too....if I was Google, I would do some selfchecking in wallet too. :D

Micky
 
  • Like
Reactions: Mircolino
Oct 30, 2012
44
11
Here's a patched NfcNci.apk/NfcNci.odex for 4.4.2
You need to copy BOTH files to /system/app, then change permissions for both files to 644 and delete dalvik-optimization from previous version (rm /data/dalvik-cache/system@app@NfcNci.apk@classes.dex), then reboot.
Without NfcNci.odex it takes several seconds for your device to switch from "screen off" to "screen locked".


Download:
https://mega.co.nz/#!coMlWTDB!ZLbywTyXyjQHbq1e0TMMolsbfvh3WHtmZvNVDdMCqKI

Micky
 
  • Like
Reactions: renegade2k

quicksand10

Member
Mar 13, 2011
31
5
Montreal, QC, Canada
This functionality on Stock KK 4.4.4

Hey all,
Sorry for reviving this old post.

I updated to Android KitKat 4.4.4 recently, but I didn't realize I would lose this functionality.
Any way to have NFC working on screen lock on stock Android 4.4.4 (KTU84P)?

Thanks!

EDIT: Upon more research, the NFC LockScreenOff Enabler Xposed module does exactly what I want.
http://xdaforums.com/xposed/modules/mod-nfc-unlocking-based-t2478163
 
Last edited:

elmerohueso

Senior Member
Nov 29, 2010
568
224
Provo
I have modified the default polling mode of NfcService.java to poll for Nfc Tags even when the screen is off. This is done for the Nexus 4. To install move the old NfcNci.apk/odex from /system/app to keep just in case, and then just copy over the modified NfcNci.apk and change the permissions to 644. I used adb shell, and adb push to move and install the file in recovery mode, but any way should work. This is my first android development, so this may not work for everyone.

Update:
Just to clarify, this is made for stock 4.2.1

Update: 2/17/13
I have made a new version for stock 4.2.2. Just download copy to /system/app/NfcNci.apk and rename /system/app/NfcNci.odex file.
Any chance of someone taking a crack at getting this working on Lollipop?
 
  • Like
Reactions: steinerlein

Top Liked Posts

  • There are no posts matching your filters.
  • 27
    I have modified the default polling mode of NfcService.java to poll for Nfc Tags even when the screen is off. This is done for the Nexus 4. To install move the old NfcNci.apk/odex from /system/app to keep just in case, and then just copy over the modified NfcNci.apk and change the permissions to 644. I used adb shell, and adb push to move and install the file in recovery mode, but any way should work. This is my first android development, so this may not work for everyone.

    Update:
    Just to clarify, this is made for stock 4.2.1

    Update: 2/17/13
    I have made a new version for stock 4.2.2. Just download copy to /system/app/NfcNci.apk and rename /system/app/NfcNci.odex file.
    9
    CM10.1 update.zip

    here a update.zip from this Version, the update.zip renamed the original NfcNci.apk to NfcNci.apk.old.
    http://xdaforums.com/showpost.php?p=36183507&postcount=53
    9
    Thanks for the testing. I will make one that works with just the screen on but locked .

    Sent from my Nexus 4 using Tapatalk 2

    Attached is a version tthat has the Nfc Polling on if the screen is on.
    6
    The One with Only work on screen on doesnt work on cm 10.1, can someone upload a Nfc.apk which works only on screen on, but locked and on CM 10.1 ?

    Nevermind, did it myself:
    2
    Google wallet works fine for me.

    Sent from my Nexus 4 using Tapatalk 2