FileDocCategorySizeDatePackage
EthernetServiceImpl.javaAPI DocAndroid 5.1 API6624Thu Mar 12 22:22:52 GMT 2015com.android.server.ethernet

EthernetServiceImpl

public class EthernetServiceImpl extends IEthernetManager.Stub
EthernetServiceImpl handles remote Ethernet operation requests by implementing the IEthernetManager interface.
hide

Fields Summary
private static final String
TAG
private final android.content.Context
mContext
private final EthernetConfigStore
mEthernetConfigStore
private final AtomicBoolean
mStarted
private android.net.IpConfiguration
mIpConfiguration
private android.os.Handler
mHandler
private final EthernetNetworkFactory
mTracker
private final android.os.RemoteCallbackList
mListeners
Constructors Summary
public EthernetServiceImpl(android.content.Context context)


       
        mContext = context;
        Log.i(TAG, "Creating EthernetConfigStore");
        mEthernetConfigStore = new EthernetConfigStore();
        mIpConfiguration = mEthernetConfigStore.readIpAndProxyConfigurations();

        Log.i(TAG, "Read stored IP configuration: " + mIpConfiguration);

        mTracker = new EthernetNetworkFactory(mListeners);
    
Methods Summary
public voidaddListener(android.net.IEthernetServiceListener listener)
Addes a listener.

param
listener A {@link IEthernetServiceListener} to add.

        if (listener == null) {
            throw new IllegalArgumentException("listener must not be null");
        }
        enforceAccessPermission();
        mListeners.register(listener);
    
protected voiddump(java.io.FileDescriptor fd, java.io.PrintWriter writer, java.lang.String[] args)

        final IndentingPrintWriter pw = new IndentingPrintWriter(writer, "  ");
        if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
                != PackageManager.PERMISSION_GRANTED) {
            pw.println("Permission Denial: can't dump EthernetService from pid="
                    + Binder.getCallingPid()
                    + ", uid=" + Binder.getCallingUid());
            return;
        }

        pw.println("Current Ethernet state: ");
        pw.increaseIndent();
        mTracker.dump(fd, pw, args);
        pw.decreaseIndent();

        pw.println();
        pw.println("Stored Ethernet configuration: ");
        pw.increaseIndent();
        pw.println(mIpConfiguration);
        pw.decreaseIndent();

        pw.println("Handler:");
        pw.increaseIndent();
        mHandler.dump(new PrintWriterPrinter(pw), "EthernetServiceImpl");
        pw.decreaseIndent();
    
private voidenforceAccessPermission()

        mContext.enforceCallingOrSelfPermission(
                android.Manifest.permission.ACCESS_NETWORK_STATE,
                "EthernetService");
    
private voidenforceChangePermission()

        mContext.enforceCallingOrSelfPermission(
                android.Manifest.permission.CHANGE_NETWORK_STATE,
                "EthernetService");
    
private voidenforceConnectivityInternalPermission()

        mContext.enforceCallingOrSelfPermission(
                android.Manifest.permission.CONNECTIVITY_INTERNAL,
                "ConnectivityService");
    
public android.net.IpConfigurationgetConfiguration()
Get Ethernet configuration

return
the Ethernet Configuration, contained in {@link IpConfiguration}.

        enforceAccessPermission();

        synchronized (mIpConfiguration) {
            return new IpConfiguration(mIpConfiguration);
        }
    
public booleanisAvailable()
Indicates whether the system currently has one or more Ethernet interfaces.

        enforceAccessPermission();
        return mTracker.isTrackingInterface();
    
public voidremoveListener(android.net.IEthernetServiceListener listener)
Removes a listener.

param
listener A {@link IEthernetServiceListener} to remove.

        if (listener == null) {
            throw new IllegalArgumentException("listener must not be null");
        }
        enforceAccessPermission();
        mListeners.unregister(listener);
    
public voidsetConfiguration(android.net.IpConfiguration config)
Set Ethernet configuration

        if (!mStarted.get()) {
            Log.w(TAG, "System isn't ready enough to change ethernet configuration");
        }

        enforceChangePermission();
        enforceConnectivityInternalPermission();

        synchronized (mIpConfiguration) {
            mEthernetConfigStore.writeIpAndProxyConfigurations(config);

            // TODO: this does not check proxy settings, gateways, etc.
            // Fix this by making IpConfiguration a complete representation of static configuration.
            if (!config.equals(mIpConfiguration)) {
                mIpConfiguration = new IpConfiguration(config);
                mTracker.stop();
                mTracker.start(mContext, mHandler);
            }
        }
    
public voidstart()

        Log.i(TAG, "Starting Ethernet service");

        HandlerThread handlerThread = new HandlerThread("EthernetServiceThread");
        handlerThread.start();
        mHandler = new Handler(handlerThread.getLooper());

        mTracker.start(mContext, mHandler);

        mStarted.set(true);