Wednesday, 7 October 2015

Sony SmartWatch 3 NFC Support Package



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 uses a lot of battery in the process.

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 severe power consumption when NFC is active.


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.

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();


Thanks:
P.S. Some time later an in-depth article on how this stuff was done will be released. I'll post the link here.














Attached Files






File Type: zip tetra_nfc_LCA43.zip -
[Click for QR Code]
(10.13 MB)







No comments:

Post a Comment