Merge "Keep ControlsActivity on orientation change" into tm-qpr-dev am: 430344861c
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/21958652 Change-Id: I3222670be809100a47c2ec18bde5e84290af6224 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -878,7 +878,7 @@
|
|||||||
android:showForAllUsers="true"
|
android:showForAllUsers="true"
|
||||||
android:finishOnTaskLaunch="true"
|
android:finishOnTaskLaunch="true"
|
||||||
android:launchMode="singleInstance"
|
android:launchMode="singleInstance"
|
||||||
android:configChanges="screenSize|smallestScreenSize|screenLayout|keyboard|keyboardHidden"
|
android:configChanges="screenLayout|keyboard|keyboardHidden|orientation"
|
||||||
android:visibleToInstantApps="true">
|
android:visibleToInstantApps="true">
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
|
|||||||
@@ -20,6 +20,8 @@ import android.content.BroadcastReceiver
|
|||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.IntentFilter
|
import android.content.IntentFilter
|
||||||
|
import android.content.pm.ActivityInfo
|
||||||
|
import android.content.res.Configuration
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.os.RemoteException
|
import android.os.RemoteException
|
||||||
import android.service.dreams.IDreamManager
|
import android.service.dreams.IDreamManager
|
||||||
@@ -57,9 +59,11 @@ class ControlsActivity @Inject constructor(
|
|||||||
private lateinit var parent: ViewGroup
|
private lateinit var parent: ViewGroup
|
||||||
private lateinit var broadcastReceiver: BroadcastReceiver
|
private lateinit var broadcastReceiver: BroadcastReceiver
|
||||||
private var mExitToDream: Boolean = false
|
private var mExitToDream: Boolean = false
|
||||||
|
private lateinit var lastConfiguration: Configuration
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
lastConfiguration = resources.configuration
|
||||||
if (featureFlags.isEnabled(Flags.USE_APP_PANELS)) {
|
if (featureFlags.isEnabled(Flags.USE_APP_PANELS)) {
|
||||||
window.addPrivateFlags(WindowManager.LayoutParams.PRIVATE_FLAG_TRUSTED_OVERLAY)
|
window.addPrivateFlags(WindowManager.LayoutParams.PRIVATE_FLAG_TRUSTED_OVERLAY)
|
||||||
}
|
}
|
||||||
@@ -92,6 +96,14 @@ class ControlsActivity @Inject constructor(
|
|||||||
initBroadcastReceiver()
|
initBroadcastReceiver()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onConfigurationChanged(newConfig: Configuration) {
|
||||||
|
super.onConfigurationChanged(newConfig)
|
||||||
|
if (lastConfiguration.diff(newConfig) and ActivityInfo.CONFIG_ORIENTATION != 0 ) {
|
||||||
|
uiController.onOrientationChange()
|
||||||
|
}
|
||||||
|
lastConfiguration = newConfig
|
||||||
|
}
|
||||||
|
|
||||||
override fun onStart() {
|
override fun onStart() {
|
||||||
super.onStart()
|
super.onStart()
|
||||||
|
|
||||||
|
|||||||
@@ -64,6 +64,8 @@ interface ControlsUiController {
|
|||||||
* This element will be the one that appears when the user first opens the controls activity.
|
* This element will be the one that appears when the user first opens the controls activity.
|
||||||
*/
|
*/
|
||||||
fun getPreferredSelectedItem(structures: List<StructureInfo>): SelectedItem
|
fun getPreferredSelectedItem(structures: List<StructureInfo>): SelectedItem
|
||||||
|
|
||||||
|
fun onOrientationChange()
|
||||||
}
|
}
|
||||||
|
|
||||||
sealed class SelectedItem {
|
sealed class SelectedItem {
|
||||||
|
|||||||
@@ -124,6 +124,7 @@ class ControlsUiControllerImpl @Inject constructor (
|
|||||||
}
|
}
|
||||||
|
|
||||||
private var selectedItem: SelectedItem = SelectedItem.EMPTY_SELECTION
|
private var selectedItem: SelectedItem = SelectedItem.EMPTY_SELECTION
|
||||||
|
private var selectionItem: SelectionItem? = null
|
||||||
private lateinit var allStructures: List<StructureInfo>
|
private lateinit var allStructures: List<StructureInfo>
|
||||||
private val controlsById = mutableMapOf<ControlKey, ControlWithState>()
|
private val controlsById = mutableMapOf<ControlKey, ControlWithState>()
|
||||||
private val controlViewsById = mutableMapOf<ControlKey, ControlViewHolder>()
|
private val controlViewsById = mutableMapOf<ControlKey, ControlViewHolder>()
|
||||||
@@ -230,6 +231,7 @@ class ControlsUiControllerImpl @Inject constructor (
|
|||||||
this.overflowMenuAdapter = null
|
this.overflowMenuAdapter = null
|
||||||
hidden = false
|
hidden = false
|
||||||
retainCache = false
|
retainCache = false
|
||||||
|
selectionItem = null
|
||||||
|
|
||||||
controlActionCoordinator.activityContext = activityContext
|
controlActionCoordinator.activityContext = activityContext
|
||||||
|
|
||||||
@@ -272,7 +274,7 @@ class ControlsUiControllerImpl @Inject constructor (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun reload(parent: ViewGroup) {
|
private fun reload(parent: ViewGroup, dismissTaskView: Boolean = true) {
|
||||||
if (hidden) return
|
if (hidden) return
|
||||||
|
|
||||||
controlsListingController.get().removeCallback(listingCallback)
|
controlsListingController.get().removeCallback(listingCallback)
|
||||||
@@ -425,6 +427,7 @@ class ControlsUiControllerImpl @Inject constructor (
|
|||||||
} else {
|
} else {
|
||||||
Log.w(ControlsUiController.TAG, "Not TaskViewFactory to display panel $selectionItem")
|
Log.w(ControlsUiController.TAG, "Not TaskViewFactory to display panel $selectionItem")
|
||||||
}
|
}
|
||||||
|
this.selectionItem = selectionItem
|
||||||
|
|
||||||
bgExecutor.execute {
|
bgExecutor.execute {
|
||||||
val intent = Intent(Intent.ACTION_MAIN)
|
val intent = Intent(Intent.ACTION_MAIN)
|
||||||
@@ -657,6 +660,7 @@ class ControlsUiControllerImpl @Inject constructor (
|
|||||||
val maxColumns = ControlAdapter.findMaxColumns(activityContext.resources)
|
val maxColumns = ControlAdapter.findMaxColumns(activityContext.resources)
|
||||||
|
|
||||||
val listView = parent.requireViewById(R.id.global_actions_controls_list) as ViewGroup
|
val listView = parent.requireViewById(R.id.global_actions_controls_list) as ViewGroup
|
||||||
|
listView.removeAllViews()
|
||||||
var lastRow: ViewGroup = createRow(inflater, listView)
|
var lastRow: ViewGroup = createRow(inflater, listView)
|
||||||
selectedStructure.controls.forEach {
|
selectedStructure.controls.forEach {
|
||||||
val key = ControlKey(selectedStructure.componentName, it.controlId)
|
val key = ControlKey(selectedStructure.componentName, it.controlId)
|
||||||
@@ -804,6 +808,15 @@ class ControlsUiControllerImpl @Inject constructor (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onOrientationChange() {
|
||||||
|
selectionItem?.let {
|
||||||
|
when (selectedItem) {
|
||||||
|
is SelectedItem.StructureItem -> createListView(it)
|
||||||
|
is SelectedItem.PanelItem -> taskViewController?.refreshBounds() ?: reload(parent)
|
||||||
|
}
|
||||||
|
} ?: reload(parent)
|
||||||
|
}
|
||||||
|
|
||||||
private fun createRow(inflater: LayoutInflater, listView: ViewGroup): ViewGroup {
|
private fun createRow(inflater: LayoutInflater, listView: ViewGroup): ViewGroup {
|
||||||
val row = inflater.inflate(R.layout.controls_row, listView, false) as ViewGroup
|
val row = inflater.inflate(R.layout.controls_row, listView, false) as ViewGroup
|
||||||
listView.addView(row)
|
listView.addView(row)
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ class PanelTaskViewController(
|
|||||||
private val activityContext: Context,
|
private val activityContext: Context,
|
||||||
private val uiExecutor: Executor,
|
private val uiExecutor: Executor,
|
||||||
private val pendingIntent: PendingIntent,
|
private val pendingIntent: PendingIntent,
|
||||||
private val taskView: TaskView,
|
val taskView: TaskView,
|
||||||
private val hide: () -> Unit = {}
|
private val hide: () -> Unit = {}
|
||||||
) {
|
) {
|
||||||
|
|
||||||
@@ -108,6 +108,10 @@ class PanelTaskViewController(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun refreshBounds() {
|
||||||
|
taskView.onLocationChanged()
|
||||||
|
}
|
||||||
|
|
||||||
fun dismiss() {
|
fun dismiss() {
|
||||||
taskView.release()
|
taskView.release()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -372,6 +372,38 @@ class ControlsUiControllerImplTest : SysuiTestCase() {
|
|||||||
verify(fakeDialogController.dialog).cancel()
|
verify(fakeDialogController.dialog).cancel()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testOnRotationWithPanelUpdateBoundsCalled() {
|
||||||
|
mockLayoutInflater()
|
||||||
|
val packageName = "pkg"
|
||||||
|
`when`(authorizedPanelsRepository.getAuthorizedPanels()).thenReturn(setOf(packageName))
|
||||||
|
val panel = SelectedItem.PanelItem("App name", ComponentName(packageName, "cls"))
|
||||||
|
val serviceInfo = setUpPanel(panel)
|
||||||
|
|
||||||
|
underTest.show(parent, {}, context)
|
||||||
|
|
||||||
|
val captor = argumentCaptor<ControlsListingController.ControlsListingCallback>()
|
||||||
|
|
||||||
|
verify(controlsListingController).addCallback(capture(captor))
|
||||||
|
captor.value.onServicesUpdated(listOf(serviceInfo))
|
||||||
|
FakeExecutor.exhaustExecutors(uiExecutor, bgExecutor)
|
||||||
|
|
||||||
|
val taskViewConsumerCaptor = argumentCaptor<Consumer<TaskView>>()
|
||||||
|
verify(taskViewFactory).create(eq(context), eq(uiExecutor), capture(taskViewConsumerCaptor))
|
||||||
|
|
||||||
|
val taskView: TaskView = mock {
|
||||||
|
`when`(this.post(any())).thenAnswer {
|
||||||
|
uiExecutor.execute(it.arguments[0] as Runnable)
|
||||||
|
true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
taskViewConsumerCaptor.value.accept(taskView)
|
||||||
|
|
||||||
|
underTest.onOrientationChange()
|
||||||
|
verify(taskView).onLocationChanged()
|
||||||
|
}
|
||||||
|
|
||||||
private fun setUpPanel(panel: SelectedItem.PanelItem): ControlsServiceInfo {
|
private fun setUpPanel(panel: SelectedItem.PanelItem): ControlsServiceInfo {
|
||||||
val activity = ComponentName(context, "activity")
|
val activity = ComponentName(context, "activity")
|
||||||
preferredPanelRepository.setSelectedComponent(
|
preferredPanelRepository.setSelectedComponent(
|
||||||
|
|||||||
@@ -152,4 +152,12 @@ class PanelTaskViewControllerTest : SysuiTestCase() {
|
|||||||
listenerCaptor.value.onTaskRemovalStarted(0)
|
listenerCaptor.value.onTaskRemovalStarted(0)
|
||||||
verify(taskView).release()
|
verify(taskView).release()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testOnRefreshBounds() {
|
||||||
|
underTest.launchTaskView()
|
||||||
|
|
||||||
|
underTest.refreshBounds()
|
||||||
|
verify(taskView).onLocationChanged()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user