com.salesforce.androidsdk.security
Class PasscodeManager

java.lang.Object
  extended by com.salesforce.androidsdk.security.PasscodeManager

public class PasscodeManager
extends java.lang.Object

This class manages the inactivity timeout, and keeps track of if the UI should locked etc.


Nested Class Summary
static class PasscodeManager.HashConfig
          Key for hashing and salts to be preprended and appended to data to increase entropy.
static class PasscodeManager.PasscodeChangeReceiver
          Receives events when the passcode flow is complete.
 
Field Summary
protected static int MIN_PASSCODE_LENGTH
           
static int PASSCODE_REQUEST_CODE
           
 
Constructor Summary
PasscodeManager(Context ctx)
          Parameterized constructor.
PasscodeManager(Context ctx, PasscodeManager.HashConfig verificationHashConfig, PasscodeManager.HashConfig encryptionHashConfig)
           
 
Method Summary
 int addFailedPasscodeAttempt()
           
 boolean check(Context ctx, java.lang.String passcode)
           
 int getFailedPasscodeAttempts()
           
 int getMinPasscodeLength()
           
 java.lang.String getPasscodeHash()
           
 int getTimeoutMs()
           
 java.lang.String hashForEncryption(java.lang.String passcode)
           
 java.lang.String hashForVerification(java.lang.String passcode)
           
 boolean hasStoredPasscode(Context ctx)
           
 boolean isEnabled()
           
 boolean isLocked()
           
 void lock(Context ctx)
           
 boolean lockIfNeeded(Activity newFrontActivity, boolean registerActivity)
           
 void nolongerFrontActivity(Activity a)
           
protected  long now()
           
 void onPause(Activity ctx)
          To be called by passcode protected activity when being paused
 boolean onResume(Activity ctx)
          To be called by passcode protected activity when being resumed When passcode screen is about to be shown, false is returned, the activity will be resumed once the user has successfully enter her passcode
 void recordUserInteraction()
          To be called by passcode protected activity whenever there is a user interaction
 void reset(Context ctx)
          Reset this passcode manager: delete stored passcode and reset fields to their starting value
 void setEnabled(boolean enabled)
          Enable/disable passcode screen.
 void setMinPasscodeLength(int minPasscodeLength)
           
 void setTimeoutMs(int newTimeout)
          Called when the access timeout for the org changes.
 boolean shouldLock()
           
 void showLockActivity(Context ctx)
           
 void store(Context ctx, java.lang.String passcode)
          Store the given passcode (hashed) in private preference
 void unlock(java.lang.String passcode)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MIN_PASSCODE_LENGTH

protected static final int MIN_PASSCODE_LENGTH
See Also:
Constant Field Values

PASSCODE_REQUEST_CODE

public static final int PASSCODE_REQUEST_CODE
See Also:
Constant Field Values
Constructor Detail

PasscodeManager

public PasscodeManager(Context ctx)
Parameterized constructor.

Parameters:
ctx - Context.
verificationHashConfig - Verification HashConfig.
encryptionHashConfig - Encryption HashConfig.

PasscodeManager

public PasscodeManager(Context ctx,
                       PasscodeManager.HashConfig verificationHashConfig,
                       PasscodeManager.HashConfig encryptionHashConfig)
Method Detail

reset

public void reset(Context ctx)
Reset this passcode manager: delete stored passcode and reset fields to their starting value


setEnabled

public void setEnabled(boolean enabled)
Enable/disable passcode screen.


isEnabled

public boolean isEnabled()
Returns:
true if passcode manager is enabled.

addFailedPasscodeAttempt

public int addFailedPasscodeAttempt()
Returns:
the new failure count

check

public boolean check(Context ctx,
                     java.lang.String passcode)
Parameters:
ctx -
passcode -
Returns:
true if passcode matches the one stored (hashed) in private preference

store

public void store(Context ctx,
                  java.lang.String passcode)
Store the given passcode (hashed) in private preference

Parameters:
ctx -
passcode -

hasStoredPasscode

public boolean hasStoredPasscode(Context ctx)
Parameters:
ctx -
Returns:
true if passcode was already created

getFailedPasscodeAttempts

public int getFailedPasscodeAttempts()
Returns:
number of failed passcode attempts

getPasscodeHash

public java.lang.String getPasscodeHash()
Returns:
a hash of the passcode that can be used for encrypting oauth tokens

isLocked

public boolean isLocked()
Returns:
true if locked

lock

public void lock(Context ctx)
Parameters:
ctx -

lockIfNeeded

public boolean lockIfNeeded(Activity newFrontActivity,
                            boolean registerActivity)
Parameters:
newFrontActivity -
registerActivity -
Returns:

nolongerFrontActivity

public void nolongerFrontActivity(Activity a)
Parameters:
a -

onPause

public void onPause(Activity ctx)
To be called by passcode protected activity when being paused


onResume

public boolean onResume(Activity ctx)
To be called by passcode protected activity when being resumed When passcode screen is about to be shown, false is returned, the activity will be resumed once the user has successfully enter her passcode

Returns:
true if the resume should be allowed to continue and false otherwise

recordUserInteraction

public void recordUserInteraction()
To be called by passcode protected activity whenever there is a user interaction


setTimeoutMs

public void setTimeoutMs(int newTimeout)
Called when the access timeout for the org changes.

Parameters:
newTimeout - New access timeout value.

getTimeoutMs

public int getTimeoutMs()

getMinPasscodeLength

public int getMinPasscodeLength()

setMinPasscodeLength

public void setMinPasscodeLength(int minPasscodeLength)

shouldLock

public boolean shouldLock()

showLockActivity

public void showLockActivity(Context ctx)

unlock

public void unlock(java.lang.String passcode)

now

protected long now()

hashForVerification

public java.lang.String hashForVerification(java.lang.String passcode)

hashForEncryption

public java.lang.String hashForEncryption(java.lang.String passcode)