EthernetManager.java revision 4e5aa2cee69f6791f8001aeb1fc12389863fab8f
14e5aa2cee69f6791f8001aeb1fc12389863fab8fLorenzo Colitti/*
24e5aa2cee69f6791f8001aeb1fc12389863fab8fLorenzo Colitti * Copyright (C) 2014 The Android Open Source Project
34e5aa2cee69f6791f8001aeb1fc12389863fab8fLorenzo Colitti *
44e5aa2cee69f6791f8001aeb1fc12389863fab8fLorenzo Colitti * Licensed under the Apache License, Version 2.0 (the "License");
54e5aa2cee69f6791f8001aeb1fc12389863fab8fLorenzo Colitti * you may not use this file except in compliance with the License.
64e5aa2cee69f6791f8001aeb1fc12389863fab8fLorenzo Colitti * You may obtain a copy of the License at
74e5aa2cee69f6791f8001aeb1fc12389863fab8fLorenzo Colitti *
84e5aa2cee69f6791f8001aeb1fc12389863fab8fLorenzo Colitti *      http://www.apache.org/licenses/LICENSE-2.0
94e5aa2cee69f6791f8001aeb1fc12389863fab8fLorenzo Colitti *
104e5aa2cee69f6791f8001aeb1fc12389863fab8fLorenzo Colitti * Unless required by applicable law or agreed to in writing, software
114e5aa2cee69f6791f8001aeb1fc12389863fab8fLorenzo Colitti * distributed under the License is distributed on an "AS IS" BASIS,
124e5aa2cee69f6791f8001aeb1fc12389863fab8fLorenzo Colitti * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
134e5aa2cee69f6791f8001aeb1fc12389863fab8fLorenzo Colitti * See the License for the specific language governing permissions and
144e5aa2cee69f6791f8001aeb1fc12389863fab8fLorenzo Colitti * limitations under the License.
154e5aa2cee69f6791f8001aeb1fc12389863fab8fLorenzo Colitti */
164e5aa2cee69f6791f8001aeb1fc12389863fab8fLorenzo Colitti
174e5aa2cee69f6791f8001aeb1fc12389863fab8fLorenzo Colittipackage android.net;
184e5aa2cee69f6791f8001aeb1fc12389863fab8fLorenzo Colitti
194e5aa2cee69f6791f8001aeb1fc12389863fab8fLorenzo Colittiimport android.content.Context;
204e5aa2cee69f6791f8001aeb1fc12389863fab8fLorenzo Colittiimport android.net.IEthernetManager;
214e5aa2cee69f6791f8001aeb1fc12389863fab8fLorenzo Colittiimport android.net.IpConfiguration;
224e5aa2cee69f6791f8001aeb1fc12389863fab8fLorenzo Colittiimport android.net.IpConfiguration.IpAssignment;
234e5aa2cee69f6791f8001aeb1fc12389863fab8fLorenzo Colittiimport android.net.IpConfiguration.ProxySettings;
244e5aa2cee69f6791f8001aeb1fc12389863fab8fLorenzo Colittiimport android.net.LinkProperties;
254e5aa2cee69f6791f8001aeb1fc12389863fab8fLorenzo Colittiimport android.os.RemoteException;
264e5aa2cee69f6791f8001aeb1fc12389863fab8fLorenzo Colitti
274e5aa2cee69f6791f8001aeb1fc12389863fab8fLorenzo Colitti/**
284e5aa2cee69f6791f8001aeb1fc12389863fab8fLorenzo Colitti * A class representing the IP configuration of the Ethernet network.
294e5aa2cee69f6791f8001aeb1fc12389863fab8fLorenzo Colitti *
304e5aa2cee69f6791f8001aeb1fc12389863fab8fLorenzo Colitti * @hide
314e5aa2cee69f6791f8001aeb1fc12389863fab8fLorenzo Colitti */
324e5aa2cee69f6791f8001aeb1fc12389863fab8fLorenzo Colittipublic class EthernetManager {
334e5aa2cee69f6791f8001aeb1fc12389863fab8fLorenzo Colitti    private static final String TAG = "EthernetManager";
344e5aa2cee69f6791f8001aeb1fc12389863fab8fLorenzo Colitti
354e5aa2cee69f6791f8001aeb1fc12389863fab8fLorenzo Colitti    private final Context mContext;
364e5aa2cee69f6791f8001aeb1fc12389863fab8fLorenzo Colitti    private final IEthernetManager mService;
374e5aa2cee69f6791f8001aeb1fc12389863fab8fLorenzo Colitti
384e5aa2cee69f6791f8001aeb1fc12389863fab8fLorenzo Colitti    /**
394e5aa2cee69f6791f8001aeb1fc12389863fab8fLorenzo Colitti     * Create a new EthernetManager instance.
404e5aa2cee69f6791f8001aeb1fc12389863fab8fLorenzo Colitti     * Applications will almost always want to use
414e5aa2cee69f6791f8001aeb1fc12389863fab8fLorenzo Colitti     * {@link android.content.Context#getSystemService Context.getSystemService()} to retrieve
424e5aa2cee69f6791f8001aeb1fc12389863fab8fLorenzo Colitti     * the standard {@link android.content.Context#ETHERNET_SERVICE Context.ETHERNET_SERVICE}.
434e5aa2cee69f6791f8001aeb1fc12389863fab8fLorenzo Colitti     */
444e5aa2cee69f6791f8001aeb1fc12389863fab8fLorenzo Colitti    public EthernetManager(Context context, IEthernetManager service) {
454e5aa2cee69f6791f8001aeb1fc12389863fab8fLorenzo Colitti        mContext = context;
464e5aa2cee69f6791f8001aeb1fc12389863fab8fLorenzo Colitti        mService = service;
474e5aa2cee69f6791f8001aeb1fc12389863fab8fLorenzo Colitti    }
484e5aa2cee69f6791f8001aeb1fc12389863fab8fLorenzo Colitti
494e5aa2cee69f6791f8001aeb1fc12389863fab8fLorenzo Colitti    /**
504e5aa2cee69f6791f8001aeb1fc12389863fab8fLorenzo Colitti     * Get Ethernet configuration
514e5aa2cee69f6791f8001aeb1fc12389863fab8fLorenzo Colitti     * @return the Ethernet Configuration, contained in {@link IpConfiguration}.
524e5aa2cee69f6791f8001aeb1fc12389863fab8fLorenzo Colitti     */
534e5aa2cee69f6791f8001aeb1fc12389863fab8fLorenzo Colitti    public IpConfiguration getConfiguration() {
544e5aa2cee69f6791f8001aeb1fc12389863fab8fLorenzo Colitti        try {
554e5aa2cee69f6791f8001aeb1fc12389863fab8fLorenzo Colitti            return mService.getConfiguration();
564e5aa2cee69f6791f8001aeb1fc12389863fab8fLorenzo Colitti        } catch (RemoteException e) {
574e5aa2cee69f6791f8001aeb1fc12389863fab8fLorenzo Colitti            return new IpConfiguration(IpAssignment.UNASSIGNED,
584e5aa2cee69f6791f8001aeb1fc12389863fab8fLorenzo Colitti                                       ProxySettings.UNASSIGNED,
594e5aa2cee69f6791f8001aeb1fc12389863fab8fLorenzo Colitti                                       new LinkProperties());
604e5aa2cee69f6791f8001aeb1fc12389863fab8fLorenzo Colitti        }
614e5aa2cee69f6791f8001aeb1fc12389863fab8fLorenzo Colitti    }
624e5aa2cee69f6791f8001aeb1fc12389863fab8fLorenzo Colitti
634e5aa2cee69f6791f8001aeb1fc12389863fab8fLorenzo Colitti    /**
644e5aa2cee69f6791f8001aeb1fc12389863fab8fLorenzo Colitti     * Set Ethernet configuration
654e5aa2cee69f6791f8001aeb1fc12389863fab8fLorenzo Colitti     * @return true if setting success
664e5aa2cee69f6791f8001aeb1fc12389863fab8fLorenzo Colitti     */
674e5aa2cee69f6791f8001aeb1fc12389863fab8fLorenzo Colitti    public void setConfiguration(IpConfiguration config) {
684e5aa2cee69f6791f8001aeb1fc12389863fab8fLorenzo Colitti        try {
694e5aa2cee69f6791f8001aeb1fc12389863fab8fLorenzo Colitti            mService.setConfiguration(config);
704e5aa2cee69f6791f8001aeb1fc12389863fab8fLorenzo Colitti        } catch (RemoteException e) {
714e5aa2cee69f6791f8001aeb1fc12389863fab8fLorenzo Colitti        }
724e5aa2cee69f6791f8001aeb1fc12389863fab8fLorenzo Colitti    }
734e5aa2cee69f6791f8001aeb1fc12389863fab8fLorenzo Colitti}
74