Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f226bc60 authored by Lorenzo Colitti's avatar Lorenzo Colitti Committed by Gerrit Code Review
Browse files

Merge "Use LinkAddress in address notifications."

parents 9e6d8f04 5ad421a3
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package android.net;

import android.net.LinkAddress;

/**
 * Callback class for receiving events from an INetworkManagementService
 *
@@ -62,7 +64,7 @@ interface INetworkManagementEventObserver {
     * @param flags The address flags.
     * @param scope The address scope.
     */
    void addressUpdated(String address, String iface, int flags, int scope);
    void addressUpdated(in LinkAddress address, String iface, int flags, int scope);

    /**
     * An interface address has been removed
@@ -72,7 +74,7 @@ interface INetworkManagementEventObserver {
     * @param flags The address flags.
     * @param scope The address scope.
     */
    void addressRemoved(String address, String iface, int flags, int scope);
    void addressRemoved(in LinkAddress address, String iface, int flags, int scope);

    /**
     * A networking quota limit has been reached. The quota might not
+3 −2
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.server.net;

import android.net.INetworkManagementEventObserver;
import android.net.LinkAddress;

/**
 * Base {@link INetworkManagementEventObserver} that provides no-op
@@ -36,12 +37,12 @@ public class BaseNetworkObserver extends INetworkManagementEventObserver.Stub {
    }

    @Override
    public void addressUpdated(String address, String iface, int flags, int scope) {
    public void addressUpdated(LinkAddress address, String iface, int flags, int scope) {
        // default no-op
    }

    @Override
    public void addressRemoved(String address, String iface, int flags, int scope) {
    public void addressRemoved(LinkAddress address, String iface, int flags, int scope) {
        // default no-op
    }

+10 −6
Original line number Diff line number Diff line
@@ -405,7 +405,7 @@ public class NetworkManagementService extends INetworkManagementService.Stub
    /**
     * Notify our observers of a new or updated interface address.
     */
    private void notifyAddressUpdated(String address, String iface, int flags, int scope) {
    private void notifyAddressUpdated(LinkAddress address, String iface, int flags, int scope) {
        final int length = mObservers.beginBroadcast();
        for (int i = 0; i < length; i++) {
            try {
@@ -420,7 +420,7 @@ public class NetworkManagementService extends INetworkManagementService.Stub
    /**
     * Notify our observers of a deleted interface address.
     */
    private void notifyAddressRemoved(String address, String iface, int flags, int scope) {
    private void notifyAddressRemoved(LinkAddress address, String iface, int flags, int scope) {
        final int length = mObservers.beginBroadcast();
        for (int i = 0; i < length; i++) {
            try {
@@ -537,17 +537,21 @@ public class NetworkManagementService extends INetworkManagementService.Stub

                    int flags;
                    int scope;
                    LinkAddress address;
                    try {
                        flags = Integer.parseInt(cooked[5]);
                        scope = Integer.parseInt(cooked[6]);
                    } catch(NumberFormatException e) {
                        throw new IllegalStateException(errorMessage);
                        address = new LinkAddress(cooked[3]);
                    } catch(NumberFormatException e) {     // Non-numeric lifetime or scope.
                        throw new IllegalStateException(errorMessage, e);
                    } catch(IllegalArgumentException e) {  // Malformed IP address.
                        throw new IllegalStateException(errorMessage, e);
                    }

                    if (cooked[2].equals("updated")) {
                        notifyAddressUpdated(cooked[3], cooked[4], flags, scope);
                        notifyAddressUpdated(address, cooked[4], flags, scope);
                    } else {
                        notifyAddressRemoved(cooked[3], cooked[4], flags, scope);
                        notifyAddressRemoved(address, cooked[4], flags, scope);
                    }
                    return true;
                    // break;
+9 −5
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.server;

import android.content.Context;
import android.net.LinkAddress;
import android.net.LocalSocket;
import android.net.LocalServerSocket;
import android.os.Binder;
@@ -157,19 +158,22 @@ public class NetworkManagementServiceTest extends AndroidTestCase {
         * IP address changes.
         */
        sendMessage("614 Address updated fe80::1/64 wlan0 128 253");
        expectSoon(observer).addressUpdated("fe80::1/64", "wlan0", 128, 253);
        expectSoon(observer).addressUpdated(
                new LinkAddress("fe80::1/64"), "wlan0", 128, 253);

        // There is no "added".
        // There is no "added", so we take this as "removed".
        sendMessage("614 Address added fe80::1/64 wlan0 128 253");
        expectSoon(observer).addressRemoved("fe80::1/64", "wlan0", 128, 253);
        expectSoon(observer).addressRemoved(
                new LinkAddress("fe80::1/64"), "wlan0", 128, 253);

        sendMessage("614 Address removed 2001:db8::1/64 wlan0 1 0");
        expectSoon(observer).addressRemoved("2001:db8::1/64", "wlan0", 1, 0);
        expectSoon(observer).addressRemoved(
                new LinkAddress("2001:db8::1/64"), "wlan0", 1, 0);

        sendMessage("614 Address removed 2001:db8::1/64 wlan0 1");
        // Not enough arguments.

        sendMessage("666 Address added 2001:db8::1/64 wlan0 1 0");
        sendMessage("666 Address removed 2001:db8::1/64 wlan0 1 0");
        // Invalid code.


+4 −4
Original line number Diff line number Diff line
@@ -240,24 +240,24 @@ public class WifiStateMachine extends StateMachine {
        }

        @Override
        public void addressUpdated(String address, String iface, int flags, int scope) {
        public void addressUpdated(LinkAddress address, String iface, int flags, int scope) {
            if (mWifiStateMachine.mInterfaceName.equals(iface)) {
                if (DBG) {
                    log("addressUpdated: " + address + " on " + iface +
                        " flags " + flags + " scope " + scope);
                }
                mWifiStateMachine.sendMessage(CMD_IP_ADDRESS_UPDATED, new LinkAddress(address));
                mWifiStateMachine.sendMessage(CMD_IP_ADDRESS_UPDATED, address);
            }
        }

        @Override
        public void addressRemoved(String address, String iface, int flags, int scope) {
        public void addressRemoved(LinkAddress address, String iface, int flags, int scope) {
            if (mWifiStateMachine.mInterfaceName.equals(iface)) {
                if (DBG) {
                    log("addressRemoved: " + address + " on " + iface +
                        " flags " + flags + " scope " + scope);
                }
                mWifiStateMachine.sendMessage(CMD_IP_ADDRESS_REMOVED, new LinkAddress(address));
                mWifiStateMachine.sendMessage(CMD_IP_ADDRESS_REMOVED, address);
            }
        }
    }