• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2020 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 com.android.internal.net.ipsec.ike.ike3gpp;
17 
18 import static android.net.ipsec.ike.IkeManager.getIkeLog;
19 
20 import android.annotation.NonNull;
21 import android.net.ipsec.ike.ike3gpp.Ike3gppData;
22 import android.net.ipsec.ike.ike3gpp.Ike3gppExtension;
23 
24 import java.util.List;
25 import java.util.Objects;
26 import java.util.concurrent.Executor;
27 
28 /**
29  * Ike3gppExchangeBase is the base for IKE exchange-specific 3GPP functionality.
30  *
31  * <p>This class is package-private.
32  */
33 abstract class Ike3gppExchangeBase {
34     private static final String TAG = Ike3gppExchangeBase.class.getSimpleName();
35 
36     @NonNull protected final Ike3gppExtension mIke3gppExtension;
37     @NonNull private final Executor mUserCbExecutor;
38 
39     /** Initializes an Ike3gppExchangeBase. */
Ike3gppExchangeBase( @onNull Ike3gppExtension ike3gppExtension, @NonNull Executor userCbExecutor)40     Ike3gppExchangeBase(
41             @NonNull Ike3gppExtension ike3gppExtension, @NonNull Executor userCbExecutor) {
42         mIke3gppExtension =
43                 Objects.requireNonNull(ike3gppExtension, "ike3gppExtension must not be null");
44         mUserCbExecutor = Objects.requireNonNull(userCbExecutor, "userCbExecutor must not be null");
45     }
46 
maybeInvokeUserCallback(List<Ike3gppData> ike3gppDataList)47     void maybeInvokeUserCallback(List<Ike3gppData> ike3gppDataList) {
48         if (ike3gppDataList.isEmpty()) return;
49 
50         try {
51             mUserCbExecutor.execute(
52                     () ->
53                             mIke3gppExtension
54                                     .getIke3gppDataListener()
55                                     .onIke3gppDataReceived(ike3gppDataList));
56         } catch (Exception e) {
57             getIkeLog().d(TAG, "Ike3gppDataListener#onIke3gppDataReceived execution failed", e);
58         }
59     }
60 }
61