am f226bc60: Merge "Use LinkAddress in address notifications."

* commit 'f226bc606af9ce5aceff6b05fc4b0200c94cb248':
  Use LinkAddress in address notifications.
This commit is contained in:
Lorenzo Colitti
2013-11-26 17:56:45 -08:00
committed by Android Git Automerger
5 changed files with 30 additions and 19 deletions

View File

@ -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

View File

@ -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
}

View File

@ -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;

View File

@ -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.

View File

@ -242,24 +242,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);
}
}
}