diff options
-rw-r--r-- | core/java/android/provider/Settings.java | 10 | ||||
-rw-r--r-- | core/res/res/values/config.xml | 17 | ||||
-rw-r--r-- | services/java/com/android/server/ThrottleService.java | 86 |
3 files changed, 68 insertions, 45 deletions
diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java index e640005..e8c09b0 100644 --- a/core/java/android/provider/Settings.java +++ b/core/java/android/provider/Settings.java @@ -3306,13 +3306,13 @@ public final class Settings { * The bandwidth throttle threshold (long) * @hide */ - public static final String THROTTLE_THRESHOLD = "throttle_threshold"; + public static final String THROTTLE_THRESHOLD_BYTES = "throttle_threshold_bytes"; /** * The bandwidth throttle value (kbps) * @hide */ - public static final String THROTTLE_VALUE = "throttle_value"; + public static final String THROTTLE_VALUE_KBITSPS = "throttle_value_kbitsps"; /** * The bandwidth throttle reset calendar day (1-28) @@ -3327,12 +3327,6 @@ public final class Settings { public static final String THROTTLE_NOTIFICATION_TYPE = "throttle_notification_type"; /** - * The interface we throttle - * @hide - */ - public static final String THROTTLE_IFACE = "throttle_iface"; - - /** * Help URI for data throttling policy * @hide */ diff --git a/core/res/res/values/config.xml b/core/res/res/values/config.xml index 7ebbab0..64f05fe 100644 --- a/core/res/res/values/config.xml +++ b/core/res/res/values/config.xml @@ -290,4 +290,21 @@ <!-- Boolean indicating if current platform supports bluetooth SCO for off call use cases --> <bool name="config_bluetooth_sco_off_call">true</bool> + + <!-- The default data-use polling period. --> + <integer name="config_datause_polling_period_sec">600</integer> + + <!-- The default data-use threshold in bytes. 0 disables--> + <integer name="config_datause_threshold_bytes">0</integer> + + <!-- The default reduced-datarate value in kilobits per sec --> + <integer name="config_datause_throttle_kbitsps">300</integer> + + <!-- The default iface on which to monitor data use --> + <string name="config_datause_iface">rmnet0</string> + + <!-- The default reduced-datarate notification mask --> + <!-- 2 means give warning --> + <integer name="config_datause_notification_type">2</integer> + </resources> diff --git a/services/java/com/android/server/ThrottleService.java b/services/java/com/android/server/ThrottleService.java index 08b003d..71557f5 100644 --- a/services/java/com/android/server/ThrottleService.java +++ b/services/java/com/android/server/ThrottleService.java @@ -66,23 +66,17 @@ public class ThrottleService extends IThrottleManager.Stub { private Context mContext; - private int mPolicyPollPeriodSec; - private static final int DEFAULT_POLLING_PERIOD_SEC = 60 * 10; private static final int TESTING_POLLING_PERIOD_SEC = 60 * 1; - private static final int TESTING_RESET_PERIOD_SEC = 60 * 3; + private static final long TESTING_THRESHOLD = 1 * 1024 * 1024; private static final int PERIOD_COUNT = 6; + private int mPolicyPollPeriodSec; private long mPolicyThreshold; - // TODO - remove testing stuff? - private static final long DEFAULT_TESTING_THRESHOLD = 1 * 1024 * 1024; - private static final long DEFAULT_THRESHOLD = 0; // off by default - private int mPolicyThrottleValue; - private static final int DEFAULT_THROTTLE_VALUE = 100; // 100 Kbps - private int mPolicyResetDay; // 1-28 + private int mPolicyNotificationsAllowedMask; private long mLastRead; // read byte count from last poll private long mLastWrite; // write byte count from last poll @@ -100,11 +94,10 @@ public class ThrottleService extends IThrottleManager.Stub { private DataRecorder mRecorder; - private String mPolicyIface; + private String mIface; private static final int NOTIFICATION_WARNING = 2; private static final int NOTIFICATION_ALL = 0xFFFFFFFF; - private int mPolicyNotificationsAllowedMask; private Notification mThrottlingNotification; private boolean mWarningNotificationSent = false; @@ -146,16 +139,15 @@ public class ThrottleService extends IThrottleManager.Stub { resolver.registerContentObserver(Settings.Secure.getUriFor( Settings.Secure.THROTTLE_POLLING_SEC), false, this); resolver.registerContentObserver(Settings.Secure.getUriFor( - Settings.Secure.THROTTLE_THRESHOLD), false, this); + Settings.Secure.THROTTLE_THRESHOLD_BYTES), false, this); resolver.registerContentObserver(Settings.Secure.getUriFor( - Settings.Secure.THROTTLE_VALUE), false, this); + Settings.Secure.THROTTLE_VALUE_KBITSPS), false, this); resolver.registerContentObserver(Settings.Secure.getUriFor( Settings.Secure.THROTTLE_RESET_DAY), false, this); resolver.registerContentObserver(Settings.Secure.getUriFor( Settings.Secure.THROTTLE_NOTIFICATION_TYPE), false, this); resolver.registerContentObserver(Settings.Secure.getUriFor( - Settings.Secure.THROTTLE_IFACE), false, this); - // TODO - add help url + Settings.Secure.THROTTLE_HELP_URI), false, this); } @Override @@ -172,18 +164,26 @@ public class ThrottleService extends IThrottleManager.Stub { public synchronized long getResetTime(String iface) { enforceAccessPermission(); - if (iface.equals(mPolicyIface) && (mRecorder != null)) mRecorder.getPeriodEnd(); + if ((iface != null) && + iface.equals(mIface) && + (mRecorder != null)) { + mRecorder.getPeriodEnd(); + } return 0; } public synchronized long getPeriodStartTime(String iface) { enforceAccessPermission(); - if (iface.equals(mPolicyIface) && (mRecorder != null)) mRecorder.getPeriodStart(); + if ((iface != null) && + iface.equals(mIface) && + (mRecorder != null)) { + mRecorder.getPeriodStart(); + } return 0; } //TODO - a better name? getCliffByteCountThreshold? public synchronized long getCliffThreshold(String iface, int cliff) { enforceAccessPermission(); - if ((cliff == 1) && iface.equals(mPolicyIface)) { + if ((iface != null) && (cliff == 1) && iface.equals(mIface)) { return mPolicyThreshold; } return 0; @@ -191,7 +191,7 @@ public class ThrottleService extends IThrottleManager.Stub { // TODO - a better name? getThrottleRate? public synchronized int getCliffLevel(String iface, int cliff) { enforceAccessPermission(); - if ((cliff == 1) && iface.equals(mPolicyIface)) { + if ((iface != null) && (cliff == 1) && iface.equals(mIface)) { return mPolicyThrottleValue; } return 0; @@ -205,7 +205,8 @@ public class ThrottleService extends IThrottleManager.Stub { public synchronized long getByteCount(String iface, int dir, int period, int ago) { enforceAccessPermission(); - if (iface.equals(mPolicyIface) && + if ((iface != null) && + iface.equals(mIface) && (period == ThrottleManager.PERIOD_CYCLE) && (mRecorder != null)) { if (dir == ThrottleManager.DIRECTION_TX) return mRecorder.getPeriodTx(ago); @@ -217,7 +218,7 @@ public class ThrottleService extends IThrottleManager.Stub { // TODO - a better name - getCurrentThrottleRate? public synchronized int getThrottle(String iface) { enforceAccessPermission(); - if (iface.equals(mPolicyIface) && (mThrottleIndex == 1)) { + if ((iface != null) && iface.equals(mIface) && (mThrottleIndex == 1)) { return mPolicyThrottleValue; } return 0; @@ -302,20 +303,27 @@ public class ThrottleService extends IThrottleManager.Stub { private void onPolicyChanged() { boolean testing = SystemProperties.get(TESTING_ENABLED_PROPERTY).equals("true"); - int pollingPeriod = DEFAULT_POLLING_PERIOD_SEC; - if (testing) pollingPeriod = TESTING_POLLING_PERIOD_SEC; + int pollingPeriod = mContext.getResources().getInteger( + com.android.internal.R.integer.config_datause_polling_period_sec); mPolicyPollPeriodSec = Settings.Secure.getInt(mContext.getContentResolver(), Settings.Secure.THROTTLE_POLLING_SEC, pollingPeriod); // TODO - remove testing stuff? - long defaultThreshold = DEFAULT_THRESHOLD; - if (testing) defaultThreshold = DEFAULT_TESTING_THRESHOLD; + long defaultThreshold = mContext.getResources().getInteger( + com.android.internal.R.integer.config_datause_threshold_bytes); + int defaultValue = mContext.getResources().getInteger( + com.android.internal.R.integer.config_datause_throttle_kbitsps); synchronized (ThrottleService.this) { mPolicyThreshold = Settings.Secure.getLong(mContext.getContentResolver(), - Settings.Secure.THROTTLE_THRESHOLD, defaultThreshold); + Settings.Secure.THROTTLE_THRESHOLD_BYTES, defaultThreshold); mPolicyThrottleValue = Settings.Secure.getInt(mContext.getContentResolver(), - Settings.Secure.THROTTLE_VALUE, DEFAULT_THROTTLE_VALUE); + Settings.Secure.THROTTLE_VALUE_KBITSPS, defaultValue); + if (testing) { + mPolicyPollPeriodSec = TESTING_POLLING_PERIOD_SEC; + mPolicyThreshold = TESTING_THRESHOLD; + } } + mPolicyResetDay = Settings.Secure.getInt(mContext.getContentResolver(), Settings.Secure.THROTTLE_RESET_DAY, -1); if (mPolicyResetDay == -1 || @@ -325,15 +333,18 @@ public class ThrottleService extends IThrottleManager.Stub { Settings.Secure.putInt(mContext.getContentResolver(), Settings.Secure.THROTTLE_RESET_DAY, mPolicyResetDay); } + mIface = mContext.getResources().getString( + com.android.internal.R.string.config_datause_iface); synchronized (ThrottleService.this) { - mPolicyIface = Settings.Secure.getString(mContext.getContentResolver(), - Settings.Secure.THROTTLE_IFACE); - // TODO - read default from resource so it's device-specific - if (mPolicyIface == null) mPolicyIface = "rmnet0"; + if (mIface == null) { + mPolicyThreshold = 0; + } } + int defaultNotificationType = mContext.getResources().getInteger( + com.android.internal.R.integer.config_datause_notification_type); mPolicyNotificationsAllowedMask = Settings.Secure.getInt(mContext.getContentResolver(), - Settings.Secure.THROTTLE_NOTIFICATION_TYPE, NOTIFICATION_ALL); + Settings.Secure.THROTTLE_NOTIFICATION_TYPE, defaultNotificationType); Slog.d(TAG, "onPolicyChanged testing=" + testing +", period=" + mPolicyPollPeriodSec + ", threshold=" + mPolicyThreshold + ", value=" + mPolicyThrottleValue + @@ -352,8 +363,8 @@ public class ThrottleService extends IThrottleManager.Stub { long incRead = 0; long incWrite = 0; try { - incRead = mNMService.getInterfaceRxCounter(mPolicyIface) - mLastRead; - incWrite = mNMService.getInterfaceTxCounter(mPolicyIface) - mLastWrite; + incRead = mNMService.getInterfaceRxCounter(mIface) - mLastRead; + incWrite = mNMService.getInterfaceTxCounter(mIface) - mLastWrite; } catch (RemoteException e) { Slog.e(TAG, "got remoteException in onPollAlarm:" + e); } @@ -383,11 +394,12 @@ public class ThrottleService extends IThrottleManager.Stub { broadcast.putExtra(ThrottleManager.EXTRA_CYCLE_END, mRecorder.getPeriodEnd()); mContext.sendStickyBroadcast(broadcast); + mAlarmManager.cancel(mPendingPollIntent); mAlarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, next, mPendingPollIntent); } private void checkThrottleAndPostNotification(long currentTotal) { - // are we even doing this? + // is throttling enabled? if (mPolicyThreshold == 0) return; @@ -399,7 +411,7 @@ public class ThrottleService extends IThrottleManager.Stub { } if (DBG) Slog.d(TAG, "Threshold " + mPolicyThreshold + " exceeded!"); try { - mNMService.setInterfaceThrottle(mPolicyIface, + mNMService.setInterfaceThrottle(mIface, mPolicyThrottleValue, mPolicyThrottleValue); } catch (Exception e) { Slog.e(TAG, "error setting Throttle: " + e); @@ -492,7 +504,7 @@ public class ThrottleService extends IThrottleManager.Stub { mThrottleIndex = THROTTLE_INDEX_UNTHROTTLED; } try { - mNMService.setInterfaceThrottle(mPolicyIface, -1, -1); + mNMService.setInterfaceThrottle(mIface, -1, -1); } catch (Exception e) { Slog.e(TAG, "error clearing Throttle: " + e); } |