From e752ae55522f2657bb26bd2351ef879a73fa6efb Mon Sep 17 00:00:00 2001 From: Hai Zhang Date: Thu, 13 Aug 2020 01:45:09 +0000 Subject: [PATCH 01/11] DO NOT MERGE Don't allow non-instant permissions for instant apps. Bug: 140256621 Test: atest EphemeralTest Change-Id: Id07342c0347c0b4d2ccb3f58a4af9fda7a20d6ef (cherry picked from commit d83e3a350d1a2a6fd317b19ad22ee5647781870e) --- .../server/pm/PackageManagerService.java | 45 +++++++++++++------ 1 file changed, 31 insertions(+), 14 deletions(-) diff --git a/services/core/java/com/android/server/pm/PackageManagerService.java b/services/core/java/com/android/server/pm/PackageManagerService.java index 63c721a5da7b3..7a38a45335724 100644 --- a/services/core/java/com/android/server/pm/PackageManagerService.java +++ b/services/core/java/com/android/server/pm/PackageManagerService.java @@ -4198,13 +4198,9 @@ public class PackageManagerService extends IPackageManager.Stub Iterator iter = matches.iterator(); while (iter.hasNext()) { final ResolveInfo rInfo = iter.next(); - final PackageSetting ps = mSettings.mPackages.get(rInfo.activityInfo.packageName); - if (ps != null) { - final PermissionsState permissionsState = ps.getPermissionsState(); - if (permissionsState.hasPermission(Manifest.permission.INSTALL_PACKAGES, 0) - || Build.IS_ENG) { - continue; - } + if (checkPermission(Manifest.permission.INSTALL_PACKAGES, + rInfo.activityInfo.packageName, 0) == PERMISSION_GRANTED || Build.IS_ENG) { + continue; } iter.remove(); } @@ -4380,8 +4376,24 @@ public class PackageManagerService extends IPackageManager.Stub final int[] gids = (flags & PackageManager.GET_GIDS) == 0 ? EMPTY_INT_ARRAY : permissionsState.computeGids(userId); // Compute granted permissions only if package has requested permissions - final Set permissions = ArrayUtils.isEmpty(p.getRequestedPermissions()) + Set permissions = ArrayUtils.isEmpty(p.getRequestedPermissions()) ? Collections.emptySet() : permissionsState.getPermissions(userId); + if (state.instantApp) { + permissions = new ArraySet<>(permissions); + permissions.removeIf(permissionName -> { + BasePermission permission = mPermissionManager.getPermissionTEMP( + permissionName); + if (permission == null) { + return true; + } + if (!permission.isInstant()) { + EventLog.writeEvent(0x534e4554, "140256621", UserHandle.getUid(userId, + ps.appId), permissionName); + return true; + } + return false; + }); + } PackageInfo packageInfo = PackageInfoUtils.generate(p, gids, flags, ps.firstInstallTime, ps.lastUpdateTime, permissions, state, userId, ps); @@ -8579,10 +8591,9 @@ public class PackageManagerService extends IPackageManager.Stub private void addPackageHoldingPermissions(ArrayList list, PackageSetting ps, String[] permissions, boolean[] tmp, int flags, int userId) { int numMatch = 0; - final PermissionsState permissionsState = ps.getPermissionsState(); for (int i=0; i Date: Mon, 31 Aug 2020 18:28:41 +0000 Subject: [PATCH 02/11] DO NOT MERGE Fix NPE in executeDeletePackageLIF. The parameter allUserHandles may sometimes be null. Change-Id: Ie58cabe4bb1cae7173ad1d027e993a0b82a9f1ef Bug: 167233572 Bug: 140256621 Test: atest EphemeralTest (cherry picked from commit 01e0f4813af8502faaa683d55dbbc024b3080741) --- .../core/java/com/android/server/pm/PackageManagerService.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/services/core/java/com/android/server/pm/PackageManagerService.java b/services/core/java/com/android/server/pm/PackageManagerService.java index 7a38a45335724..c3c655d632e74 100644 --- a/services/core/java/com/android/server/pm/PackageManagerService.java +++ b/services/core/java/com/android/server/pm/PackageManagerService.java @@ -19198,7 +19198,8 @@ public class PackageManagerService extends IPackageManager.Stub // We need to get the permission state before package state is (potentially) destroyed. final SparseBooleanArray hadSuspendAppsPermission = new SparseBooleanArray(); - for (int userId : allUserHandles) { + // allUserHandles could be null, so call mUserManager.getUserIds() directly which is cached anyway. + for (int userId : mUserManager.getUserIds()) { hadSuspendAppsPermission.put(userId, checkPermission(Manifest.permission.SUSPEND_APPS, packageName, userId) == PERMISSION_GRANTED); } From 27ef1fc697faed77c7d2bdabf9432718680e1cae Mon Sep 17 00:00:00 2001 From: Andrii Kulian Date: Fri, 31 Jul 2020 18:46:28 -0700 Subject: [PATCH 03/11] Require permission to create trusted displays Bug: 162627132 Test: atest VirtualDisplayTest#testTrustedVirtualDisplay Test: atest frameworks/base/packages/SystemUI/tests/src/com/android/systemui/bubbles Test: atest DisplayTest Test: atest VirtualDisplayTest#testTrustedVirtualDisplay Test: atest VirtualDisplayTest#testUntrustedSysDecorVirtualDisplay Test: adb logcat -b events Change-Id: Id06b2013ef5fdeadf321f14f8b611c733031d54d Merged-In: Id06b2013ef5fdeadf321f14f8b611c733031d54d (cherry picked from commit f21c885ca7e86f77c808ab17fe1de650474de487) --- core/java/android/app/ActivityView.java | 15 +++++++++++++-- .../window/VirtualDisplayTaskEmbedder.java | 9 ++++++++- core/tests/coretests/AndroidManifest.xml | 1 + .../hardware/display/VirtualDisplayTest.java | 19 +++++++++++++++++++ .../systemui/bubbles/BubbleExpandedView.java | 2 +- .../server/display/DisplayManagerService.java | 15 +++++++++++---- 6 files changed, 53 insertions(+), 8 deletions(-) diff --git a/core/java/android/app/ActivityView.java b/core/java/android/app/ActivityView.java index 98a23f2b00750..3cb6293f07066 100644 --- a/core/java/android/app/ActivityView.java +++ b/core/java/android/app/ActivityView.java @@ -105,7 +105,8 @@ public class ActivityView extends ViewGroup implements android.window.TaskEmbedd public ActivityView( @NonNull Context context, @NonNull AttributeSet attrs, int defStyle, boolean singleTaskInstance, boolean usePublicVirtualDisplay) { - this(context, attrs, defStyle, singleTaskInstance, usePublicVirtualDisplay, false); + this(context, attrs, defStyle, singleTaskInstance, usePublicVirtualDisplay, + false /* disableSurfaceViewBackgroundLayer */); } /** @hide */ @@ -113,12 +114,22 @@ public class ActivityView extends ViewGroup implements android.window.TaskEmbedd @NonNull Context context, @NonNull AttributeSet attrs, int defStyle, boolean singleTaskInstance, boolean usePublicVirtualDisplay, boolean disableSurfaceViewBackgroundLayer) { + this(context, attrs, defStyle, singleTaskInstance, usePublicVirtualDisplay, + disableSurfaceViewBackgroundLayer, false /* useTrustedDisplay */); + } + + // TODO(b/162901735): Refactor ActivityView with Builder + /** @hide */ + public ActivityView( + @NonNull Context context, @NonNull AttributeSet attrs, int defStyle, + boolean singleTaskInstance, boolean usePublicVirtualDisplay, + boolean disableSurfaceViewBackgroundLayer, boolean useTrustedDisplay) { super(context, attrs, defStyle); if (useTaskOrganizer()) { mTaskEmbedder = new TaskOrganizerTaskEmbedder(context, this); } else { mTaskEmbedder = new VirtualDisplayTaskEmbedder(context, this, singleTaskInstance, - usePublicVirtualDisplay); + usePublicVirtualDisplay, useTrustedDisplay); } mSurfaceView = new SurfaceView(context, null, 0, 0, disableSurfaceViewBackgroundLayer); // Since ActivityView#getAlpha has been overridden, we should use parent class's alpha diff --git a/core/java/android/window/VirtualDisplayTaskEmbedder.java b/core/java/android/window/VirtualDisplayTaskEmbedder.java index 9ccb4c172158d..9013da36007e4 100644 --- a/core/java/android/window/VirtualDisplayTaskEmbedder.java +++ b/core/java/android/window/VirtualDisplayTaskEmbedder.java @@ -19,6 +19,7 @@ package android.window; import static android.hardware.display.DisplayManager.VIRTUAL_DISPLAY_FLAG_DESTROY_CONTENT_ON_REMOVAL; import static android.hardware.display.DisplayManager.VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY; import static android.hardware.display.DisplayManager.VIRTUAL_DISPLAY_FLAG_PUBLIC; +import static android.hardware.display.DisplayManager.VIRTUAL_DISPLAY_FLAG_TRUSTED; import static android.view.Display.INVALID_DISPLAY; import android.app.ActivityManager; @@ -63,6 +64,7 @@ public class VirtualDisplayTaskEmbedder extends TaskEmbedder { private int mDisplayDensityDpi; private final boolean mSingleTaskInstance; private final boolean mUsePublicVirtualDisplay; + private final boolean mUseTrustedDisplay; private VirtualDisplay mVirtualDisplay; private Insets mForwardedInsets; private DisplayMetrics mTmpDisplayMetrics; @@ -77,10 +79,12 @@ public class VirtualDisplayTaskEmbedder extends TaskEmbedder { * only applicable if virtual displays are used */ public VirtualDisplayTaskEmbedder(Context context, VirtualDisplayTaskEmbedder.Host host, - boolean singleTaskInstance, boolean usePublicVirtualDisplay) { + boolean singleTaskInstance, boolean usePublicVirtualDisplay, + boolean useTrustedDisplay) { super(context, host); mSingleTaskInstance = singleTaskInstance; mUsePublicVirtualDisplay = usePublicVirtualDisplay; + mUseTrustedDisplay = useTrustedDisplay; } /** @@ -103,6 +107,9 @@ public class VirtualDisplayTaskEmbedder extends TaskEmbedder { if (mUsePublicVirtualDisplay) { virtualDisplayFlags |= VIRTUAL_DISPLAY_FLAG_PUBLIC; } + if (mUseTrustedDisplay) { + virtualDisplayFlags |= VIRTUAL_DISPLAY_FLAG_TRUSTED; + } mVirtualDisplay = displayManager.createVirtualDisplay( DISPLAY_NAME + "@" + System.identityHashCode(this), mHost.getWidth(), diff --git a/core/tests/coretests/AndroidManifest.xml b/core/tests/coretests/AndroidManifest.xml index 5c2841aff1d83..7597e87321530 100644 --- a/core/tests/coretests/AndroidManifest.xml +++ b/core/tests/coretests/AndroidManifest.xml @@ -129,6 +129,7 @@ + diff --git a/core/tests/coretests/src/android/hardware/display/VirtualDisplayTest.java b/core/tests/coretests/src/android/hardware/display/VirtualDisplayTest.java index daf613976358e..0f6284d22d106 100644 --- a/core/tests/coretests/src/android/hardware/display/VirtualDisplayTest.java +++ b/core/tests/coretests/src/android/hardware/display/VirtualDisplayTest.java @@ -247,6 +247,25 @@ public class VirtualDisplayTest extends AndroidTestCase { assertDisplayUnregistered(display); } + /** + * Ensures that an application can create a trusted virtual display with the permission + * {@code ADD_TRUSTED_DISPLAY}. + */ + public void testTrustedVirtualDisplay() throws Exception { + VirtualDisplay virtualDisplay = mDisplayManager.createVirtualDisplay(NAME, + WIDTH, HEIGHT, DENSITY, mSurface, + DisplayManager.VIRTUAL_DISPLAY_FLAG_TRUSTED); + assertNotNull("virtual display must not be null", virtualDisplay); + + Display display = virtualDisplay.getDisplay(); + try { + assertDisplayRegistered(display, Display.FLAG_PRIVATE | Display.FLAG_TRUSTED); + } finally { + virtualDisplay.release(); + } + assertDisplayUnregistered(display); + } + private void assertDisplayRegistered(Display display, int flags) { assertNotNull("display object must not be null", display); assertTrue("display must be valid", display.isValid()); diff --git a/packages/SystemUI/src/com/android/systemui/bubbles/BubbleExpandedView.java b/packages/SystemUI/src/com/android/systemui/bubbles/BubbleExpandedView.java index 3d3171208b150..110a5ab67f0d8 100644 --- a/packages/SystemUI/src/com/android/systemui/bubbles/BubbleExpandedView.java +++ b/packages/SystemUI/src/com/android/systemui/bubbles/BubbleExpandedView.java @@ -301,7 +301,7 @@ public class BubbleExpandedView extends LinearLayout { mActivityView = new ActivityView(mContext, null /* attrs */, 0 /* defStyle */, true /* singleTaskInstance */, false /* usePublicVirtualDisplay*/, - true /* disableSurfaceViewBackgroundLayer */); + true /* disableSurfaceViewBackgroundLayer */, true /* useTrustedDisplay */); // Set ActivityView's alpha value as zero, since there is no view content to be shown. setContentVisibility(false); diff --git a/services/core/java/com/android/server/display/DisplayManagerService.java b/services/core/java/com/android/server/display/DisplayManagerService.java index 1058000e0b68f..9a8be287690fd 100644 --- a/services/core/java/com/android/server/display/DisplayManagerService.java +++ b/services/core/java/com/android/server/display/DisplayManagerService.java @@ -86,6 +86,7 @@ import android.os.UserHandle; import android.os.UserManager; import android.provider.Settings; import android.text.TextUtils; +import android.util.EventLog; import android.util.IntArray; import android.util.Pair; import android.util.Slog; @@ -2191,10 +2192,16 @@ public final class DisplayManagerService extends SystemService { } } - if (callingUid == Process.SYSTEM_UID - || checkCallingPermission(ADD_TRUSTED_DISPLAY, "createVirtualDisplay()")) { - flags |= VIRTUAL_DISPLAY_FLAG_TRUSTED; - } else { + if (callingUid != Process.SYSTEM_UID && (flags & VIRTUAL_DISPLAY_FLAG_TRUSTED) != 0) { + if (!checkCallingPermission(ADD_TRUSTED_DISPLAY, "createVirtualDisplay()")) { + EventLog.writeEvent(0x534e4554, "162627132", callingUid, + "Attempt to create a trusted display without holding permission!"); + throw new SecurityException("Requires ADD_TRUSTED_DISPLAY permission to " + + "create a trusted virtual display."); + } + } + + if ((flags & VIRTUAL_DISPLAY_FLAG_TRUSTED) == 0) { flags &= ~VIRTUAL_DISPLAY_FLAG_SHOULD_SHOW_SYSTEM_DECORATIONS; } From d3a2b5832f6ca9da74cda814ec76aec679b3389a Mon Sep 17 00:00:00 2001 From: Seigo Nonaka Date: Wed, 26 Aug 2020 14:42:08 -0700 Subject: [PATCH 04/11] Accept repeated locale as an input of LocaleList construction. Repeated locale has not been accepted and IllegalArgumentException is thrown. Instead of throwing exception, dropping repeated locale instead. Bug: 152410253 Test: atest LocaleListTest Change-Id: I80f243678ac3024eaeb0349f770cff897df7f332 (cherry picked from commit 7ee68787cca0837f59658d5174e1d586dfe80ad4) --- core/java/android/os/LocaleList.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/core/java/android/os/LocaleList.java b/core/java/android/os/LocaleList.java index ab4bb0b9f2cd0..9c0bc45a346e9 100644 --- a/core/java/android/os/LocaleList.java +++ b/core/java/android/os/LocaleList.java @@ -25,6 +25,7 @@ import android.icu.util.ULocale; import com.android.internal.annotations.GuardedBy; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.HashSet; @@ -151,18 +152,18 @@ public final class LocaleList implements Parcelable { /** * Creates a new {@link LocaleList}. * + * If two or more same locales are passed, the repeated locales will be dropped. *

For empty lists of {@link Locale} items it is better to use {@link #getEmptyLocaleList()}, * which returns a pre-constructed empty list.

* * @throws NullPointerException if any of the input locales is null. - * @throws IllegalArgumentException if any of the input locales repeat. */ public LocaleList(@NonNull Locale... list) { if (list.length == 0) { mList = sEmptyList; mStringRepresentation = ""; } else { - final Locale[] localeList = new Locale[list.length]; + final ArrayList localeList = new ArrayList<>(); final HashSet seenLocales = new HashSet(); final StringBuilder sb = new StringBuilder(); for (int i = 0; i < list.length; i++) { @@ -170,10 +171,10 @@ public final class LocaleList implements Parcelable { if (l == null) { throw new NullPointerException("list[" + i + "] is null"); } else if (seenLocales.contains(l)) { - throw new IllegalArgumentException("list[" + i + "] is a repetition"); + // Dropping duplicated locale entries. } else { final Locale localeClone = (Locale) l.clone(); - localeList[i] = localeClone; + localeList.add(localeClone); sb.append(localeClone.toLanguageTag()); if (i < list.length - 1) { sb.append(','); @@ -181,7 +182,7 @@ public final class LocaleList implements Parcelable { seenLocales.add(localeClone); } } - mList = localeList; + mList = localeList.toArray(new Locale[localeList.size()]); mStringRepresentation = sb.toString(); } } From aaf6b40e1746db6189f6078dcd28d8f153a4cc50 Mon Sep 17 00:00:00 2001 From: Julia Reynolds Date: Wed, 26 Aug 2020 17:07:53 -0400 Subject: [PATCH 05/11] Sanitize more of the notification text fields Test: manual; monitor SystemUI performance when an app tries to post a messaging style notification with messages with long text Bug: 158304295 Bug: 147358092 Merged-In: c953fdf6bc498ca791aed49df04e5a07c935b63a Change-Id: I0e2ea12fc3351b1a56645b556720ea2306f5422a (cherry picked from commit c953fdf6bc498ca791aed49df04e5a07c935b63a) (cherry picked from commit a19f9ed2b1c04fe7e73bab1a8ca51400dbf8a07a) --- core/java/android/app/Notification.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/java/android/app/Notification.java b/core/java/android/app/Notification.java index 79d2a8102358a..609083e719ba6 100644 --- a/core/java/android/app/Notification.java +++ b/core/java/android/app/Notification.java @@ -207,7 +207,7 @@ public class Notification implements Parcelable *

* Avoids spamming the system with overly large strings such as full e-mails. */ - private static final int MAX_CHARSEQUENCE_LENGTH = 5 * 1024; + private static final int MAX_CHARSEQUENCE_LENGTH = 1024; /** * Maximum entries of reply text that are accepted by Builder and friends. @@ -7830,7 +7830,7 @@ public class Notification implements Parcelable */ public Message(@NonNull CharSequence text, long timestamp, @Nullable Person sender, boolean remoteInputHistory) { - mText = text; + mText = safeCharSequence(text); mTimestamp = timestamp; mSender = sender; mRemoteInputHistory = remoteInputHistory; @@ -7944,7 +7944,7 @@ public class Notification implements Parcelable bundle.putLong(KEY_TIMESTAMP, mTimestamp); if (mSender != null) { // Legacy listeners need this - bundle.putCharSequence(KEY_SENDER, mSender.getName()); + bundle.putCharSequence(KEY_SENDER, safeCharSequence(mSender.getName())); bundle.putParcelable(KEY_SENDER_PERSON, mSender); } if (mDataMimeType != null) { From d3021c68cbbef89dfb18b1a6fa4b816a2b2ec3ee Mon Sep 17 00:00:00 2001 From: Jeff Chang Date: Fri, 7 Aug 2020 16:08:15 +0800 Subject: [PATCH 06/11] [RESTRICT AUTOMERGE] Update the visibility of activities on sleeping display Activity with showWhenLocked flag is visible when screen is off and leads to activity restart called. This CL update the visibility condition for showWhenLocked and dismisskeyguard activities and refer the keyguard visibility to ensure the function works as expected. Bug: 161036653 Test: atest ActivityRecordTests atest CtsWindowManagerDeviceTestCases:KeyguardTests atest CtsWindowManagerDeviceTestCases:KeyguardLockedTests Change-Id: I9d56e40de964e9d11193fec7008f8d880028ac50 (cherry picked from commit 73d6c7926d2cdc39de617f7213fc85f303501f37) (cherry picked from commit 31fc73a70719ed9a07a9a865c71b602e2fd0c53e) (cherry picked from commit 1e8e7a94872de70aa6e661fe960854e01447b1c0) --- .../com/android/server/wm/ActivityRecord.java | 15 ++++------ .../server/wm/ActivityRecordTests.java | 28 +++++++++++++++++++ 2 files changed, 34 insertions(+), 9 deletions(-) diff --git a/services/core/java/com/android/server/wm/ActivityRecord.java b/services/core/java/com/android/server/wm/ActivityRecord.java index 3e9377ed06649..41e48b8ec9db5 100644 --- a/services/core/java/com/android/server/wm/ActivityRecord.java +++ b/services/core/java/com/android/server/wm/ActivityRecord.java @@ -4578,15 +4578,6 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A return false; } - // Check if the activity is on a sleeping display, and if it can turn it ON. - if (getDisplay().isSleeping()) { - final boolean canTurnScreenOn = !mSetToSleep || canTurnScreenOn() - || canShowWhenLocked() || containsDismissKeyguardWindow(); - if (!canTurnScreenOn) { - return false; - } - } - // Now check whether it's really visible depending on Keyguard state, and update // {@link ActivityStack} internal states. // Inform the method if this activity is the top activity of this stack, but exclude the @@ -4597,6 +4588,12 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A final boolean visibleIgnoringDisplayStatus = stack.checkKeyguardVisibility(this, visibleIgnoringKeyguard, isTop && isTopNotPinnedStack); + // Check if the activity is on a sleeping display, and if it can turn it ON. + // TODO(b/163993448): Do not make activity visible before display awake. + if (visibleIgnoringDisplayStatus && getDisplay().isSleeping()) { + return !mSetToSleep || canTurnScreenOn(); + } + return visibleIgnoringDisplayStatus; } diff --git a/services/tests/wmtests/src/com/android/server/wm/ActivityRecordTests.java b/services/tests/wmtests/src/com/android/server/wm/ActivityRecordTests.java index c7b45efb2de18..6ab0697206e35 100644 --- a/services/tests/wmtests/src/com/android/server/wm/ActivityRecordTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/ActivityRecordTests.java @@ -1099,6 +1099,34 @@ public class ActivityRecordTests extends ActivityTestsBase { verify(topActivity).destroyIfPossible(anyString()); } + /** + * Verify the visibility of a show-when-locked and dismiss keyguard activity on sleeping + * display. + */ + @Test + public void testDisplaySleeping_activityInvisible() { + final KeyguardController keyguardController = + mActivity.mStackSupervisor.getKeyguardController(); + doReturn(true).when(keyguardController).isKeyguardLocked(); + final ActivityRecord topActivity = new ActivityBuilder(mService).setTask(mTask).build(); + topActivity.mVisibleRequested = true; + topActivity.nowVisible = true; + topActivity.setState(RESUMED, "test" /*reason*/); + doReturn(true).when(topActivity).containsDismissKeyguardWindow(); + doCallRealMethod().when(mRootWindowContainer).ensureActivitiesVisible( + any() /* starting */, anyInt() /* configChanges */, + anyBoolean() /* preserveWindows */, anyBoolean() /* notifyClients */); + topActivity.setShowWhenLocked(true); + + // Verify the top activity is occluded keyguard. + assertEquals(topActivity, mStack.topRunningActivity()); + assertTrue(mStack.topActivityOccludesKeyguard()); + + final DisplayContent display = mActivity.mDisplayContent; + doReturn(true).when(display).isSleeping(); + assertFalse(topActivity.shouldBeVisible()); + } + /** * Verify that complete finish request for a show-when-locked activity must ensure the * keyguard occluded state being updated. From 5f1da89be43978af737cdfdce94a6dcd9d9370ed Mon Sep 17 00:00:00 2001 From: Tiger Huang Date: Thu, 13 Aug 2020 22:43:52 +0800 Subject: [PATCH 07/11] Update requested state after applying pending frames When there is an insets animation, we will stop updating insets source frames until the animation is done. The previous logic didn't update the frames within the requested state while the animation is done. And the frames was relied by InsetsPolicy while playing transient bar animation. If the frames don't match the display, the insets would be wrong, and the animation wouldn't be played correctly. Fix: 161134197 Test: atest InsetsControllerTest Merged-In: Id8f3c1956fbfe3ad16f167ff76297dde6c634e81 Change-Id: Id8f3c1956fbfe3ad16f167ff76297dde6c634e81 (cherry picked from commit 23c75281ef0de8fb2b44fb93d8cf36ecf86454c7) (cherry picked from commit dfc8abb1ffc7bf6c7d7b47cf2e9e14bf6422f95c) --- core/java/android/view/InsetsController.java | 9 ++++++--- .../src/android/view/InsetsControllerTest.java | 15 +++++++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/core/java/android/view/InsetsController.java b/core/java/android/view/InsetsController.java index c383bc7a4d700..985829f6c885d 100644 --- a/core/java/android/view/InsetsController.java +++ b/core/java/android/view/InsetsController.java @@ -1134,15 +1134,14 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation if (invokeCallback) { control.cancel(); } + boolean stateChanged = false; for (int i = mRunningAnimations.size() - 1; i >= 0; i--) { RunningAnimation runningAnimation = mRunningAnimations.get(i); if (runningAnimation.runner == control) { mRunningAnimations.remove(i); ArraySet types = toInternalType(control.getTypes()); for (int j = types.size() - 1; j >= 0; j--) { - if (getSourceConsumer(types.valueAt(j)).notifyAnimationFinished()) { - mHost.notifyInsetsChanged(); - } + stateChanged |= getSourceConsumer(types.valueAt(j)).notifyAnimationFinished(); } if (invokeCallback && runningAnimation.startDispatched) { dispatchAnimationEnd(runningAnimation.runner.getAnimation()); @@ -1150,6 +1149,10 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation break; } } + if (stateChanged) { + mHost.notifyInsetsChanged(); + updateRequestedState(); + } } private void applyLocalVisibilityOverride() { diff --git a/core/tests/coretests/src/android/view/InsetsControllerTest.java b/core/tests/coretests/src/android/view/InsetsControllerTest.java index 801cd4ddb94e9..48695aa5a3291 100644 --- a/core/tests/coretests/src/android/view/InsetsControllerTest.java +++ b/core/tests/coretests/src/android/view/InsetsControllerTest.java @@ -27,6 +27,7 @@ import static android.view.InsetsState.ITYPE_NAVIGATION_BAR; import static android.view.InsetsState.ITYPE_STATUS_BAR; import static android.view.ViewRootImpl.NEW_INSETS_MODE_FULL; import static android.view.WindowInsets.Type.ime; +import static android.view.WindowInsets.Type.navigationBars; import static android.view.WindowInsets.Type.statusBars; import static android.view.WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE; @@ -742,6 +743,20 @@ public class InsetsControllerTest { mController.onControlsChanged(createSingletonControl(ITYPE_IME)); assertEquals(newState.getSource(ITYPE_IME), mTestHost.getModifiedState().peekSource(ITYPE_IME)); + + // The modified frames cannot be updated if there is an animation. + mController.onControlsChanged(createSingletonControl(ITYPE_NAVIGATION_BAR)); + mController.hide(navigationBars()); + newState = new InsetsState(mController.getState(), true /* copySource */); + newState.getSource(ITYPE_NAVIGATION_BAR).getFrame().top--; + mController.onStateChanged(newState); + assertNotEquals(newState.getSource(ITYPE_NAVIGATION_BAR), + mTestHost.getModifiedState().peekSource(ITYPE_NAVIGATION_BAR)); + + // The modified frames can be updated while the animation is done. + mController.cancelExistingAnimations(); + assertEquals(newState.getSource(ITYPE_NAVIGATION_BAR), + mTestHost.getModifiedState().peekSource(ITYPE_NAVIGATION_BAR)); }); } From 1f0f8417000e62f243fd7cb0d4339e8c7cfd1eb3 Mon Sep 17 00:00:00 2001 From: Julia Reynolds Date: Wed, 2 Sep 2020 16:32:09 -0400 Subject: [PATCH 08/11] Add screenshot back to power menu for some devices Test: atest Bug: 155251236 Change-Id: I190a03385b9136748aa75dbd26ed4556cf81599a (cherry picked from commit 858b4ae2b2ff6870e739192f4046a3ed2f914407) (cherry picked from commit 238de217662d27688c644ddcd523bf12b3404d9e) --- core/res/res/values/config.xml | 1 + .../globalactions/GlobalActionsDialog.java | 22 +++++++++++++++++- .../GlobalActionsDialogTest.java | 23 +++++++++++++++++++ 3 files changed, 45 insertions(+), 1 deletion(-) diff --git a/core/res/res/values/config.xml b/core/res/res/values/config.xml index 39d20bbff3ba9..6ca5bf27f54c9 100644 --- a/core/res/res/values/config.xml +++ b/core/res/res/values/config.xml @@ -2774,6 +2774,7 @@ power restart logout + screenshot bugreport diff --git a/packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsDialog.java b/packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsDialog.java index b2e91643bed2d..016ad45f7d75e 100644 --- a/packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsDialog.java +++ b/packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsDialog.java @@ -19,6 +19,7 @@ import static android.view.WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM; import static android.view.WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS; import static android.view.WindowManager.ScreenshotSource.SCREENSHOT_GLOBAL_ACTIONS; import static android.view.WindowManager.TAKE_SCREENSHOT_FULLSCREEN; +import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_2BUTTON; import static com.android.internal.widget.LockPatternUtils.StrongAuthTracker.SOME_AUTH_REQUIRED_AFTER_USER_REQUEST; import static com.android.internal.widget.LockPatternUtils.StrongAuthTracker.STRONG_AUTH_NOT_REQUIRED; @@ -547,7 +548,7 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener, if (!mDeviceProvisioned && !action.showBeforeProvisioning()) { return false; } - return true; + return action.shouldShow(); } /** @@ -962,6 +963,8 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener, @VisibleForTesting class ScreenshotAction extends SinglePressAction implements LongPressAction { + final String KEY_SYSTEM_NAV_2BUTTONS = "system_nav_2buttons"; + public ScreenshotAction() { super(R.drawable.ic_screenshot, R.string.global_action_screenshot); } @@ -993,6 +996,19 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener, return false; } + @Override + public boolean shouldShow() { + // Include screenshot in power menu for legacy nav because it is not accessible + // through Recents in that mode + return is2ButtonNavigationEnabled(); + } + + boolean is2ButtonNavigationEnabled() { + return NAV_BAR_MODE_2BUTTON == mContext.getResources().getInteger( + com.android.internal.R.integer.config_navBarInteractionMode); + } + + @Override public boolean onLongPress() { if (FeatureFlagUtils.isEnabled(mContext, FeatureFlagUtils.SCREENRECORD_LONG_PRESS)) { @@ -1616,6 +1632,10 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener, * @return */ CharSequence getMessage(); + + default boolean shouldShow() { + return true; + } } /** diff --git a/packages/SystemUI/tests/src/com/android/systemui/globalactions/GlobalActionsDialogTest.java b/packages/SystemUI/tests/src/com/android/systemui/globalactions/GlobalActionsDialogTest.java index ac8c6710e0419..5e2e7c0750430 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/globalactions/GlobalActionsDialogTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/globalactions/GlobalActionsDialogTest.java @@ -49,6 +49,7 @@ import android.testing.TestableLooper; import android.util.FeatureFlagUtils; import android.view.IWindowManager; import android.view.View; +import android.view.WindowManagerPolicyConstants; import android.widget.FrameLayout; import androidx.test.filters.SmallTest; @@ -241,6 +242,28 @@ public class GlobalActionsDialogTest extends SysuiTestCase { verifyLogPosted(GlobalActionsDialog.GlobalActionsEvent.GA_SCREENSHOT_LONG_PRESS); } + @Test + public void testShouldShowScreenshot() { + mContext.getOrCreateTestableResources().addOverride( + com.android.internal.R.integer.config_navBarInteractionMode, + WindowManagerPolicyConstants.NAV_BAR_MODE_2BUTTON); + + GlobalActionsDialog.ScreenshotAction screenshotAction = + mGlobalActionsDialog.makeScreenshotActionForTesting(); + assertThat(screenshotAction.shouldShow()).isTrue(); + } + + @Test + public void testShouldNotShowScreenshot() { + mContext.getOrCreateTestableResources().addOverride( + com.android.internal.R.integer.config_navBarInteractionMode, + WindowManagerPolicyConstants.NAV_BAR_MODE_3BUTTON); + + GlobalActionsDialog.ScreenshotAction screenshotAction = + mGlobalActionsDialog.makeScreenshotActionForTesting(); + assertThat(screenshotAction.shouldShow()).isFalse(); + } + private void verifyLogPosted(GlobalActionsDialog.GlobalActionsEvent event) { mTestableLooper.processAllMessages(); verify(mUiEventLogger, times(1)) From e3e68f6a52d7cecbbd982eab25336e9d44cd4061 Mon Sep 17 00:00:00 2001 From: Beverly Date: Tue, 15 Sep 2020 09:23:54 -0400 Subject: [PATCH 09/11] Add telecom to priorityOnlyDndExemptPackages telecom plays dialer's ringtone, so we allow them to play sounds when DND is on in priority mode. We trust that telecom will abide by the DND rules and exceptions (ie: checking for starred contacts) Test: manual Bug: 163525045 Change-Id: I798f1d968821e7d1b0a97b9b034c1ef0726f8242 Merged-In: I798f1d968821e7d1b0a97b9b034c1ef0726f8242 (cherry picked from commit c384c930fd64e8c8e02b7bc28314b7f692ef8c9f) --- core/res/res/values/config.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/core/res/res/values/config.xml b/core/res/res/values/config.xml index 6ca5bf27f54c9..46f2fdeb5e513 100644 --- a/core/res/res/values/config.xml +++ b/core/res/res/values/config.xml @@ -3478,6 +3478,7 @@ mode --> com.android.dialer + com.android.server.telecom com.android.systemui android From cf36be8ab100a4d3891dcb02fa3978f90b509459 Mon Sep 17 00:00:00 2001 From: Jeff Chang Date: Mon, 21 Sep 2020 16:55:15 +0800 Subject: [PATCH 10/11] [RESTRICT AUTOMERGE]Don't finish noHistory activity while it is on the topmost. There was no top running activity in the target task result in the NPE. The CL makes sure the top running noHistory activity is not finished when launched again and have protection for getTopNonFinishingActivity. Bug: 159507052 Test: atest testNoHistoryActivityNotFinished Change-Id: Id582f28d79bec052115e07d98c097c7d50c11609 (cherry picked from commit 59a51c6ba9219835d0419b5e5b2cde80bd695b4b) --- services/core/java/com/android/server/wm/ActivityStack.java | 5 +++-- .../core/java/com/android/server/wm/ActivityStarter.java | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/services/core/java/com/android/server/wm/ActivityStack.java b/services/core/java/com/android/server/wm/ActivityStack.java index e9768a26f571a..2b785c57a61c5 100644 --- a/services/core/java/com/android/server/wm/ActivityStack.java +++ b/services/core/java/com/android/server/wm/ActivityStack.java @@ -1704,8 +1704,9 @@ class ActivityStack extends Task { // If the most recent activity was noHistory but was only stopped rather // than stopped+finished because the device went to sleep, we need to make // sure to finish it as we're making a new activity topmost. - if (shouldSleepActivities() && mLastNoHistoryActivity != null && - !mLastNoHistoryActivity.finishing) { + if (shouldSleepActivities() && mLastNoHistoryActivity != null + && !mLastNoHistoryActivity.finishing + && mLastNoHistoryActivity != next) { if (DEBUG_STATES) Slog.d(TAG_STATES, "no-history finish of " + mLastNoHistoryActivity + " on new resume"); mLastNoHistoryActivity.finishIfPossible("resume-no-history", false /* oomAdj */); diff --git a/services/core/java/com/android/server/wm/ActivityStarter.java b/services/core/java/com/android/server/wm/ActivityStarter.java index b3786212ea720..35ccc4347e65a 100644 --- a/services/core/java/com/android/server/wm/ActivityStarter.java +++ b/services/core/java/com/android/server/wm/ActivityStarter.java @@ -1481,9 +1481,10 @@ class ActivityStarter { // anyone interested in this piece of information. final ActivityStack homeStack = targetTask.getDisplayArea().getRootHomeTask(); final boolean homeTaskVisible = homeStack != null && homeStack.shouldBeVisible(null); + final ActivityRecord top = targetTask.getTopNonFinishingActivity(); + final boolean visible = top != null && top.isVisible(); mService.getTaskChangeNotificationController().notifyActivityRestartAttempt( - targetTask.getTaskInfo(), homeTaskVisible, clearedTask, - targetTask.getTopNonFinishingActivity().isVisible()); + targetTask.getTaskInfo(), homeTaskVisible, clearedTask, visible); } } From 3ac4e62a75760b000cf243dd7d123decc70284da Mon Sep 17 00:00:00 2001 From: Charles Chen Date: Mon, 28 Sep 2020 02:57:01 +0000 Subject: [PATCH 11/11] Revert "Require permission to create trusted displays" This reverts commit f21c885ca7e86f77c808ab17fe1de650474de487. Reason for revert: Have regression b/168268396. Needs to pull out from Nov. builds. Bug: 162627132 Change-Id: I29fa3937d1655a0cc7591abcfa2067f4fb2b2bcb (cherry picked from commit ac67bee2165e7762f969258d1c39445229d1068d) --- core/java/android/app/ActivityView.java | 15 ++------------- .../window/VirtualDisplayTaskEmbedder.java | 9 +-------- core/tests/coretests/AndroidManifest.xml | 1 - .../hardware/display/VirtualDisplayTest.java | 19 ------------------- .../systemui/bubbles/BubbleExpandedView.java | 2 +- .../server/display/DisplayManagerService.java | 15 ++++----------- 6 files changed, 8 insertions(+), 53 deletions(-) diff --git a/core/java/android/app/ActivityView.java b/core/java/android/app/ActivityView.java index 3cb6293f07066..98a23f2b00750 100644 --- a/core/java/android/app/ActivityView.java +++ b/core/java/android/app/ActivityView.java @@ -105,8 +105,7 @@ public class ActivityView extends ViewGroup implements android.window.TaskEmbedd public ActivityView( @NonNull Context context, @NonNull AttributeSet attrs, int defStyle, boolean singleTaskInstance, boolean usePublicVirtualDisplay) { - this(context, attrs, defStyle, singleTaskInstance, usePublicVirtualDisplay, - false /* disableSurfaceViewBackgroundLayer */); + this(context, attrs, defStyle, singleTaskInstance, usePublicVirtualDisplay, false); } /** @hide */ @@ -114,22 +113,12 @@ public class ActivityView extends ViewGroup implements android.window.TaskEmbedd @NonNull Context context, @NonNull AttributeSet attrs, int defStyle, boolean singleTaskInstance, boolean usePublicVirtualDisplay, boolean disableSurfaceViewBackgroundLayer) { - this(context, attrs, defStyle, singleTaskInstance, usePublicVirtualDisplay, - disableSurfaceViewBackgroundLayer, false /* useTrustedDisplay */); - } - - // TODO(b/162901735): Refactor ActivityView with Builder - /** @hide */ - public ActivityView( - @NonNull Context context, @NonNull AttributeSet attrs, int defStyle, - boolean singleTaskInstance, boolean usePublicVirtualDisplay, - boolean disableSurfaceViewBackgroundLayer, boolean useTrustedDisplay) { super(context, attrs, defStyle); if (useTaskOrganizer()) { mTaskEmbedder = new TaskOrganizerTaskEmbedder(context, this); } else { mTaskEmbedder = new VirtualDisplayTaskEmbedder(context, this, singleTaskInstance, - usePublicVirtualDisplay, useTrustedDisplay); + usePublicVirtualDisplay); } mSurfaceView = new SurfaceView(context, null, 0, 0, disableSurfaceViewBackgroundLayer); // Since ActivityView#getAlpha has been overridden, we should use parent class's alpha diff --git a/core/java/android/window/VirtualDisplayTaskEmbedder.java b/core/java/android/window/VirtualDisplayTaskEmbedder.java index 9013da36007e4..9ccb4c172158d 100644 --- a/core/java/android/window/VirtualDisplayTaskEmbedder.java +++ b/core/java/android/window/VirtualDisplayTaskEmbedder.java @@ -19,7 +19,6 @@ package android.window; import static android.hardware.display.DisplayManager.VIRTUAL_DISPLAY_FLAG_DESTROY_CONTENT_ON_REMOVAL; import static android.hardware.display.DisplayManager.VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY; import static android.hardware.display.DisplayManager.VIRTUAL_DISPLAY_FLAG_PUBLIC; -import static android.hardware.display.DisplayManager.VIRTUAL_DISPLAY_FLAG_TRUSTED; import static android.view.Display.INVALID_DISPLAY; import android.app.ActivityManager; @@ -64,7 +63,6 @@ public class VirtualDisplayTaskEmbedder extends TaskEmbedder { private int mDisplayDensityDpi; private final boolean mSingleTaskInstance; private final boolean mUsePublicVirtualDisplay; - private final boolean mUseTrustedDisplay; private VirtualDisplay mVirtualDisplay; private Insets mForwardedInsets; private DisplayMetrics mTmpDisplayMetrics; @@ -79,12 +77,10 @@ public class VirtualDisplayTaskEmbedder extends TaskEmbedder { * only applicable if virtual displays are used */ public VirtualDisplayTaskEmbedder(Context context, VirtualDisplayTaskEmbedder.Host host, - boolean singleTaskInstance, boolean usePublicVirtualDisplay, - boolean useTrustedDisplay) { + boolean singleTaskInstance, boolean usePublicVirtualDisplay) { super(context, host); mSingleTaskInstance = singleTaskInstance; mUsePublicVirtualDisplay = usePublicVirtualDisplay; - mUseTrustedDisplay = useTrustedDisplay; } /** @@ -107,9 +103,6 @@ public class VirtualDisplayTaskEmbedder extends TaskEmbedder { if (mUsePublicVirtualDisplay) { virtualDisplayFlags |= VIRTUAL_DISPLAY_FLAG_PUBLIC; } - if (mUseTrustedDisplay) { - virtualDisplayFlags |= VIRTUAL_DISPLAY_FLAG_TRUSTED; - } mVirtualDisplay = displayManager.createVirtualDisplay( DISPLAY_NAME + "@" + System.identityHashCode(this), mHost.getWidth(), diff --git a/core/tests/coretests/AndroidManifest.xml b/core/tests/coretests/AndroidManifest.xml index 7597e87321530..5c2841aff1d83 100644 --- a/core/tests/coretests/AndroidManifest.xml +++ b/core/tests/coretests/AndroidManifest.xml @@ -129,7 +129,6 @@ - diff --git a/core/tests/coretests/src/android/hardware/display/VirtualDisplayTest.java b/core/tests/coretests/src/android/hardware/display/VirtualDisplayTest.java index 0f6284d22d106..daf613976358e 100644 --- a/core/tests/coretests/src/android/hardware/display/VirtualDisplayTest.java +++ b/core/tests/coretests/src/android/hardware/display/VirtualDisplayTest.java @@ -247,25 +247,6 @@ public class VirtualDisplayTest extends AndroidTestCase { assertDisplayUnregistered(display); } - /** - * Ensures that an application can create a trusted virtual display with the permission - * {@code ADD_TRUSTED_DISPLAY}. - */ - public void testTrustedVirtualDisplay() throws Exception { - VirtualDisplay virtualDisplay = mDisplayManager.createVirtualDisplay(NAME, - WIDTH, HEIGHT, DENSITY, mSurface, - DisplayManager.VIRTUAL_DISPLAY_FLAG_TRUSTED); - assertNotNull("virtual display must not be null", virtualDisplay); - - Display display = virtualDisplay.getDisplay(); - try { - assertDisplayRegistered(display, Display.FLAG_PRIVATE | Display.FLAG_TRUSTED); - } finally { - virtualDisplay.release(); - } - assertDisplayUnregistered(display); - } - private void assertDisplayRegistered(Display display, int flags) { assertNotNull("display object must not be null", display); assertTrue("display must be valid", display.isValid()); diff --git a/packages/SystemUI/src/com/android/systemui/bubbles/BubbleExpandedView.java b/packages/SystemUI/src/com/android/systemui/bubbles/BubbleExpandedView.java index 110a5ab67f0d8..3d3171208b150 100644 --- a/packages/SystemUI/src/com/android/systemui/bubbles/BubbleExpandedView.java +++ b/packages/SystemUI/src/com/android/systemui/bubbles/BubbleExpandedView.java @@ -301,7 +301,7 @@ public class BubbleExpandedView extends LinearLayout { mActivityView = new ActivityView(mContext, null /* attrs */, 0 /* defStyle */, true /* singleTaskInstance */, false /* usePublicVirtualDisplay*/, - true /* disableSurfaceViewBackgroundLayer */, true /* useTrustedDisplay */); + true /* disableSurfaceViewBackgroundLayer */); // Set ActivityView's alpha value as zero, since there is no view content to be shown. setContentVisibility(false); diff --git a/services/core/java/com/android/server/display/DisplayManagerService.java b/services/core/java/com/android/server/display/DisplayManagerService.java index 9a8be287690fd..1058000e0b68f 100644 --- a/services/core/java/com/android/server/display/DisplayManagerService.java +++ b/services/core/java/com/android/server/display/DisplayManagerService.java @@ -86,7 +86,6 @@ import android.os.UserHandle; import android.os.UserManager; import android.provider.Settings; import android.text.TextUtils; -import android.util.EventLog; import android.util.IntArray; import android.util.Pair; import android.util.Slog; @@ -2192,16 +2191,10 @@ public final class DisplayManagerService extends SystemService { } } - if (callingUid != Process.SYSTEM_UID && (flags & VIRTUAL_DISPLAY_FLAG_TRUSTED) != 0) { - if (!checkCallingPermission(ADD_TRUSTED_DISPLAY, "createVirtualDisplay()")) { - EventLog.writeEvent(0x534e4554, "162627132", callingUid, - "Attempt to create a trusted display without holding permission!"); - throw new SecurityException("Requires ADD_TRUSTED_DISPLAY permission to " - + "create a trusted virtual display."); - } - } - - if ((flags & VIRTUAL_DISPLAY_FLAG_TRUSTED) == 0) { + if (callingUid == Process.SYSTEM_UID + || checkCallingPermission(ADD_TRUSTED_DISPLAY, "createVirtualDisplay()")) { + flags |= VIRTUAL_DISPLAY_FLAG_TRUSTED; + } else { flags &= ~VIRTUAL_DISPLAY_FLAG_SHOULD_SHOW_SYSTEM_DECORATIONS; }