summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeff Sharkey <jsharkey@android.com>2011-06-13 00:14:31 -0700
committerJeff Sharkey <jsharkey@android.com>2011-06-13 00:14:31 -0700
commitaf11d4859582a9736aa204562f0beac5a7d60934 (patch)
tree58231807c7ac38064b124297fb9a4f64b04a2855
parent22c055e6424e0e9579711545d8f4800c0f796db8 (diff)
downloadframeworks_base-af11d4859582a9736aa204562f0beac5a7d60934.zip
frameworks_base-af11d4859582a9736aa204562f0beac5a7d60934.tar.gz
frameworks_base-af11d4859582a9736aa204562f0beac5a7d60934.tar.bz2
Fix test-related build breakage.
Change-Id: I48a3dbbdc49d742d6ad19cff34ee8da4b3949bb8
-rw-r--r--services/java/com/android/server/net/NetworkPolicyManagerService.java45
-rw-r--r--services/tests/servicestests/src/com/android/server/NetworkPolicyManagerServiceTest.java14
2 files changed, 21 insertions, 38 deletions
diff --git a/services/java/com/android/server/net/NetworkPolicyManagerService.java b/services/java/com/android/server/net/NetworkPolicyManagerService.java
index 169fb4b..e7d6063 100644
--- a/services/java/com/android/server/net/NetworkPolicyManagerService.java
+++ b/services/java/com/android/server/net/NetworkPolicyManagerService.java
@@ -55,7 +55,6 @@ import android.os.Environment;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.IPowerManager;
-import android.os.Message;
import android.os.RemoteCallbackList;
import android.os.RemoteException;
import android.telephony.TelephonyManager;
@@ -126,8 +125,6 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
private static final long TIME_CACHE_MAX_AGE = DAY_IN_MILLIS;
- private static final int MSG_RULES_CHANGED = 0x1;
-
private final Context mContext;
private final IActivityManager mActivityManager;
private final IPowerManager mPowerManager;
@@ -186,7 +183,7 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
mHandlerThread = new HandlerThread(TAG);
mHandlerThread.start();
- mHandler = new Handler(mHandlerThread.getLooper(), mHandlerCallback);
+ mHandler = new Handler(mHandlerThread.getLooper());
mPolicyFile = new AtomicFile(new File(systemDir, "netpolicy.xml"));
}
@@ -718,8 +715,17 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
mUidRules.put(uid, uidRules);
// dispatch changed rule to existing listeners
- mHandler.obtainMessage(MSG_RULES_CHANGED, uid, uidRules).sendToTarget();
-
+ final int length = mListeners.beginBroadcast();
+ for (int i = 0; i < length; i++) {
+ final INetworkPolicyListener listener = mListeners.getBroadcastItem(i);
+ if (listener != null) {
+ try {
+ listener.onRulesChanged(uid, uidRules);
+ } catch (RemoteException e) {
+ }
+ }
+ }
+ mListeners.finishBroadcast();
}
private String getActiveSubscriberId() {
@@ -728,33 +734,6 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
return telephony.getSubscriberId();
}
- private Handler.Callback mHandlerCallback = new Handler.Callback() {
- /** {@inheritDoc} */
- public boolean handleMessage(Message msg) {
- switch (msg.what) {
- case MSG_RULES_CHANGED: {
- final int uid = msg.arg1;
- final int uidRules = msg.arg2;
- final int length = mListeners.beginBroadcast();
- for (int i = 0; i < length; i++) {
- final INetworkPolicyListener listener = mListeners.getBroadcastItem(i);
- if (listener != null) {
- try {
- listener.onRulesChanged(uid, uidRules);
- } catch (RemoteException e) {
- }
- }
- }
- mListeners.finishBroadcast();
- return true;
- }
- default: {
- return false;
- }
- }
- }
- };
-
private static void collectKeys(SparseIntArray source, SparseBooleanArray target) {
final int size = source.size();
for (int i = 0; i < size; i++) {
diff --git a/services/tests/servicestests/src/com/android/server/NetworkPolicyManagerServiceTest.java b/services/tests/servicestests/src/com/android/server/NetworkPolicyManagerServiceTest.java
index f831ca3..476aded 100644
--- a/services/tests/servicestests/src/com/android/server/NetworkPolicyManagerServiceTest.java
+++ b/services/tests/servicestests/src/com/android/server/NetworkPolicyManagerServiceTest.java
@@ -297,7 +297,7 @@ public class NetworkPolicyManagerServiceTest extends AndroidTestCase {
final long currentTime = parseTime("2007-11-14T00:00:00.000Z");
final long expectedCycle = parseTime("2007-11-05T00:00:00.000Z");
- final NetworkPolicy policy = new NetworkPolicy(5, 1024L, 1024L);
+ final NetworkPolicy policy = new NetworkPolicy(TEMPLATE_WIFI, null, 5, 1024L, 1024L);
final long actualCycle = computeLastCycleBoundary(currentTime, policy);
assertEquals(expectedCycle, actualCycle);
}
@@ -307,7 +307,7 @@ public class NetworkPolicyManagerServiceTest extends AndroidTestCase {
final long currentTime = parseTime("2007-11-14T00:00:00.000Z");
final long expectedCycle = parseTime("2007-10-20T00:00:00.000Z");
- final NetworkPolicy policy = new NetworkPolicy(20, 1024L, 1024L);
+ final NetworkPolicy policy = new NetworkPolicy(TEMPLATE_WIFI, null, 20, 1024L, 1024L);
final long actualCycle = computeLastCycleBoundary(currentTime, policy);
assertEquals(expectedCycle, actualCycle);
}
@@ -317,7 +317,7 @@ public class NetworkPolicyManagerServiceTest extends AndroidTestCase {
final long currentTime = parseTime("2007-02-14T00:00:00.000Z");
final long expectedCycle = parseTime("2007-01-30T00:00:00.000Z");
- final NetworkPolicy policy = new NetworkPolicy(30, 1024L, 1024L);
+ final NetworkPolicy policy = new NetworkPolicy(TEMPLATE_WIFI, null, 30, 1024L, 1024L);
final long actualCycle = computeLastCycleBoundary(currentTime, policy);
assertEquals(expectedCycle, actualCycle);
}
@@ -327,7 +327,7 @@ public class NetworkPolicyManagerServiceTest extends AndroidTestCase {
final long currentTime = parseTime("2007-03-14T00:00:00.000Z");
final long expectedCycle = parseTime("2007-03-01T00:00:00.000Z");
- final NetworkPolicy policy = new NetworkPolicy(30, 1024L, 1024L);
+ final NetworkPolicy policy = new NetworkPolicy(TEMPLATE_WIFI, null, 30, 1024L, 1024L);
final long actualCycle = computeLastCycleBoundary(currentTime, policy);
assertEquals(expectedCycle, actualCycle);
}
@@ -366,7 +366,7 @@ public class NetworkPolicyManagerServiceTest extends AndroidTestCase {
// TODO: write up NetworkManagementService mock
replay();
- mService.setNetworkPolicy(TEMPLATE_WIFI, null, new NetworkPolicy(CYCLE_DAY, 1024L, 2048L));
+ setNetworkPolicies(new NetworkPolicy(TEMPLATE_WIFI, null, CYCLE_DAY, 1024L, 2048L));
verifyAndReset();
}
@@ -376,6 +376,10 @@ public class NetworkPolicyManagerServiceTest extends AndroidTestCase {
return result.toMillis(true);
}
+ private void setNetworkPolicies(NetworkPolicy... policies) {
+ mService.setNetworkPolicies(policies);
+ }
+
private static NetworkState buildWifi() {
final NetworkInfo info = new NetworkInfo(TYPE_WIFI, 0, null, null);
info.setDetailedState(DetailedState.CONNECTED, null, null);