1/*
2 * Copyright (C) 2016 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
17package android.net;
18
19import android.os.HandlerThread;
20import android.os.Looper;
21
22/**
23 * Shared singleton connectivity thread for the system.  This is a thread for
24 * connectivity operations such as AsyncChannel connections to system services.
25 * Various connectivity manager objects can use this singleton as a common
26 * resource for their handlers instead of creating separate threads of their own.
27 * @hide
28 */
29public final class ConnectivityThread extends HandlerThread {
30    private static ConnectivityThread sInstance;
31
32    private ConnectivityThread() {
33        super("ConnectivityThread");
34    }
35
36    private static synchronized ConnectivityThread getInstance() {
37        if (sInstance == null) {
38            sInstance = new ConnectivityThread();
39            sInstance.start();
40        }
41        return sInstance;
42    }
43
44    public static ConnectivityThread get() {
45        return getInstance();
46    }
47
48    public static Looper getInstanceLooper() {
49        return getInstance().getLooper();
50    }
51}
52