1 /*
2  * Copyright (C) 2015 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.systemui.statusbar.connectivity;
17 
18 import android.content.Context;
19 import android.net.NetworkCapabilities;
20 
21 import com.android.settingslib.AccessibilityContentDescriptions;
22 import com.android.settingslib.SignalIcon.IconGroup;
23 
24 import java.util.BitSet;
25 
26 /** */
27 public class EthernetSignalController extends
28         SignalController<ConnectivityState, IconGroup> {
29 
EthernetSignalController(Context context, CallbackHandler callbackHandler, NetworkControllerImpl networkController)30     public EthernetSignalController(Context context,
31             CallbackHandler callbackHandler, NetworkControllerImpl networkController) {
32         super("EthernetSignalController", context, NetworkCapabilities.TRANSPORT_ETHERNET,
33                 callbackHandler, networkController);
34         mCurrentState.iconGroup = mLastState.iconGroup = new IconGroup(
35                 "Ethernet Icons",
36                 EthernetIcons.ETHERNET_ICONS,
37                 null,
38                 AccessibilityContentDescriptions.ETHERNET_CONNECTION_VALUES,
39                 0, 0, 0, 0,
40                 AccessibilityContentDescriptions.ETHERNET_CONNECTION_VALUES[0]);
41     }
42 
43     @Override
updateConnectivity(BitSet connectedTransports, BitSet validatedTransports)44     public void updateConnectivity(BitSet connectedTransports, BitSet validatedTransports) {
45         mCurrentState.connected = connectedTransports.get(mTransportType);
46         super.updateConnectivity(connectedTransports, validatedTransports);
47     }
48 
49     @Override
notifyListeners(SignalCallback callback)50     public void notifyListeners(SignalCallback callback) {
51         boolean ethernetVisible = mCurrentState.connected;
52         String contentDescription = getTextIfExists(getContentDescription()).toString();
53         // TODO: wire up data transfer using WifiSignalPoller.
54         callback.setEthernetIndicators(new IconState(ethernetVisible, getCurrentIconId(),
55                 contentDescription));
56     }
57 
58     @Override
getContentDescription()59     public int getContentDescription() {
60         if (mCurrentState.connected) {
61             return getIcons().contentDesc[1];
62         } else {
63             return getIcons().discContentDesc;
64         }
65     }
66 
67     @Override
cleanState()68     public ConnectivityState cleanState() {
69         return new ConnectivityState();
70     }
71 }
72