android.content.Intent#ACTION_USER_UNLOCKED源码实例Demo

下面列出了android.content.Intent#ACTION_USER_UNLOCKED 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: firebase-android-sdk   文件: FirebaseAppTest.java
@Test
public void testDirectBoot_shouldPreserveDataCollectionAfterUnlock() {
  Context mockContext = createForwardingMockContext();

  isUserUnlocked.set(false);
  FirebaseApp firebaseApp = FirebaseApp.initializeApp(mockContext);
  assert (firebaseApp != null);
  firebaseApp.setDataCollectionDefaultEnabled(false);
  assertFalse(firebaseApp.isDataCollectionDefaultEnabled());
  // User unlocks the device.
  isUserUnlocked.set(true);
  Intent userUnlockBroadcast = new Intent(Intent.ACTION_USER_UNLOCKED);
  localBroadcastManager.sendBroadcastSync(userUnlockBroadcast);

  assertFalse(firebaseApp.isDataCollectionDefaultEnabled());
  firebaseApp.setDataCollectionDefaultEnabled(true);
  assertTrue(firebaseApp.isDataCollectionDefaultEnabled());
  firebaseApp.setDataCollectionDefaultEnabled(false);
  assertFalse(firebaseApp.isDataCollectionDefaultEnabled());
  // Because default is true.
  firebaseApp.setDataCollectionDefaultEnabled(null);
  assertTrue(firebaseApp.isDataCollectionDefaultEnabled());
}
 
源代码2 项目: firebase-android-sdk   文件: FirebaseApp.java
private static void ensureReceiverRegistered(Context applicationContext) {
  if (INSTANCE.get() == null) {
    UserUnlockReceiver receiver = new UserUnlockReceiver(applicationContext);
    if (INSTANCE.compareAndSet(null /* expected */, receiver)) {
      IntentFilter intentFilter = new IntentFilter(Intent.ACTION_USER_UNLOCKED);
      applicationContext.registerReceiver(receiver, intentFilter);
    }
  }
}
 
源代码3 项目: firebase-android-sdk   文件: FirebaseAppTest.java
@Test
public void testDirectBoot_shouldInitializeEagerComponentsOnDeviceUnlock() {
  Context mockContext = createForwardingMockContext();

  isUserUnlocked.set(false);
  FirebaseApp firebaseApp = FirebaseApp.initializeApp(mockContext);

  InitTracker tracker = firebaseApp.get(InitTracker.class);
  EagerSdkVerifier sdkVerifier = firebaseApp.get(EagerSdkVerifier.class);

  // APIs are not initialized.
  assertThat(tracker.isInitialized()).isFalse();

  assertThat(sdkVerifier.isAuthInitialized()).isFalse();
  assertThat(sdkVerifier.isAnalyticsInitialized()).isFalse();

  // User unlocks the device.
  isUserUnlocked.set(true);
  Intent userUnlockBroadcast = new Intent(Intent.ACTION_USER_UNLOCKED);
  localBroadcastManager.sendBroadcastSync(userUnlockBroadcast);

  // APIs are initialized.
  assertThat(tracker.isInitialized()).isTrue();

  assertThat(sdkVerifier.isAuthInitialized()).isTrue();
  assertThat(sdkVerifier.isAnalyticsInitialized()).isTrue();
}
 
源代码4 项目: android_9.0.0_r45   文件: UserController.java
/**
 * Step from {@link UserState#STATE_RUNNING_UNLOCKING} to
 * {@link UserState#STATE_RUNNING_UNLOCKED}.
 */
void finishUserUnlocked(final UserState uss) {
    final int userId = uss.mHandle.getIdentifier();
    // Only keep marching forward if user is actually unlocked
    if (!StorageManager.isUserKeyUnlocked(userId)) return;
    synchronized (mLock) {
        // Bail if we ended up with a stale user
        if (mStartedUsers.get(uss.mHandle.getIdentifier()) != uss) return;

        // Do not proceed if unexpected state
        if (!uss.setState(STATE_RUNNING_UNLOCKING, STATE_RUNNING_UNLOCKED)) {
            return;
        }
    }
    mInjector.getUserManagerInternal().setUserState(userId, uss.state);
    uss.mUnlockProgress.finish();

    // Get unaware persistent apps running and start any unaware providers
    // in already-running apps that are partially aware
    if (userId == UserHandle.USER_SYSTEM) {
        mInjector.startPersistentApps(PackageManager.MATCH_DIRECT_BOOT_UNAWARE);
    }
    mInjector.installEncryptionUnawareProviders(userId);

    // Dispatch unlocked to external apps
    final Intent unlockedIntent = new Intent(Intent.ACTION_USER_UNLOCKED);
    unlockedIntent.putExtra(Intent.EXTRA_USER_HANDLE, userId);
    unlockedIntent.addFlags(
            Intent.FLAG_RECEIVER_REGISTERED_ONLY | Intent.FLAG_RECEIVER_FOREGROUND);
    mInjector.broadcastIntent(unlockedIntent, null, null, 0, null,
            null, null, AppOpsManager.OP_NONE, null, false, false, MY_PID, SYSTEM_UID,
            userId);

    if (getUserInfo(userId).isManagedProfile()) {
        UserInfo parent = mInjector.getUserManager().getProfileParent(userId);
        if (parent != null) {
            final Intent profileUnlockedIntent = new Intent(
                    Intent.ACTION_MANAGED_PROFILE_UNLOCKED);
            profileUnlockedIntent.putExtra(Intent.EXTRA_USER, UserHandle.of(userId));
            profileUnlockedIntent.addFlags(
                    Intent.FLAG_RECEIVER_REGISTERED_ONLY
                            | Intent.FLAG_RECEIVER_FOREGROUND);
            mInjector.broadcastIntent(profileUnlockedIntent,
                    null, null, 0, null, null, null, AppOpsManager.OP_NONE,
                    null, false, false, MY_PID, SYSTEM_UID,
                    parent.id);
        }
    }

    // Send PRE_BOOT broadcasts if user fingerprint changed; we
    // purposefully block sending BOOT_COMPLETED until after all
    // PRE_BOOT receivers are finished to avoid ANR'ing apps
    final UserInfo info = getUserInfo(userId);
    if (!Objects.equals(info.lastLoggedInFingerprint, Build.FINGERPRINT)) {
        // Suppress double notifications for managed profiles that
        // were unlocked automatically as part of their parent user
        // being unlocked.
        final boolean quiet;
        if (info.isManagedProfile()) {
            quiet = !uss.tokenProvided
                    || !mLockPatternUtils.isSeparateProfileChallengeEnabled(userId);
        } else {
            quiet = false;
        }
        mInjector.sendPreBootBroadcast(userId, quiet,
                () -> finishUserUnlockedCompleted(uss));
    } else {
        finishUserUnlockedCompleted(uss);
    }
}
 
 方法所在类
 同类方法