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_INITIALIZED = -1; 26 static int NETWORK_NOT_CONNECTED = 0; 27 static int NETWORK_CONNECTED = 1; 28 29 @NetworkStatus getNetworkStatus()30 int getNetworkStatus(); 31 32 /** 33 * Registers a listener on network changes and immediately calls {@code onNetworkChanged} on it 34 * with the current network status. 35 */ registerListener(Listener listener)36 void registerListener(Listener listener); 37 unregisterListener(Listener listener)38 void unregisterListener(Listener listener); 39 40 /** 41 * Possible network statuses . 42 */ 43 @IntDef({ 44 NETWORK_NOT_INITIALIZED, 45 NETWORK_NOT_CONNECTED, 46 NETWORK_CONNECTED 47 }) 48 @interface NetworkStatus { 49 } 50 51 /** 52 * Listener for network status change notification. 53 */ 54 interface Listener { onNetworkChanged(@etworkStatus int newNetworkStatus)55 void onNetworkChanged(@NetworkStatus int newNetworkStatus); 56 } 57 } 58