aboutsummaryrefslogtreecommitdiff
path: root/src/java/com/android/ike/ikev2/IkeManager.java
blob: 38ab15ba4835f418a2a66c5b10ee40df316e5415 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*
 * Copyright (C) 2019 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.android.ike.ikev2;

import android.content.Context;

import com.android.ike.utils.Log;
import com.android.internal.annotations.VisibleForTesting;

import java.util.concurrent.Executor;

/** This class contains methods for managing IKE sessions. */
public final class IkeManager {
    private static final String IKE_TAG = "IKE";
    private static final boolean LOG_SENSITIVE = false;

    private static Log sIkeLog = new Log(IKE_TAG, LOG_SENSITIVE);

    private final Context mContext;

    /**
     * Construct an instance of {@link IkeManager}
     *
     * @param context the application context.
     */
    public IkeManager(Context context) {
        mContext = context;
    }

    /**
     * Construct an instance of {@link IkeSession} and start the IKE Session setup process.
     *
     * <p>This method will immediately return a management object {@link IkeSession} and
     * asynchronously initiate the IKE Session setup process. Users will be notified of the IKE
     * Session and Child Session negotiation results on the callback arguments.
     *
     * @param ikeSessionOptions the {@link IkeSessionOptions} that contains acceptable IKE Session
     *     configurations.
     * @param firstChildSessionOptions the {@link ChildSessionOptions} that contains acceptable
     *     first Child Session configurations.
     * @param userCbExecutor the {@link Executor} upon which all callbacks will be posted. For
     *     security and consistency, the callbacks posted to this executor MUST be executed
     *     serially, in the order they were posted.
     * @param ikeSessionCallback the {@link IkeSessionCallback} interface to notify users the state
     *     changes of the IKE Session.
     * @param firstChildSessionCallback the {@link ChildSessionCallback} interface to notify users
     *     the state changes of the Child Session.
     * @return an instance of {@link IkeSession}
     */
    public IkeSession openIkeSession(
            IkeSessionOptions ikeSessionOptions,
            ChildSessionOptions firstChildSessionOptions,
            Executor userCbExecutor,
            IkeSessionCallback ikeSessionCallback,
            ChildSessionCallback firstChildSessionCallback) {
        return new IkeSession(
                mContext,
                ikeSessionOptions,
                firstChildSessionOptions,
                userCbExecutor,
                ikeSessionCallback,
                firstChildSessionCallback);
    }

    /** Returns IKE logger. */
    public static Log getIkeLog() {
        return sIkeLog;
    }

    @VisibleForTesting
    static void setIkeLog(Log log) {
        sIkeLog = log;
    }

    @VisibleForTesting
    static void resetIkeLog() {
        sIkeLog = new Log(IKE_TAG, LOG_SENSITIVE);
    }
}