Attend XDA's Second Annual Developer Conference, XDA:DevCon 2014!
5,741,583 Members 39,998 Now Online
XDA Developers Android and Mobile Development Forum

[DEV] NFC Unlock

Tip us?
 
tombriden
Old
#1  
Recognized Developer - OP
Thanks Meter 314
Posts: 211
Join Date: Mar 2010
Location: Leighton Buzzard

 
DONATE TO ME
Default [DEV] NFC Unlock

Hi, I've been building my own N5 ROM for a while now but don't have the time to release/maintain/support it plus there are plenty of other options out there that are very similar. BUT, I recently got me an NFC Ring and so wanted to build NFC unlocking into the framework and this is something that currently can only be achieved using an Xposed module so I thought I'd share the code.


First of all, a huge thanks to MohammadAG and qwerty12 for their work on the Xposed module here as this is what a lot of my changes are based on.


The first thing I did was modify Nfc and Settings apps so you can choose when to enable Nfc Polling...
  • Polling off
  • Screen off
  • Screen on and locked
  • Screen on and unlocked
  • Screen on and locked only - this is a new mode i've put in that turns Nfc on with the screen and then off again once unlocked. As I only use Nfc on my phone for unlocking, this is really useful as its nice on the battery and doesn't prompt with the empty tag viewer every time i unlock!

Then, using the Xposed module as a basis for the code I added Nfc unlocking into the framework and Nfc app as well as a new item under Security Settings where you can add/remove tags that are allowed to unlock.

In terms of security:
  • the Nfc tag acts as an override to whatever other lock screen you're using, pattern, pin etc.
  • The tag contents are only handled if the screen is unlocked. If polling is set to 'screen on and locked' then the tag will be picked up as soon as the device is unlocked but there's no way for an unauthorised tag to have its contents handled while the screen is off or on and locked.
  • The unlock is triggered from the Nfc app as an intent, it's probably possible to trigger this intent from elsewhere but the tags uid is checked from within the keyguard while handling it so the uid needs to be known and passed as part of the intent for this to work.

It's all working nicely for me so far but given I'm not massively familiar with the guts of the android lock screen security and creating new UI's, there's probably room for improvement.

So, ROM devs feel free to add this to your ROMs, giving credit where credit is due and let me know of any fixes or improvements either here or as pull requests on my github. The modified repos are here:

https://github.com/AospPlus/android_.../aosp-plus_4.4
https://github.com/AospPlus/android_.../aosp-plus_4.4
https://github.com/AospPlus/android_.../aosp-plus_4.4
Tom
--------------------------
My Github
Find me on IRC
--------------------------

Current Phone: Nexus 5 32GB Black running AOSP+
Current Tablet: ASUS Infinity TF700T running CM11.0

Previously
HTC One X+ (with a cracked screen :-/ ) running AOSP+
HTC One X running TripNRaVeR CM10.1 (Bricked into APX mode)
Desire HD running IceColdSandwich
HTC Hero running CronosDroid
The Following 12 Users Say Thank You to tombriden For This Useful Post: [ Click to Expand ]
 
simonsgray
Old
#2  
Member
Thanks Meter 3
Posts: 94
Join Date: Feb 2011
Location: Ottawa
So I fully apologize because I know this is not the right place to ask this question, however, this is exactly what i'm looking for.

'm running an n5 with elementalx 1.00 and rooted stock 4.4.4. I would like to add this functionality to my phone, because i too (****ing eventually) have a NFCRing.

I'm not a dev, so i understand that this request is tricky for you to help me with. but anything you can suggest, to avoid dealing with the xposed framework or the relatively useless functionality of the NFC ring unlock app, would be greatly appreciated.

Simon


Quote:
Originally Posted by tombriden View Post
Hi, I've been building my own N5 ROM for a while now but don't have the time to release/maintain/support it plus there are plenty of other options out there that are very similar. BUT, I recently got me an NFC Ring and so wanted to build NFC unlocking into the framework and this is something that currently can only be achieved using an Xposed module so I thought I'd share the code.


First of all, a huge thanks to MohammadAG and qwerty12 for their work on the Xposed module here as this is what a lot of my changes are based on.


The first thing I did was modify Nfc and Settings apps so you can choose when to enable Nfc Polling...
  • Polling off
  • Screen off
  • Screen on and locked
  • Screen on and unlocked
  • Screen on and locked only - this is a new mode i've put in that turns Nfc on with the screen and then off again once unlocked. As I only use Nfc on my phone for unlocking, this is really useful as its nice on the battery and doesn't prompt with the empty tag viewer every time i unlock!

Then, using the Xposed module as a basis for the code I added Nfc unlocking into the framework and Nfc app as well as a new item under Security Settings where you can add/remove tags that are allowed to unlock.

In terms of security:
  • the Nfc tag acts as an override to whatever other lock screen you're using, pattern, pin etc.
  • The tag contents are only handled if the screen is unlocked. If polling is set to 'screen on and locked' then the tag will be picked up as soon as the device is unlocked but there's no way for an unauthorised tag to have its contents handled while the screen is off or on and locked.
  • The unlock is triggered from the Nfc app as an intent, it's probably possible to trigger this intent from elsewhere but the tags uid is checked from within the keyguard while handling it so the uid needs to be known and passed as part of the intent for this to work.

It's all working nicely for me so far but given I'm not massively familiar with the guts of the android lock screen security and creating new UI's, there's probably room for improvement.

So, ROM devs feel free to add this to your ROMs, giving credit where credit is due and let me know of any fixes or improvements either here or as pull requests on my github. The modified repos are here:

https://github.com/AospPlus/android_.../aosp-plus_4.4
https://github.com/AospPlus/android_.../aosp-plus_4.4
https://github.com/AospPlus/android_.../aosp-plus_4.4
--
Si!
Phone History:
Motorola C333 -> Motorola C350 -> Motorola V635i -> Sony Ericsson M600i -> Blackberry Pearl 8130 x3 -> Sony Ericsson Xperia X10 (stock 1.6 - rooted 2.1 - WolfBreak 2.3.3) -> Sony Ericsson Xperia Arc (rooted 2.3.3) - Sony Xperia Ion (BL Unlocked - Rooted Stock 2.3.7)

Tablet History:
Acer Iconia A500 (rooted 3.0 - rooted 3.1 - Virtuous X00m 3.2) -> Google Nexus 7 (BL Unlocked - Rooted Stock 4.1)
 
tombriden
Old
#3  
Recognized Developer - OP
Thanks Meter 314
Posts: 211
Join Date: Mar 2010
Location: Leighton Buzzard

 
DONATE TO ME
Hey man, give me a few days and ill compile a pure aosp rom with just these changes and hopefully you should just be able to push I think 4 system files and have the functionality.

Sent from my AOSP+ on HammerHead using Tapatalk
Tom
--------------------------
My Github
Find me on IRC
--------------------------

Current Phone: Nexus 5 32GB Black running AOSP+
Current Tablet: ASUS Infinity TF700T running CM11.0

Previously
HTC One X+ (with a cracked screen :-/ ) running AOSP+
HTC One X running TripNRaVeR CM10.1 (Bricked into APX mode)
Desire HD running IceColdSandwich
HTC Hero running CronosDroid
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes