• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2021 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.internal.telephony.data;
18 
19 import android.annotation.CallbackExecutor;
20 import android.annotation.NonNull;
21 
22 import com.android.internal.annotations.VisibleForTesting;
23 
24 import java.util.concurrent.Executor;
25 
26 /**
27  * This is the generic callback used for passing information between telephony data modules.
28  */
29 public class DataCallback {
30     /** The executor of the callback. */
31     private final @NonNull Executor mExecutor;
32 
33     /**
34      * Constructor
35      *
36      * @param executor The executor of the callback.
37      */
DataCallback(@onNull @allbackExecutor Executor executor)38     public DataCallback(@NonNull @CallbackExecutor Executor executor) {
39         mExecutor = executor;
40     }
41 
42     /**
43      * @return The executor of the callback.
44      */
45     @VisibleForTesting
getExecutor()46     public @NonNull Executor getExecutor() {
47         return mExecutor;
48     }
49 
50     /**
51      * Invoke the callback from executor.
52      *
53      * @param runnable The callback method to invoke.
54      */
invokeFromExecutor(@onNull Runnable runnable)55     public void invokeFromExecutor(@NonNull Runnable runnable) {
56         mExecutor.execute(runnable);
57     }
58 }
59