Skip to content

Instantly share code, notes, and snippets.

@huttneab
Created March 8, 2013 14:58
Show Gist options
  • Save huttneab/5116982 to your computer and use it in GitHub Desktop.
Save huttneab/5116982 to your computer and use it in GitHub Desktop.
public class PasswordUtils {
private static final String TAG = "PasswordUtils";
private static boolean mScreenIsLocked = false;
private static PasswordUtils mInstance = null;
// private static KeyCachingService keyCachingService;
private static Context mContext;
private PasswordUtils(Context context) {
// initialize KeyCachingService
// Intent bindIntent = new Intent(context.getApplicationContext(), KeyCachingService.class);
// context.getApplicationContext().bindService(bindIntent, serviceConnection, Context.BIND_AUTO_CREATE);
}
public static PasswordUtils getInstance(Context context) {
if (mInstance == null) {
mContext = context;
mInstance = new PasswordUtils(context);
}
return mInstance;
}
public static void init(Context context){
if (mInstance == null) {
mInstance = new PasswordUtils(context);
}
}
// public ServiceConnection serviceConnection = new ServiceConnection() {
// public void onServiceConnected(ComponentName className, IBinder service) {
//
// keyCachingService = ((KeyCachingService.KeyCachingBinder) service).getService();
// }
//
// public void onServiceDisconnected(ComponentName name) {
// keyCachingService = null;
// }
// };
public void setScreenLock(boolean isLocked) {
mScreenIsLocked = isLocked;
}
public boolean screenIsLocked() {
return mScreenIsLocked || !hasPassword();
}
public boolean hasPassword() {
return SecureComMmsSmsDatabaseHelper.getInstance(mContext).hasPassword() && PrivateKeyDatabaseHelper.getInstance(mContext).hasPassword();
// if (keyCachingService == null) {
// return false;
// } else {
// return keyCachingService.hasPassword();
// }
}
public void failedCheckRedirect(Context context) {
Intent myIntent = new Intent(context, KeyguardScreen.class);
myIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
myIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
context.startActivity(myIntent);
}
public void failedCheckRedirect(Context context, Intent intent) {
Intent myIntent = new Intent(context, KeyguardScreen.class);
myIntent.putExtra("failed_check_redirect", intent);
context.startActivity(myIntent);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment