Merge "Remove stray commas in javadoc" into udc-dev
diff --git a/packages/SettingsLib/res/values/strings.xml b/packages/SettingsLib/res/values/strings.xml
index f581091..dac7f8d 100644
--- a/packages/SettingsLib/res/values/strings.xml
+++ b/packages/SettingsLib/res/values/strings.xml
@@ -1327,6 +1327,12 @@
     <string name="media_transfer_this_device_name" product="default">This phone</string>
     <!-- Name of the tablet device. [CHAR LIMIT=30] -->
     <string name="media_transfer_this_device_name" product="tablet">This tablet</string>
+    <!-- Name of the dock device. [CHAR LIMIT=30] -->
+    <string name="media_transfer_dock_speaker_device_name">Dock speaker</string>
+    <!-- Default name of the external device. [CHAR LIMIT=30] -->
+    <string name="media_transfer_external_device_name">External Device</string>
+    <!-- Default name of the connected device. [CHAR LIMIT=30] -->
+    <string name="media_transfer_default_device_name">Connected device</string>
     <!-- Name of the phone device with an active remote session. [CHAR LIMIT=30] -->
     <string name="media_transfer_this_phone">This phone</string>
     <!-- Sub status indicates device is not available due to an unknown error. [CHAR LIMIT=NONE] -->
diff --git a/packages/SettingsLib/src/com/android/settingslib/media/PhoneMediaDevice.java b/packages/SettingsLib/src/com/android/settingslib/media/PhoneMediaDevice.java
index 1c82be9..34519c9 100644
--- a/packages/SettingsLib/src/com/android/settingslib/media/PhoneMediaDevice.java
+++ b/packages/SettingsLib/src/com/android/settingslib/media/PhoneMediaDevice.java
@@ -70,13 +70,17 @@
                 name = mContext.getString(R.string.media_transfer_wired_usb_device_name);
                 break;
             case TYPE_DOCK:
-            case TYPE_HDMI:
-                name = mRouteInfo.getName();
+                name = mContext.getString(R.string.media_transfer_dock_speaker_device_name);
                 break;
             case TYPE_BUILTIN_SPEAKER:
-            default:
                 name = mContext.getString(R.string.media_transfer_this_device_name);
                 break;
+            case TYPE_HDMI:
+                name = mContext.getString(R.string.media_transfer_external_device_name);
+                break;
+            default:
+                name = mContext.getString(R.string.media_transfer_default_device_name);
+                break;
         }
         return name.toString();
     }
diff --git a/packages/SystemUI/src/com/android/systemui/controls/management/ControlsListingControllerImpl.kt b/packages/SystemUI/src/com/android/systemui/controls/management/ControlsListingControllerImpl.kt
index 8ba060e..1eba667 100644
--- a/packages/SystemUI/src/com/android/systemui/controls/management/ControlsListingControllerImpl.kt
+++ b/packages/SystemUI/src/com/android/systemui/controls/management/ControlsListingControllerImpl.kt
@@ -35,6 +35,7 @@
 import com.android.systemui.flags.FeatureFlags
 import com.android.systemui.flags.Flags
 import com.android.systemui.settings.UserTracker
+import com.android.systemui.util.ActivityTaskManagerProxy
 import com.android.systemui.util.asIndenting
 import com.android.systemui.util.indentIfPossible
 import java.io.PrintWriter
@@ -67,6 +68,7 @@
     @Background private val backgroundExecutor: Executor,
     private val serviceListingBuilder: (Context) -> ServiceListing,
     private val userTracker: UserTracker,
+    private val activityTaskManagerProxy: ActivityTaskManagerProxy,
     dumpManager: DumpManager,
     private val featureFlags: FeatureFlags
 ) : ControlsListingController, Dumpable {
@@ -76,9 +78,18 @@
             context: Context,
             @Background executor: Executor,
             userTracker: UserTracker,
+            activityTaskManagerProxy: ActivityTaskManagerProxy,
             dumpManager: DumpManager,
             featureFlags: FeatureFlags
-    ) : this(context, executor, ::createServiceListing, userTracker, dumpManager, featureFlags)
+    ) : this(
+        context,
+        executor,
+        ::createServiceListing,
+        userTracker,
+        activityTaskManagerProxy,
+        dumpManager,
+        featureFlags
+    )
 
     private var serviceListing = serviceListingBuilder(context)
     // All operations in background thread
@@ -113,7 +124,8 @@
     }
 
     private fun updateServices(newServices: List<ControlsServiceInfo>) {
-        if (featureFlags.isEnabled(Flags.USE_APP_PANELS)) {
+        if (featureFlags.isEnabled(Flags.USE_APP_PANELS) &&
+                activityTaskManagerProxy.supportsMultiWindow(context)) {
             val allowAllApps = featureFlags.isEnabled(Flags.APP_PANELS_ALL_APPS_ALLOWED)
             newServices.forEach {
                 it.resolvePanelActivity(allowAllApps) }
diff --git a/packages/SystemUI/src/com/android/systemui/media/MediaProjectionPermissionActivity.java b/packages/SystemUI/src/com/android/systemui/media/MediaProjectionPermissionActivity.java
index c9c2ea2..f6a2f37 100644
--- a/packages/SystemUI/src/com/android/systemui/media/MediaProjectionPermissionActivity.java
+++ b/packages/SystemUI/src/com/android/systemui/media/MediaProjectionPermissionActivity.java
@@ -29,6 +29,7 @@
 import android.app.Activity;
 import android.app.ActivityManager;
 import android.app.AlertDialog;
+import android.content.Context;
 import android.content.DialogInterface;
 import android.content.Intent;
 import android.content.pm.ApplicationInfo;
@@ -203,14 +204,17 @@
             dialogTitle = getString(R.string.media_projection_dialog_title, appName);
         }
 
+        // Using application context for the dialog, instead of the activity context, so we get
+        // the correct screen width when in split screen.
+        Context dialogContext = getApplicationContext();
         if (isPartialScreenSharingEnabled()) {
-            mDialog = new MediaProjectionPermissionDialog(this, () -> {
+            mDialog = new MediaProjectionPermissionDialog(dialogContext, () -> {
                 ScreenShareOption selectedOption =
                         ((MediaProjectionPermissionDialog) mDialog).getSelectedScreenShareOption();
                 grantMediaProjectionPermission(selectedOption.getMode());
             }, () -> finish(RECORD_CANCEL, /* projection= */ null), appName);
         } else {
-            AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this,
+            AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(dialogContext,
                     R.style.Theme_SystemUI_Dialog)
                     .setTitle(dialogTitle)
                     .setIcon(R.drawable.ic_media_projection_permission)
@@ -263,7 +267,10 @@
         final UserHandle hostUserHandle = getHostUserHandle();
         if (mScreenCaptureDevicePolicyResolver.get()
                 .isScreenCaptureCompletelyDisabled(hostUserHandle)) {
-            AlertDialog dialog = new ScreenCaptureDisabledDialog(this);
+            // Using application context for the dialog, instead of the activity context, so we get
+            // the correct screen width when in split screen.
+            Context dialogContext = getApplicationContext();
+            AlertDialog dialog = new ScreenCaptureDisabledDialog(dialogContext);
             setUpDialog(dialog);
             dialog.show();
             return true;
diff --git a/packages/SystemUI/src/com/android/systemui/util/ActivityTaskManagerProxy.kt b/packages/SystemUI/src/com/android/systemui/util/ActivityTaskManagerProxy.kt
new file mode 100644
index 0000000..6e82cf6
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/util/ActivityTaskManagerProxy.kt
@@ -0,0 +1,30 @@
+/*
+ * Copyright (C) 2023 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.systemui.util
+
+import android.app.ActivityTaskManager
+import android.content.Context
+import com.android.systemui.dagger.SysUISingleton
+import javax.inject.Inject
+
+/** Proxy for static calls to [ActivityTaskManager]. */
+@SysUISingleton
+class ActivityTaskManagerProxy @Inject constructor() {
+
+    /** Calls [ActivityTaskManager.supportsMultiWindow] */
+    fun supportsMultiWindow(context: Context) = ActivityTaskManager.supportsMultiWindow(context)
+}
diff --git a/packages/SystemUI/tests/src/com/android/systemui/controls/management/ControlsListingControllerImplTest.kt b/packages/SystemUI/tests/src/com/android/systemui/controls/management/ControlsListingControllerImplTest.kt
index 10bfc1b..ee213f7 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/controls/management/ControlsListingControllerImplTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/controls/management/ControlsListingControllerImplTest.kt
@@ -39,6 +39,7 @@
 import com.android.systemui.flags.Flags.APP_PANELS_ALL_APPS_ALLOWED
 import com.android.systemui.flags.Flags.USE_APP_PANELS
 import com.android.systemui.settings.UserTracker
+import com.android.systemui.util.ActivityTaskManagerProxy
 import com.android.systemui.util.concurrency.FakeExecutor
 import com.android.systemui.util.mockito.any
 import com.android.systemui.util.mockito.argThat
@@ -88,6 +89,8 @@
     private lateinit var packageManager: PackageManager
     @Mock
     private lateinit var featureFlags: FeatureFlags
+    @Mock
+    private lateinit var activityTaskManagerProxy: ActivityTaskManagerProxy
 
     private var componentName = ComponentName("pkg", "class1")
     private var activityName = ComponentName("pkg", "activity")
@@ -112,6 +115,7 @@
         // Return disabled by default
         `when`(packageManager.getComponentEnabledSetting(any()))
                 .thenReturn(PackageManager.COMPONENT_ENABLED_STATE_DISABLED)
+        `when`(activityTaskManagerProxy.supportsMultiWindow(any())).thenReturn(true)
         mContext.setMockPackageManager(packageManager)
 
         mContext.orCreateTestableResources
@@ -136,6 +140,7 @@
                 executor,
                 { mockSL },
                 userTracker,
+                activityTaskManagerProxy,
                 dumpManager,
                 featureFlags
         )
@@ -171,6 +176,7 @@
                 exec,
                 { mockServiceListing },
                 userTracker,
+                activityTaskManagerProxy,
                 dumpManager,
                 featureFlags
         )
@@ -637,7 +643,34 @@
         assertThat(services[0].serviceInfo.componentName).isEqualTo(componentName)
     }
 
+    @Test
+    fun testNoPanelIfMultiWindowNotSupported() {
+        `when`(activityTaskManagerProxy.supportsMultiWindow(any())).thenReturn(false)
 
+        val serviceInfo = ServiceInfo(
+            componentName,
+            activityName
+        )
+
+        `when`(packageManager.getComponentEnabledSetting(eq(activityName)))
+            .thenReturn(PackageManager.COMPONENT_ENABLED_STATE_DEFAULT)
+
+        setUpQueryResult(listOf(
+            ActivityInfo(
+                activityName,
+                enabled = true,
+                exported = true,
+                permission = Manifest.permission.BIND_CONTROLS
+            )
+        ))
+
+        val list = listOf(serviceInfo)
+        serviceListingCallbackCaptor.value.onServicesReloaded(list)
+
+        executor.runAllReady()
+
+        assertNull(controller.getCurrentServices()[0].panelActivity)
+    }
 
     private fun ServiceInfo(
             componentName: ComponentName,
diff --git a/services/core/java/com/android/server/wm/ActivityTaskManagerService.java b/services/core/java/com/android/server/wm/ActivityTaskManagerService.java
index 4d4ffba..a650d77 100644
--- a/services/core/java/com/android/server/wm/ActivityTaskManagerService.java
+++ b/services/core/java/com/android/server/wm/ActivityTaskManagerService.java
@@ -3560,10 +3560,10 @@
                 mRootWindowContainer.forAllDisplays(displayContent -> {
                     mKeyguardController.keyguardGoingAway(displayContent.getDisplayId(), flags);
                 });
-                WallpaperManagerInternal wallpaperManagerInternal = getWallpaperManagerInternal();
-                if (wallpaperManagerInternal != null) {
-                    wallpaperManagerInternal.onKeyguardGoingAway();
-                }
+            }
+            WallpaperManagerInternal wallpaperManagerInternal = getWallpaperManagerInternal();
+            if (wallpaperManagerInternal != null) {
+                wallpaperManagerInternal.onKeyguardGoingAway();
             }
         } finally {
             Binder.restoreCallingIdentity(token);