1 /* 2 * Copyright (C) 2024 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.server.telecom; 18 19 /** 20 * Any android.telecom.Call service (e.g. ConnectionService, TransactionalService) that declares 21 * a {@link CallSourceService} should implement this interface in order to cache the callback. 22 * The callback will be executed once the service is set. 23 */ 24 public interface CachedCallback { 25 26 /** 27 * This callback is caching a state, meaning any new CachedCallbacks with the same 28 * {@link #getCallbackId()} will REPLACE any existing CachedCallback. 29 */ 30 int TYPE_STATE = 0; 31 /** 32 * This callback is caching a Queue, meaning that any new CachedCallbacks with the same 33 * {@link #getCallbackId()} will enqueue as a FIFO queue and each instance of this 34 * CachedCallback will run {@link #executeCallback(CallSourceService, Call)}. 35 */ 36 int TYPE_QUEUE = 1; 37 38 /** 39 * This method allows the callback to determine whether it is caching a {@link #TYPE_STATE} or 40 * a {@link #TYPE_QUEUE}. 41 * 42 * @return Either {@link #TYPE_STATE} or {@link #TYPE_QUEUE} based on the callback type. 43 */ getCacheType()44 int getCacheType(); 45 46 /** 47 * This method executes the callback that was cached because the service was not available 48 * at the time the callback was ready. 49 * 50 * @param service that was recently set (e.g. ConnectionService) 51 * @param call that had a null service at the time the callback was ready. The service is now 52 * non-null in the call and can be executed/ 53 */ executeCallback(CallSourceService service, Call call)54 void executeCallback(CallSourceService service, Call call); 55 56 /** 57 * The ID that this CachedCallback should use to identify itself as a distinct operation. 58 * <p> 59 * If {@link #TYPE_STATE} is set for {@link #getCacheType()}, and a CachedCallback with the 60 * same ID is called multiple times while the service is not set, ONLY the last callback will be 61 * sent to the client since the last callback is the most relevant. 62 * <p> 63 * If {@link #TYPE_QUEUE} is set for {@link #getCacheType()} and the CachedCallback with the 64 * same ID is called multiple times while the service is not set, each CachedCallback will be 65 * enqueued in FIFO order. Once the service is set, {@link #executeCallback} will be called 66 * for each CachedCallback with the same ID. 67 * 68 * @return A unique callback id that will be used differentiate this CachedCallback type with 69 * other CachedCallback types. 70 */ getCallbackId()71 String getCallbackId(); 72 } 73