Java Code Examples for android.app.KeyguardManager#createConfirmDeviceCredentialIntent()

The following examples show how to use android.app.KeyguardManager#createConfirmDeviceCredentialIntent() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ActivityStartInterceptor.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/**
 * Creates an intent to intercept the current activity start with Confirm Credentials if needed.
 *
 * @return The intercepting intent if needed.
 */
private Intent interceptWithConfirmCredentialsIfNeeded(ActivityInfo aInfo, int userId) {
    if (!mUserController.shouldConfirmCredentials(userId)) {
        return null;
    }
    // TODO(b/28935539): should allow certain activities to bypass work challenge
    final IntentSender target = createIntentSenderForOriginalIntent(Binder.getCallingUid(),
            FLAG_CANCEL_CURRENT | FLAG_ONE_SHOT | FLAG_IMMUTABLE);
    final KeyguardManager km = (KeyguardManager) mServiceContext
            .getSystemService(KEYGUARD_SERVICE);
    final Intent newIntent = km.createConfirmDeviceCredentialIntent(null, null, userId);
    if (newIntent == null) {
        return null;
    }
    newIntent.setFlags(FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS |
            FLAG_ACTIVITY_TASK_ON_HOME);
    newIntent.putExtra(EXTRA_PACKAGE_NAME, aInfo.packageName);
    newIntent.putExtra(EXTRA_INTENT, target);
    return newIntent;
}
 
Example 2
Source File: KS.java    From ETHWallet with GNU General Public License v3.0 6 votes vote down vote up
public static void showAuthenticationScreen(Context context, int requestCode) {
	// Create the Confirm Credentials screen. You can customize the title and description. Or
	// we will provide a generic one for you if you leave it null
	Log.e(TAG, "showAuthenticationScreen: ");
	if (context instanceof Activity) {
		Activity app = (Activity) context;
		KeyguardManager mKeyguardManager = (KeyguardManager) app.getSystemService(Context.KEYGUARD_SERVICE);
		if (mKeyguardManager == null) {
			return;
		}
		Intent intent = mKeyguardManager
				.createConfirmDeviceCredentialIntent(
						context.getString(R.string.unlock_screen_title_android),
						context.getString(R.string.unlock_screen_prompt_android));
		if (intent != null) {
			app.startActivityForResult(intent, requestCode);
		} else {
			Log.e(TAG, "showAuthenticationScreen: failed to create intent for auth");
			app.finish();
		}
	} else {
		Log.e(TAG, "showAuthenticationScreen: context is not activity!");
	}
}
 
Example 3
Source File: KS.java    From trust-wallet-android-source with GNU General Public License v3.0 6 votes vote down vote up
public static void showAuthenticationScreen(Context context, int requestCode) {
	// Create the Confirm Credentials screen. You can customize the title and description. Or
	// we will provide a generic one for you if you leave it null
	Log.e(TAG, "showAuthenticationScreen: ");
	if (context instanceof Activity) {
		Activity app = (Activity) context;
		KeyguardManager mKeyguardManager = (KeyguardManager) app.getSystemService(Context.KEYGUARD_SERVICE);
		if (mKeyguardManager == null) {
			return;
		}
		Intent intent = mKeyguardManager
				.createConfirmDeviceCredentialIntent(
						context.getString(R.string.unlock_screen_title_android),
						context.getString(R.string.unlock_screen_prompt_android));
		if (intent != null) {
			app.startActivityForResult(intent, requestCode);
		} else {
			Log.e(TAG, "showAuthenticationScreen: failed to create intent for auth");
			app.finish();
		}
	} else {
		Log.e(TAG, "showAuthenticationScreen: context is not activity!");
	}
}
 
Example 4
Source File: LockSettingsService.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
private void showEncryptionNotificationForProfile(UserHandle user) {
    Resources r = mContext.getResources();
    CharSequence title = r.getText(
            com.android.internal.R.string.user_encrypted_title);
    CharSequence message = r.getText(
            com.android.internal.R.string.profile_encrypted_message);
    CharSequence detail = r.getText(
            com.android.internal.R.string.profile_encrypted_detail);

    final KeyguardManager km = (KeyguardManager) mContext.getSystemService(KEYGUARD_SERVICE);
    final Intent unlockIntent = km.createConfirmDeviceCredentialIntent(null, null,
            user.getIdentifier());
    if (unlockIntent == null) {
        return;
    }
    unlockIntent.setFlags(
            Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
    PendingIntent intent = PendingIntent.getActivity(mContext, 0, unlockIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    showEncryptionNotification(user, title, message, detail, intent);
}
 
Example 5
Source File: BiometricActivity.java    From cordova-plugin-fingerprint-aio with MIT License 6 votes vote down vote up
private void showAuthenticationScreen() {
    KeyguardManager keyguardManager = ContextCompat
            .getSystemService(this, KeyguardManager.class);
    if (keyguardManager == null
            || android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.LOLLIPOP) {
        return;
    }
    if (keyguardManager.isKeyguardSecure()) {
        Intent intent = keyguardManager
                .createConfirmDeviceCredentialIntent(mPromptInfo.getTitle(), mPromptInfo.getDescription());
        this.startActivityForResult(intent, REQUEST_CODE_CONFIRM_DEVICE_CREDENTIALS);
    } else {
        // Show a message that the user hasn't set up a lock screen.
        finishWithError(PluginError.BIOMETRIC_SCREEN_GUARD_UNSECURED);
    }
}
 
Example 6
Source File: SecureCredentialsManager.java    From Auth0.Android with MIT License 6 votes vote down vote up
/**
 * Require the user to authenticate using the configured LockScreen before accessing the credentials.
 * This feature is disabled by default and will only work if the device is running on Android version 21 or up and if the user
 * has configured a secure LockScreen (PIN, Pattern, Password or Fingerprint).
 * <p>
 * The activity passed as first argument here must override the {@link Activity#onActivityResult(int, int, Intent)} method and
 * call {@link SecureCredentialsManager#checkAuthenticationResult(int, int)} with the received parameters.
 *
 * @param activity    a valid activity context. Will be used in the authentication request to launch a LockScreen intent.
 * @param requestCode the request code to use in the authentication request. Must be a value between 1 and 255.
 * @param title       the text to use as title in the authentication screen. Passing null will result in using the OS's default value.
 * @param description the text to use as description in the authentication screen. On some Android versions it might not be shown. Passing null will result in using the OS's default value.
 * @return whether this device supports requiring authentication or not. This result can be ignored safely.
 */
public boolean requireAuthentication(@NonNull Activity activity, @IntRange(from = 1, to = 255) int requestCode, @Nullable String title, @Nullable String description) {
    if (requestCode < 1 || requestCode > 255) {
        throw new IllegalArgumentException("Request code must be a value between 1 and 255.");
    }
    KeyguardManager kManager = (KeyguardManager) activity.getSystemService(Context.KEYGUARD_SERVICE);
    this.authIntent = Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP ? kManager.createConfirmDeviceCredentialIntent(title, description) : null;
    this.authenticateBeforeDecrypt = ((Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && kManager.isDeviceSecure())
            || (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && kManager.isKeyguardSecure()))
            && authIntent != null;
    if (authenticateBeforeDecrypt) {
        this.activity = activity;
        this.authenticationRequestCode = requestCode;
    }
    return authenticateBeforeDecrypt;
}
 
Example 7
Source File: SmartLockHelper.java    From samples-android with Apache License 2.0 5 votes vote down vote up
@TargetApi(LOLLIPOP)
private void showConfirmCredentials(Activity activity) {
    KeyguardManager keyguardManager = (KeyguardManager) activity.getSystemService(Context.KEYGUARD_SERVICE);
    Intent intent = keyguardManager.createConfirmDeviceCredentialIntent(
            activity.getString(R.string.unlock_screen_title), "");
    if (intent != null) {
        activity.startActivityForResult(intent, REQUEST_CODE_CREDENTIALS);
    }
}
 
Example 8
Source File: LockedActivity.java    From nextcloud-notes with GNU General Public License v3.0 5 votes vote down vote up
private void askToUnlock() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && NotesApplication.isLocked()) {
        KeyguardManager keyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
        if (keyguardManager != null) {
            Intent i = keyguardManager.createConfirmDeviceCredentialIntent(getString(R.string.unlock_notes), null);
            i.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
            startActivityForResult(i, REQUEST_CODE_UNLOCK);
        } else {
            Log.e(TAG, "Keyguard manager is null");
        }
    }
}
 
Example 9
Source File: PinActivity.java    From GreenBits with GNU General Public License v3.0 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.M)
private void showAuthenticationScreen() {
    final KeyguardManager keyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
    final Intent intent = keyguardManager.createConfirmDeviceCredentialIntent(null, null);
    if (intent != null) {
        startActivityForResult(intent, ACTIVITY_REQUEST_CODE);
    }
}
 
Example 10
Source File: KeyStoreAES.java    From GreenBits with GNU General Public License v3.0 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static void showAuthenticationScreen(final Activity act) {
    final KeyguardManager keyguardManager = (KeyguardManager) act.getSystemService(Context.KEYGUARD_SERVICE);
    final Intent intent = keyguardManager.createConfirmDeviceCredentialIntent(null, null);
    if (intent != null) {
        act.startActivityForResult(intent, ACTIVITY_REQUEST_CODE);
    }
}
 
Example 11
Source File: KeychainAuthenticatedActivity.java    From Android-Vault with Apache License 2.0 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.M)
private void showAuthenticationScreen(int requestCode) {
    KeyguardManager keyguardManager = getSystemService(KeyguardManager.class);
    Intent intent = keyguardManager.createConfirmDeviceCredentialIntent(getString(R.string.please_login_title), getString(R.string.please_login_message));
    if (intent != null) {
        startActivityForResult(intent, requestCode);
    }
}
 
Example 12
Source File: ScreenLockUtil.java    From deltachat-android with GNU General Public License v3.0 5 votes vote down vote up
public static boolean applyScreenLock(Activity activity, int requestCode) {
    KeyguardManager keyguardManager = (KeyguardManager) activity.getSystemService(Context.KEYGUARD_SERVICE);
    Intent intent;
    if (keyguardManager != null && isScreenLockAvailable()) {
        intent = keyguardManager.createConfirmDeviceCredentialIntent(activity.getString(R.string.screenlock_unlock_title), activity.getString(R.string.screenlock_unlock_description));
        if (intent != null) {
            activity.startActivityForResult(intent, requestCode);
            return true;
        }
    }
    return false;
}
 
Example 13
Source File: SmartLockHelper.java    From samples-android with Apache License 2.0 5 votes vote down vote up
@TargetApi(LOLLIPOP)
private void showConfirmCredentials(Activity activity) {
    KeyguardManager keyguardManager = (KeyguardManager) activity.getSystemService(Context.KEYGUARD_SERVICE);
    Intent intent = keyguardManager.createConfirmDeviceCredentialIntent(
            activity.getString(R.string.unlock_screen_title), "");
    if (intent != null) {
        activity.startActivityForResult(intent, REQUEST_CODE_CREDENTIALS);
    }
}
 
Example 14
Source File: SignTransactionDialog.java    From alpha-wallet-android with MIT License 5 votes vote down vote up
private void showAuthenticationScreen()
{
    KeyguardManager mKeyguardManager = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE);
    Intent intent = mKeyguardManager.createConfirmDeviceCredentialIntent(unlockTitle, unlockDetail);
    if (intent != null) {
        context.startActivityForResult(intent, REQUEST_CODE_CONFIRM_DEVICE_CREDENTIALS + callBackId.ordinal());
    }
}
 
Example 15
Source File: KeyStoreAES.java    From green_android with GNU General Public License v3.0 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static void showAuthenticationScreen(final Activity act, final String network) throws RuntimeException {
    final KeyguardManager keyguardManager = (KeyguardManager) act.getSystemService(Context.KEYGUARD_SERVICE);
    final boolean isSaveActivity = (act instanceof PinSaveActivity);
    final String authTitle = !isSaveActivity ? act.getString(R.string.id_blockstream_green) : "";
    final String authDesc = !isSaveActivity ? act.getString(R.string.id_log_in_into_your_s_wallet, network) : "";
    final Intent intent = keyguardManager.createConfirmDeviceCredentialIntent(authTitle, authDesc);
    if (intent == null)
        throw new RuntimeException();
    act.startActivityForResult(intent, ACTIVITY_REQUEST_CODE);
}
 
Example 16
Source File: UserAuthenticationLocker.java    From cashuwallet with MIT License 5 votes vote down vote up
public static UserAuthenticationHandler defaultHandler(Continuation<Object[]> ret) {
    return (context, cont) -> {
        KeyguardManager keyguardManager = context.getSystemService(KeyguardManager.class);
        Intent intent = keyguardManager == null ? null : keyguardManager.createConfirmDeviceCredentialIntent(null, null);
        if (intent == null) {
            cont.run();
            return;
        }
        ret.cont(new Object[]{ intent, cont });
    };
}
 
Example 17
Source File: UserManagerService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * Show confirm credential screen to unlock user in order to turn off quiet mode.
 */
private void showConfirmCredentialToDisableQuietMode(
        @UserIdInt int userHandle, @Nullable IntentSender target) {
    // otherwise, we show a profile challenge to trigger decryption of the user
    final KeyguardManager km = (KeyguardManager) mContext.getSystemService(
            Context.KEYGUARD_SERVICE);
    // We should use userHandle not credentialOwnerUserId here, as even if it is unified
    // lock, confirm screenlock page will know and show personal challenge, and unlock
    // work profile when personal challenge is correct
    final Intent unlockIntent = km.createConfirmDeviceCredentialIntent(null, null,
            userHandle);
    if (unlockIntent == null) {
        return;
    }
    final Intent callBackIntent = new Intent(
            ACTION_DISABLE_QUIET_MODE_AFTER_UNLOCK);
    if (target != null) {
        callBackIntent.putExtra(Intent.EXTRA_INTENT, target);
    }
    callBackIntent.putExtra(Intent.EXTRA_USER_ID, userHandle);
    callBackIntent.setPackage(mContext.getPackageName());
    callBackIntent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
    final PendingIntent pendingIntent = PendingIntent.getBroadcast(
            mContext,
            0,
            callBackIntent,
            PendingIntent.FLAG_CANCEL_CURRENT |
                    PendingIntent.FLAG_ONE_SHOT |
                    PendingIntent.FLAG_IMMUTABLE);
    // After unlocking the challenge, it will disable quiet mode and run the original
    // intentSender
    unlockIntent.putExtra(Intent.EXTRA_INTENT, pendingIntent.getIntentSender());
    unlockIntent.setFlags(FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
    mContext.startActivity(unlockIntent);
}