Lorenzo Colitti | 4e5aa2c | 2014-05-21 16:23:43 -0700 | [diff] [blame^] | 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 android.net; |
| 18 | |
| 19 | import android.content.Context; |
| 20 | import android.net.IEthernetManager; |
| 21 | import android.net.IpConfiguration; |
| 22 | import android.net.IpConfiguration.IpAssignment; |
| 23 | import android.net.IpConfiguration.ProxySettings; |
| 24 | import android.net.LinkProperties; |
| 25 | import android.os.RemoteException; |
| 26 | |
| 27 | /** |
| 28 | * A class representing the IP configuration of the Ethernet network. |
| 29 | * |
| 30 | * @hide |
| 31 | */ |
| 32 | public class EthernetManager { |
| 33 | private static final String TAG = "EthernetManager"; |
| 34 | |
| 35 | private final Context mContext; |
| 36 | private final IEthernetManager mService; |
| 37 | |
| 38 | /** |
| 39 | * Create a new EthernetManager instance. |
| 40 | * Applications will almost always want to use |
| 41 | * {@link android.content.Context#getSystemService Context.getSystemService()} to retrieve |
| 42 | * the standard {@link android.content.Context#ETHERNET_SERVICE Context.ETHERNET_SERVICE}. |
| 43 | */ |
| 44 | public EthernetManager(Context context, IEthernetManager service) { |
| 45 | mContext = context; |
| 46 | mService = service; |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * Get Ethernet configuration |
| 51 | * @return the Ethernet Configuration, contained in {@link IpConfiguration}. |
| 52 | */ |
| 53 | public IpConfiguration getConfiguration() { |
| 54 | try { |
| 55 | return mService.getConfiguration(); |
| 56 | } catch (RemoteException e) { |
| 57 | return new IpConfiguration(IpAssignment.UNASSIGNED, |
| 58 | ProxySettings.UNASSIGNED, |
| 59 | new LinkProperties()); |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * Set Ethernet configuration |
| 65 | * @return true if setting success |
| 66 | */ |
| 67 | public void setConfiguration(IpConfiguration config) { |
| 68 | try { |
| 69 | mService.setConfiguration(config); |
| 70 | } catch (RemoteException e) { |
| 71 | } |
| 72 | } |
| 73 | } |