From a9262a0be46091ad6e2073945d39070ffb6a722b Mon Sep 17 00:00:00 2001 From: shafik Date: Tue, 30 Jun 2020 21:29:10 +0100 Subject: [PATCH 1/8] Always kill app when M_E_S is denied StorageManagerService gets notified that MANAGE_EXTERNAL_STORAGE was denied from AppOpsService#setUidMode, which means that we can't get the package name. However, SMS only kills the app if it has the package name. This is unnecessary since we use ActivityManager#killUid. This change removes the conditions that package name should be provided in order for SMS to kill the app. Test: manual - check bug Fix: 160253075 Change-Id: I0a411cf5224714c09744ffd3ade14267024efb67 --- .../com/android/server/StorageManagerService.java | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/services/core/java/com/android/server/StorageManagerService.java b/services/core/java/com/android/server/StorageManagerService.java index 6e8eca3f46cf1..678387c540edc 100644 --- a/services/core/java/com/android/server/StorageManagerService.java +++ b/services/core/java/com/android/server/StorageManagerService.java @@ -4736,7 +4736,7 @@ class StorageManagerService extends IStorageManager.Stub return true; } - private void killAppForOpChange(int code, int uid, String packageName) { + private void killAppForOpChange(int code, int uid) { final IActivityManager am = ActivityManager.getService(); try { am.killUid(UserHandle.getAppId(uid), UserHandle.USER_ALL, @@ -4753,7 +4753,7 @@ class StorageManagerService extends IStorageManager.Stub switch(code) { case OP_REQUEST_INSTALL_PACKAGES: // Always kill regardless of op change, to remount apps /storage - killAppForOpChange(code, uid, packageName); + killAppForOpChange(code, uid); return; case OP_MANAGE_EXTERNAL_STORAGE: if (mode != MODE_ALLOWED) { @@ -4762,12 +4762,7 @@ class StorageManagerService extends IStorageManager.Stub // results in a bad UX, especially since the gid only gives access // to unreliable volumes, USB OTGs that are rarely mounted. The app // will get the external_storage gid on next organic restart. - if (packageName != null) { - killAppForOpChange(code, uid, packageName); - } else { - // TODO(b/158283222) this can happen, figure out if we need - // to kill in this case as well. - } + killAppForOpChange(code, uid); } return; case OP_LEGACY_STORAGE: From e44b5a2641a76835f1dc62bb9ca5c3292480ce9b Mon Sep 17 00:00:00 2001 From: Kyunglyul Hyun Date: Wed, 1 Jul 2020 11:57:27 +0900 Subject: [PATCH 2/8] Add FEATURE_REMOTE_GROUP_PLAYBACK Can be used to distinguish a group route from single device routes Bug: 160113560 Test: N/A Change-Id: Id65aded4ce396bbfaec7040fc2227b769f8c5794 --- media/java/android/media/MediaRoute2Info.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/media/java/android/media/MediaRoute2Info.java b/media/java/android/media/MediaRoute2Info.java index fad25e071f90b..7e9d2d809fddf 100644 --- a/media/java/android/media/MediaRoute2Info.java +++ b/media/java/android/media/MediaRoute2Info.java @@ -313,6 +313,14 @@ public final class MediaRoute2Info implements Parcelable { public static final String FEATURE_REMOTE_VIDEO_PLAYBACK = "android.media.route.feature.REMOTE_VIDEO_PLAYBACK"; + /** + * Route feature: Remote group playback. + *

+ * @hide + */ + public static final String FEATURE_REMOTE_GROUP_PLAYBACK = + "android.media.route.feature.REMOTE_GROUP_PLAYBACK"; + final String mId; final CharSequence mName; final List mFeatures; From 9661a45db0b81af56fc7773ce40c8a9f2892ab50 Mon Sep 17 00:00:00 2001 From: Jaewan Kim Date: Tue, 30 Jun 2020 14:58:43 +0900 Subject: [PATCH 3/8] Exclude MediaSession2 from the media button session This prevents unexpected Session2Token change notification when the MediaSession2 token is selected as media button session. Bug: 160136629 Test: Run CTS Change-Id: I68650564fbbdaf3f3e85d41f3989cc8b08c36322 --- .../java/com/android/server/media/MediaSessionService.java | 2 +- .../core/java/com/android/server/media/MediaSessionStack.java | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/services/core/java/com/android/server/media/MediaSessionService.java b/services/core/java/com/android/server/media/MediaSessionService.java index 242132c8e5ff4..dc86163ae1311 100644 --- a/services/core/java/com/android/server/media/MediaSessionService.java +++ b/services/core/java/com/android/server/media/MediaSessionService.java @@ -2096,7 +2096,7 @@ public class MediaSessionService extends SystemService implements Monitor { boolean asSystemService, KeyEvent keyEvent, boolean needWakeLock) { if (mCurrentFullUserRecord.getMediaButtonSessionLocked() instanceof MediaSession2Record) { - // TODO(jaewan): Implement + // TODO(jaewan): Make MediaSession2 to receive media key event return; } MediaSessionRecord session = null; diff --git a/services/core/java/com/android/server/media/MediaSessionStack.java b/services/core/java/com/android/server/media/MediaSessionStack.java index 402355a0161ac..b678c8962a219 100644 --- a/services/core/java/com/android/server/media/MediaSessionStack.java +++ b/services/core/java/com/android/server/media/MediaSessionStack.java @@ -244,6 +244,10 @@ class MediaSessionStack { private MediaSessionRecordImpl findMediaButtonSession(int uid) { MediaSessionRecordImpl mediaButtonSession = null; for (MediaSessionRecordImpl session : mSessions) { + if (session instanceof MediaSession2Record) { + // TODO(jaewan): Make MediaSession2 to receive media key event + continue; + } if (uid == session.getUid()) { if (session.checkPlaybackActiveState( mAudioPlayerStateMonitor.isPlaybackActive(session.getUid()))) { From 97c1b4a34b35c53f71d95a18985c287b75e905e6 Mon Sep 17 00:00:00 2001 From: Tiger Huang Date: Thu, 2 Jul 2020 01:44:39 +0800 Subject: [PATCH 4/8] Apply the requested insets sources if possible If the client doesn't change the insets, we use the dispatched source. In this way, the task snapshot can have the same insets as the client. Fix: 152931762 Test: atest TaskSnapshotControllerTest Change-Id: Ib0315ce0a8ab32e1c653eeed725fecccb54b3aa8 --- .../android/server/wm/TaskSnapshotController.java | 14 +++++++++++++- .../com/android/server/wm/TaskSnapshotSurface.java | 5 ++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/services/core/java/com/android/server/wm/TaskSnapshotController.java b/services/core/java/com/android/server/wm/TaskSnapshotController.java index 51cf858715b4d..c2021303c11c2 100644 --- a/services/core/java/com/android/server/wm/TaskSnapshotController.java +++ b/services/core/java/com/android/server/wm/TaskSnapshotController.java @@ -40,6 +40,7 @@ import android.util.ArraySet; import android.util.Slog; import android.view.InsetsSource; import android.view.InsetsState; +import android.view.InsetsState.InternalInsetsType; import android.view.SurfaceControl; import android.view.ThreadedRenderer; import android.view.WindowInsets; @@ -480,7 +481,9 @@ class TaskSnapshotController { task.getTaskDescription().getBackgroundColor(), 255); final LayoutParams attrs = mainWindow.getAttrs(); final InsetsPolicy insetsPolicy = mainWindow.getDisplayContent().getInsetsPolicy(); - final InsetsState insetsState = insetsPolicy.getInsetsForDispatch(mainWindow); + final InsetsState insetsState = + new InsetsState(insetsPolicy.getInsetsForDispatch(mainWindow)); + mergeInsetsSources(insetsState, mainWindow.getRequestedInsetsState()); final Rect systemBarInsets = getSystemBarInsets(mainWindow.getFrameLw(), insetsState); final SystemBarBackgroundPainter decorPainter = new SystemBarBackgroundPainter(attrs.flags, attrs.privateFlags, attrs.systemUiVisibility, task.getTaskDescription(), @@ -600,6 +603,15 @@ class TaskSnapshotController { return 0; } + static void mergeInsetsSources(InsetsState base, InsetsState other) { + for (@InternalInsetsType int type = 0; type < InsetsState.SIZE; type++) { + final InsetsSource source = other.peekSource(type); + if (source != null) { + base.addSource(source); + } + } + } + static Rect getSystemBarInsets(Rect frame, InsetsState state) { return state.calculateInsets(frame, null /* ignoringVisibilityState */, false /* isScreenRound */, false /* alwaysConsumeSystemBars */, diff --git a/services/core/java/com/android/server/wm/TaskSnapshotSurface.java b/services/core/java/com/android/server/wm/TaskSnapshotSurface.java index 3fc09c93550cf..448b4aae7a88b 100644 --- a/services/core/java/com/android/server/wm/TaskSnapshotSurface.java +++ b/services/core/java/com/android/server/wm/TaskSnapshotSurface.java @@ -42,6 +42,7 @@ import static com.android.internal.policy.DecorView.STATUS_BAR_COLOR_VIEW_ATTRIB import static com.android.internal.policy.DecorView.getNavigationBarRect; import static com.android.server.wm.ProtoLogGroup.WM_DEBUG_STARTING_WINDOW; import static com.android.server.wm.TaskSnapshotController.getSystemBarInsets; +import static com.android.server.wm.TaskSnapshotController.mergeInsetsSources; import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME; import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM; @@ -243,7 +244,9 @@ class TaskSnapshotSurface implements StartingSurface { final InsetsPolicy insetsPolicy = topFullscreenOpaqueWindow.getDisplayContent() .getInsetsPolicy(); - insetsState = insetsPolicy.getInsetsForDispatch(topFullscreenOpaqueWindow); + insetsState = + new InsetsState(insetsPolicy.getInsetsForDispatch(topFullscreenOpaqueWindow)); + mergeInsetsSources(insetsState, topFullscreenOpaqueWindow.getRequestedInsetsState()); } try { final int res = session.addToDisplay(window, window.mSeq, layoutParams, From 5a6696991ff34606aab2a327eb782cae45076682 Mon Sep 17 00:00:00 2001 From: Jaewan Kim Date: Sat, 27 Jun 2020 04:37:46 +0900 Subject: [PATCH 5/8] Fix flaky media key event related CTS tests Media key events had been incorrectly dispatched to the MediaSession2, which is closed from the app side, but MediaSessionService didn't get the notification for it. It may happen if MediaController2 from the MediaSession2 was connecting and also MediaSession2 was closing. This fix ensures that closing session is always propagated to the controller in onConnect(). Test: Run following tests 10 times (previously flaky ~50%) $ atest CtsMediaTestCases:android.media.cts.MediaSessionTest Bug: 159865360 Change-Id: If16f8c665214614961f28f9406225af19fdad1a8 --- apex/media/framework/java/android/media/MediaSession2.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apex/media/framework/java/android/media/MediaSession2.java b/apex/media/framework/java/android/media/MediaSession2.java index 081e76ab0215e..6560afedab0fa 100644 --- a/apex/media/framework/java/android/media/MediaSession2.java +++ b/apex/media/framework/java/android/media/MediaSession2.java @@ -404,7 +404,7 @@ public class MediaSession2 implements AutoCloseable { mCallback.onPostConnect(MediaSession2.this, controllerInfo); connected = true; } finally { - if (!connected) { + if (!connected || isClosed()) { if (DEBUG) { Log.d(TAG, "Rejecting connection or notifying that session is closed" + ", controllerInfo=" + controllerInfo); From 69947c067109b6c9b92a2bdd792e5a74d598611a Mon Sep 17 00:00:00 2001 From: Adrian Roos Date: Wed, 1 Jul 2020 16:23:05 +0200 Subject: [PATCH 6/8] Revert new logic around FLAG_ALT_FOCUSABLE_IM This broke several apps because it means certain NON_FOCUSABLE windows are now layered wrong w.r.t the IME, and also no longer get IME insets. Originally, this was introduced because the IME target was used to compute which window gets control, but this is now computed based on the window actually connecting to the IME as reported per IMMS. Reverts I941571c97145d77b0a59d030cf2a8c8318f3b59f. Bug: 143898978 Bug: 140641950 Bug: 145812508 Bug: 141738570 Bug: 144619551 Fixes: 159438771 Test: atest WindowStateTests atest FocusHandlingTest atest WindowManager_LayoutParamsTest Also manually using steps: 1. Launch gmail compose activity 2. start typing in receipient field 3. verify that even thoug the suggestions popup window w/ FLAG_NOT_FOCUSABLE becomes the IME target, control and insets still work. Change-Id: If451276b1a8c485ec88965d8d30ec8fd3836620f --- core/java/android/view/WindowManager.java | 28 +++++++++++++------ .../com/android/server/wm/WindowState.java | 21 ++++++-------- .../android/server/wm/WindowStateTests.java | 18 ++---------- 3 files changed, 31 insertions(+), 36 deletions(-) diff --git a/core/java/android/view/WindowManager.java b/core/java/android/view/WindowManager.java index 76071278edf83..5c6269421a1f6 100644 --- a/core/java/android/view/WindowManager.java +++ b/core/java/android/view/WindowManager.java @@ -1454,11 +1454,22 @@ public interface WindowManager extends ViewManager { @Deprecated public static final int FLAG_LAYOUT_INSET_DECOR = 0x00010000; - /** Window flag: When set, input method can't interact with the focusable window - * and can be placed to use more space and cover the input method. - * Note: When combined with {@link #FLAG_NOT_FOCUSABLE}, this flag has no - * effect since input method cannot interact with windows having {@link #FLAG_NOT_FOCUSABLE} - * flag set. + /** Window flag: when set, inverts the input method focusability of the window. + * + * The effect of setting this flag depends on whether {@link #FLAG_NOT_FOCUSABLE} is set: + *

+ * If {@link #FLAG_NOT_FOCUSABLE} is not set, i.e. when the window is focusable, + * setting this flag prevents this window from becoming the target of the input method. + * Consequently, it will not be able to interact with the input method, + * and will be layered above the input method (unless there is another input method + * target above it). + * + *

+ * If {@link #FLAG_NOT_FOCUSABLE} is set, setting this flag requests for the window + * to be the input method target even though the window is not focusable. + * Consequently, it will be layered below the input method. + * Note: Windows that set {@link #FLAG_NOT_FOCUSABLE} cannot interact with the input method, + * regardless of this flag. */ public static final int FLAG_ALT_FOCUSABLE_IM = 0x00020000; @@ -2142,13 +2153,12 @@ public interface WindowManager extends ViewManager { * focus. In particular, this checks the * {@link #FLAG_NOT_FOCUSABLE} and {@link #FLAG_ALT_FOCUSABLE_IM} * flags and returns true if the combination of the two corresponds - * to a window that needs to be behind the input method so that the - * user can type into it. + * to a window that can use the input method. * * @param flags The current window manager flags. * - * @return Returns {@code true} if such a window should be behind/interact - * with an input method, {@code false} if not. + * @return Returns {@code true} if a window with the given flags would be able to + * use the input method, {@code false} if not. */ public static boolean mayUseInputMethod(int flags) { return (flags & FLAG_NOT_FOCUSABLE) != FLAG_NOT_FOCUSABLE diff --git a/services/core/java/com/android/server/wm/WindowState.java b/services/core/java/com/android/server/wm/WindowState.java index d4d2f4d7a4920..b65020d7eaa66 100644 --- a/services/core/java/com/android/server/wm/WindowState.java +++ b/services/core/java/com/android/server/wm/WindowState.java @@ -2394,12 +2394,15 @@ class WindowState extends WindowContainer implements WindowManagerP if (mAttrs.type == TYPE_APPLICATION_STARTING) { // Ignore mayUseInputMethod for starting window for now. // TODO(b/159911356): Remove this special casing (originally added in commit e75d872). - } else if (PixelFormat.formatHasAlpha(mAttrs.format)) { - // Support legacy use cases where transparent windows can still be ime target with - // FLAG_NOT_FOCUSABLE and ALT_FOCUSABLE_IM set. - // Certain apps listen for IME insets using transparent windows and ADJUST_NOTHING to - // manually synchronize app content to IME animation b/144619551. - // TODO(b/145812508): remove this once new focus management is complete b/141738570 + } else { + // TODO(b/145812508): Clean this up in S, may depend on b/141738570 + // The current logic lets windows become the "ime target" even though they are + // not-focusable and can thus never actually start input. + // Ideally, this would reject windows where mayUseInputMethod() == false, but this + // also impacts Z-ordering of and delivery of IME insets to child windows, which means + // that simply disallowing non-focusable windows would break apps. + // See b/159438771, b/144619551. + final int fl = mAttrs.flags & (FLAG_NOT_FOCUSABLE | FLAG_ALT_FOCUSABLE_IM); // Can only be an IME target if both FLAG_NOT_FOCUSABLE and FLAG_ALT_FOCUSABLE_IM are @@ -2407,12 +2410,6 @@ class WindowState extends WindowContainer implements WindowManagerP if (fl != 0 && fl != (FLAG_NOT_FOCUSABLE | FLAG_ALT_FOCUSABLE_IM)) { return false; } - } else if (!WindowManager.LayoutParams.mayUseInputMethod(mAttrs.flags)) { - // Can be an IME target only if: - // 1. FLAG_NOT_FOCUSABLE is not set - // 2. FLAG_ALT_FOCUSABLE_IM is not set - // 3. not a starting window. - return false; } if (DEBUG_INPUT_METHOD) { diff --git a/services/tests/wmtests/src/com/android/server/wm/WindowStateTests.java b/services/tests/wmtests/src/com/android/server/wm/WindowStateTests.java index 4a0f48cf2ccb9..360d73b5bd872 100644 --- a/services/tests/wmtests/src/com/android/server/wm/WindowStateTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/WindowStateTests.java @@ -67,7 +67,6 @@ import static org.mockito.Mockito.when; import android.graphics.Insets; import android.graphics.Matrix; -import android.graphics.PixelFormat; import android.graphics.Rect; import android.os.RemoteException; import android.platform.test.annotations.Presubmit; @@ -229,22 +228,11 @@ public class WindowStateTests extends WindowTestsBase { appWindow.mAttrs.flags |= (FLAG_NOT_FOCUSABLE | FLAG_ALT_FOCUSABLE_IM); imeWindow.mAttrs.flags |= (FLAG_NOT_FOCUSABLE | FLAG_ALT_FOCUSABLE_IM); - // Visible app window with flags FLAG_NOT_FOCUSABLE or FLAG_ALT_FOCUSABLE_IM can't be IME - // target while an IME window can never be an IME target regardless of its visibility - // or flags. - assertFalse(appWindow.canBeImeTarget()); + // Visible app window with flags can be IME target while an IME window can never be an IME + // target regardless of its visibility or flags. + assertTrue(appWindow.canBeImeTarget()); assertFalse(imeWindow.canBeImeTarget()); - // b/145812508: special legacy use-case for transparent/translucent windows. - appWindow.mAttrs.format = PixelFormat.TRANSPARENT; - assertTrue(appWindow.canBeImeTarget()); - - appWindow.mAttrs.format = PixelFormat.OPAQUE; - appWindow.mAttrs.flags &= ~FLAG_ALT_FOCUSABLE_IM; - assertFalse(appWindow.canBeImeTarget()); - appWindow.mAttrs.flags &= ~FLAG_NOT_FOCUSABLE; - assertTrue(appWindow.canBeImeTarget()); - // Verify PINNED windows can't be IME target. int initialMode = appWindow.mActivityRecord.getWindowingMode(); appWindow.mActivityRecord.setWindowingMode(WINDOWING_MODE_PINNED); From a2127eb4468e2e9c6796fc94859c0ee976c0dd5a Mon Sep 17 00:00:00 2001 From: Sahana Rao Date: Thu, 2 Jul 2020 12:23:13 +0000 Subject: [PATCH 7/8] [DO NOT MERGE]Revert "Flip ENABLE_DYNAMIC_PERMISSIONS, attempt #6." This reverts commit 5dad7cd45efef5d40a9fde9466c1fe946a2acc04. Reason for revert: b/159995598 Bug: 159995598, 115619667 Change-Id: I6df037161dc36da7f8b33292529bbc37058f819c --- .../java/com/android/server/uri/UriGrantsManagerService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/core/java/com/android/server/uri/UriGrantsManagerService.java b/services/core/java/com/android/server/uri/UriGrantsManagerService.java index 5f6323369d0a5..c38d649ada9bd 100644 --- a/services/core/java/com/android/server/uri/UriGrantsManagerService.java +++ b/services/core/java/com/android/server/uri/UriGrantsManagerService.java @@ -115,7 +115,7 @@ public class UriGrantsManagerService extends IUriGrantsManager.Stub { private static final String TAG = "UriGrantsManagerService"; // Maximum number of persisted Uri grants a package is allowed private static final int MAX_PERSISTED_URI_GRANTS = 128; - private static final boolean ENABLE_DYNAMIC_PERMISSIONS = true; + private static final boolean ENABLE_DYNAMIC_PERMISSIONS = false; private final Object mLock = new Object(); private final H mH; From d346b43c1fff4b74a42258f3591812d26030c7f2 Mon Sep 17 00:00:00 2001 From: Anton Hansson Date: Thu, 2 Jul 2020 16:41:45 +0100 Subject: [PATCH 8/8] Make module stubs publicly visible Previously they were limited to frameworks/base so that they could be combined into the "main" android stubs. However, limiting their visibility is inflexible and unnecessary, and due to limitations in the build system also makes it impossible to create rules for prebuilts of these module stubs that set `prefer: false`. This CL makes it possible to disable the prebuilts, which multiple downstream branches would like to do. Bug: 159902351 Test: m nothing (with prefer: false on prebuilts) Change-Id: Id0eee4bf4e78f5dfddf6ad569e49719fefde658e --- apex/Android.bp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/apex/Android.bp b/apex/Android.bp index 371bd7fc94799..992648b04ef04 100644 --- a/apex/Android.bp +++ b/apex/Android.bp @@ -94,10 +94,8 @@ java_defaults { annotations_enabled: true, - // The stub libraries must be visible to frameworks/base so they can be combined - // into API specific libraries. stubs_library_visibility: [ - "//frameworks/base", // Framework + "//visibility:public", ], // Set the visibility of the modules creating the stubs source.