Merge "Removed Throttle Manager as obsolete"
This commit is contained in:
committed by
Android (Google) Code Review
commit
f849124b6b
@@ -123,7 +123,6 @@ LOCAL_SRC_FILES += \
|
|||||||
core/java/android/hardware/usb/IUsbManager.aidl \
|
core/java/android/hardware/usb/IUsbManager.aidl \
|
||||||
core/java/android/net/IConnectivityManager.aidl \
|
core/java/android/net/IConnectivityManager.aidl \
|
||||||
core/java/android/net/INetworkManagementEventObserver.aidl \
|
core/java/android/net/INetworkManagementEventObserver.aidl \
|
||||||
core/java/android/net/IThrottleManager.aidl \
|
|
||||||
core/java/android/net/INetworkPolicyListener.aidl \
|
core/java/android/net/INetworkPolicyListener.aidl \
|
||||||
core/java/android/net/INetworkPolicyManager.aidl \
|
core/java/android/net/INetworkPolicyManager.aidl \
|
||||||
core/java/android/net/INetworkStatsService.aidl \
|
core/java/android/net/INetworkStatsService.aidl \
|
||||||
|
|||||||
@@ -63,8 +63,6 @@ import android.net.ConnectivityManager;
|
|||||||
import android.net.IConnectivityManager;
|
import android.net.IConnectivityManager;
|
||||||
import android.net.INetworkPolicyManager;
|
import android.net.INetworkPolicyManager;
|
||||||
import android.net.NetworkPolicyManager;
|
import android.net.NetworkPolicyManager;
|
||||||
import android.net.ThrottleManager;
|
|
||||||
import android.net.IThrottleManager;
|
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.net.nsd.INsdManager;
|
import android.net.nsd.INsdManager;
|
||||||
import android.net.nsd.NsdManager;
|
import android.net.nsd.NsdManager;
|
||||||
@@ -474,12 +472,6 @@ class ContextImpl extends Context {
|
|||||||
return new TelephonyManager(ctx.getOuterContext());
|
return new TelephonyManager(ctx.getOuterContext());
|
||||||
}});
|
}});
|
||||||
|
|
||||||
registerService(THROTTLE_SERVICE, new StaticServiceFetcher() {
|
|
||||||
public Object createStaticService() {
|
|
||||||
IBinder b = ServiceManager.getService(THROTTLE_SERVICE);
|
|
||||||
return new ThrottleManager(IThrottleManager.Stub.asInterface(b));
|
|
||||||
}});
|
|
||||||
|
|
||||||
registerService(UI_MODE_SERVICE, new ServiceFetcher() {
|
registerService(UI_MODE_SERVICE, new ServiceFetcher() {
|
||||||
public Object createService(ContextImpl ctx) {
|
public Object createService(ContextImpl ctx) {
|
||||||
return new UiModeManager();
|
return new UiModeManager();
|
||||||
|
|||||||
@@ -1991,17 +1991,6 @@ public abstract class Context {
|
|||||||
*/
|
*/
|
||||||
public static final String CONNECTIVITY_SERVICE = "connectivity";
|
public static final String CONNECTIVITY_SERVICE = "connectivity";
|
||||||
|
|
||||||
/**
|
|
||||||
* Use with {@link #getSystemService} to retrieve a {@link
|
|
||||||
* android.net.ThrottleManager} for handling management of
|
|
||||||
* throttling.
|
|
||||||
*
|
|
||||||
* @hide
|
|
||||||
* @see #getSystemService
|
|
||||||
* @see android.net.ThrottleManager
|
|
||||||
*/
|
|
||||||
public static final String THROTTLE_SERVICE = "throttle";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Use with {@link #getSystemService} to retrieve a {@link
|
* Use with {@link #getSystemService} to retrieve a {@link
|
||||||
* android.os.IUpdateLock} for managing runtime sequences that
|
* android.os.IUpdateLock} for managing runtime sequences that
|
||||||
|
|||||||
@@ -1,40 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) 2010, The Android Open Source Project
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package android.net;
|
|
||||||
|
|
||||||
import android.os.IBinder;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Interface that answers queries about data transfer amounts and throttling
|
|
||||||
*/
|
|
||||||
/** {@hide} */
|
|
||||||
interface IThrottleManager
|
|
||||||
{
|
|
||||||
long getByteCount(String iface, int dir, int period, int ago);
|
|
||||||
|
|
||||||
int getThrottle(String iface);
|
|
||||||
|
|
||||||
long getResetTime(String iface);
|
|
||||||
|
|
||||||
long getPeriodStartTime(String iface);
|
|
||||||
|
|
||||||
long getCliffThreshold(String iface, int cliff);
|
|
||||||
|
|
||||||
int getCliffLevel(String iface, int cliff);
|
|
||||||
|
|
||||||
String getHelpUri();
|
|
||||||
}
|
|
||||||
@@ -1,214 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2008 The Android Open Source Project
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package android.net;
|
|
||||||
|
|
||||||
import android.annotation.SdkConstant;
|
|
||||||
import android.annotation.SdkConstant.SdkConstantType;
|
|
||||||
import android.os.Binder;
|
|
||||||
import android.os.RemoteException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Class that handles throttling. It provides read/write numbers per interface
|
|
||||||
* and methods to apply throttled rates.
|
|
||||||
* {@hide}
|
|
||||||
*/
|
|
||||||
public class ThrottleManager
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Broadcast each polling period to indicate new data counts.
|
|
||||||
*
|
|
||||||
* Includes four extras:
|
|
||||||
* EXTRA_CYCLE_READ - a long of the read bytecount for the current cycle
|
|
||||||
* EXTRA_CYCLE_WRITE -a long of the write bytecount for the current cycle
|
|
||||||
* EXTRA_CYLCE_START -a long of MS for the cycle start time
|
|
||||||
* EXTRA_CYCLE_END -a long of MS for the cycle stop time
|
|
||||||
* {@hide}
|
|
||||||
*/
|
|
||||||
public static final String THROTTLE_POLL_ACTION = "android.net.thrott.POLL_ACTION";
|
|
||||||
/**
|
|
||||||
* The lookup key for a long for the read bytecount for this period. Retrieve with
|
|
||||||
* {@link android.content.Intent#getLongExtra(String)}.
|
|
||||||
* {@hide}
|
|
||||||
*/
|
|
||||||
public static final String EXTRA_CYCLE_READ = "cycleRead";
|
|
||||||
/**
|
|
||||||
* contains a long of the number of bytes written in the cycle
|
|
||||||
* {@hide}
|
|
||||||
*/
|
|
||||||
public static final String EXTRA_CYCLE_WRITE = "cycleWrite";
|
|
||||||
/**
|
|
||||||
* contains a long of the number of bytes read in the cycle
|
|
||||||
* {@hide}
|
|
||||||
*/
|
|
||||||
public static final String EXTRA_CYCLE_START = "cycleStart";
|
|
||||||
/**
|
|
||||||
* contains a long of the ms since 1970 used to init a calendar, etc for the end
|
|
||||||
* of the cycle
|
|
||||||
* {@hide}
|
|
||||||
*/
|
|
||||||
public static final String EXTRA_CYCLE_END = "cycleEnd";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Broadcast when the thottle level changes.
|
|
||||||
* {@hide}
|
|
||||||
*/
|
|
||||||
public static final String THROTTLE_ACTION = "android.net.thrott.THROTTLE_ACTION";
|
|
||||||
/**
|
|
||||||
* int of the current bandwidth in TODO
|
|
||||||
* {@hide}
|
|
||||||
*/
|
|
||||||
public static final String EXTRA_THROTTLE_LEVEL = "level";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Broadcast on boot and whenever the settings change.
|
|
||||||
* {@hide}
|
|
||||||
*/
|
|
||||||
public static final String POLICY_CHANGED_ACTION = "android.net.thrott.POLICY_CHANGED_ACTION";
|
|
||||||
|
|
||||||
// {@hide}
|
|
||||||
public static final int DIRECTION_TX = 0;
|
|
||||||
// {@hide}
|
|
||||||
public static final int DIRECTION_RX = 1;
|
|
||||||
|
|
||||||
// {@hide}
|
|
||||||
public static final int PERIOD_CYCLE = 0;
|
|
||||||
// {@hide}
|
|
||||||
public static final int PERIOD_YEAR = 1;
|
|
||||||
// {@hide}
|
|
||||||
public static final int PERIOD_MONTH = 2;
|
|
||||||
// {@hide}
|
|
||||||
public static final int PERIOD_WEEK = 3;
|
|
||||||
// @hide
|
|
||||||
public static final int PERIOD_7DAY = 4;
|
|
||||||
// @hide
|
|
||||||
public static final int PERIOD_DAY = 5;
|
|
||||||
// @hide
|
|
||||||
public static final int PERIOD_24HOUR = 6;
|
|
||||||
// @hide
|
|
||||||
public static final int PERIOD_HOUR = 7;
|
|
||||||
// @hide
|
|
||||||
public static final int PERIOD_60MIN = 8;
|
|
||||||
// @hide
|
|
||||||
public static final int PERIOD_MINUTE = 9;
|
|
||||||
// @hide
|
|
||||||
public static final int PERIOD_60SEC = 10;
|
|
||||||
// @hide
|
|
||||||
public static final int PERIOD_SECOND = 11;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* returns a long of the ms from the epoch to the time the current cycle ends for the
|
|
||||||
* named interface
|
|
||||||
* {@hide}
|
|
||||||
*/
|
|
||||||
public long getResetTime(String iface) {
|
|
||||||
try {
|
|
||||||
return mService.getResetTime(iface);
|
|
||||||
} catch (RemoteException e) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* returns a long of the ms from the epoch to the time the current cycle started for the
|
|
||||||
* named interface
|
|
||||||
* {@hide}
|
|
||||||
*/
|
|
||||||
public long getPeriodStartTime(String iface) {
|
|
||||||
try {
|
|
||||||
return mService.getPeriodStartTime(iface);
|
|
||||||
} catch (RemoteException e) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* returns a long of the byte count either read or written on the named interface
|
|
||||||
* for the period described. Direction is either DIRECTION_RX or DIRECTION_TX and
|
|
||||||
* period may only be PERIOD_CYCLE for the current cycle (other periods may be supported
|
|
||||||
* in the future). Ago indicates the number of periods in the past to lookup - 0 means
|
|
||||||
* the current period, 1 is the last one, 2 was two periods ago..
|
|
||||||
* {@hide}
|
|
||||||
*/
|
|
||||||
public long getByteCount(String iface, int direction, int period, int ago) {
|
|
||||||
try {
|
|
||||||
return mService.getByteCount(iface, direction, period, ago);
|
|
||||||
} catch (RemoteException e) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* returns the number of bytes read+written after which a particular cliff
|
|
||||||
* takes effect on the named iface. Currently only cliff #1 is supported (1 step)
|
|
||||||
* {@hide}
|
|
||||||
*/
|
|
||||||
public long getCliffThreshold(String iface, int cliff) {
|
|
||||||
try {
|
|
||||||
return mService.getCliffThreshold(iface, cliff);
|
|
||||||
} catch (RemoteException e) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* returns the thottling bandwidth (bps) for a given cliff # on the named iface.
|
|
||||||
* only cliff #1 is currently supported.
|
|
||||||
* {@hide}
|
|
||||||
*/
|
|
||||||
public int getCliffLevel(String iface, int cliff) {
|
|
||||||
try {
|
|
||||||
return mService.getCliffLevel(iface, cliff);
|
|
||||||
} catch (RemoteException e) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* returns the help URI for throttling
|
|
||||||
* {@hide}
|
|
||||||
*/
|
|
||||||
public String getHelpUri() {
|
|
||||||
try {
|
|
||||||
return mService.getHelpUri();
|
|
||||||
} catch (RemoteException e) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private IThrottleManager mService;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Don't allow use of default constructor.
|
|
||||||
*/
|
|
||||||
@SuppressWarnings({"UnusedDeclaration"})
|
|
||||||
private ThrottleManager() {
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@hide}
|
|
||||||
*/
|
|
||||||
public ThrottleManager(IThrottleManager service) {
|
|
||||||
if (service == null) {
|
|
||||||
throw new IllegalArgumentException(
|
|
||||||
"ThrottleManager() cannot be constructed with null service");
|
|
||||||
}
|
|
||||||
mService = service;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -305,23 +305,6 @@ interface INetworkManagementService
|
|||||||
*/
|
*/
|
||||||
boolean isBandwidthControlEnabled();
|
boolean isBandwidthControlEnabled();
|
||||||
|
|
||||||
/**
|
|
||||||
* Configures bandwidth throttling on an interface.
|
|
||||||
*/
|
|
||||||
void setInterfaceThrottle(String iface, int rxKbps, int txKbps);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the currently configured RX throttle values
|
|
||||||
* for the specified interface
|
|
||||||
*/
|
|
||||||
int getInterfaceRxThrottle(String iface);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the currently configured TX throttle values
|
|
||||||
* for the specified interface
|
|
||||||
*/
|
|
||||||
int getInterfaceTxThrottle(String iface);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets idletimer for an interface.
|
* Sets idletimer for an interface.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -1344,49 +1344,6 @@ public class NetworkManagementService extends INetworkManagementService.Stub
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setInterfaceThrottle(String iface, int rxKbps, int txKbps) {
|
|
||||||
mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
|
|
||||||
try {
|
|
||||||
mConnector.execute("interface", "setthrottle", iface, rxKbps, txKbps);
|
|
||||||
} catch (NativeDaemonConnectorException e) {
|
|
||||||
throw e.rethrowAsParcelableException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private int getInterfaceThrottle(String iface, boolean rx) {
|
|
||||||
final NativeDaemonEvent event;
|
|
||||||
try {
|
|
||||||
event = mConnector.execute("interface", "getthrottle", iface, rx ? "rx" : "tx");
|
|
||||||
} catch (NativeDaemonConnectorException e) {
|
|
||||||
throw e.rethrowAsParcelableException();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (rx) {
|
|
||||||
event.checkCode(InterfaceRxThrottleResult);
|
|
||||||
} else {
|
|
||||||
event.checkCode(InterfaceTxThrottleResult);
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
return Integer.parseInt(event.getMessage());
|
|
||||||
} catch (NumberFormatException e) {
|
|
||||||
throw new IllegalStateException("unexpected response:" + event);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getInterfaceRxThrottle(String iface) {
|
|
||||||
mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
|
|
||||||
return getInterfaceThrottle(iface, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getInterfaceTxThrottle(String iface) {
|
|
||||||
mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
|
|
||||||
return getInterfaceThrottle(iface, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setDefaultInterfaceForDns(String iface) {
|
public void setDefaultInterfaceForDns(String iface) {
|
||||||
mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
|
mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
|
||||||
|
|||||||
@@ -146,7 +146,6 @@ class ServerThread extends Thread {
|
|||||||
TwilightService twilight = null;
|
TwilightService twilight = null;
|
||||||
UiModeManagerService uiMode = null;
|
UiModeManagerService uiMode = null;
|
||||||
RecognitionManagerService recognition = null;
|
RecognitionManagerService recognition = null;
|
||||||
ThrottleService throttle = null;
|
|
||||||
NetworkTimeUpdateService networkTimeUpdater = null;
|
NetworkTimeUpdateService networkTimeUpdater = null;
|
||||||
CommonTimeManagementService commonTimeMgmtService = null;
|
CommonTimeManagementService commonTimeMgmtService = null;
|
||||||
InputManagerService inputManager = null;
|
InputManagerService inputManager = null;
|
||||||
@@ -510,15 +509,6 @@ class ServerThread extends Thread {
|
|||||||
reportWtf("starting Service Discovery Service", e);
|
reportWtf("starting Service Discovery Service", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
|
||||||
Slog.i(TAG, "Throttle Service");
|
|
||||||
throttle = new ThrottleService(context);
|
|
||||||
ServiceManager.addService(
|
|
||||||
Context.THROTTLE_SERVICE, throttle);
|
|
||||||
} catch (Throwable e) {
|
|
||||||
reportWtf("starting ThrottleService", e);
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Slog.i(TAG, "UpdateLock Service");
|
Slog.i(TAG, "UpdateLock Service");
|
||||||
ServiceManager.addService(Context.UPDATE_LOCK_SERVICE,
|
ServiceManager.addService(Context.UPDATE_LOCK_SERVICE,
|
||||||
@@ -839,7 +829,6 @@ class ServerThread extends Thread {
|
|||||||
final ConnectivityService connectivityF = connectivity;
|
final ConnectivityService connectivityF = connectivity;
|
||||||
final DockObserver dockF = dock;
|
final DockObserver dockF = dock;
|
||||||
final UsbService usbF = usb;
|
final UsbService usbF = usb;
|
||||||
final ThrottleService throttleF = throttle;
|
|
||||||
final TwilightService twilightF = twilight;
|
final TwilightService twilightF = twilight;
|
||||||
final UiModeManagerService uiModeF = uiMode;
|
final UiModeManagerService uiModeF = uiMode;
|
||||||
final AppWidgetService appWidgetF = appWidget;
|
final AppWidgetService appWidgetF = appWidget;
|
||||||
@@ -951,11 +940,6 @@ class ServerThread extends Thread {
|
|||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
reportWtf("making Country Detector Service ready", e);
|
reportWtf("making Country Detector Service ready", e);
|
||||||
}
|
}
|
||||||
try {
|
|
||||||
if (throttleF != null) throttleF.systemReady();
|
|
||||||
} catch (Throwable e) {
|
|
||||||
reportWtf("making Throttle Service ready", e);
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
if (networkTimeUpdaterF != null) networkTimeUpdaterF.systemReady();
|
if (networkTimeUpdaterF != null) networkTimeUpdaterF.systemReady();
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -1,353 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2011 The Android Open Source Project
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.android.server;
|
|
||||||
|
|
||||||
import static android.net.NetworkStats.SET_DEFAULT;
|
|
||||||
import static android.net.NetworkStats.TAG_NONE;
|
|
||||||
import static android.net.NetworkStats.UID_ALL;
|
|
||||||
import static org.easymock.EasyMock.createMock;
|
|
||||||
import static org.easymock.EasyMock.eq;
|
|
||||||
import static org.easymock.EasyMock.expect;
|
|
||||||
import static org.easymock.EasyMock.expectLastCall;
|
|
||||||
import static org.easymock.EasyMock.isA;
|
|
||||||
import static org.easymock.EasyMock.replay;
|
|
||||||
import static org.easymock.EasyMock.reset;
|
|
||||||
import static org.easymock.EasyMock.verify;
|
|
||||||
|
|
||||||
import android.content.ContentResolver;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.net.INetworkManagementEventObserver;
|
|
||||||
import android.net.NetworkStats;
|
|
||||||
import android.net.ThrottleManager;
|
|
||||||
import android.os.IBinder;
|
|
||||||
import android.os.INetworkManagementService;
|
|
||||||
import android.os.ServiceManager;
|
|
||||||
import android.os.SystemClock;
|
|
||||||
import android.provider.Settings;
|
|
||||||
import android.test.AndroidTestCase;
|
|
||||||
import android.test.suitebuilder.annotation.LargeTest;
|
|
||||||
import android.test.suitebuilder.annotation.Suppress;
|
|
||||||
import android.text.format.DateUtils;
|
|
||||||
import android.util.Log;
|
|
||||||
import android.util.TrustedTime;
|
|
||||||
|
|
||||||
import java.util.concurrent.Future;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests for {@link ThrottleService}.
|
|
||||||
*/
|
|
||||||
@LargeTest
|
|
||||||
public class ThrottleServiceTest extends AndroidTestCase {
|
|
||||||
private static final String TAG = "ThrottleServiceTest";
|
|
||||||
|
|
||||||
private static final long MB_IN_BYTES = 1024 * 1024;
|
|
||||||
|
|
||||||
private static final int TEST_KBITPS = 222;
|
|
||||||
private static final int TEST_RESET_DAY = 11;
|
|
||||||
|
|
||||||
private static final String TEST_IFACE = "test0";
|
|
||||||
|
|
||||||
private BroadcastInterceptingContext mWatchingContext;
|
|
||||||
private INetworkManagementService mMockNMService;
|
|
||||||
private TrustedTime mMockTime;
|
|
||||||
|
|
||||||
private ThrottleService mThrottleService;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setUp() throws Exception {
|
|
||||||
super.setUp();
|
|
||||||
|
|
||||||
mWatchingContext = new BroadcastInterceptingContext(getContext());
|
|
||||||
|
|
||||||
mMockNMService = createMock(INetworkManagementService.class);
|
|
||||||
mMockTime = createMock(TrustedTime.class);
|
|
||||||
|
|
||||||
mThrottleService = new ThrottleService(
|
|
||||||
mWatchingContext, mMockNMService, mMockTime, TEST_IFACE);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void tearDown() throws Exception {
|
|
||||||
mWatchingContext = null;
|
|
||||||
mMockNMService = null;
|
|
||||||
|
|
||||||
mThrottleService.shutdown();
|
|
||||||
mThrottleService = null;
|
|
||||||
|
|
||||||
clearThrottlePolicy();
|
|
||||||
|
|
||||||
super.tearDown();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testNoPolicyNotThrottled() throws Exception {
|
|
||||||
expectTimeCurrent();
|
|
||||||
expectSystemReady();
|
|
||||||
|
|
||||||
// provide stats without policy, verify not throttled
|
|
||||||
expectGetInterfaceCounter(1 * MB_IN_BYTES, 2 * MB_IN_BYTES);
|
|
||||||
expectSetInterfaceThrottle(-1, -1);
|
|
||||||
|
|
||||||
replay(mMockTime, mMockNMService);
|
|
||||||
systemReady();
|
|
||||||
verify(mMockTime, mMockNMService);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testUnderLimitNotThrottled() throws Exception {
|
|
||||||
setThrottlePolicy(200 * MB_IN_BYTES, TEST_KBITPS, TEST_RESET_DAY);
|
|
||||||
|
|
||||||
expectTimeCurrent();
|
|
||||||
expectSystemReady();
|
|
||||||
|
|
||||||
// provide stats under limits, and verify not throttled
|
|
||||||
expectGetInterfaceCounter(1 * MB_IN_BYTES, 2 * MB_IN_BYTES);
|
|
||||||
expectSetInterfaceThrottle(-1, -1);
|
|
||||||
|
|
||||||
replay(mMockTime, mMockNMService);
|
|
||||||
systemReady();
|
|
||||||
verify(mMockTime, mMockNMService);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testOverLimitThrottled() throws Exception {
|
|
||||||
setThrottlePolicy(200 * MB_IN_BYTES, TEST_KBITPS, TEST_RESET_DAY);
|
|
||||||
|
|
||||||
expectTimeCurrent();
|
|
||||||
expectSystemReady();
|
|
||||||
|
|
||||||
// provide stats over limits, and verify throttled
|
|
||||||
expectGetInterfaceCounter(500 * MB_IN_BYTES, 600 * MB_IN_BYTES);
|
|
||||||
expectSetInterfaceThrottle(TEST_KBITPS, TEST_KBITPS);
|
|
||||||
|
|
||||||
replay(mMockTime, mMockNMService);
|
|
||||||
systemReady();
|
|
||||||
verify(mMockTime, mMockNMService);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testUnderThenOverLimitThrottled() throws Exception {
|
|
||||||
setThrottlePolicy(201 * MB_IN_BYTES, TEST_KBITPS, TEST_RESET_DAY);
|
|
||||||
|
|
||||||
expectTimeCurrent();
|
|
||||||
expectSystemReady();
|
|
||||||
|
|
||||||
// provide stats right under 201MB limit, verify not throttled
|
|
||||||
expectGetInterfaceCounter(100 * MB_IN_BYTES, 100 * MB_IN_BYTES);
|
|
||||||
expectSetInterfaceThrottle(-1, -1);
|
|
||||||
|
|
||||||
replay(mMockTime, mMockNMService);
|
|
||||||
systemReady();
|
|
||||||
verify(mMockTime, mMockNMService);
|
|
||||||
reset(mMockTime, mMockNMService);
|
|
||||||
|
|
||||||
expectTimeCurrent();
|
|
||||||
|
|
||||||
// adjust usage to bump over limit, verify throttle kicks in
|
|
||||||
expectGetInterfaceCounter(105 * MB_IN_BYTES, 100 * MB_IN_BYTES);
|
|
||||||
expectSetInterfaceThrottle(TEST_KBITPS, TEST_KBITPS);
|
|
||||||
|
|
||||||
// and kick poll event which should throttle
|
|
||||||
replay(mMockTime, mMockNMService);
|
|
||||||
forceServicePoll();
|
|
||||||
verify(mMockTime, mMockNMService);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testUpdatedPolicyThrottled() throws Exception {
|
|
||||||
setThrottlePolicy(500 * MB_IN_BYTES, TEST_KBITPS, TEST_RESET_DAY);
|
|
||||||
|
|
||||||
expectTimeCurrent();
|
|
||||||
expectSystemReady();
|
|
||||||
|
|
||||||
// provide stats under limit, verify not throttled
|
|
||||||
expectGetInterfaceCounter(50 * MB_IN_BYTES, 50 * MB_IN_BYTES);
|
|
||||||
expectSetInterfaceThrottle(-1, -1);
|
|
||||||
|
|
||||||
replay(mMockTime, mMockNMService);
|
|
||||||
systemReady();
|
|
||||||
verify(mMockTime, mMockNMService);
|
|
||||||
reset(mMockTime, mMockNMService);
|
|
||||||
|
|
||||||
expectTimeCurrent();
|
|
||||||
|
|
||||||
// provide same stats, but verify that modified policy will throttle
|
|
||||||
expectGetInterfaceCounter(50 * MB_IN_BYTES, 50 * MB_IN_BYTES);
|
|
||||||
expectSetInterfaceThrottle(TEST_KBITPS, TEST_KBITPS);
|
|
||||||
|
|
||||||
replay(mMockTime, mMockNMService);
|
|
||||||
|
|
||||||
// now adjust policy to bump usage over limit
|
|
||||||
setThrottlePolicy(5 * MB_IN_BYTES, TEST_KBITPS, TEST_RESET_DAY);
|
|
||||||
|
|
||||||
// and wait for policy updated broadcast
|
|
||||||
mWatchingContext.nextBroadcastIntent(ThrottleManager.POLICY_CHANGED_ACTION).get();
|
|
||||||
|
|
||||||
verify(mMockTime, mMockNMService);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testWithPolicyOverLimitThrottledAndRemovedAfterCycle() throws Exception {
|
|
||||||
setThrottlePolicy(90 * MB_IN_BYTES, TEST_KBITPS, TEST_RESET_DAY);
|
|
||||||
|
|
||||||
final long baseTime = System.currentTimeMillis();
|
|
||||||
|
|
||||||
expectTime(baseTime);
|
|
||||||
expectSystemReady();
|
|
||||||
|
|
||||||
// provide stats over limit, verify throttle kicks in
|
|
||||||
expectGetInterfaceCounter(50 * MB_IN_BYTES, 50 * MB_IN_BYTES);
|
|
||||||
expectSetInterfaceThrottle(TEST_KBITPS, TEST_KBITPS);
|
|
||||||
|
|
||||||
replay(mMockTime, mMockNMService);
|
|
||||||
systemReady();
|
|
||||||
verify(mMockTime, mMockNMService);
|
|
||||||
reset(mMockTime, mMockNMService);
|
|
||||||
|
|
||||||
// pretend that time has jumped forward two months
|
|
||||||
expectTime(baseTime + DateUtils.WEEK_IN_MILLIS * 8);
|
|
||||||
|
|
||||||
// provide slightly updated stats, but verify throttle is removed
|
|
||||||
expectGetInterfaceCounter(60 * MB_IN_BYTES, 60 * MB_IN_BYTES);
|
|
||||||
expectSetInterfaceThrottle(-1, -1);
|
|
||||||
|
|
||||||
// and kick poll event which should throttle
|
|
||||||
replay(mMockTime, mMockNMService);
|
|
||||||
forceServiceReset();
|
|
||||||
verify(mMockTime, mMockNMService);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Suppress
|
|
||||||
public void testReturnStats() throws Exception {
|
|
||||||
final IBinder b = ServiceManager.getService(Context.NETWORKMANAGEMENT_SERVICE);
|
|
||||||
final INetworkManagementService nmService = INetworkManagementService.Stub.asInterface(b);
|
|
||||||
|
|
||||||
// test is currently no-op, just exercises stats apis
|
|
||||||
Log.d(TAG, nmService.getNetworkStatsSummaryDev().toString());
|
|
||||||
Log.d(TAG, nmService.getNetworkStatsSummaryXt().toString());
|
|
||||||
Log.d(TAG, nmService.getNetworkStatsDetail().toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Persist the given {@link ThrottleService} policy into {@link Settings}.
|
|
||||||
*/
|
|
||||||
public void setThrottlePolicy(long thresholdBytes, int valueKbitps, int resetDay) {
|
|
||||||
final ContentResolver resolver = getContext().getContentResolver();
|
|
||||||
Settings.Global.putLong(resolver, Settings.Global.THROTTLE_THRESHOLD_BYTES, thresholdBytes);
|
|
||||||
Settings.Global.putInt(resolver, Settings.Global.THROTTLE_VALUE_KBITSPS, valueKbitps);
|
|
||||||
Settings.Global.putInt(resolver, Settings.Global.THROTTLE_RESET_DAY, resetDay);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Clear any {@link ThrottleService} policy from {@link Settings}.
|
|
||||||
*/
|
|
||||||
public void clearThrottlePolicy() {
|
|
||||||
final ContentResolver resolver = getContext().getContentResolver();
|
|
||||||
Settings.Global.putString(resolver, Settings.Global.THROTTLE_THRESHOLD_BYTES, null);
|
|
||||||
Settings.Global.putString(resolver, Settings.Global.THROTTLE_VALUE_KBITSPS, null);
|
|
||||||
Settings.Global.putString(resolver, Settings.Global.THROTTLE_RESET_DAY, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Expect any {@link TrustedTime} mock calls, and respond with
|
|
||||||
* {@link System#currentTimeMillis()}.
|
|
||||||
*/
|
|
||||||
public void expectTimeCurrent() throws Exception {
|
|
||||||
expectTime(System.currentTimeMillis());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Expect any {@link TrustedTime} mock calls, and respond with the given
|
|
||||||
* time in response to {@link TrustedTime#currentTimeMillis()}.
|
|
||||||
*/
|
|
||||||
public void expectTime(long currentTime) throws Exception {
|
|
||||||
expect(mMockTime.forceRefresh()).andReturn(false).anyTimes();
|
|
||||||
expect(mMockTime.hasCache()).andReturn(true).anyTimes();
|
|
||||||
expect(mMockTime.currentTimeMillis()).andReturn(currentTime).anyTimes();
|
|
||||||
expect(mMockTime.getCacheAge()).andReturn(0L).anyTimes();
|
|
||||||
expect(mMockTime.getCacheCertainty()).andReturn(0L).anyTimes();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Expect {@link ThrottleService#systemReady()} generated calls, such as
|
|
||||||
* connecting with {@link NetworkManagementService} mock.
|
|
||||||
*/
|
|
||||||
public void expectSystemReady() throws Exception {
|
|
||||||
mMockNMService.registerObserver(isA(INetworkManagementEventObserver.class));
|
|
||||||
expectLastCall().atLeastOnce();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Expect {@link NetworkManagementService#getNetworkStatsSummaryDev()} mock
|
|
||||||
* calls, responding with the given counter values.
|
|
||||||
*/
|
|
||||||
public void expectGetInterfaceCounter(long rx, long tx) throws Exception {
|
|
||||||
// TODO: provide elapsedRealtime mock to match TimeAuthority
|
|
||||||
final NetworkStats stats = new NetworkStats(SystemClock.elapsedRealtime(), 1);
|
|
||||||
stats.addValues(TEST_IFACE, UID_ALL, SET_DEFAULT, TAG_NONE, rx, 0L, tx, 0L, 0);
|
|
||||||
|
|
||||||
expect(mMockNMService.getNetworkStatsSummaryDev()).andReturn(stats).atLeastOnce();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Expect {@link NetworkManagementService#setInterfaceThrottle} mock call
|
|
||||||
* with the specified parameters.
|
|
||||||
*/
|
|
||||||
public void expectSetInterfaceThrottle(int rx, int tx) throws Exception {
|
|
||||||
mMockNMService.setInterfaceThrottle(isA(String.class), eq(rx), eq(tx));
|
|
||||||
expectLastCall().atLeastOnce();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Dispatch {@link ThrottleService#systemReady()} and block until finished.
|
|
||||||
*/
|
|
||||||
public void systemReady() throws Exception {
|
|
||||||
final Future<Intent> policyChanged = mWatchingContext.nextBroadcastIntent(
|
|
||||||
ThrottleManager.POLICY_CHANGED_ACTION);
|
|
||||||
final Future<Intent> pollAction = mWatchingContext.nextBroadcastIntent(
|
|
||||||
ThrottleManager.THROTTLE_POLL_ACTION);
|
|
||||||
|
|
||||||
mThrottleService.systemReady();
|
|
||||||
|
|
||||||
// wait for everything to settle; for policy to update and for first poll
|
|
||||||
policyChanged.get();
|
|
||||||
pollAction.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Dispatch {@link ThrottleService#dispatchPoll()} and block until finished.
|
|
||||||
*/
|
|
||||||
public void forceServicePoll() throws Exception {
|
|
||||||
// during systemReady() service already pushed a sticky broadcast, so we
|
|
||||||
// need to skip the immediate and wait for the updated sticky.
|
|
||||||
final Future<Intent> pollAction = mWatchingContext.nextBroadcastIntent(
|
|
||||||
ThrottleManager.THROTTLE_POLL_ACTION);
|
|
||||||
|
|
||||||
mThrottleService.dispatchPoll();
|
|
||||||
|
|
||||||
pollAction.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Dispatch {@link ThrottleService#dispatchReset()} and block until finished.
|
|
||||||
*/
|
|
||||||
public void forceServiceReset() throws Exception {
|
|
||||||
// during systemReady() service already pushed a sticky broadcast, so we
|
|
||||||
// need to skip the immediate and wait for the updated sticky.
|
|
||||||
final Future<Intent> pollAction = mWatchingContext.nextBroadcastIntent(
|
|
||||||
ThrottleManager.THROTTLE_POLL_ACTION);
|
|
||||||
|
|
||||||
mThrottleService.dispatchReset();
|
|
||||||
|
|
||||||
pollAction.get();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user