So, after a considerable amount of time I finally managed to properly start the NFC module in SW3. It can do all things a module on your phone can do, however, it causes elevated battery usage while doing so.
Warnings:
Technical details:
Currently this is more of a proof-of-concept work and security was a big problem when developing. NfcService requires several permissions declared as system|signed which means it has to be signed with the same certificates used to sign the remaining system. I did not manage to do that, so I patched services.jar to ignore bad certificates.
(This paragraph is deprecated) When device boots even if NFC adapter is active, it does not get full power right away. Instead, it sets up a BroadcastReceiver to catch ACTION_SCREEN_ON and ACTION_SCREEN_OFF events to power the module only when screen is lit. However, power manager service on SmartWatch 3 never sends these broadcasts, so the module never gets a signal to turn on. I am yet to figure out why, in the meantime I patched NfcService to turn the module regardless of current screen state. It does not start consuming power until a tag is first detected, after which the battery can be drained with rate up to 50% per hour.
Features:
The package does not include apps to read and write tags, emulate cards and use Android Beam.
Instaling:
Uninstalling:
Usage:
Example code to check NFC:
Changes:
Thanks:
Warnings:
- This package is for build LCA43 only (can be seen in Settings->About)
- Can screw up boot if you install this on a different build and/or customized system
- Future OTA updates can also corrupt your sytem. Restore to a stock ROM before installing them.
- Make backups of system and boot partitions before installing
- Uses insecure kernel (with SElinux disabled) and disables signature checks in services.jar
- Preview/development purposes only, it disables initial tag (used for quick pairing) and causes moderate power consumption when NFC is active and screen is turned on.
Technical details:
Currently this is more of a proof-of-concept work and security was a big problem when developing. NfcService requires several permissions declared as system|signed which means it has to be signed with the same certificates used to sign the remaining system. I did not manage to do that, so I patched services.jar to ignore bad certificates.
(This paragraph is deprecated) When device boots even if NFC adapter is active, it does not get full power right away. Instead, it sets up a BroadcastReceiver to catch ACTION_SCREEN_ON and ACTION_SCREEN_OFF events to power the module only when screen is lit. However, power manager service on SmartWatch 3 never sends these broadcasts, so the module never gets a signal to turn on. I am yet to figure out why, in the meantime I patched NfcService to turn the module regardless of current screen state. It does not start consuming power until a tag is first detected, after which the battery can be drained with rate up to 50% per hour.
Features:
- Full NFC support (tag reading, writing, HCE (card emulation) and P2P (Android Beam))
- Configuration app to turn NFC module on and off
- Watchface to monitor current NFC module state
The package does not include apps to read and write tags, emulate cards and use Android Beam.
Instaling:
- If you need to omit certain components (like watchface), feel free to remove them from the package files
- Boot into recovery (I am using TWRP found here)
- Back up your system and boot partitions in case something goes wrong or you want to remove the package
- Push the package using adb:
Code:
adb push nfc.zip /sdcard/nfc.zip
- Tap "Install" on the screen
- Locate nfc.zip
- Install it
- Boot into system
Uninstalling:
- Restore system and boot partitions from your backup
Usage:
- You can control your NFC module using NFC Configuration app
- If you want to monitor NFC module state all the time, use NFC Status watchface (long tap on the screen to set up)
- To view a tag install tag editing app via adb
Example code to check NFC:
Code:
NfcManager nfcManager = (NfcManager)this.getBaseContext().getSystemService(Context.NFC_SERVICE);
NfcAdapter nfcAdapter = nfcManager.getDefaultAdapter();
boolean isAdapterEnabled = (nfcAdapter != null) && nfcAdapter.isEnabled();
Changes:
- 08.10.2015 0.2 Fixed constant battery drain. Reduced tag polling rate.
- 07.10.2015 First release
Thanks:
- crpalmer for his kernel build configs
- Michael Roland for his article on NFC support in SW3
- Cyanogenmod team (CM was used to build NFC binaries)
Attachments
Last edited: