1 /* 2 * Copyright (C) 2014 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 17 package com.android.tv.settings.connectivity; 18 19 import android.content.Context; 20 import android.net.EthernetManager; 21 import android.net.EthernetNetworkUpdateRequest; 22 import android.net.IpConfiguration; 23 import android.net.wifi.WifiManager; 24 25 import com.android.tv.settings.R; 26 27 /** 28 * Ethernet configuration that implements NetworkConfiguration. 29 */ 30 class EthernetConfig implements NetworkConfiguration { 31 private final EthernetManager mEthernetManager; 32 private IpConfiguration mIpConfiguration; 33 private final String mName; 34 private final String mInterfaceName; 35 EthernetConfig(Context context, String iface, IpConfiguration initialConfig)36 EthernetConfig(Context context, String iface, IpConfiguration initialConfig) { 37 mEthernetManager = (EthernetManager) context.getSystemService(Context.ETHERNET_SERVICE); 38 mIpConfiguration = initialConfig; 39 mInterfaceName = iface; 40 mName = context.getResources().getString(R.string.connectivity_ethernet); 41 } 42 43 @Override setIpConfiguration(IpConfiguration configuration)44 public void setIpConfiguration(IpConfiguration configuration) { 45 mIpConfiguration = configuration; 46 } 47 48 @Override getIpConfiguration()49 public IpConfiguration getIpConfiguration() { 50 return mIpConfiguration; 51 } 52 53 @Override save(WifiManager.ActionListener listener)54 public void save(WifiManager.ActionListener listener) { 55 if (mInterfaceName != null) { 56 final EthernetNetworkUpdateRequest request = 57 new EthernetNetworkUpdateRequest.Builder() 58 .setIpConfiguration(mIpConfiguration) 59 .build(); 60 mEthernetManager.updateConfiguration(mInterfaceName, request, r -> r.run(), 61 null /* network listener */); 62 } 63 64 if (listener != null) { 65 listener.onSuccess(); 66 } 67 } 68 69 @Override getPrintableName()70 public String getPrintableName() { 71 return mName; 72 } 73 } 74