1 /* 2 * Copyright (C) 2019 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.systemui.controls.controller 18 19 import android.content.ComponentName 20 import android.service.controls.Control 21 import android.service.controls.ControlsProviderService 22 import android.service.controls.actions.ControlAction 23 import com.android.systemui.util.UserAwareController 24 import java.util.function.Consumer 25 26 /** 27 * Controller for keeping track of any [ControlsProviderService] that needs to be bound. 28 * 29 * This controller serves as an interface between [ControlsController] and the services. 30 * 31 * This controller being a [UserAwareController] means that all binding and requests will be 32 * performed on services bound as the current user. 33 */ 34 interface ControlsBindingController : UserAwareController { 35 36 /** 37 * Request bind to a service and load all controls. 38 * 39 * @param component The [ComponentName] of the service to bind 40 * @param callback a callback to return the loaded controls to (or an error). 41 * @return a runnable to cancel the load 42 */ bindAndLoadnull43 fun bindAndLoad(component: ComponentName, callback: LoadCallback): Runnable 44 45 /** 46 * Request bind to a service and load a limited number of suggested controls. 47 * 48 * @param component The [ComponentName] of the service to bind 49 * @param callback a callback to return the loaded controls to (or an error). 50 */ 51 fun bindAndLoadSuggested(component: ComponentName, callback: LoadCallback) 52 53 /** 54 * Request to bind to the given service. This should only be used for services using the full 55 * [ControlsProviderService] API, where SystemUI renders the devices' UI. 56 * 57 * @param component The [ComponentName] of the service to bind 58 */ 59 fun bindService(component: ComponentName) 60 61 /** 62 * Bind to a service that provides a Device Controls panel (embedded activity). This will allow 63 * the app to remain "warm", and reduce latency. 64 * 65 * @param component The [ComponentName] of the [ControlsProviderService] to bind. 66 */ 67 fun bindServiceForPanel(component: ComponentName) 68 69 /** 70 * Send a subscribe message to retrieve status of a set of controls. 71 * 72 * @param structureInfo structure containing the controls to update 73 */ 74 fun subscribe(structureInfo: StructureInfo) 75 76 /** 77 * Send an action performed on a [Control]. 78 * 79 * @param componentName name of the component 80 * @param controlInfo information about the actioned control 81 * @param action the action performed on the control 82 */ 83 fun action(componentName: ComponentName, controlInfo: ControlInfo, action: ControlAction) 84 85 /** 86 * Unsubscribe from all services to stop status updates. 87 */ 88 fun unsubscribe() 89 90 /** 91 * Notify this controller that this component has been removed (uninstalled). 92 */ 93 fun onComponentRemoved(componentName: ComponentName) 94 95 /** 96 * Consumer for load calls. 97 * 98 * Supports also sending error messages. 99 */ 100 interface LoadCallback : Consumer<List<Control>> { 101 102 /** 103 * Indicates an error loading. 104 * 105 * @message an error message. 106 */ 107 fun error(message: String) 108 } 109 } 110