Loading packages/SystemUI/src/com/android/systemui/controls/controller/ControlsBindingController.kt +2 −1 Original line number Diff line number Diff line Loading @@ -38,8 +38,9 @@ interface ControlsBindingController : UserAwareController { * * @param component The [ComponentName] of the service to bind * @param callback a callback to return the loaded controls to (or an error). * @return a runnable to cancel the load */ fun bindAndLoad(component: ComponentName, callback: LoadCallback) fun bindAndLoad(component: ComponentName, callback: LoadCallback): Runnable /** * Request to bind to the given service. Loading packages/SystemUI/src/com/android/systemui/controls/controller/ControlsBindingControllerImpl.kt +12 −3 Original line number Diff line number Diff line Loading @@ -116,8 +116,10 @@ open class ControlsBindingControllerImpl @Inject constructor( override fun bindAndLoad( component: ComponentName, callback: ControlsBindingController.LoadCallback ) { retrieveLifecycleManager(component)?.maybeBindAndLoad(LoadSubscriber(callback)) ): Runnable { val subscriber = LoadSubscriber(callback) retrieveLifecycleManager(component)?.maybeBindAndLoad(subscriber) return subscriber.loadCancel() } override fun subscribe(structureInfo: StructureInfo) { Loading Loading @@ -208,7 +210,6 @@ open class ControlsBindingControllerImpl @Inject constructor( ) : CallbackRunnable(token) { override fun doRun() { callback.accept(list) provider?.unbindService() } } Loading Loading @@ -292,8 +293,14 @@ open class ControlsBindingControllerImpl @Inject constructor( ) : IControlsSubscriber.Stub() { val loadedControls = ArrayList<Control>() var hasError = false private var _loadCancelInternal: (() -> Unit)? = null fun loadCancel() = Runnable { Log.d(TAG, "Cancel load requested") _loadCancelInternal?.invoke() } override fun onSubscribe(token: IBinder, subs: IControlsSubscription) { _loadCancelInternal = subs::cancel backgroundExecutor.execute(OnSubscribeRunnable(token, subs)) } Loading @@ -302,10 +309,12 @@ open class ControlsBindingControllerImpl @Inject constructor( } override fun onError(token: IBinder, s: String) { hasError = true _loadCancelInternal = {} backgroundExecutor.execute(OnLoadErrorRunnable(token, s, callback)) } override fun onComplete(token: IBinder) { _loadCancelInternal = {} if (!hasError) { backgroundExecutor.execute(OnLoadRunnable(token, loadedControls, callback)) } Loading packages/SystemUI/src/com/android/systemui/controls/controller/ControlsController.kt +5 −0 Original line number Diff line number Diff line Loading @@ -58,6 +58,11 @@ interface ControlsController : UserAwareController { dataCallback: Consumer<LoadData> ) /** * Cancels a pending load call */ fun cancelLoad() /** * Request to subscribe for favorited controls per structure * Loading packages/SystemUI/src/com/android/systemui/controls/controller/ControlsControllerImpl.kt +14 −5 Original line number Diff line number Diff line Loading @@ -72,6 +72,8 @@ class ControlsControllerImpl @Inject constructor ( private var userChanging: Boolean = true private var loadCanceller: Runnable? = null private var currentUser = UserHandle.of(ActivityManager.getCurrentUser()) override val currentUserId get() = currentUser.identifier Loading Loading @@ -213,8 +215,9 @@ class ControlsControllerImpl @Inject constructor ( if (!confirmAvailability()) { if (userChanging) { // Try again later, userChanging should not last forever. If so, we have bigger // problems executor.executeDelayed( // problems. This will return a runnable that allows to cancel the delayed version, // it will not be able to cancel the load if loadCanceller = executor.executeDelayed( { loadForComponent(componentName, dataCallback) }, USER_CHANGE_RETRY_DELAY, TimeUnit.MILLISECONDS Loading @@ -224,10 +227,11 @@ class ControlsControllerImpl @Inject constructor ( } return } bindingController.bindAndLoad( loadCanceller = bindingController.bindAndLoad( componentName, object : ControlsBindingController.LoadCallback { override fun accept(controls: List<Control>) { loadCanceller = null executor.execute { val favoritesForComponentKeys = Favorites .getControlsForComponent(componentName).map { it.controlId } Loading @@ -251,12 +255,12 @@ class ControlsControllerImpl @Inject constructor ( controlsWithFavorite, favoritesForComponentKeys ) dataCallback.accept(loadData) } } override fun error(message: String) { loadCanceller = null executor.execute { val loadData = Favorites.getControlsForComponent(componentName) .let { controls -> Loading @@ -269,7 +273,6 @@ class ControlsControllerImpl @Inject constructor ( true ) } dataCallback.accept(loadData) } } Loading @@ -277,6 +280,12 @@ class ControlsControllerImpl @Inject constructor ( ) } override fun cancelLoad() { loadCanceller?.let { executor.execute(it) } } private fun createRemovedStatus( componentName: ComponentName, controlInfo: ControlInfo, Loading packages/SystemUI/src/com/android/systemui/controls/management/ControlsFavoritingActivity.kt +15 −8 Original line number Diff line number Diff line Loading @@ -70,6 +70,7 @@ class ControlsFavoritingActivity @Inject constructor( private lateinit var iconFrame: View private lateinit var pageIndicator: ManagementPageIndicator private var mTooltipManager: TooltipManager? = null private lateinit var doneButton: View private var listOfStructures = emptyList<StructureContainer>() private lateinit var comparator: Comparator<StructureContainer> Loading Loading @@ -137,6 +138,7 @@ class ControlsFavoritingActivity @Inject constructor( StructureContainer(it.key, AllModel(it.value, favoriteKeys, emptyZoneString)) }.sortedWith(comparator) executor.execute { doneButton.isEnabled = true structurePager.adapter = StructureAdapter(listOfStructures) if (error) { statusText.text = resources.getText(R.string.controls_favorite_load_error) Loading Loading @@ -180,6 +182,7 @@ class ControlsFavoritingActivity @Inject constructor( layoutResource = R.layout.controls_management_favorites inflate() } statusText = requireViewById(R.id.status_message) if (shouldShowTooltip()) { mTooltipManager = TooltipManager(statusText.context, Loading Loading @@ -248,17 +251,20 @@ class ControlsFavoritingActivity @Inject constructor( } } requireViewById<Button>(R.id.done).setOnClickListener { doneButton = requireViewById<Button>(R.id.done).apply { isEnabled = false setOnClickListener { if (component == null) return@setOnClickListener listOfStructures.forEach { val favoritesForStorage = it.model.favorites.map { it.build() } controller.replaceFavoritesForStructure(StructureInfo(component!!, it.structureName, favoritesForStorage)) controller.replaceFavoritesForStructure( StructureInfo(component!!, it.structureName, favoritesForStorage) ) } finishAffinity() } } } override fun onPause() { super.onPause() Loading @@ -273,6 +279,7 @@ class ControlsFavoritingActivity @Inject constructor( override fun onDestroy() { currentUserTracker.stopTracking() listingController.removeCallback(listingCallback) controller.cancelLoad() super.onDestroy() } Loading Loading
packages/SystemUI/src/com/android/systemui/controls/controller/ControlsBindingController.kt +2 −1 Original line number Diff line number Diff line Loading @@ -38,8 +38,9 @@ interface ControlsBindingController : UserAwareController { * * @param component The [ComponentName] of the service to bind * @param callback a callback to return the loaded controls to (or an error). * @return a runnable to cancel the load */ fun bindAndLoad(component: ComponentName, callback: LoadCallback) fun bindAndLoad(component: ComponentName, callback: LoadCallback): Runnable /** * Request to bind to the given service. Loading
packages/SystemUI/src/com/android/systemui/controls/controller/ControlsBindingControllerImpl.kt +12 −3 Original line number Diff line number Diff line Loading @@ -116,8 +116,10 @@ open class ControlsBindingControllerImpl @Inject constructor( override fun bindAndLoad( component: ComponentName, callback: ControlsBindingController.LoadCallback ) { retrieveLifecycleManager(component)?.maybeBindAndLoad(LoadSubscriber(callback)) ): Runnable { val subscriber = LoadSubscriber(callback) retrieveLifecycleManager(component)?.maybeBindAndLoad(subscriber) return subscriber.loadCancel() } override fun subscribe(structureInfo: StructureInfo) { Loading Loading @@ -208,7 +210,6 @@ open class ControlsBindingControllerImpl @Inject constructor( ) : CallbackRunnable(token) { override fun doRun() { callback.accept(list) provider?.unbindService() } } Loading Loading @@ -292,8 +293,14 @@ open class ControlsBindingControllerImpl @Inject constructor( ) : IControlsSubscriber.Stub() { val loadedControls = ArrayList<Control>() var hasError = false private var _loadCancelInternal: (() -> Unit)? = null fun loadCancel() = Runnable { Log.d(TAG, "Cancel load requested") _loadCancelInternal?.invoke() } override fun onSubscribe(token: IBinder, subs: IControlsSubscription) { _loadCancelInternal = subs::cancel backgroundExecutor.execute(OnSubscribeRunnable(token, subs)) } Loading @@ -302,10 +309,12 @@ open class ControlsBindingControllerImpl @Inject constructor( } override fun onError(token: IBinder, s: String) { hasError = true _loadCancelInternal = {} backgroundExecutor.execute(OnLoadErrorRunnable(token, s, callback)) } override fun onComplete(token: IBinder) { _loadCancelInternal = {} if (!hasError) { backgroundExecutor.execute(OnLoadRunnable(token, loadedControls, callback)) } Loading
packages/SystemUI/src/com/android/systemui/controls/controller/ControlsController.kt +5 −0 Original line number Diff line number Diff line Loading @@ -58,6 +58,11 @@ interface ControlsController : UserAwareController { dataCallback: Consumer<LoadData> ) /** * Cancels a pending load call */ fun cancelLoad() /** * Request to subscribe for favorited controls per structure * Loading
packages/SystemUI/src/com/android/systemui/controls/controller/ControlsControllerImpl.kt +14 −5 Original line number Diff line number Diff line Loading @@ -72,6 +72,8 @@ class ControlsControllerImpl @Inject constructor ( private var userChanging: Boolean = true private var loadCanceller: Runnable? = null private var currentUser = UserHandle.of(ActivityManager.getCurrentUser()) override val currentUserId get() = currentUser.identifier Loading Loading @@ -213,8 +215,9 @@ class ControlsControllerImpl @Inject constructor ( if (!confirmAvailability()) { if (userChanging) { // Try again later, userChanging should not last forever. If so, we have bigger // problems executor.executeDelayed( // problems. This will return a runnable that allows to cancel the delayed version, // it will not be able to cancel the load if loadCanceller = executor.executeDelayed( { loadForComponent(componentName, dataCallback) }, USER_CHANGE_RETRY_DELAY, TimeUnit.MILLISECONDS Loading @@ -224,10 +227,11 @@ class ControlsControllerImpl @Inject constructor ( } return } bindingController.bindAndLoad( loadCanceller = bindingController.bindAndLoad( componentName, object : ControlsBindingController.LoadCallback { override fun accept(controls: List<Control>) { loadCanceller = null executor.execute { val favoritesForComponentKeys = Favorites .getControlsForComponent(componentName).map { it.controlId } Loading @@ -251,12 +255,12 @@ class ControlsControllerImpl @Inject constructor ( controlsWithFavorite, favoritesForComponentKeys ) dataCallback.accept(loadData) } } override fun error(message: String) { loadCanceller = null executor.execute { val loadData = Favorites.getControlsForComponent(componentName) .let { controls -> Loading @@ -269,7 +273,6 @@ class ControlsControllerImpl @Inject constructor ( true ) } dataCallback.accept(loadData) } } Loading @@ -277,6 +280,12 @@ class ControlsControllerImpl @Inject constructor ( ) } override fun cancelLoad() { loadCanceller?.let { executor.execute(it) } } private fun createRemovedStatus( componentName: ComponentName, controlInfo: ControlInfo, Loading
packages/SystemUI/src/com/android/systemui/controls/management/ControlsFavoritingActivity.kt +15 −8 Original line number Diff line number Diff line Loading @@ -70,6 +70,7 @@ class ControlsFavoritingActivity @Inject constructor( private lateinit var iconFrame: View private lateinit var pageIndicator: ManagementPageIndicator private var mTooltipManager: TooltipManager? = null private lateinit var doneButton: View private var listOfStructures = emptyList<StructureContainer>() private lateinit var comparator: Comparator<StructureContainer> Loading Loading @@ -137,6 +138,7 @@ class ControlsFavoritingActivity @Inject constructor( StructureContainer(it.key, AllModel(it.value, favoriteKeys, emptyZoneString)) }.sortedWith(comparator) executor.execute { doneButton.isEnabled = true structurePager.adapter = StructureAdapter(listOfStructures) if (error) { statusText.text = resources.getText(R.string.controls_favorite_load_error) Loading Loading @@ -180,6 +182,7 @@ class ControlsFavoritingActivity @Inject constructor( layoutResource = R.layout.controls_management_favorites inflate() } statusText = requireViewById(R.id.status_message) if (shouldShowTooltip()) { mTooltipManager = TooltipManager(statusText.context, Loading Loading @@ -248,17 +251,20 @@ class ControlsFavoritingActivity @Inject constructor( } } requireViewById<Button>(R.id.done).setOnClickListener { doneButton = requireViewById<Button>(R.id.done).apply { isEnabled = false setOnClickListener { if (component == null) return@setOnClickListener listOfStructures.forEach { val favoritesForStorage = it.model.favorites.map { it.build() } controller.replaceFavoritesForStructure(StructureInfo(component!!, it.structureName, favoritesForStorage)) controller.replaceFavoritesForStructure( StructureInfo(component!!, it.structureName, favoritesForStorage) ) } finishAffinity() } } } override fun onPause() { super.onPause() Loading @@ -273,6 +279,7 @@ class ControlsFavoritingActivity @Inject constructor( override fun onDestroy() { currentUserTracker.stopTracking() listingController.removeCallback(listingCallback) controller.cancelLoad() super.onDestroy() } Loading