Search in sources :

Example 31 with KeyguardManager

use of android.app.KeyguardManager in project platform_frameworks_base by android.

the class UserManagerService method trySetQuietModeDisabled.

@Override
public boolean trySetQuietModeDisabled(int userHandle, IntentSender target) {
    checkManageUsersPermission("silence profile");
    if (StorageManager.isUserKeyUnlocked(userHandle) || !mLockPatternUtils.isSecure(userHandle)) {
        // if the user is already unlocked, no need to show a profile challenge
        setQuietModeEnabled(userHandle, false);
        return true;
    }
    long identity = Binder.clearCallingIdentity();
    try {
        // 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 false;
        }
        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);
    } finally {
        Binder.restoreCallingIdentity(identity);
    }
    return false;
}
Also used : PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) KeyguardManager(android.app.KeyguardManager)

Example 32 with KeyguardManager

use of android.app.KeyguardManager in project android_frameworks_base by DirtyUnicorns.

the class LockSettingsService method showEncryptionNotificationForProfile.

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);
}
Also used : PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) Resources(android.content.res.Resources) PendingIntent(android.app.PendingIntent) KeyguardManager(android.app.KeyguardManager)

Example 33 with KeyguardManager

use of android.app.KeyguardManager in project android_frameworks_base by DirtyUnicorns.

the class UserManagerService method trySetQuietModeDisabled.

@Override
public boolean trySetQuietModeDisabled(int userHandle, IntentSender target) {
    checkManageUsersPermission("silence profile");
    if (StorageManager.isUserKeyUnlocked(userHandle) || !mLockPatternUtils.isSecure(userHandle)) {
        // if the user is already unlocked, no need to show a profile challenge
        setQuietModeEnabled(userHandle, false);
        return true;
    }
    long identity = Binder.clearCallingIdentity();
    try {
        // 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 false;
        }
        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);
    } finally {
        Binder.restoreCallingIdentity(identity);
    }
    return false;
}
Also used : PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) KeyguardManager(android.app.KeyguardManager)

Example 34 with KeyguardManager

use of android.app.KeyguardManager in project android_frameworks_base by DirtyUnicorns.

the class ActivityStarter method showConfirmDeviceCredential.

void showConfirmDeviceCredential(int userId) {
    // First, retrieve the stack that we want to resume after credential is confirmed.
    ActivityStack targetStack;
    ActivityStack fullscreenStack = mSupervisor.getStack(FULLSCREEN_WORKSPACE_STACK_ID);
    ActivityStack freeformStack = mSupervisor.getStack(FREEFORM_WORKSPACE_STACK_ID);
    if (fullscreenStack != null && fullscreenStack.getStackVisibilityLocked(null) != ActivityStack.STACK_INVISIBLE) {
        // Single window case and the case that the docked stack is shown with fullscreen stack.
        targetStack = fullscreenStack;
    } else if (freeformStack != null && freeformStack.getStackVisibilityLocked(null) != ActivityStack.STACK_INVISIBLE) {
        targetStack = freeformStack;
    } else {
        // The case that the docked stack is shown with recent.
        targetStack = mSupervisor.getStack(HOME_STACK_ID);
    }
    if (targetStack == null) {
        return;
    }
    final KeyguardManager km = (KeyguardManager) mService.mContext.getSystemService(Context.KEYGUARD_SERVICE);
    final Intent credential = km.createConfirmDeviceCredentialIntent(null, null, userId);
    // For safety, check null here in case users changed the setting after the checking.
    if (credential == null) {
        return;
    }
    final ActivityRecord activityRecord = targetStack.topRunningActivityLocked();
    if (activityRecord != null) {
        final IIntentSender target = mService.getIntentSenderLocked(ActivityManager.INTENT_SENDER_ACTIVITY, activityRecord.launchedFromPackage, activityRecord.launchedFromUid, activityRecord.userId, null, null, 0, new Intent[] { activityRecord.intent }, new String[] { activityRecord.resolvedType }, PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_IMMUTABLE, null);
        credential.putExtra(Intent.EXTRA_INTENT, new IntentSender(target));
        // Show confirm credentials activity.
        startConfirmCredentialIntent(credential);
    }
}
Also used : IIntentSender(android.content.IIntentSender) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) IntentSender(android.content.IntentSender) IIntentSender(android.content.IIntentSender) KeyguardManager(android.app.KeyguardManager)

Example 35 with KeyguardManager

use of android.app.KeyguardManager in project android_frameworks_base by DirtyUnicorns.

the class ActivityStartInterceptor method interceptWithConfirmCredentialsIfNeeded.

/**
     * Creates an intent to intercept the current activity start with Confirm Credentials if needed.
     *
     * @return The intercepting intent if needed.
     */
private Intent interceptWithConfirmCredentialsIfNeeded(Intent intent, String resolvedType, ActivityInfo aInfo, String callingPackage, int userId) {
    if (!mService.mUserController.shouldConfirmCredentials(userId)) {
        return null;
    }
    // Allow direct boot aware activity to be displayed before the user is unlocked.
    if (aInfo.directBootAware && mService.mUserController.isUserRunningLocked(userId, ActivityManager.FLAG_AND_LOCKED)) {
        return null;
    }
    final IIntentSender target = mService.getIntentSenderLocked(INTENT_SENDER_ACTIVITY, callingPackage, Binder.getCallingUid(), userId, null, null, 0, new Intent[] { intent }, new String[] { resolvedType }, FLAG_CANCEL_CURRENT | FLAG_ONE_SHOT | FLAG_IMMUTABLE, null);
    final KeyguardManager km = (KeyguardManager) mService.mContext.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, new IntentSender(target));
    return newIntent;
}
Also used : IIntentSender(android.content.IIntentSender) Intent(android.content.Intent) IIntentSender(android.content.IIntentSender) IntentSender(android.content.IntentSender) KeyguardManager(android.app.KeyguardManager)

Aggregations

KeyguardManager (android.app.KeyguardManager)46 Intent (android.content.Intent)25 PendingIntent (android.app.PendingIntent)14 IIntentSender (android.content.IIntentSender)10 IntentSender (android.content.IntentSender)10 PowerManager (android.os.PowerManager)8 Resources (android.content.res.Resources)5 RemoteException (android.os.RemoteException)4 Context (android.content.Context)3 SuppressLint (android.annotation.SuppressLint)2 WindowManager (android.view.WindowManager)2 Activity (android.app.Activity)1 ActivityManager (android.app.ActivityManager)1 AlarmManager (android.app.AlarmManager)1 IActivityManager (android.app.IActivityManager)1 NotificationManager (android.app.NotificationManager)1 ActivityNotFoundException (android.content.ActivityNotFoundException)1 DialogInterface (android.content.DialogInterface)1 SensorManager (android.hardware.SensorManager)1 CameraAccessException (android.hardware.camera2.CameraAccessException)1