[Source] Variable Size Pattern Lockscreen

Search This thread

Smasher816

Senior Member
Jan 16, 2011
405
201
Missouri
plus.google.com
For those who don't know, my pattern lockscreen modification has been merged into CyanogenMod 10.
This thread is designed to explain this modification so it can be enjoyed on more roms and devices.
I will also consider other lockscreen modification sugestions.

This addition is now in any CM10 based rom built after 09/01/2012 2:22
If you want to read about how or why I created this mod - continue reading post 1
If you want to implement this feature in your rom - skip to post 2
If you want to admire some screenshots - skip to post 3

Basic design process:
I finally learned how to compile android from source, so I figured I might as well start editing the source some.
Looking at my phone's lockscreen I thought, "Wouldn't it be cool if it was 5x5, it should be as easy as changing some 3s to 5s..."

I began with a lot of searches in the framworks/base folder.
I searched for the incorect pattern error message, found the localization file,
searched for the key, found the PatternUnlockScreen
and finally ended up with LockPatternView.java.

Any time I found 3 (or its variations) I replaced it with the variable PATTERN_SIZE.
3->PATTERN_SIZE, 2->PATTERN_SIZE-1, 9->PatternSize^2, etc

This allowed me to change the patterns appearance at compile time; however, it would only store a 3x3 pattern and could not be changed by a user.
These problems had me digging through LockPatternUtils and the android settings implementation.

Eventually I had a simi working setting (required restart) http://xdaforums.com/showthread.php?t=1267420.
Later, school kept me busy and CM9 came out removing my changes.
With the release of CM10 I decided to recreate the modification from scratch, this time with everything working correctly.
 
Last edited:

Smasher816

Senior Member
Jan 16, 2011
405
201
Missouri
plus.google.com
Summary of required changes:
There are two modified projects
frameworks/base - http://review.cyanogenmod.com/#/c/20613/
packages/apps/Settings - http://review.cyanogenmod.com/#/c/20614/

Code:
Frameworks:
	LockPatternView.java:
		Replace '3' and its variations with a private static int 'PATTERN_SIZE' (must be static to be called from static functions). (This is the only modification required for a static sized pattern, everything else is for the settings implementation)
		Add functions to get and set 'PATTERN_SIZE' (changing size requires recreating a few variables). 
		Update 'Cell' class to alow size changes (recreate and initialize 'sCells' to the new size).
		Recreate '// Check for gaps in existing pattern' to support any size patterns and gaps. (This was a challenge to create my own optimized method to achieve this, if you have any improvements please let me know)
	LockPatternUtils.java:
		Replace '3' with a static int 'PATTERN_SIZE'
		Add functions to get, set, and update 'PATTERN_SIZE'
		Add get and set Integer functions to interface with the android settings
	ILockSettings.aidl:
		Add protypes for the get and set Integer functions
	LockSettingsService.java:
		Add functions to read and write Integers to the settings database
	Settings.java:
		Add keys for 'LOCK_PATTERN_SIZE' to the settings database
	PatternUnlockScreen.java:
		Read lockPatternSize from the utils and change the view's size to reflect it
		Update the utils PATTERN_SIZE before checking a pattern

Settings:
	AndroidManifest.xml:
		Add activity to choose the pattern size
	strings.xml:
		Add entries for the various sizes. (These could be localized; add more keys if you want to expand the size past 6x6)
	security_settings_pattern_size.xml: (New File)
		Add buttons for the various sizes (Can add more buttons for more sizes)
	ConfirmLockPatternSize:
		Make mLockPatternView's size respect the saved size 
	ChooseLockGeneric.java:
		Go strait to 'ChooseLockPatternSize.class'. It will forward to the tutorial or pattern choosing activities.
	ChooseLockPatternSize.java: (New File)
		Inflate the menu with new xml file
		Check which button was clicked. (This is what actually determines the 'PATTERN_SIZE' that will later be saved)
		Forward 'PATTERN_SIZE' in the intent to the next activity.
	ChooseLockPatternTutorial.java:
		Set the tutorial's mPatternView size to the one passed in the intent.
		Forward 'PATTERN_SIZE' to the next activity.
	ChooseLockPattern.java:
		Set mLockPatternView's size to the one passed in the intent (Don't save it until they have actually confirmed a pattern of the new size)
		Save the new PATTERN_SIZE with LockPatternUtils

All of the required code is contained in the two gerrit commits above.
Simply obtain the source for your rom and make the changes as needed.

Feel free to improve the source, add more sizes (fyi, 10x10 is almost unusable), or anything else (however, it would be nice to give me some credit if you use this code).
Post if you have any questions, I am also up for suggestions.
 
Last edited:

Smasher816

Senior Member
Jan 16, 2011
405
201
Missouri
plus.google.com

Attachments

  • Screenshot_2012-09-01-23-22-46.jpg
    Screenshot_2012-09-01-23-22-46.jpg
    13.8 KB · Views: 1,113
  • Screenshot_2012-09-01-23-21-09.jpg
    Screenshot_2012-09-01-23-21-09.jpg
    10.7 KB · Views: 1,080
  • Screenshot_2012-09-01-23-21-36.jpg
    Screenshot_2012-09-01-23-21-36.jpg
    12.6 KB · Views: 1,002
  • Screenshot_2012-09-01-23-22-00.jpg
    Screenshot_2012-09-01-23-22-00.jpg
    17.5 KB · Views: 1,049
  • Screenshot_2012-09-01-23-22-12.jpg
    Screenshot_2012-09-01-23-22-12.jpg
    17.8 KB · Views: 1,022
  • Screenshot_2012-09-01-23-22-28.jpg
    Screenshot_2012-09-01-23-22-28.jpg
    18.4 KB · Views: 968
  • Screenshot_2012-09-01-23-23-43.jpg
    Screenshot_2012-09-01-23-23-43.jpg
    22.4 KB · Views: 1,096
Last edited:

nonsleepr

Member
Feb 13, 2010
9
2
Pattern unlock coordinates in log

Hi, I just found out, that coordinates of unlock pattern are printed out to logcat.
Like that:
Code:
V/SMASHER816( 1656): (0, 0)
V/SMASHER816( 1656): (1, 0)
V/SMASHER816( 1656): (2, 0)
V/SMASHER816( 1656): (3, 0)
V/SMASHER816( 1656): (3, 1)
V/SMASHER816( 1656): (3, 2)
V/SMASHER816( 1656): (3, 3)
I think, it is not secure, so, it's better to remove logging of this stuff.
 

natediddy1120

Member
Jan 26, 2010
9
0
www.nathan-forbes.com
Hi, I just found out, that coordinates of unlock pattern are printed out to logcat.
Like that:
Code:
V/SMASHER816( 1656): (0, 0)
V/SMASHER816( 1656): (1, 0)
V/SMASHER816( 1656): (2, 0)
V/SMASHER816( 1656): (3, 0)
V/SMASHER816( 1656): (3, 1)
V/SMASHER816( 1656): (3, 2)
V/SMASHER816( 1656): (3, 3)
I think, it is not secure, so, it's better to remove logging of this stuff.

Looks like the line that was logging this has been removed in cm10. Not sure what the OP's logic was on adding this in the first place?
 
Last edited:

ccbeam

Senior Member
Jun 8, 2008
70
8
Flashable zip possible?

I love this, but not every dev incorporates it.
Is it possible to make this code change into a flashable zip with 3, 4, or 5 as the options?

TIA
 
  • Like
Reactions: Adizzzle

FelixCited

Senior Member
Dec 9, 2011
91
10
Perth, Australia
I love this, but not every dev incorporates it.
Is it possible to make this code change into a flashable zip with 3, 4, or 5 as the options?

TIA

Sorry if this has been already answered but I'd also like to know the outcome. A flashable zip would be perfect.

Seems like a great way to add more security. I have searched for this and cant find any other usable info on how to do it without compiling it into a rom which I have no idea about
 

3ncrypt3d

Member
Apr 10, 2012
21
1
Great Idea

I wonder now why something so simple yet effective in means of improving the pattern locks level of security wouldnt have occurred to google in the first place. I suppose they figure the average end user lacks the memory recall to move beyond a max 3x3 grid pattern.Idk but I love it and am looking forward to incorporating into my own TW ROM.
 

Top Liked Posts

  • There are no posts matching your filters.
  • 9
    For those who don't know, my pattern lockscreen modification has been merged into CyanogenMod 10.
    This thread is designed to explain this modification so it can be enjoyed on more roms and devices.
    I will also consider other lockscreen modification sugestions.

    This addition is now in any CM10 based rom built after 09/01/2012 2:22
    If you want to read about how or why I created this mod - continue reading post 1
    If you want to implement this feature in your rom - skip to post 2
    If you want to admire some screenshots - skip to post 3

    Basic design process:
    I finally learned how to compile android from source, so I figured I might as well start editing the source some.
    Looking at my phone's lockscreen I thought, "Wouldn't it be cool if it was 5x5, it should be as easy as changing some 3s to 5s..."

    I began with a lot of searches in the framworks/base folder.
    I searched for the incorect pattern error message, found the localization file,
    searched for the key, found the PatternUnlockScreen
    and finally ended up with LockPatternView.java.

    Any time I found 3 (or its variations) I replaced it with the variable PATTERN_SIZE.
    3->PATTERN_SIZE, 2->PATTERN_SIZE-1, 9->PatternSize^2, etc

    This allowed me to change the patterns appearance at compile time; however, it would only store a 3x3 pattern and could not be changed by a user.
    These problems had me digging through LockPatternUtils and the android settings implementation.

    Eventually I had a simi working setting (required restart) http://xdaforums.com/showthread.php?t=1267420.
    Later, school kept me busy and CM9 came out removing my changes.
    With the release of CM10 I decided to recreate the modification from scratch, this time with everything working correctly.
    4
    Summary of required changes:
    There are two modified projects
    frameworks/base - http://review.cyanogenmod.com/#/c/20613/
    packages/apps/Settings - http://review.cyanogenmod.com/#/c/20614/

    Code:
    Frameworks:
    	LockPatternView.java:
    		Replace '3' and its variations with a private static int 'PATTERN_SIZE' (must be static to be called from static functions). (This is the only modification required for a static sized pattern, everything else is for the settings implementation)
    		Add functions to get and set 'PATTERN_SIZE' (changing size requires recreating a few variables). 
    		Update 'Cell' class to alow size changes (recreate and initialize 'sCells' to the new size).
    		Recreate '// Check for gaps in existing pattern' to support any size patterns and gaps. (This was a challenge to create my own optimized method to achieve this, if you have any improvements please let me know)
    	LockPatternUtils.java:
    		Replace '3' with a static int 'PATTERN_SIZE'
    		Add functions to get, set, and update 'PATTERN_SIZE'
    		Add get and set Integer functions to interface with the android settings
    	ILockSettings.aidl:
    		Add protypes for the get and set Integer functions
    	LockSettingsService.java:
    		Add functions to read and write Integers to the settings database
    	Settings.java:
    		Add keys for 'LOCK_PATTERN_SIZE' to the settings database
    	PatternUnlockScreen.java:
    		Read lockPatternSize from the utils and change the view's size to reflect it
    		Update the utils PATTERN_SIZE before checking a pattern
    
    Settings:
    	AndroidManifest.xml:
    		Add activity to choose the pattern size
    	strings.xml:
    		Add entries for the various sizes. (These could be localized; add more keys if you want to expand the size past 6x6)
    	security_settings_pattern_size.xml: (New File)
    		Add buttons for the various sizes (Can add more buttons for more sizes)
    	ConfirmLockPatternSize:
    		Make mLockPatternView's size respect the saved size 
    	ChooseLockGeneric.java:
    		Go strait to 'ChooseLockPatternSize.class'. It will forward to the tutorial or pattern choosing activities.
    	ChooseLockPatternSize.java: (New File)
    		Inflate the menu with new xml file
    		Check which button was clicked. (This is what actually determines the 'PATTERN_SIZE' that will later be saved)
    		Forward 'PATTERN_SIZE' in the intent to the next activity.
    	ChooseLockPatternTutorial.java:
    		Set the tutorial's mPatternView size to the one passed in the intent.
    		Forward 'PATTERN_SIZE' to the next activity.
    	ChooseLockPattern.java:
    		Set mLockPatternView's size to the one passed in the intent (Don't save it until they have actually confirmed a pattern of the new size)
    		Save the new PATTERN_SIZE with LockPatternUtils

    All of the required code is contained in the two gerrit commits above.
    Simply obtain the source for your rom and make the changes as needed.

    Feel free to improve the source, add more sizes (fyi, 10x10 is almost unusable), or anything else (however, it would be nice to give me some credit if you use this code).
    Post if you have any questions, I am also up for suggestions.
    2
    Screenshots: http://androtransfer.com/development/smasher816/media
    See attached photos (larger inline photos coming soon)
    2
    Pattern unlock coordinates in log

    Hi, I just found out, that coordinates of unlock pattern are printed out to logcat.
    Like that:
    Code:
    V/SMASHER816( 1656): (0, 0)
    V/SMASHER816( 1656): (1, 0)
    V/SMASHER816( 1656): (2, 0)
    V/SMASHER816( 1656): (3, 0)
    V/SMASHER816( 1656): (3, 1)
    V/SMASHER816( 1656): (3, 2)
    V/SMASHER816( 1656): (3, 3)
    I think, it is not secure, so, it's better to remove logging of this stuff.
    2
    This would like be perfect as an Xposed module ;)

    Envoyé depuis mon GT-I9505 avec Tapatalk 4