1 /*
2  * Copyright (C) 2017 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.wallpaper.module;
17 
18 import androidx.annotation.IntDef;
19 
20 /**
21  * Provides current status of the network. Abstraction layer above Android's ConnectivityManager
22  * used for testability.
23  */
24 public interface NetworkStatusNotifier {
25     static int NETWORK_NOT_CONNECTED = 0;
26     static int NETWORK_CONNECTED = 1;
27 
28     @NetworkStatus
getNetworkStatus()29     int getNetworkStatus();
30 
31     /**
32      * Registers a listener on network changes and immediately calls {@code onNetworkChanged} on it
33      * with the current network status.
34      */
registerListener(Listener listener)35     void registerListener(Listener listener);
36 
unregisterListener(Listener listener)37     void unregisterListener(Listener listener);
38 
39     /**
40      * Possible network statuses .
41      */
42     @IntDef({
43             NETWORK_NOT_CONNECTED,
44             NETWORK_CONNECTED
45     })
46     @interface NetworkStatus {
47     }
48 
49     /**
50      * Listener for network status change notification.
51      */
52     interface Listener {
onNetworkChanged(@etworkStatus int newNetworkStatus)53         void onNetworkChanged(@NetworkStatus int newNetworkStatus);
54     }
55 }
56