Add build config values for data use defaults
Don't use hard coded defaults - use build configs instead. Iface is now ONLY set by config so gservices doesn't need to. bug:2576057 Change-Id: I8f9e3bc51af3b1cdf8bb4290a43197d9c01e2a14
This commit is contained in:
@ -3306,13 +3306,13 @@ public final class Settings {
|
|||||||
* The bandwidth throttle threshold (long)
|
* The bandwidth throttle threshold (long)
|
||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
public static final String THROTTLE_THRESHOLD = "throttle_threshold";
|
public static final String THROTTLE_THRESHOLD_BYTES = "throttle_threshold_bytes";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The bandwidth throttle value (kbps)
|
* The bandwidth throttle value (kbps)
|
||||||
* @hide
|
* @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)
|
* The bandwidth throttle reset calendar day (1-28)
|
||||||
@ -3326,12 +3326,6 @@ public final class Settings {
|
|||||||
*/
|
*/
|
||||||
public static final String THROTTLE_NOTIFICATION_TYPE = "throttle_notification_type";
|
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
|
* Help URI for data throttling policy
|
||||||
* @hide
|
* @hide
|
||||||
|
@ -290,4 +290,21 @@
|
|||||||
<!-- Boolean indicating if current platform supports bluetooth SCO for off call
|
<!-- Boolean indicating if current platform supports bluetooth SCO for off call
|
||||||
use cases -->
|
use cases -->
|
||||||
<bool name="config_bluetooth_sco_off_call">true</bool>
|
<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>
|
</resources>
|
||||||
|
@ -66,23 +66,17 @@ public class ThrottleService extends IThrottleManager.Stub {
|
|||||||
|
|
||||||
private Context mContext;
|
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_POLLING_PERIOD_SEC = 60 * 1;
|
||||||
|
|
||||||
private static final int TESTING_RESET_PERIOD_SEC = 60 * 3;
|
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 static final int PERIOD_COUNT = 6;
|
||||||
|
|
||||||
|
private int mPolicyPollPeriodSec;
|
||||||
private long mPolicyThreshold;
|
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 int mPolicyThrottleValue;
|
||||||
private static final int DEFAULT_THROTTLE_VALUE = 100; // 100 Kbps
|
|
||||||
|
|
||||||
private int mPolicyResetDay; // 1-28
|
private int mPolicyResetDay; // 1-28
|
||||||
|
private int mPolicyNotificationsAllowedMask;
|
||||||
|
|
||||||
private long mLastRead; // read byte count from last poll
|
private long mLastRead; // read byte count from last poll
|
||||||
private long mLastWrite; // write 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 DataRecorder mRecorder;
|
||||||
|
|
||||||
private String mPolicyIface;
|
private String mIface;
|
||||||
|
|
||||||
private static final int NOTIFICATION_WARNING = 2;
|
private static final int NOTIFICATION_WARNING = 2;
|
||||||
private static final int NOTIFICATION_ALL = 0xFFFFFFFF;
|
private static final int NOTIFICATION_ALL = 0xFFFFFFFF;
|
||||||
private int mPolicyNotificationsAllowedMask;
|
|
||||||
|
|
||||||
private Notification mThrottlingNotification;
|
private Notification mThrottlingNotification;
|
||||||
private boolean mWarningNotificationSent = false;
|
private boolean mWarningNotificationSent = false;
|
||||||
@ -146,16 +139,15 @@ public class ThrottleService extends IThrottleManager.Stub {
|
|||||||
resolver.registerContentObserver(Settings.Secure.getUriFor(
|
resolver.registerContentObserver(Settings.Secure.getUriFor(
|
||||||
Settings.Secure.THROTTLE_POLLING_SEC), false, this);
|
Settings.Secure.THROTTLE_POLLING_SEC), false, this);
|
||||||
resolver.registerContentObserver(Settings.Secure.getUriFor(
|
resolver.registerContentObserver(Settings.Secure.getUriFor(
|
||||||
Settings.Secure.THROTTLE_THRESHOLD), false, this);
|
Settings.Secure.THROTTLE_THRESHOLD_BYTES), false, this);
|
||||||
resolver.registerContentObserver(Settings.Secure.getUriFor(
|
resolver.registerContentObserver(Settings.Secure.getUriFor(
|
||||||
Settings.Secure.THROTTLE_VALUE), false, this);
|
Settings.Secure.THROTTLE_VALUE_KBITSPS), false, this);
|
||||||
resolver.registerContentObserver(Settings.Secure.getUriFor(
|
resolver.registerContentObserver(Settings.Secure.getUriFor(
|
||||||
Settings.Secure.THROTTLE_RESET_DAY), false, this);
|
Settings.Secure.THROTTLE_RESET_DAY), false, this);
|
||||||
resolver.registerContentObserver(Settings.Secure.getUriFor(
|
resolver.registerContentObserver(Settings.Secure.getUriFor(
|
||||||
Settings.Secure.THROTTLE_NOTIFICATION_TYPE), false, this);
|
Settings.Secure.THROTTLE_NOTIFICATION_TYPE), false, this);
|
||||||
resolver.registerContentObserver(Settings.Secure.getUriFor(
|
resolver.registerContentObserver(Settings.Secure.getUriFor(
|
||||||
Settings.Secure.THROTTLE_IFACE), false, this);
|
Settings.Secure.THROTTLE_HELP_URI), false, this);
|
||||||
// TODO - add help url
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -172,18 +164,26 @@ public class ThrottleService extends IThrottleManager.Stub {
|
|||||||
|
|
||||||
public synchronized long getResetTime(String iface) {
|
public synchronized long getResetTime(String iface) {
|
||||||
enforceAccessPermission();
|
enforceAccessPermission();
|
||||||
if (iface.equals(mPolicyIface) && (mRecorder != null)) mRecorder.getPeriodEnd();
|
if ((iface != null) &&
|
||||||
|
iface.equals(mIface) &&
|
||||||
|
(mRecorder != null)) {
|
||||||
|
mRecorder.getPeriodEnd();
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
public synchronized long getPeriodStartTime(String iface) {
|
public synchronized long getPeriodStartTime(String iface) {
|
||||||
enforceAccessPermission();
|
enforceAccessPermission();
|
||||||
if (iface.equals(mPolicyIface) && (mRecorder != null)) mRecorder.getPeriodStart();
|
if ((iface != null) &&
|
||||||
|
iface.equals(mIface) &&
|
||||||
|
(mRecorder != null)) {
|
||||||
|
mRecorder.getPeriodStart();
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
//TODO - a better name? getCliffByteCountThreshold?
|
//TODO - a better name? getCliffByteCountThreshold?
|
||||||
public synchronized long getCliffThreshold(String iface, int cliff) {
|
public synchronized long getCliffThreshold(String iface, int cliff) {
|
||||||
enforceAccessPermission();
|
enforceAccessPermission();
|
||||||
if ((cliff == 1) && iface.equals(mPolicyIface)) {
|
if ((iface != null) && (cliff == 1) && iface.equals(mIface)) {
|
||||||
return mPolicyThreshold;
|
return mPolicyThreshold;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
@ -191,7 +191,7 @@ public class ThrottleService extends IThrottleManager.Stub {
|
|||||||
// TODO - a better name? getThrottleRate?
|
// TODO - a better name? getThrottleRate?
|
||||||
public synchronized int getCliffLevel(String iface, int cliff) {
|
public synchronized int getCliffLevel(String iface, int cliff) {
|
||||||
enforceAccessPermission();
|
enforceAccessPermission();
|
||||||
if ((cliff == 1) && iface.equals(mPolicyIface)) {
|
if ((iface != null) && (cliff == 1) && iface.equals(mIface)) {
|
||||||
return mPolicyThrottleValue;
|
return mPolicyThrottleValue;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
@ -205,7 +205,8 @@ public class ThrottleService extends IThrottleManager.Stub {
|
|||||||
|
|
||||||
public synchronized long getByteCount(String iface, int dir, int period, int ago) {
|
public synchronized long getByteCount(String iface, int dir, int period, int ago) {
|
||||||
enforceAccessPermission();
|
enforceAccessPermission();
|
||||||
if (iface.equals(mPolicyIface) &&
|
if ((iface != null) &&
|
||||||
|
iface.equals(mIface) &&
|
||||||
(period == ThrottleManager.PERIOD_CYCLE) &&
|
(period == ThrottleManager.PERIOD_CYCLE) &&
|
||||||
(mRecorder != null)) {
|
(mRecorder != null)) {
|
||||||
if (dir == ThrottleManager.DIRECTION_TX) return mRecorder.getPeriodTx(ago);
|
if (dir == ThrottleManager.DIRECTION_TX) return mRecorder.getPeriodTx(ago);
|
||||||
@ -217,7 +218,7 @@ public class ThrottleService extends IThrottleManager.Stub {
|
|||||||
// TODO - a better name - getCurrentThrottleRate?
|
// TODO - a better name - getCurrentThrottleRate?
|
||||||
public synchronized int getThrottle(String iface) {
|
public synchronized int getThrottle(String iface) {
|
||||||
enforceAccessPermission();
|
enforceAccessPermission();
|
||||||
if (iface.equals(mPolicyIface) && (mThrottleIndex == 1)) {
|
if ((iface != null) && iface.equals(mIface) && (mThrottleIndex == 1)) {
|
||||||
return mPolicyThrottleValue;
|
return mPolicyThrottleValue;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
@ -302,20 +303,27 @@ public class ThrottleService extends IThrottleManager.Stub {
|
|||||||
private void onPolicyChanged() {
|
private void onPolicyChanged() {
|
||||||
boolean testing = SystemProperties.get(TESTING_ENABLED_PROPERTY).equals("true");
|
boolean testing = SystemProperties.get(TESTING_ENABLED_PROPERTY).equals("true");
|
||||||
|
|
||||||
int pollingPeriod = DEFAULT_POLLING_PERIOD_SEC;
|
int pollingPeriod = mContext.getResources().getInteger(
|
||||||
if (testing) pollingPeriod = TESTING_POLLING_PERIOD_SEC;
|
com.android.internal.R.integer.config_datause_polling_period_sec);
|
||||||
mPolicyPollPeriodSec = Settings.Secure.getInt(mContext.getContentResolver(),
|
mPolicyPollPeriodSec = Settings.Secure.getInt(mContext.getContentResolver(),
|
||||||
Settings.Secure.THROTTLE_POLLING_SEC, pollingPeriod);
|
Settings.Secure.THROTTLE_POLLING_SEC, pollingPeriod);
|
||||||
|
|
||||||
// TODO - remove testing stuff?
|
// TODO - remove testing stuff?
|
||||||
long defaultThreshold = DEFAULT_THRESHOLD;
|
long defaultThreshold = mContext.getResources().getInteger(
|
||||||
if (testing) defaultThreshold = DEFAULT_TESTING_THRESHOLD;
|
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) {
|
synchronized (ThrottleService.this) {
|
||||||
mPolicyThreshold = Settings.Secure.getLong(mContext.getContentResolver(),
|
mPolicyThreshold = Settings.Secure.getLong(mContext.getContentResolver(),
|
||||||
Settings.Secure.THROTTLE_THRESHOLD, defaultThreshold);
|
Settings.Secure.THROTTLE_THRESHOLD_BYTES, defaultThreshold);
|
||||||
mPolicyThrottleValue = Settings.Secure.getInt(mContext.getContentResolver(),
|
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(),
|
mPolicyResetDay = Settings.Secure.getInt(mContext.getContentResolver(),
|
||||||
Settings.Secure.THROTTLE_RESET_DAY, -1);
|
Settings.Secure.THROTTLE_RESET_DAY, -1);
|
||||||
if (mPolicyResetDay == -1 ||
|
if (mPolicyResetDay == -1 ||
|
||||||
@ -325,15 +333,18 @@ public class ThrottleService extends IThrottleManager.Stub {
|
|||||||
Settings.Secure.putInt(mContext.getContentResolver(),
|
Settings.Secure.putInt(mContext.getContentResolver(),
|
||||||
Settings.Secure.THROTTLE_RESET_DAY, mPolicyResetDay);
|
Settings.Secure.THROTTLE_RESET_DAY, mPolicyResetDay);
|
||||||
}
|
}
|
||||||
|
mIface = mContext.getResources().getString(
|
||||||
|
com.android.internal.R.string.config_datause_iface);
|
||||||
synchronized (ThrottleService.this) {
|
synchronized (ThrottleService.this) {
|
||||||
mPolicyIface = Settings.Secure.getString(mContext.getContentResolver(),
|
if (mIface == null) {
|
||||||
Settings.Secure.THROTTLE_IFACE);
|
mPolicyThreshold = 0;
|
||||||
// TODO - read default from resource so it's device-specific
|
}
|
||||||
if (mPolicyIface == null) mPolicyIface = "rmnet0";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int defaultNotificationType = mContext.getResources().getInteger(
|
||||||
|
com.android.internal.R.integer.config_datause_notification_type);
|
||||||
mPolicyNotificationsAllowedMask = Settings.Secure.getInt(mContext.getContentResolver(),
|
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 +
|
Slog.d(TAG, "onPolicyChanged testing=" + testing +", period=" + mPolicyPollPeriodSec +
|
||||||
", threshold=" + mPolicyThreshold + ", value=" + mPolicyThrottleValue +
|
", threshold=" + mPolicyThreshold + ", value=" + mPolicyThrottleValue +
|
||||||
@ -352,8 +363,8 @@ public class ThrottleService extends IThrottleManager.Stub {
|
|||||||
long incRead = 0;
|
long incRead = 0;
|
||||||
long incWrite = 0;
|
long incWrite = 0;
|
||||||
try {
|
try {
|
||||||
incRead = mNMService.getInterfaceRxCounter(mPolicyIface) - mLastRead;
|
incRead = mNMService.getInterfaceRxCounter(mIface) - mLastRead;
|
||||||
incWrite = mNMService.getInterfaceTxCounter(mPolicyIface) - mLastWrite;
|
incWrite = mNMService.getInterfaceTxCounter(mIface) - mLastWrite;
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
Slog.e(TAG, "got remoteException in onPollAlarm:" + 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());
|
broadcast.putExtra(ThrottleManager.EXTRA_CYCLE_END, mRecorder.getPeriodEnd());
|
||||||
mContext.sendStickyBroadcast(broadcast);
|
mContext.sendStickyBroadcast(broadcast);
|
||||||
|
|
||||||
|
mAlarmManager.cancel(mPendingPollIntent);
|
||||||
mAlarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, next, mPendingPollIntent);
|
mAlarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, next, mPendingPollIntent);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkThrottleAndPostNotification(long currentTotal) {
|
private void checkThrottleAndPostNotification(long currentTotal) {
|
||||||
// are we even doing this?
|
// is throttling enabled?
|
||||||
if (mPolicyThreshold == 0)
|
if (mPolicyThreshold == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -399,7 +411,7 @@ public class ThrottleService extends IThrottleManager.Stub {
|
|||||||
}
|
}
|
||||||
if (DBG) Slog.d(TAG, "Threshold " + mPolicyThreshold + " exceeded!");
|
if (DBG) Slog.d(TAG, "Threshold " + mPolicyThreshold + " exceeded!");
|
||||||
try {
|
try {
|
||||||
mNMService.setInterfaceThrottle(mPolicyIface,
|
mNMService.setInterfaceThrottle(mIface,
|
||||||
mPolicyThrottleValue, mPolicyThrottleValue);
|
mPolicyThrottleValue, mPolicyThrottleValue);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Slog.e(TAG, "error setting Throttle: " + e);
|
Slog.e(TAG, "error setting Throttle: " + e);
|
||||||
@ -492,7 +504,7 @@ public class ThrottleService extends IThrottleManager.Stub {
|
|||||||
mThrottleIndex = THROTTLE_INDEX_UNTHROTTLED;
|
mThrottleIndex = THROTTLE_INDEX_UNTHROTTLED;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
mNMService.setInterfaceThrottle(mPolicyIface, -1, -1);
|
mNMService.setInterfaceThrottle(mIface, -1, -1);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Slog.e(TAG, "error clearing Throttle: " + e);
|
Slog.e(TAG, "error clearing Throttle: " + e);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user