Loading the camera preview correctly with direct boot

With direct boot the camera preview could be loaded in a wrong
state when the device was started. This ensures that it's reloaded
more often and should always be up to date and also fixes the
bug that the camera preview couldn't be loaded initially.

Change-Id: Ib43e322a9d6ef05d8519ebc85f4509441829e528
Fixes: 30420861
This commit is contained in:
Selim Cinek
2016-08-02 16:00:12 -07:00
parent 0fc298ffc7
commit 5f1450229b
3 changed files with 35 additions and 12 deletions

View File

@@ -16,6 +16,9 @@
package com.android.systemui.statusbar.phone;
import static android.view.accessibility.AccessibilityNodeInfo.ACTION_CLICK;
import static android.view.accessibility.AccessibilityNodeInfo.AccessibilityAction;
import android.app.ActivityManager;
import android.app.ActivityManagerNative;
import android.app.ActivityOptions;
@@ -65,9 +68,6 @@ import com.android.systemui.statusbar.policy.AccessibilityController;
import com.android.systemui.statusbar.policy.FlashlightController;
import com.android.systemui.statusbar.policy.PreviewInflater;
import static android.view.accessibility.AccessibilityNodeInfo.ACTION_CLICK;
import static android.view.accessibility.AccessibilityNodeInfo.AccessibilityAction;
/**
* Implementation for the bottom area of the Keyguard, including camera/phone affordance and status
* text.
@@ -403,7 +403,7 @@ public class KeyguardBottomAreaView extends FrameLayout implements View.OnClickL
public void bindCameraPrewarmService() {
Intent intent = getCameraIntent();
ActivityInfo targetInfo = PreviewInflater.getTargetActivityInfo(mContext, intent,
KeyguardUpdateMonitor.getCurrentUser());
KeyguardUpdateMonitor.getCurrentUser(), true /* onlyDirectBootAware */);
if (targetInfo != null && targetInfo.metaData != null) {
String clazz = targetInfo.metaData.getString(
MediaStore.META_DATA_STILL_IMAGE_CAMERA_PREWARM_SERVICE);
@@ -590,10 +590,16 @@ public class KeyguardBottomAreaView extends FrameLayout implements View.OnClickL
}
private void inflateCameraPreview() {
View previewBefore = mCameraPreview;
boolean visibleBefore = false;
if (previewBefore != null) {
mPreviewContainer.removeView(previewBefore);
visibleBefore = previewBefore.getVisibility() == View.VISIBLE;
}
mCameraPreview = mPreviewInflater.inflatePreview(getCameraIntent());
if (mCameraPreview != null) {
mPreviewContainer.addView(mCameraPreview);
mCameraPreview.setVisibility(View.INVISIBLE);
mCameraPreview.setVisibility(visibleBefore ? View.VISIBLE : View.INVISIBLE);
}
}
@@ -712,4 +718,9 @@ public class KeyguardBottomAreaView extends FrameLayout implements View.OnClickL
updateLeftAffordanceIcon();
updateLeftPreview();
}
public void onKeyguardShowingChanged() {
updateLeftAffordance();
inflateCameraPreview();
}
}

View File

@@ -1013,7 +1013,7 @@ public class NotificationPanelView extends PanelView implements
mKeyguardStatusBar.setAlpha(1f);
mKeyguardStatusBar.setVisibility(keyguardShowing ? View.VISIBLE : View.INVISIBLE);
if (keyguardShowing && oldState != mStatusBarState) {
mKeyguardBottomArea.updateLeftAffordance();
mKeyguardBottomArea.onKeyguardShowingChanged();
mAfforanceHelper.updatePreviews();
}
}

View File

@@ -119,13 +119,16 @@ public class PreviewInflater {
private WidgetInfo getWidgetInfo(Intent intent) {
PackageManager packageManager = mContext.getPackageManager();
int flags = PackageManager.MATCH_DEFAULT_ONLY
| PackageManager.MATCH_DIRECT_BOOT_AWARE
| PackageManager.MATCH_DIRECT_BOOT_UNAWARE;
final List<ResolveInfo> appList = packageManager.queryIntentActivitiesAsUser(
intent, PackageManager.MATCH_DEFAULT_ONLY, KeyguardUpdateMonitor.getCurrentUser());
intent, flags, KeyguardUpdateMonitor.getCurrentUser());
if (appList.size() == 0) {
return null;
}
ResolveInfo resolved = packageManager.resolveActivityAsUser(intent,
PackageManager.MATCH_DEFAULT_ONLY | PackageManager.GET_META_DATA,
flags | PackageManager.GET_META_DATA,
KeyguardUpdateMonitor.getCurrentUser());
if (wouldLaunchResolverActivity(resolved, appList)) {
return null;
@@ -139,23 +142,32 @@ public class PreviewInflater {
public static boolean wouldLaunchResolverActivity(Context ctx, Intent intent,
int currentUserId) {
return getTargetActivityInfo(ctx, intent, currentUserId) == null;
return getTargetActivityInfo(ctx, intent, currentUserId, false /* onlyDirectBootAware */)
== null;
}
/**
* @param onlyDirectBootAware a boolean indicating whether the matched activity packages must
* be direct boot aware when in direct boot mode if false, all
* packages are considered a match even if they are not aware.
* @return the target activity info of the intent it resolves to a specific package or
* {@code null} if it resolved to the resolver activity
*/
public static ActivityInfo getTargetActivityInfo(Context ctx, Intent intent,
int currentUserId) {
int currentUserId, boolean onlyDirectBootAware) {
PackageManager packageManager = ctx.getPackageManager();
int flags = PackageManager.MATCH_DEFAULT_ONLY;
if (!onlyDirectBootAware) {
flags |= PackageManager.MATCH_DIRECT_BOOT_AWARE
| PackageManager.MATCH_DIRECT_BOOT_UNAWARE;
}
final List<ResolveInfo> appList = packageManager.queryIntentActivitiesAsUser(
intent, PackageManager.MATCH_DEFAULT_ONLY, currentUserId);
intent, flags, currentUserId);
if (appList.size() == 0) {
return null;
}
ResolveInfo resolved = packageManager.resolveActivityAsUser(intent,
PackageManager.MATCH_DEFAULT_ONLY | PackageManager.GET_META_DATA, currentUserId);
flags | PackageManager.GET_META_DATA, currentUserId);
if (resolved == null || wouldLaunchResolverActivity(resolved, appList)) {
return null;
} else {