1 /* 2 * Copyright (C) 2018 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License 15 */ 16 17 package com.android.settings.password; 18 19 import android.app.Activity; 20 import android.app.ActivityManager; 21 import android.app.ActivityOptions; 22 import android.app.IActivityManager; 23 import android.app.admin.DevicePolicyManager; 24 import android.content.Intent; 25 import android.content.IntentSender; 26 import android.os.RemoteException; 27 import android.os.UserManager; 28 import android.view.View; 29 import android.view.WindowInsets; 30 import android.view.WindowInsetsController; 31 32 import androidx.annotation.NonNull; 33 34 import com.android.internal.widget.LockPatternUtils; 35 36 /** Class containing methods shared between CDCA and CDCBA */ 37 public class ConfirmDeviceCredentialUtils { 38 checkForPendingIntent(Activity activity)39 public static void checkForPendingIntent(Activity activity) { 40 // See Change-Id I52c203735fa9b53fd2f7df971824747eeb930f36 for context 41 int taskId = activity.getIntent().getIntExtra(Intent.EXTRA_TASK_ID, -1); 42 if (taskId != -1) { 43 try { 44 IActivityManager activityManager = ActivityManager.getService(); 45 final ActivityOptions options = ActivityOptions.makeBasic(); 46 activityManager.startActivityFromRecents(taskId, options.toBundle()); 47 return; 48 } catch (RemoteException e) { 49 // Do nothing. 50 } 51 } 52 IntentSender intentSender = activity.getIntent().getParcelableExtra(Intent.EXTRA_INTENT); 53 if (intentSender != null) { 54 try { 55 ActivityOptions activityOptions = 56 ActivityOptions.makeBasic() 57 .setPendingIntentBackgroundActivityStartMode( 58 ActivityOptions.MODE_BACKGROUND_ACTIVITY_START_ALLOWED); 59 activity.startIntentSenderForResult(intentSender, -1, null, 0, 0, 0, 60 activityOptions.toBundle()); 61 } catch (IntentSender.SendIntentException e) { 62 /* ignore */ 63 } 64 } 65 } 66 reportSuccessfulAttempt(LockPatternUtils utils, UserManager userManager, DevicePolicyManager dpm, int userId, boolean isStrongAuth)67 public static void reportSuccessfulAttempt(LockPatternUtils utils, UserManager userManager, 68 DevicePolicyManager dpm, int userId, boolean isStrongAuth) { 69 if (isStrongAuth) { 70 utils.reportSuccessfulPasswordAttempt(userId); 71 } else { 72 dpm.reportSuccessfulBiometricAttempt(userId); 73 } 74 if (userManager.isManagedProfile(userId)) { 75 // Keyguard is responsible to disable StrongAuth for primary user. Disable StrongAuth 76 // for work challenge only here. 77 utils.userPresent(userId); 78 } 79 } 80 81 /** 82 * Request hiding soft-keyboard before animating away credential UI, in case IME 83 * insets animation get delayed by dismissing animation. 84 * @param view used to get root {@link WindowInsets} and {@link WindowInsetsController}. 85 */ hideImeImmediately(@onNull View view)86 public static void hideImeImmediately(@NonNull View view) { 87 if (view.isAttachedToWindow() 88 && view.getRootWindowInsets().isVisible(WindowInsets.Type.ime())) { 89 view.getWindowInsetsController().hide(WindowInsets.Type.ime()); 90 } 91 } 92 } 93