Sony SmartWatch 3 NFC Support Package

Search This thread

ebones

Member
Aug 26, 2015
20
29
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:
  • 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:
 

Attachments

  • tetra_nfc_LCA43.zip
    10.1 MB · Views: 3,942
  • tetra_nfc_LCA43_0.2.zip
    10.1 MB · Views: 12,154
Last edited:

matejdro

Senior Member
Jul 9, 2009
1,362
152
OMG I can't believe someone actually did this. Can't wait to get home to try it.

Question though: You said it is causes severe power consumption. I assume this is only when NFC is on all the time (even when device is in ambient mode)? Can NFC be set to run only when device is fully on?
 

ebones

Member
Aug 26, 2015
20
29
Question though: You said it is causes severe power consumption. I assume this is only when NFC is on all the time (even when device is in ambient mode)? Can NFC be set to run only when device is fully on?
Yes, it does so only when the service is turned on in the settings. More specifically, when you turn it on, power consumption (and heat) raise a little bit, but not dramatically. That is until you bring a tag nearby which causes a lot of heat and battery drain. If you turn the service off, however, the watch goes back to normal (no need to reboot).

Can NFC be set to run only when device is fully on?
I think so. I am currently working on a solution, which will most likely be finding a way to broadcast ACTION_SCREEN_* messages.
 
  • Like
Reactions: mattnmag

matejdro

Senior Member
Jul 9, 2009
1,362
152
So if I understand correctly, drain will not stop after you remove the watch from the tag? How about polling for connectivity every second or so and if tag is detached, automatically restart the NFC radio?

---------- Post added at 03:09 PM ---------- Previous post was at 02:26 PM ----------

Regarding ambient mode, you can register this receiver to receive status of screen going from/to ambient mode:

Code:
<uses-permission android:name="com.google.android.wearable.permission.RECEIVE_AMBIENT_DREAM_STATE" />

...

<intent-filter>
    <action android:name="com.google.android.wearable.action.AMBIENT_STARTED" />
</intent-filter>
<intent-filter>
    <action android:name="com.google.android.wearable.action.AMBIENT_STOPPED" />
</intent-filter>

RECEIVE_AMBIENT_DREAM_STATE is system permission though, so it needs to be handled by service installed on /system partition.
 
  • Like
Reactions: ebones

ebones

Member
Aug 26, 2015
20
29
Thanks, this is great! I'll try and modify NfcService tomorrow to catch these along ACTION_SCREEN. Permissions shouldn't be a problem, the service is run as system anyway.
 
  • Like
Reactions: mattnmag

andrewia

Senior Member
Oct 20, 2012
132
104
This is fantastic news! Thanks for all your hard work and I look forward to trying out builds.
 

ebones

Member
Aug 26, 2015
20
29
Good news!

I have uploaded a new package; NFC no longer drains battery when the screen is in ambient mode (it is now normal 1-3% per hour compared to previous 50%). Thanks matejdro for pointing out required permissions!

I have also slightly decreased tag polling rate. This causes a slight delay when reading a tag, but reduces produced heat when watch screen is on.
 

matejdro

Senior Member
Jul 9, 2009
1,362
152
I just released small utility that triggers intents on the phone when watch detects a tag: http://xdaforums.com/smartwatch-3/themes-apps/nfctagrelay-automate-life-scanning-tags-t3222332 . Been using it for some time now and it works great!

Two remarks:
  • I noticed watch tends to reboot itself occasionally. Most often it happens when trying to scan a tag, but sometimes it also happens randomly when I'm nowhere near a tag and watch is not even active. Not completely sure if this is your mod (it might be something else with my setup), but I don't recall it ever happening before I installed it.
  • I recommend you add small subtle vibe when tag is detected. I'm using 75ms on above mentioned utility which works well but it would be better if this was integarted into the NFC service as pretty much any use case would need user to know when tag is scanned and when can you lift your arm back up.
 
  • Like
Reactions: andrewia

KewlRobD

Senior Member
Oct 13, 2006
197
5
So will enabling the NFC chip allow it to interact with an app on your phone?. For example I have an app on my phone for home automation. From the app I can turn lights on and off. I can assign an NFC tag to an action in the app. So I walk in a room, tap my phone to the tag and the app turns on the light. It would be great if I could get the same result by tapping my SmartWatch to the tag.
 

Chris_Jones_7

New member
Feb 1, 2016
1
0
Is there any way to use HCE then, if there's full NEC support? I love the fact you've managed to do this, but now I've installed the package I've not really got anything to apply this great leap forward to. I'm not experienced with Android coding, but I know a few people who have some experience. Is there anything you can tell me beforehand? We're after trying to emulate our college ID cards which use NFC, and they only use the UID to open doors, it would seem.
 

ebones

Member
Aug 26, 2015
20
29
What about sources of your version of kernel?

I have used build configs by crpalmer along with these sources. The only difference in config is that I completely disabled SElinux. I have attached my config and diff below.

View attachment kernel_config.tar.gz

how can i config the hce?
Is there any way to use HCE then, if there's full NEC support? I love the fact you've managed to do this, but now I've installed the package I've not really got anything to apply this great leap forward to. I'm not experienced with Android coding, but I know a few people who have some experience. Is there anything you can tell me beforehand? We're after trying to emulate our college ID cards which use NFC, and they only use the UID to open doors, it would seem.
The chip does have HCE (since stock firmware uses an application to write Bluetooth pairing tag at boot). It also should support HCE for Java apps, however, I didn't do any tests on that, so I can't tell if it will start out-of-the box. As for configuring it, I was planning to post updated config app later this month.

So will enabling the NFC chip allow it to interact with an app on your phone?. For example I have an app on my phone for home automation. From the app I can turn lights on and off. I can assign an NFC tag to an action in the app. So I walk in a room, tap my phone to the tag and the app turns on the light. It would be great if I could get the same result by tapping my SmartWatch to the tag.
If I got it right, what you are suggesting is an app that can use NFC on your watch as a remote sensor while main functions work on your phone; I am not aware of any apps that can do that. You could try installing phone app on SW via adb.
 
Last edited:

anandr165

Member
Feb 11, 2016
7
0
Any ideas where I can see this watch in store in USA?

What the title says. I wanted to get a feel of the watch before spending $250.
 

Top Liked Posts

  • There are no posts matching your filters.
  • 22
    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:
    • 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:
    4
    Good news!

    I have uploaded a new package; NFC no longer drains battery when the screen is in ambient mode (it is now normal 1-3% per hour compared to previous 50%). Thanks matejdro for pointing out required permissions!

    I have also slightly decreased tag polling rate. This causes a slight delay when reading a tag, but reduces produced heat when watch screen is on.
    2
    I hope that author (or someone else with his permission) will continue work on this tool.
    This tool has been used by many diabetics to enable SSW 3 to read Libre sensors. It's more discreet way to do reading it than using phone or dedicated reader and it is one device less in (summer) pocket. Also, using NFC enabled SSW3, even some basic CGM were 'developed'.

    So, thanks @ebones for his discovery/work :)
    1
    Question though: You said it is causes severe power consumption. I assume this is only when NFC is on all the time (even when device is in ambient mode)? Can NFC be set to run only when device is fully on?
    Yes, it does so only when the service is turned on in the settings. More specifically, when you turn it on, power consumption (and heat) raise a little bit, but not dramatically. That is until you bring a tag nearby which causes a lot of heat and battery drain. If you turn the service off, however, the watch goes back to normal (no need to reboot).

    Can NFC be set to run only when device is fully on?
    I think so. I am currently working on a solution, which will most likely be finding a way to broadcast ACTION_SCREEN_* messages.
    1
    Hey were you able to get this working? I have a tic pro and wanted to try this.
    It is fairly easy in my opinion but I'm super busy until about October. We have to build wearos with android.hardware.nfc enabled. Also for the TWP3. Also I'll continue making Nexmon for both