DO NOT MERGE IpConnectivityMetrics reads buffer size in settings
am: ff0b58627f
Change-Id: I5c433faa0d43202ae1169fdba4c42c09dd9c17dd
This commit is contained in:
@@ -7178,6 +7178,13 @@ public final class Settings {
|
|||||||
*/
|
*/
|
||||||
public static final String MOBILE_DATA_ALWAYS_ON = "mobile_data_always_on";
|
public static final String MOBILE_DATA_ALWAYS_ON = "mobile_data_always_on";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Size of the event buffer for IP connectivity metrics.
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
public static final String CONNECTIVITY_METRICS_BUFFER_SIZE =
|
||||||
|
"connectivity_metrics_buffer_size";
|
||||||
|
|
||||||
/** {@hide} */
|
/** {@hide} */
|
||||||
public static final String NETSTATS_ENABLED = "netstats_enabled";
|
public static final String NETSTATS_ENABLED = "netstats_enabled";
|
||||||
/** {@hide} */
|
/** {@hide} */
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import android.net.IIpConnectivityMetrics;
|
|||||||
import android.net.metrics.IpConnectivityLog;
|
import android.net.metrics.IpConnectivityLog;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
|
import android.provider.Settings;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Base64;
|
import android.util.Base64;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
@@ -32,6 +33,7 @@ import java.io.FileDescriptor;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.function.ToIntFunction;
|
||||||
|
|
||||||
import static com.android.server.connectivity.metrics.IpConnectivityLogClass.IpConnectivityEvent;
|
import static com.android.server.connectivity.metrics.IpConnectivityLogClass.IpConnectivityEvent;
|
||||||
|
|
||||||
@@ -51,6 +53,8 @@ final public class IpConnectivityMetrics extends SystemService {
|
|||||||
|
|
||||||
// Default size of the event buffer. Once the buffer is full, incoming events are dropped.
|
// Default size of the event buffer. Once the buffer is full, incoming events are dropped.
|
||||||
private static final int DEFAULT_BUFFER_SIZE = 2000;
|
private static final int DEFAULT_BUFFER_SIZE = 2000;
|
||||||
|
// Maximum size of the event buffer.
|
||||||
|
private static final int MAXIMUM_BUFFER_SIZE = DEFAULT_BUFFER_SIZE * 10;
|
||||||
|
|
||||||
// Lock ensuring that concurrent manipulations of the event buffer are correct.
|
// Lock ensuring that concurrent manipulations of the event buffer are correct.
|
||||||
// There are three concurrent operations to synchronize:
|
// There are three concurrent operations to synchronize:
|
||||||
@@ -70,11 +74,18 @@ final public class IpConnectivityMetrics extends SystemService {
|
|||||||
@GuardedBy("mLock")
|
@GuardedBy("mLock")
|
||||||
private int mCapacity;
|
private int mCapacity;
|
||||||
|
|
||||||
public IpConnectivityMetrics(Context ctx) {
|
private final ToIntFunction<Context> mCapacityGetter;
|
||||||
|
|
||||||
|
public IpConnectivityMetrics(Context ctx, ToIntFunction<Context> capacityGetter) {
|
||||||
super(ctx);
|
super(ctx);
|
||||||
|
mCapacityGetter = capacityGetter;
|
||||||
initBuffer();
|
initBuffer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IpConnectivityMetrics(Context ctx) {
|
||||||
|
this(ctx, READ_BUFFER_SIZE);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStart() {
|
public void onStart() {
|
||||||
if (DBG) Log.d(TAG, "onStart");
|
if (DBG) Log.d(TAG, "onStart");
|
||||||
@@ -93,7 +104,7 @@ final public class IpConnectivityMetrics extends SystemService {
|
|||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
public int bufferCapacity() {
|
public int bufferCapacity() {
|
||||||
return DEFAULT_BUFFER_SIZE; // TODO: read from config
|
return mCapacityGetter.applyAsInt(getContext());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initBuffer() {
|
private void initBuffer() {
|
||||||
@@ -233,4 +244,13 @@ final public class IpConnectivityMetrics extends SystemService {
|
|||||||
getContext().enforceCallingOrSelfPermission(what, "IpConnectivityMetrics");
|
getContext().enforceCallingOrSelfPermission(what, "IpConnectivityMetrics");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private static final ToIntFunction<Context> READ_BUFFER_SIZE = (ctx) -> {
|
||||||
|
int size = Settings.Global.getInt(ctx.getContentResolver(),
|
||||||
|
Settings.Global.CONNECTIVITY_METRICS_BUFFER_SIZE, DEFAULT_BUFFER_SIZE);
|
||||||
|
if (size <= 0) {
|
||||||
|
return DEFAULT_BUFFER_SIZE;
|
||||||
|
}
|
||||||
|
return Math.min(size, MAXIMUM_BUFFER_SIZE);
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ public class IpConnectivityMetricsTest extends TestCase {
|
|||||||
|
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
mService = new IpConnectivityMetrics(mCtx);
|
mService = new IpConnectivityMetrics(mCtx, (ctx) -> 2000);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testLoggingEvents() throws Exception {
|
public void testLoggingEvents() throws Exception {
|
||||||
|
|||||||
Reference in New Issue
Block a user