Matt Pietal | 10eae31 | 2019-12-10 08:46:45 -0500 | [diff] [blame] | 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 | package android.service.controls; |
| 17 | |
Fabian Kozynski | d6f4840 | 2020-02-05 13:01:04 -0500 | [diff] [blame] | 18 | import android.Manifest; |
Matt Pietal | 10eae31 | 2019-12-10 08:46:45 -0500 | [diff] [blame] | 19 | import android.annotation.NonNull; |
Matt Pietal | d0553b0 | 2020-02-13 07:08:58 -0500 | [diff] [blame] | 20 | import android.annotation.Nullable; |
Matt Pietal | 10eae31 | 2019-12-10 08:46:45 -0500 | [diff] [blame] | 21 | import android.annotation.SdkConstant; |
| 22 | import android.annotation.SdkConstant.SdkConstantType; |
| 23 | import android.app.Service; |
Fabian Kozynski | d6f4840 | 2020-02-05 13:01:04 -0500 | [diff] [blame] | 24 | import android.content.ComponentName; |
| 25 | import android.content.Context; |
Matt Pietal | 10eae31 | 2019-12-10 08:46:45 -0500 | [diff] [blame] | 26 | import android.content.Intent; |
| 27 | import android.os.Bundle; |
| 28 | import android.os.Handler; |
| 29 | import android.os.IBinder; |
| 30 | import android.os.Looper; |
| 31 | import android.os.Message; |
Fabian Kozynski | ee57f49 | 2019-12-30 12:30:24 -0500 | [diff] [blame] | 32 | import android.os.RemoteException; |
Fabian Kozynski | 2d21212 | 2019-12-17 12:22:46 -0500 | [diff] [blame] | 33 | import android.service.controls.actions.ControlAction; |
Fabian Kozynski | 1bb26b5 | 2020-01-08 18:20:36 -0500 | [diff] [blame] | 34 | import android.service.controls.actions.ControlActionWrapper; |
Fabian Kozynski | ee57f49 | 2019-12-30 12:30:24 -0500 | [diff] [blame] | 35 | import android.service.controls.templates.ControlTemplate; |
| 36 | import android.text.TextUtils; |
| 37 | import android.util.Log; |
Matt Pietal | 10eae31 | 2019-12-10 08:46:45 -0500 | [diff] [blame] | 38 | |
Fabian Kozynski | ee57f49 | 2019-12-30 12:30:24 -0500 | [diff] [blame] | 39 | import com.android.internal.util.Preconditions; |
| 40 | |
Matt Pietal | 10eae31 | 2019-12-10 08:46:45 -0500 | [diff] [blame] | 41 | import java.util.List; |
Fabian Kozynski | 1bb26b5 | 2020-01-08 18:20:36 -0500 | [diff] [blame] | 42 | import java.util.concurrent.Flow.Publisher; |
| 43 | import java.util.concurrent.Flow.Subscriber; |
| 44 | import java.util.concurrent.Flow.Subscription; |
| 45 | import java.util.function.Consumer; |
Matt Pietal | 10eae31 | 2019-12-10 08:46:45 -0500 | [diff] [blame] | 46 | |
| 47 | /** |
| 48 | * Service implementation allowing applications to contribute controls to the |
| 49 | * System UI. |
Matt Pietal | 10eae31 | 2019-12-10 08:46:45 -0500 | [diff] [blame] | 50 | */ |
| 51 | public abstract class ControlsProviderService extends Service { |
| 52 | |
| 53 | @SdkConstant(SdkConstantType.SERVICE_ACTION) |
Fabian Kozynski | 1bb26b5 | 2020-01-08 18:20:36 -0500 | [diff] [blame] | 54 | public static final String SERVICE_CONTROLS = |
| 55 | "android.service.controls.ControlsProviderService"; |
Fabian Kozynski | d6f4840 | 2020-02-05 13:01:04 -0500 | [diff] [blame] | 56 | |
| 57 | /** |
| 58 | * @hide |
| 59 | */ |
| 60 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
| 61 | public static final String ACTION_ADD_CONTROL = |
| 62 | "android.service.controls.action.ADD_CONTROL"; |
| 63 | |
| 64 | /** |
| 65 | * @hide |
| 66 | */ |
| 67 | public static final String EXTRA_CONTROL = |
| 68 | "android.service.controls.extra.CONTROL"; |
| 69 | |
Fabian Kozynski | 1bb26b5 | 2020-01-08 18:20:36 -0500 | [diff] [blame] | 70 | /** |
| 71 | * @hide |
| 72 | */ |
Fabian Kozynski | ee57f49 | 2019-12-30 12:30:24 -0500 | [diff] [blame] | 73 | public static final String CALLBACK_BUNDLE = "CALLBACK_BUNDLE"; |
Fabian Kozynski | 1bb26b5 | 2020-01-08 18:20:36 -0500 | [diff] [blame] | 74 | |
| 75 | /** |
| 76 | * @hide |
| 77 | */ |
Fabian Kozynski | ee57f49 | 2019-12-30 12:30:24 -0500 | [diff] [blame] | 78 | public static final String CALLBACK_TOKEN = "CALLBACK_TOKEN"; |
| 79 | |
Fabian Kozynski | 1bb26b5 | 2020-01-08 18:20:36 -0500 | [diff] [blame] | 80 | public static final @NonNull String TAG = "ControlsProviderService"; |
Matt Pietal | 10eae31 | 2019-12-10 08:46:45 -0500 | [diff] [blame] | 81 | |
Fabian Kozynski | ee57f49 | 2019-12-30 12:30:24 -0500 | [diff] [blame] | 82 | private IBinder mToken; |
Matt Pietal | 10eae31 | 2019-12-10 08:46:45 -0500 | [diff] [blame] | 83 | private RequestHandler mHandler; |
| 84 | |
| 85 | /** |
Matt Pietal | d0553b0 | 2020-02-13 07:08:58 -0500 | [diff] [blame] | 86 | * Publisher for all available controls |
| 87 | * |
| 88 | * Retrieve all available controls. Use the stateless builder {@link Control.StatelessBuilder} |
| 89 | * to build each Control. Call {@link Subscriber#onComplete} when done loading all unique |
| 90 | * controls, or {@link Subscriber#onError} for error scenarios. Duplicate Controls will |
| 91 | * replace the original. |
| 92 | */ |
Matt Pietal | bb3be65 | 2020-02-24 08:51:19 -0500 | [diff] [blame] | 93 | @NonNull |
Matt Pietal | e44217b | 2020-02-26 08:48:37 -0500 | [diff] [blame] | 94 | public abstract Publisher<Control> createPublisherForAllAvailable(); |
Matt Pietal | d0553b0 | 2020-02-13 07:08:58 -0500 | [diff] [blame] | 95 | |
| 96 | /** |
| 97 | * (Optional) Publisher for suggested controls |
| 98 | * |
| 99 | * The service may be asked to provide a small number of recommended controls, in |
| 100 | * order to suggest some controls to the user for favoriting. The controls shall be built using |
Matt Pietal | 1f7c817 | 2020-05-26 14:29:06 -0400 | [diff] [blame] | 101 | * the stateless builder {@link Control.StatelessBuilder}. The total number of controls |
| 102 | * requested through {@link Subscription#request} will be restricted to a maximum. Within this |
| 103 | * larger limit, only 6 controls per structure will be loaded. Therefore, it is advisable to |
| 104 | * seed multiple structures if they exist. Any control sent over this limit will be discarded. |
| 105 | * Call {@link Subscriber#onComplete} when done, or {@link Subscriber#onError} for error |
| 106 | * scenarios. |
Matt Pietal | d0553b0 | 2020-02-13 07:08:58 -0500 | [diff] [blame] | 107 | */ |
| 108 | @Nullable |
Matt Pietal | e44217b | 2020-02-26 08:48:37 -0500 | [diff] [blame] | 109 | public Publisher<Control> createPublisherForSuggested() { |
Matt Pietal | d0553b0 | 2020-02-13 07:08:58 -0500 | [diff] [blame] | 110 | return null; |
| 111 | } |
| 112 | |
| 113 | /** |
| 114 | * Return a valid Publisher for the given controlIds. This publisher will be asked to provide |
| 115 | * updates for the given list of controlIds as long as the {@link Subscription} is valid. |
| 116 | * Calls to {@link Subscriber#onComplete} will not be expected. Instead, wait for the call from |
Matt Pietal | e44217b | 2020-02-26 08:48:37 -0500 | [diff] [blame] | 117 | * {@link Subscription#cancel} to indicate that updates are no longer required. It is expected |
| 118 | * that controls provided by this publisher were created using {@link Control.StatefulBuilder}. |
Matt Pietal | 10eae31 | 2019-12-10 08:46:45 -0500 | [diff] [blame] | 119 | */ |
Fabian Kozynski | 1bb26b5 | 2020-01-08 18:20:36 -0500 | [diff] [blame] | 120 | @NonNull |
Matt Pietal | e44217b | 2020-02-26 08:48:37 -0500 | [diff] [blame] | 121 | public abstract Publisher<Control> createPublisherFor(@NonNull List<String> controlIds); |
Matt Pietal | 10eae31 | 2019-12-10 08:46:45 -0500 | [diff] [blame] | 122 | |
| 123 | /** |
| 124 | * The user has interacted with a Control. The action is dictated by the type of |
Fabian Kozynski | 1bb26b5 | 2020-01-08 18:20:36 -0500 | [diff] [blame] | 125 | * {@link ControlAction} that was sent. A response can be sent via |
| 126 | * {@link Consumer#accept}, with the Integer argument being one of the provided |
| 127 | * {@link ControlAction.ResponseResult}. The Integer should indicate whether the action |
| 128 | * was received successfully, or if additional prompts should be presented to |
| 129 | * the user. Any visual control updates should be sent via the Publisher. |
Matt Pietal | 10eae31 | 2019-12-10 08:46:45 -0500 | [diff] [blame] | 130 | */ |
Fabian Kozynski | 1bb26b5 | 2020-01-08 18:20:36 -0500 | [diff] [blame] | 131 | public abstract void performControlAction(@NonNull String controlId, |
| 132 | @NonNull ControlAction action, @NonNull Consumer<Integer> consumer); |
Matt Pietal | 10eae31 | 2019-12-10 08:46:45 -0500 | [diff] [blame] | 133 | |
| 134 | @Override |
Fabian Kozynski | 1bb26b5 | 2020-01-08 18:20:36 -0500 | [diff] [blame] | 135 | @NonNull |
| 136 | public final IBinder onBind(@NonNull Intent intent) { |
Matt Pietal | 10eae31 | 2019-12-10 08:46:45 -0500 | [diff] [blame] | 137 | mHandler = new RequestHandler(Looper.getMainLooper()); |
| 138 | |
Fabian Kozynski | ee57f49 | 2019-12-30 12:30:24 -0500 | [diff] [blame] | 139 | Bundle bundle = intent.getBundleExtra(CALLBACK_BUNDLE); |
Fabian Kozynski | ee57f49 | 2019-12-30 12:30:24 -0500 | [diff] [blame] | 140 | mToken = bundle.getBinder(CALLBACK_TOKEN); |
Matt Pietal | 10eae31 | 2019-12-10 08:46:45 -0500 | [diff] [blame] | 141 | |
| 142 | return new IControlsProvider.Stub() { |
Matt Pietal | d0553b0 | 2020-02-13 07:08:58 -0500 | [diff] [blame] | 143 | public void load(IControlsSubscriber subscriber) { |
| 144 | mHandler.obtainMessage(RequestHandler.MSG_LOAD, subscriber).sendToTarget(); |
Matt Pietal | 10eae31 | 2019-12-10 08:46:45 -0500 | [diff] [blame] | 145 | } |
| 146 | |
Matt Pietal | d0553b0 | 2020-02-13 07:08:58 -0500 | [diff] [blame] | 147 | public void loadSuggested(IControlsSubscriber subscriber) { |
| 148 | mHandler.obtainMessage(RequestHandler.MSG_LOAD_SUGGESTED, subscriber) |
| 149 | .sendToTarget(); |
Matt Pietal | 587a5f7 | 2020-02-07 09:34:49 -0500 | [diff] [blame] | 150 | } |
| 151 | |
Fabian Kozynski | 1bb26b5 | 2020-01-08 18:20:36 -0500 | [diff] [blame] | 152 | public void subscribe(List<String> controlIds, |
| 153 | IControlsSubscriber subscriber) { |
| 154 | SubscribeMessage msg = new SubscribeMessage(controlIds, subscriber); |
| 155 | mHandler.obtainMessage(RequestHandler.MSG_SUBSCRIBE, msg).sendToTarget(); |
Matt Pietal | 10eae31 | 2019-12-10 08:46:45 -0500 | [diff] [blame] | 156 | } |
| 157 | |
Fabian Kozynski | 1bb26b5 | 2020-01-08 18:20:36 -0500 | [diff] [blame] | 158 | public void action(String controlId, ControlActionWrapper action, |
| 159 | IControlsActionCallback cb) { |
| 160 | ActionMessage msg = new ActionMessage(controlId, action.getWrappedAction(), cb); |
| 161 | mHandler.obtainMessage(RequestHandler.MSG_ACTION, msg).sendToTarget(); |
Matt Pietal | 10eae31 | 2019-12-10 08:46:45 -0500 | [diff] [blame] | 162 | } |
| 163 | }; |
| 164 | } |
| 165 | |
| 166 | @Override |
Matt Pietal | e44217b | 2020-02-26 08:48:37 -0500 | [diff] [blame] | 167 | public final boolean onUnbind(@NonNull Intent intent) { |
Matt Pietal | 10eae31 | 2019-12-10 08:46:45 -0500 | [diff] [blame] | 168 | mHandler = null; |
| 169 | return true; |
| 170 | } |
| 171 | |
| 172 | private class RequestHandler extends Handler { |
| 173 | private static final int MSG_LOAD = 1; |
| 174 | private static final int MSG_SUBSCRIBE = 2; |
Fabian Kozynski | 1bb26b5 | 2020-01-08 18:20:36 -0500 | [diff] [blame] | 175 | private static final int MSG_ACTION = 3; |
Matt Pietal | 587a5f7 | 2020-02-07 09:34:49 -0500 | [diff] [blame] | 176 | private static final int MSG_LOAD_SUGGESTED = 4; |
| 177 | |
Matt Pietal | 10eae31 | 2019-12-10 08:46:45 -0500 | [diff] [blame] | 178 | RequestHandler(Looper looper) { |
| 179 | super(looper); |
| 180 | } |
| 181 | |
| 182 | public void handleMessage(Message msg) { |
| 183 | switch(msg.what) { |
Matt Pietal | d0553b0 | 2020-02-13 07:08:58 -0500 | [diff] [blame] | 184 | case MSG_LOAD: { |
| 185 | final IControlsSubscriber cs = (IControlsSubscriber) msg.obj; |
| 186 | final SubscriberProxy proxy = new SubscriberProxy(true, mToken, cs); |
Matt Pietal | 587a5f7 | 2020-02-07 09:34:49 -0500 | [diff] [blame] | 187 | |
Matt Pietal | e44217b | 2020-02-26 08:48:37 -0500 | [diff] [blame] | 188 | ControlsProviderService.this.createPublisherForAllAvailable().subscribe(proxy); |
Matt Pietal | 10eae31 | 2019-12-10 08:46:45 -0500 | [diff] [blame] | 189 | break; |
Matt Pietal | d0553b0 | 2020-02-13 07:08:58 -0500 | [diff] [blame] | 190 | } |
Fabian Kozynski | 1bb26b5 | 2020-01-08 18:20:36 -0500 | [diff] [blame] | 191 | |
Matt Pietal | d0553b0 | 2020-02-13 07:08:58 -0500 | [diff] [blame] | 192 | case MSG_LOAD_SUGGESTED: { |
| 193 | final IControlsSubscriber cs = (IControlsSubscriber) msg.obj; |
| 194 | final SubscriberProxy proxy = new SubscriberProxy(true, mToken, cs); |
| 195 | |
| 196 | Publisher<Control> publisher = |
Matt Pietal | e44217b | 2020-02-26 08:48:37 -0500 | [diff] [blame] | 197 | ControlsProviderService.this.createPublisherForSuggested(); |
Matt Pietal | d0553b0 | 2020-02-13 07:08:58 -0500 | [diff] [blame] | 198 | if (publisher == null) { |
| 199 | Log.i(TAG, "No publisher provided for suggested controls"); |
| 200 | proxy.onComplete(); |
| 201 | } else { |
| 202 | publisher.subscribe(proxy); |
| 203 | } |
| 204 | break; |
| 205 | } |
| 206 | |
| 207 | case MSG_SUBSCRIBE: { |
Fabian Kozynski | 1bb26b5 | 2020-01-08 18:20:36 -0500 | [diff] [blame] | 208 | final SubscribeMessage sMsg = (SubscribeMessage) msg.obj; |
Matt Pietal | d0553b0 | 2020-02-13 07:08:58 -0500 | [diff] [blame] | 209 | final SubscriberProxy proxy = new SubscriberProxy(false, mToken, |
| 210 | sMsg.mSubscriber); |
Fabian Kozynski | 1bb26b5 | 2020-01-08 18:20:36 -0500 | [diff] [blame] | 211 | |
Matt Pietal | e44217b | 2020-02-26 08:48:37 -0500 | [diff] [blame] | 212 | ControlsProviderService.this.createPublisherFor(sMsg.mControlIds) |
| 213 | .subscribe(proxy); |
Matt Pietal | d0553b0 | 2020-02-13 07:08:58 -0500 | [diff] [blame] | 214 | break; |
| 215 | } |
| 216 | |
| 217 | case MSG_ACTION: { |
Fabian Kozynski | 1bb26b5 | 2020-01-08 18:20:36 -0500 | [diff] [blame] | 218 | final ActionMessage aMsg = (ActionMessage) msg.obj; |
| 219 | ControlsProviderService.this.performControlAction(aMsg.mControlId, |
| 220 | aMsg.mAction, consumerFor(aMsg.mControlId, aMsg.mCb)); |
Matt Pietal | 10eae31 | 2019-12-10 08:46:45 -0500 | [diff] [blame] | 221 | break; |
Matt Pietal | d0553b0 | 2020-02-13 07:08:58 -0500 | [diff] [blame] | 222 | } |
Matt Pietal | 10eae31 | 2019-12-10 08:46:45 -0500 | [diff] [blame] | 223 | } |
| 224 | } |
Fabian Kozynski | 1bb26b5 | 2020-01-08 18:20:36 -0500 | [diff] [blame] | 225 | |
| 226 | private Consumer<Integer> consumerFor(final String controlId, |
| 227 | final IControlsActionCallback cb) { |
| 228 | return (@NonNull Integer response) -> { |
| 229 | Preconditions.checkNotNull(response); |
| 230 | if (!ControlAction.isValidResponse(response)) { |
| 231 | Log.e(TAG, "Not valid response result: " + response); |
| 232 | response = ControlAction.RESPONSE_UNKNOWN; |
| 233 | } |
| 234 | try { |
| 235 | cb.accept(mToken, controlId, response); |
| 236 | } catch (RemoteException ex) { |
| 237 | ex.rethrowAsRuntimeException(); |
| 238 | } |
| 239 | }; |
| 240 | } |
Matt Pietal | d0553b0 | 2020-02-13 07:08:58 -0500 | [diff] [blame] | 241 | } |
Fabian Kozynski | 1bb26b5 | 2020-01-08 18:20:36 -0500 | [diff] [blame] | 242 | |
Matt Pietal | d0553b0 | 2020-02-13 07:08:58 -0500 | [diff] [blame] | 243 | private static boolean isStatelessControl(Control control) { |
| 244 | return (control.getStatus() == Control.STATUS_UNKNOWN |
Fabian Kozynski | 95dcd24 | 2020-03-03 14:25:55 -0500 | [diff] [blame] | 245 | && control.getControlTemplate().getTemplateType() |
| 246 | == ControlTemplate.TYPE_NO_TEMPLATE |
Matt Pietal | d0553b0 | 2020-02-13 07:08:58 -0500 | [diff] [blame] | 247 | && TextUtils.isEmpty(control.getStatusText())); |
| 248 | } |
| 249 | |
| 250 | private static class SubscriberProxy implements Subscriber<Control> { |
| 251 | private IBinder mToken; |
| 252 | private IControlsSubscriber mCs; |
| 253 | private boolean mEnforceStateless; |
| 254 | |
| 255 | SubscriberProxy(boolean enforceStateless, IBinder token, IControlsSubscriber cs) { |
| 256 | mEnforceStateless = enforceStateless; |
| 257 | mToken = token; |
| 258 | mCs = cs; |
| 259 | } |
| 260 | |
| 261 | public void onSubscribe(Subscription subscription) { |
| 262 | try { |
| 263 | mCs.onSubscribe(mToken, new SubscriptionAdapter(subscription)); |
| 264 | } catch (RemoteException ex) { |
| 265 | ex.rethrowAsRuntimeException(); |
| 266 | } |
| 267 | } |
| 268 | public void onNext(@NonNull Control control) { |
| 269 | Preconditions.checkNotNull(control); |
| 270 | try { |
| 271 | if (mEnforceStateless && !isStatelessControl(control)) { |
| 272 | Log.w(TAG, "onNext(): control is not stateless. Use the " |
| 273 | + "Control.StatelessBuilder() to build the control."); |
| 274 | control = new Control.StatelessBuilder(control).build(); |
| 275 | } |
| 276 | mCs.onNext(mToken, control); |
| 277 | } catch (RemoteException ex) { |
| 278 | ex.rethrowAsRuntimeException(); |
| 279 | } |
| 280 | } |
| 281 | public void onError(Throwable t) { |
| 282 | try { |
| 283 | mCs.onError(mToken, t.toString()); |
| 284 | } catch (RemoteException ex) { |
| 285 | ex.rethrowAsRuntimeException(); |
| 286 | } |
| 287 | } |
| 288 | public void onComplete() { |
| 289 | try { |
| 290 | mCs.onComplete(mToken); |
| 291 | } catch (RemoteException ex) { |
| 292 | ex.rethrowAsRuntimeException(); |
| 293 | } |
Fabian Kozynski | 1bb26b5 | 2020-01-08 18:20:36 -0500 | [diff] [blame] | 294 | } |
Matt Pietal | 10eae31 | 2019-12-10 08:46:45 -0500 | [diff] [blame] | 295 | } |
| 296 | |
Fabian Kozynski | d6f4840 | 2020-02-05 13:01:04 -0500 | [diff] [blame] | 297 | /** |
| 298 | * Request SystemUI to prompt the user to add a control to favorites. |
| 299 | * |
| 300 | * @param context A context |
| 301 | * @param componentName Component name of the {@link ControlsProviderService} |
| 302 | * @param control A stateless control to show to the user |
| 303 | */ |
| 304 | public static void requestAddControl(@NonNull Context context, |
| 305 | @NonNull ComponentName componentName, |
| 306 | @NonNull Control control) { |
| 307 | Preconditions.checkNotNull(context); |
| 308 | Preconditions.checkNotNull(componentName); |
| 309 | Preconditions.checkNotNull(control); |
Fabian Kozynski | a9be39d | 2020-03-27 10:08:12 -0400 | [diff] [blame] | 310 | final String controlsPackage = context.getString( |
| 311 | com.android.internal.R.string.config_controlsPackage); |
Fabian Kozynski | d6f4840 | 2020-02-05 13:01:04 -0500 | [diff] [blame] | 312 | Intent intent = new Intent(ACTION_ADD_CONTROL); |
| 313 | intent.putExtra(Intent.EXTRA_COMPONENT_NAME, componentName); |
Fabian Kozynski | a9be39d | 2020-03-27 10:08:12 -0400 | [diff] [blame] | 314 | intent.setPackage(controlsPackage); |
Fabian Kozynski | d6f4840 | 2020-02-05 13:01:04 -0500 | [diff] [blame] | 315 | if (isStatelessControl(control)) { |
| 316 | intent.putExtra(EXTRA_CONTROL, control); |
| 317 | } else { |
| 318 | intent.putExtra(EXTRA_CONTROL, new Control.StatelessBuilder(control).build()); |
| 319 | } |
| 320 | context.sendBroadcast(intent, Manifest.permission.BIND_CONTROLS); |
| 321 | } |
| 322 | |
Fabian Kozynski | 1bb26b5 | 2020-01-08 18:20:36 -0500 | [diff] [blame] | 323 | private static class SubscriptionAdapter extends IControlsSubscription.Stub { |
| 324 | final Subscription mSubscription; |
Matt Pietal | 10eae31 | 2019-12-10 08:46:45 -0500 | [diff] [blame] | 325 | |
Fabian Kozynski | 1bb26b5 | 2020-01-08 18:20:36 -0500 | [diff] [blame] | 326 | SubscriptionAdapter(Subscription s) { |
| 327 | this.mSubscription = s; |
| 328 | } |
| 329 | |
| 330 | public void request(long n) { |
| 331 | mSubscription.request(n); |
| 332 | } |
| 333 | |
| 334 | public void cancel() { |
| 335 | mSubscription.cancel(); |
| 336 | } |
| 337 | } |
| 338 | |
| 339 | private static class ActionMessage { |
| 340 | final String mControlId; |
| 341 | final ControlAction mAction; |
| 342 | final IControlsActionCallback mCb; |
| 343 | |
| 344 | ActionMessage(String controlId, ControlAction action, IControlsActionCallback cb) { |
| 345 | this.mControlId = controlId; |
Matt Pietal | 10eae31 | 2019-12-10 08:46:45 -0500 | [diff] [blame] | 346 | this.mAction = action; |
Fabian Kozynski | 1bb26b5 | 2020-01-08 18:20:36 -0500 | [diff] [blame] | 347 | this.mCb = cb; |
| 348 | } |
| 349 | } |
| 350 | |
| 351 | private static class SubscribeMessage { |
| 352 | final List<String> mControlIds; |
| 353 | final IControlsSubscriber mSubscriber; |
| 354 | |
| 355 | SubscribeMessage(List<String> controlIds, IControlsSubscriber subscriber) { |
| 356 | this.mControlIds = controlIds; |
| 357 | this.mSubscriber = subscriber; |
Matt Pietal | 10eae31 | 2019-12-10 08:46:45 -0500 | [diff] [blame] | 358 | } |
| 359 | } |
Matt Pietal | 10eae31 | 2019-12-10 08:46:45 -0500 | [diff] [blame] | 360 | } |