FORUMS
Remove All Ads from XDA

Sony SmartWatch 3 NFC Support Package

20 posts
Thanks Meter: 28
 
By ebones, Junior Member on 7th October 2015, 10:26 AM
Post Reply Email Thread
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:
Attached Files
File Type: zip tetra_nfc_LCA43.zip - [Click for QR Code] (10.13 MB, 1796 views)
File Type: zip tetra_nfc_LCA43_0.2.zip - [Click for QR Code] (10.13 MB, 6652 views)
The Following 21 Users Say Thank You to ebones For This Useful Post: [ View ] Gift ebones Ad-Free
 
 
7th October 2015, 12:46 PM |#2  
Senior Member
Thanks Meter: 139
 
More
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?
7th October 2015, 12:58 PM |#3  
OP Junior Member
Thanks Meter: 28
 
More
Quote:

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).

Quote:

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.
The Following User Says Thank You to ebones For This Useful Post: [ View ] Gift ebones Ad-Free
7th October 2015, 02:09 PM |#4  
Senior Member
Thanks Meter: 139
 
More
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.
The Following User Says Thank You to matejdro For This Useful Post: [ View ] Gift matejdro Ad-Free
7th October 2015, 03:23 PM |#5  
OP Junior Member
Thanks Meter: 28
 
More
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.
The Following User Says Thank You to ebones For This Useful Post: [ View ] Gift ebones Ad-Free
7th October 2015, 04:09 PM |#6  
Senior Member
Thanks Meter: 105
 
More
This is fantastic news! Thanks for all your hard work and I look forward to trying out builds.
8th October 2015, 03:46 PM |#7  
OP Junior Member
Thanks Meter: 28
 
More
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.
The Following 4 Users Say Thank You to ebones For This Useful Post: [ View ] Gift ebones Ad-Free
10th October 2015, 08:54 PM |#8  
Senior Member
Thanks Meter: 139
 
More
I just released small utility that triggers intents on the phone when watch detects a tag: http://forum.xda-developers.com/smar...-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.
The Following User Says Thank You to matejdro For This Useful Post: [ View ] Gift matejdro Ad-Free
18th December 2015, 11:28 PM |#9  
Senior Member
Flag Murmansk - St. Petersburg
Thanks Meter: 8
 
Donate to Me
More
What about sources of your version of kernel?
26th December 2015, 11:22 AM |#10  
Member
Flag Lienz
Thanks Meter: 7
 
More
how can i config the hce?
28th January 2016, 06:25 PM |#11  
KewlRobD's Avatar
Senior Member
Thanks Meter: 5
 
More
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.
Post Reply Subscribe to Thread

Guest Quick Reply (no urls or BBcode)
Message:
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes