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 */ 43 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. 55 * 56 * @param component The [ComponentName] of the service to bind 57 */ 58 fun bindService(component: ComponentName) 59 60 /** 61 * Send a subscribe message to retrieve status of a set of controls. 62 * 63 * @param structureInfo structure containing the controls to update 64 */ 65 fun subscribe(structureInfo: StructureInfo) 66 67 /** 68 * Send an action performed on a [Control]. 69 * 70 * @param componentName name of the component 71 * @param controlInfo information about the actioned control 72 * @param action the action performed on the control 73 */ 74 fun action(componentName: ComponentName, controlInfo: ControlInfo, action: ControlAction) 75 76 /** 77 * Unsubscribe from all services to stop status updates. 78 */ 79 fun unsubscribe() 80 81 /** 82 * Notify this controller that this component has been removed (uninstalled). 83 */ 84 fun onComponentRemoved(componentName: ComponentName) 85 86 /** 87 * Consumer for load calls. 88 * 89 * Supports also sending error messages. 90 */ 91 interface LoadCallback : Consumer<List<Control>> { 92 93 /** 94 * Indicates an error loading. 95 * 96 * @message an error message. 97 */ 98 fun error(message: String) 99 } 100 } 101