Search in sources :

Example 96 with KeyguardManager

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

the class ImfBaseTestCase method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    final String packageName = getInstrumentation().getTargetContext().getPackageName();
    Intent intent = new Intent(Intent.ACTION_MAIN);
    intent.addFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
    mTargetActivity = launchActivityWithIntent(packageName, mTargetActivityClass, intent);
    // expect ime to auto pop up if device has no hard keyboard
    int keyboardType = mTargetActivity.getResources().getConfiguration().keyboard;
    mExpectAutoPop = (keyboardType == Configuration.KEYBOARD_NOKEYS || keyboardType == Configuration.KEYBOARD_UNDEFINED);
    mImm = InputMethodManager.getInstance();
    KeyguardManager keyguardManager = (KeyguardManager) getInstrumentation().getContext().getSystemService(Context.KEYGUARD_SERVICE);
    keyguardManager.newKeyguardLock("imftest").disableKeyguard();
}
Also used : Intent(android.content.Intent) KeyguardManager(android.app.KeyguardManager)

Example 97 with KeyguardManager

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

the class ShutdownThread method shutdownInner.

static void shutdownInner(final Context context, boolean confirm) {
    // any additional calls are just returned
    synchronized (sIsStartedGuard) {
        if (sIsStarted) {
            Log.d(TAG, "Request to shutdown already running, returning.");
            return;
        }
    }
    final int longPressBehavior = context.getResources().getInteger(com.android.internal.R.integer.config_longPressOnPowerBehavior);
    final int resourceId = mRebootSafeMode ? com.android.internal.R.string.reboot_safemode_confirm : (longPressBehavior == 2 ? com.android.internal.R.string.shutdown_confirm_question : com.android.internal.R.string.shutdown_confirm);
    final int titleResourceId = mRebootSafeMode ? com.android.internal.R.string.reboot_safemode_title : (mReboot ? com.android.internal.R.string.reboot_system : com.android.internal.R.string.power_off);
    Log.d(TAG, "Notifying thread to start shutdown longPressBehavior=" + longPressBehavior);
    if (confirm) {
        final CloseDialogReceiver closer = new CloseDialogReceiver(context);
        if (sConfirmDialog != null) {
            sConfirmDialog.dismiss();
            sConfirmDialog = null;
        }
        if (mReboot && !mRebootSafeMode) {
            // Determine if primary user is logged in
            boolean isPrimary = UserHandle.getCallingUserId() == UserHandle.USER_OWNER;
            // See if the advanced reboot menu is enabled
            // (only if primary user) and check the keyguard state
            int advancedReboot = isPrimary ? getAdvancedReboot(context) : 0;
            KeyguardManager km = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE);
            boolean locked = km.inKeyguardRestrictedInputMode();
            if ((advancedReboot == 1 && !locked) || advancedReboot == 2) {
                // Include options in power menu for rebooting into recovery or bootloader
                sConfirmDialog = new AlertDialog.Builder(context).setTitle(titleResourceId).setSingleChoiceItems(com.android.internal.R.array.shutdown_reboot_options, 0, new DialogInterface.OnClickListener() {

                    public void onClick(DialogInterface dialog, int which) {
                        if (which < 0)
                            return;
                        String[] actions = context.getResources().getStringArray(com.android.internal.R.array.shutdown_reboot_actions);
                        if (actions != null && which < actions.length) {
                            mReason = actions[which];
                            if (actions[which].equals(HOT_REBOOT)) {
                                mRebootHot = true;
                            } else {
                                mRebootHot = false;
                            }
                        }
                    }
                }).setPositiveButton(com.android.internal.R.string.yes, new DialogInterface.OnClickListener() {

                    public void onClick(DialogInterface dialog, int which) {
                        if (mRebootHot) {
                            mRebootHot = false;
                            try {
                                final IActivityManager am = ActivityManagerNative.asInterface(ServiceManager.checkService("activity"));
                                if (am != null) {
                                    am.restart();
                                }
                            } catch (RemoteException e) {
                                Log.e(TAG, "failure trying to perform hot reboot", e);
                            }
                        } else {
                            mReboot = true;
                            beginShutdownSequence(context);
                        }
                    }
                }).setNegativeButton(com.android.internal.R.string.no, new DialogInterface.OnClickListener() {

                    public void onClick(DialogInterface dialog, int which) {
                        mReboot = false;
                        mRebootHot = false;
                        dialog.cancel();
                    }
                }).create();
                sConfirmDialog.setOnKeyListener(new DialogInterface.OnKeyListener() {

                    public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
                        if (keyCode == KeyEvent.KEYCODE_BACK) {
                            mReboot = false;
                            mRebootHot = false;
                            dialog.cancel();
                        }
                        return true;
                    }
                });
            }
        }
        if (sConfirmDialog == null) {
            sConfirmDialog = new AlertDialog.Builder(context).setTitle(titleResourceId).setMessage(resourceId).setPositiveButton(com.android.internal.R.string.yes, new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int which) {
                    beginShutdownSequence(context);
                }
            }).setNegativeButton(com.android.internal.R.string.no, null).create();
        }
        closer.dialog = sConfirmDialog;
        sConfirmDialog.setOnDismissListener(closer);
        WindowManager.LayoutParams attrs = sConfirmDialog.getWindow().getAttributes();
        boolean isPrimary = UserHandle.getCallingUserId() == UserHandle.USER_OWNER;
        int powermenuAnimations = isPrimary ? getPowermenuAnimations(context) : 0;
        switch(powermenuAnimations) {
            case 0:
                attrs.windowAnimations = R.style.GlobalActionsAnimationEnter;
                attrs.gravity = Gravity.CENTER | Gravity.CENTER_HORIZONTAL;
                break;
            case 1:
                attrs.windowAnimations = R.style.GlobalActionsAnimation;
                attrs.gravity = Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL;
                break;
            case 2:
                attrs.windowAnimations = R.style.GlobalActionsAnimationTop;
                attrs.gravity = Gravity.TOP | Gravity.CENTER_HORIZONTAL;
                break;
        }
        sConfirmDialog.getWindow().setDimAmount(setPowerRebootDialogDim(context));
        sConfirmDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG);
        sConfirmDialog.show();
    } else {
        beginShutdownSequence(context);
    }
}
Also used : DialogInterface(android.content.DialogInterface) WindowManager(android.view.WindowManager) KeyEvent(android.view.KeyEvent) RemoteException(android.os.RemoteException) KeyguardManager(android.app.KeyguardManager) IActivityManager(android.app.IActivityManager)

Example 98 with KeyguardManager

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

the class ConnectivityManagerTestBase method turnScreenOn.

// Turn screen on
protected void turnScreenOn() {
    logv("Turn screen on");
    PowerManager pm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
    pm.wakeUp(SystemClock.uptimeMillis());
    // disable lock screen
    KeyguardManager km = (KeyguardManager) mContext.getSystemService(Context.KEYGUARD_SERVICE);
    if (km.inKeyguardRestrictedInputMode()) {
        sendKeys(KeyEvent.KEYCODE_MENU);
    }
}
Also used : PowerManager(android.os.PowerManager) KeyguardManager(android.app.KeyguardManager)

Example 99 with KeyguardManager

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

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)

Example 100 with KeyguardManager

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

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)

Aggregations

KeyguardManager (android.app.KeyguardManager)155 Intent (android.content.Intent)68 Context (android.content.Context)21 PendingIntent (android.app.PendingIntent)20 PowerManager (android.os.PowerManager)18 SuppressLint (android.annotation.SuppressLint)16 CancellationSignal (android.os.CancellationSignal)12 BiometricPrompt (android.hardware.biometrics.BiometricPrompt)11 Handler (android.os.Handler)11 IIntentSender (android.content.IIntentSender)10 IntentSender (android.content.IntentSender)10 FingerprintManager (android.hardware.fingerprint.FingerprintManager)10 TelephonyManager (android.telephony.TelephonyManager)8 TwoStatePreference (androidx.preference.TwoStatePreference)8 IOException (java.io.IOException)7 Uri (android.net.Uri)6 ProgressDialog (android.app.ProgressDialog)5 Resources (android.content.res.Resources)5 ConnectivityManager (android.net.ConnectivityManager)5 Bundle (android.os.Bundle)5