Merge "Convert PrintRecommendationService to Android.bp."
diff --git a/core/java/android/bluetooth/BluetoothProfileConnector.java b/core/java/android/bluetooth/BluetoothProfileConnector.java
index d9987249..863fd36 100644
--- a/core/java/android/bluetooth/BluetoothProfileConnector.java
+++ b/core/java/android/bluetooth/BluetoothProfileConnector.java
@@ -32,12 +32,12 @@
* @hide
*/
public abstract class BluetoothProfileConnector<T> {
- private int mProfileId;
+ private final int mProfileId;
private BluetoothProfile.ServiceListener mServiceListener;
- private BluetoothProfile mProfileProxy;
+ private final BluetoothProfile mProfileProxy;
private Context mContext;
- private String mProfileName;
- private String mServiceName;
+ private final String mProfileName;
+ private final String mServiceName;
private volatile T mService;
private final IBluetoothStateChangeCallback mBluetoothStateChangeCallback =
@@ -65,7 +65,7 @@
logDebug("Proxy object disconnected");
doUnbind();
if (mServiceListener != null) {
- mServiceListener.onServiceDisconnected(BluetoothProfile.A2DP);
+ mServiceListener.onServiceDisconnected(mProfileId);
}
}
};
diff --git a/core/java/android/net/util/DnsUtils.java b/core/java/android/net/util/DnsUtils.java
index e6abd50..7908353 100644
--- a/core/java/android/net/util/DnsUtils.java
+++ b/core/java/android/net/util/DnsUtils.java
@@ -141,14 +141,17 @@
*/
public static @NonNull List<InetAddress> rfc6724Sort(@Nullable Network network,
@NonNull List<InetAddress> answers) {
- List<SortableAddress> sortableAnswerList = new ArrayList<>();
- answers.forEach(addr -> sortableAnswerList.add(
- new SortableAddress(addr, findSrcAddress(network, addr))));
+ final ArrayList<SortableAddress> sortableAnswerList = new ArrayList<>();
+ for (InetAddress addr : answers) {
+ sortableAnswerList.add(new SortableAddress(addr, findSrcAddress(network, addr)));
+ }
Collections.sort(sortableAnswerList, sRfc6724Comparator);
final List<InetAddress> sortedAnswers = new ArrayList<>();
- sortableAnswerList.forEach(ans -> sortedAnswers.add(ans.address));
+ for (SortableAddress ans : sortableAnswerList) {
+ sortedAnswers.add(ans.address);
+ }
return sortedAnswers;
}
diff --git a/libs/hwui/JankTracker.cpp b/libs/hwui/JankTracker.cpp
index 39ed9a0..2016b5e 100644
--- a/libs/hwui/JankTracker.cpp
+++ b/libs/hwui/JankTracker.cpp
@@ -138,7 +138,7 @@
(*mGlobalData)->reportJank();
}
- bool isTripleBuffered = mSwapDeadline > frame[FrameInfoIndex::IntendedVsync];
+ bool isTripleBuffered = (mSwapDeadline - frame[FrameInfoIndex::IntendedVsync]) > (mFrameInterval * 0.1);
mSwapDeadline = std::max(mSwapDeadline + mFrameInterval,
frame[FrameInfoIndex::IntendedVsync] + mFrameInterval);
diff --git a/packages/NetworkStack/tests/lib/Android.bp b/packages/NetworkStack/tests/lib/Android.bp
new file mode 100644
index 0000000..f45a81c
--- /dev/null
+++ b/packages/NetworkStack/tests/lib/Android.bp
@@ -0,0 +1,26 @@
+//
+// Copyright (C) 2019 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.
+//
+
+java_library {
+ name: "net-tests-utils",
+ srcs: [
+ "src/**/*.java",
+ "src/**/*.kt",
+ ],
+ static_libs: [
+ "kotlin-test",
+ ],
+}
diff --git a/packages/NetworkStack/tests/lib/src/com/android/testutils/HandlerUtils.kt b/packages/NetworkStack/tests/lib/src/com/android/testutils/HandlerUtils.kt
new file mode 100644
index 0000000..3dce5a5
--- /dev/null
+++ b/packages/NetworkStack/tests/lib/src/com/android/testutils/HandlerUtils.kt
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 2019 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.testutils
+
+import android.os.ConditionVariable
+import android.os.Handler
+import android.os.HandlerThread
+import java.util.concurrent.Executor
+import kotlin.test.fail
+
+/**
+ * Block until the specified Handler or HandlerThread becomes idle, or until timeoutMs has passed.
+ */
+fun Handler.waitForIdle(timeoutMs: Long) = waitForIdleHandler(this, timeoutMs)
+fun HandlerThread.waitForIdle(timeoutMs: Long) = waitForIdleHandler(this.threadHandler, timeoutMs)
+fun waitForIdleHandler(handler: HandlerThread, timeoutMs: Long) {
+ waitForIdleHandler(handler.threadHandler, timeoutMs)
+}
+fun waitForIdleHandler(handler: Handler, timeoutMs: Long) {
+ val cv = ConditionVariable(false)
+ handler.post(cv::open)
+ if (!cv.block(timeoutMs)) {
+ fail("Handler did not become idle after ${timeoutMs}ms")
+ }
+}
+
+/**
+ * Block until the given Serial Executor becomes idle, or until timeoutMs has passed.
+ */
+fun waitForIdleSerialExecutor(executor: Executor, timeoutMs: Long) {
+ val cv = ConditionVariable()
+ executor.execute(cv::open)
+ if (!cv.block(timeoutMs)) {
+ fail("Executor did not become idle after ${timeoutMs}ms")
+ }
+}
diff --git a/packages/NetworkStack/tests/unit/Android.bp b/packages/NetworkStack/tests/unit/Android.bp
index 85951eb..48b13b0 100644
--- a/packages/NetworkStack/tests/unit/Android.bp
+++ b/packages/NetworkStack/tests/unit/Android.bp
@@ -23,6 +23,7 @@
static_libs: [
"androidx.test.rules",
"mockito-target-extended-minus-junit4",
+ "net-tests-utils",
"NetworkStackBase",
"testables",
],
diff --git a/packages/NetworkStack/tests/unit/src/com/android/server/connectivity/NetworkMonitorTest.java b/packages/NetworkStack/tests/unit/src/com/android/server/connectivity/NetworkMonitorTest.java
index 262641d..e4c1d17 100644
--- a/packages/NetworkStack/tests/unit/src/com/android/server/connectivity/NetworkMonitorTest.java
+++ b/packages/NetworkStack/tests/unit/src/com/android/server/connectivity/NetworkMonitorTest.java
@@ -92,6 +92,7 @@
import com.android.networkstack.R;
import com.android.networkstack.metrics.DataStallDetectionStats;
import com.android.networkstack.metrics.DataStallStatsUtils;
+import com.android.testutils.HandlerUtilsKt;
import org.junit.After;
import org.junit.Before;
@@ -420,7 +421,7 @@
final WrappedNetworkMonitor nm = new WrappedNetworkMonitor();
nm.start();
setNetworkCapabilities(nm, nc);
- waitForIdle(nm.getHandler());
+ HandlerUtilsKt.waitForIdle(nm.getHandler(), HANDLER_TIMEOUT_MS);
mCreatedNetworkMonitors.add(nm);
return nm;
}
@@ -437,15 +438,7 @@
private void setNetworkCapabilities(NetworkMonitor nm, NetworkCapabilities nc) {
nm.notifyNetworkCapabilitiesChanged(nc);
- waitForIdle(nm.getHandler());
- }
-
- private void waitForIdle(Handler handler) {
- final ConditionVariable cv = new ConditionVariable(false);
- handler.post(cv::open);
- if (!cv.block(HANDLER_TIMEOUT_MS)) {
- fail("Timed out waiting for handler");
- }
+ HandlerUtilsKt.waitForIdle(nm.getHandler(), HANDLER_TIMEOUT_MS);
}
@Test
@@ -1125,7 +1118,7 @@
} catch (RemoteException e) {
fail("Unexpected exception: " + e);
}
- waitForIdle(monitor.getHandler());
+ HandlerUtilsKt.waitForIdle(monitor.getHandler(), HANDLER_TIMEOUT_MS);
return monitor;
}
diff --git a/services/core/java/com/android/server/pm/PackageDexOptimizer.java b/services/core/java/com/android/server/pm/PackageDexOptimizer.java
index 6623526..6ae05ff 100644
--- a/services/core/java/com/android/server/pm/PackageDexOptimizer.java
+++ b/services/core/java/com/android/server/pm/PackageDexOptimizer.java
@@ -508,13 +508,25 @@
*/
private String getRealCompilerFilter(ApplicationInfo info, String targetCompilerFilter,
boolean isUsedByOtherApps) {
- int flags = info.flags;
- boolean vmSafeMode = (flags & ApplicationInfo.FLAG_VM_SAFE_MODE) != 0;
// When a priv app is configured to run out of box, only verify it.
if (info.isPrivilegedApp() && DexManager.isPackageSelectedToRunOob(info.packageName)) {
return "verify";
}
- if (vmSafeMode) {
+
+ // We force vmSafeMode on debuggable apps as well:
+ // - the runtime ignores their compiled code
+ // - they generally have lots of methods that could make the compiler used run
+ // out of memory (b/130828957)
+ // Note that forcing the compiler filter here applies to all compilations (even if they
+ // are done via adb shell commands). That's ok because right now the runtime will ignore
+ // the compiled code anyway. The alternative would have been to update either
+ // PackageDexOptimizer#canOptimizePackage or PackageManagerService#getOptimizablePackages
+ // but that would have the downside of possibly producing a big odex files which would
+ // be ignored anyway.
+ boolean vmSafeModeOrDebuggable = ((info.flags & ApplicationInfo.FLAG_VM_SAFE_MODE) != 0)
+ || ((info.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0);
+
+ if (vmSafeModeOrDebuggable) {
return getSafeModeCompilerFilter(targetCompilerFilter);
}
diff --git a/services/core/java/com/android/server/pm/PackageManagerService.java b/services/core/java/com/android/server/pm/PackageManagerService.java
index ba2b37f..9bb417c 100644
--- a/services/core/java/com/android/server/pm/PackageManagerService.java
+++ b/services/core/java/com/android/server/pm/PackageManagerService.java
@@ -168,8 +168,8 @@
import android.content.pm.InstantAppResolveInfo;
import android.content.pm.InstrumentationInfo;
import android.content.pm.IntentFilterVerificationInfo;
-import android.content.pm.PackageBackwardCompatibility;
import android.content.pm.KeySet;
+import android.content.pm.PackageBackwardCompatibility;
import android.content.pm.PackageCleanItem;
import android.content.pm.PackageInfo;
import android.content.pm.PackageInfoLite;
@@ -259,7 +259,6 @@
import android.util.ArrayMap;
import android.util.ArraySet;
import android.util.Base64;
-import android.util.ByteStringUtils;
import android.util.DisplayMetrics;
import android.util.EventLog;
import android.util.ExceptionUtils;
@@ -299,8 +298,6 @@
import com.android.internal.util.IndentingPrintWriter;
import com.android.internal.util.Preconditions;
import com.android.internal.util.XmlUtils;
-import com.android.internal.util.function.QuadFunction;
-import com.android.internal.util.function.TriFunction;
import com.android.server.AttributeCache;
import com.android.server.DeviceIdleController;
import com.android.server.EventLogTags;
@@ -336,6 +333,7 @@
import dalvik.system.VMRuntime;
import libcore.io.IoUtils;
+import libcore.util.HexEncoding;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
@@ -380,7 +378,6 @@
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.BiConsumer;
-import java.util.function.BiFunction;
import java.util.function.Predicate;
/**
@@ -9972,8 +9969,9 @@
// lib signing cert could have rotated beyond the one expected, check to see
// if the new one has been blessed by the old
- if (!libPkg.mSigningDetails.hasSha256Certificate(
- ByteStringUtils.fromHexToByteArray(expectedCertDigests[0]))) {
+ byte[] digestBytes = HexEncoding.decode(
+ expectedCertDigests[0], false /* allowSingleChar */);
+ if (!libPkg.mSigningDetails.hasSha256Certificate(digestBytes)) {
throw new PackageManagerException(
INSTALL_FAILED_MISSING_SHARED_LIBRARY,
"Package " + packageName + " requires differently signed" +
diff --git a/tests/net/Android.bp b/tests/net/Android.bp
index 306cc51..eb25acf 100644
--- a/tests/net/Android.bp
+++ b/tests/net/Android.bp
@@ -10,6 +10,7 @@
"framework-protos",
"androidx.test.rules",
"mockito-target-minus-junit4",
+ "net-tests-utils",
"platform-test-annotations",
"services.core",
"services.net",
diff --git a/tests/net/java/android/net/nsd/NsdManagerTest.java b/tests/net/java/android/net/nsd/NsdManagerTest.java
index 2d2bccb..cf7587a 100644
--- a/tests/net/java/android/net/nsd/NsdManagerTest.java
+++ b/tests/net/java/android/net/nsd/NsdManagerTest.java
@@ -16,8 +16,6 @@
package android.net.nsd;
-import static com.android.internal.util.TestUtils.waitForIdleHandler;
-
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
@@ -40,6 +38,7 @@
import androidx.test.runner.AndroidJUnit4;
import com.android.internal.util.AsyncChannel;
+import com.android.testutils.HandlerUtilsKt;
import org.junit.After;
import org.junit.Before;
@@ -74,7 +73,7 @@
@After
public void tearDown() throws Exception {
- mServiceHandler.waitForIdle(mTimeoutMs);
+ HandlerUtilsKt.waitForIdle(mServiceHandler, mTimeoutMs);
mServiceHandler.chan.disconnect();
mServiceHandler.stop();
if (mManager != null) {
@@ -334,7 +333,7 @@
}
int verifyRequest(int expectedMessageType) {
- mServiceHandler.waitForIdle(mTimeoutMs);
+ HandlerUtilsKt.waitForIdle(mServiceHandler, mTimeoutMs);
verify(mServiceHandler, timeout(mTimeoutMs)).handleMessage(any());
reset(mServiceHandler);
Message received = mServiceHandler.getLastMessage();
@@ -366,10 +365,6 @@
lastMessage.copyFrom(msg);
}
- void waitForIdle(long timeoutMs) {
- waitForIdleHandler(this, timeoutMs);
- }
-
@Override
public void handleMessage(Message msg) {
setLastMessage(msg);
diff --git a/tests/net/java/android/net/util/DnsUtilsTest.java b/tests/net/java/android/net/util/DnsUtilsTest.java
index 42e340b..b626db8 100644
--- a/tests/net/java/android/net/util/DnsUtilsTest.java
+++ b/tests/net/java/android/net/util/DnsUtilsTest.java
@@ -57,24 +57,38 @@
@Test
public void testRfc6724Comparator() {
final List<DnsUtils.SortableAddress> test = Arrays.asList(
- makeSortableAddress("216.58.200.36"), // Ipv4
- makeSortableAddress("2404:6800:4008:801::2004"), // global
- makeSortableAddress("::1"), // loop back
- makeSortableAddress("fe80::c46f:1cff:fe04:39b4"), // link local
- makeSortableAddress("::ffff:192.168.95.3"), // IPv4-mapped IPv6
- makeSortableAddress("2001::47c1"), // teredo tunneling
- makeSortableAddress("::216.58.200.36"), // IPv4-compatible
- makeSortableAddress("3ffe::1234:5678")); // 6bone
+ // Ipv4
+ makeSortableAddress("216.58.200.36", "192.168.1.1"),
+ // global with different scope src
+ makeSortableAddress("2404:6800:4008:801::2004", "fe80::1111:2222"),
+ // global without src addr
+ makeSortableAddress("2404:6800:cafe:801::1"),
+ // loop back
+ makeSortableAddress("::1", "::1"),
+ // link local
+ makeSortableAddress("fe80::c46f:1cff:fe04:39b4", "fe80::1"),
+ // teredo tunneling
+ makeSortableAddress("2001::47c1", "2001::2"),
+ // 6bone without src addr
+ makeSortableAddress("3ffe::1234:5678"),
+ // IPv4-compatible
+ makeSortableAddress("::216.58.200.36", "::216.58.200.9"),
+ // 6bone
+ makeSortableAddress("3ffe::1234:5678", "3ffe::1234:1"),
+ // IPv4-mapped IPv6
+ makeSortableAddress("::ffff:192.168.95.7", "::ffff:192.168.95.1"));
final List<InetAddress> expected = Arrays.asList(
stringToAddress("::1"), // loop back
stringToAddress("fe80::c46f:1cff:fe04:39b4"), // link local
- stringToAddress("2404:6800:4008:801::2004"), // global
stringToAddress("216.58.200.36"), // Ipv4
- stringToAddress("::ffff:192.168.95.3"), // IPv4-mapped IPv6
+ stringToAddress("::ffff:192.168.95.7"), // IPv4-mapped IPv6
stringToAddress("2001::47c1"), // teredo tunneling
- stringToAddress("::216.58.200.36"), // IPv4-compatible
- stringToAddress("3ffe::1234:5678")); // 6bone
+ stringToAddress("::216.58.200.36"), // IPv4-compatible
+ stringToAddress("3ffe::1234:5678"), // 6bone
+ stringToAddress("2404:6800:4008:801::2004"), // global with different scope src
+ stringToAddress("2404:6800:cafe:801::1"), // global without src addr
+ stringToAddress("3ffe::1234:5678")); // 6bone without src addr
Collections.sort(test, new DnsUtils.Rfc6724Comparator());
diff --git a/tests/net/java/com/android/server/ConnectivityServiceTest.java b/tests/net/java/com/android/server/ConnectivityServiceTest.java
index cb774ba..1a8d905 100644
--- a/tests/net/java/com/android/server/ConnectivityServiceTest.java
+++ b/tests/net/java/com/android/server/ConnectivityServiceTest.java
@@ -68,10 +68,6 @@
import static android.net.NetworkPolicyManager.RULE_REJECT_METERED;
import static android.net.RouteInfo.RTN_UNREACHABLE;
-import static com.android.internal.util.TestUtils.waitForIdleHandler;
-import static com.android.internal.util.TestUtils.waitForIdleLooper;
-import static com.android.internal.util.TestUtils.waitForIdleSerialExecutor;
-
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@@ -196,6 +192,7 @@
import com.android.server.connectivity.Vpn;
import com.android.server.net.NetworkPinner;
import com.android.server.net.NetworkPolicyManagerInternal;
+import com.android.testutils.HandlerUtilsKt;
import org.junit.After;
import org.junit.Before;
@@ -375,19 +372,19 @@
public void waitForIdle(int timeoutMsAsInt) {
long timeoutMs = timeoutMsAsInt;
- waitForIdleHandler(mService.mHandlerThread, timeoutMs);
+ HandlerUtilsKt.waitForIdle(mService.mHandlerThread, timeoutMs);
waitForIdle(mCellNetworkAgent, timeoutMs);
waitForIdle(mWiFiNetworkAgent, timeoutMs);
waitForIdle(mEthernetNetworkAgent, timeoutMs);
- waitForIdleHandler(mService.mHandlerThread, timeoutMs);
- waitForIdleLooper(ConnectivityThread.getInstanceLooper(), timeoutMs);
+ HandlerUtilsKt.waitForIdle(mService.mHandlerThread, timeoutMs);
+ HandlerUtilsKt.waitForIdle(ConnectivityThread.get(), timeoutMs);
}
public void waitForIdle(MockNetworkAgent agent, long timeoutMs) {
if (agent == null) {
return;
}
- waitForIdleHandler(agent.mHandlerThread, timeoutMs);
+ HandlerUtilsKt.waitForIdle(agent.mHandlerThread, timeoutMs);
}
private void waitForIdle() {
@@ -1220,7 +1217,7 @@
}
public void waitForIdle(int timeoutMs) {
- waitForIdleHandler(mHandlerThread, timeoutMs);
+ HandlerUtilsKt.waitForIdle(mHandlerThread, timeoutMs);
}
public void waitForIdle() {
@@ -4107,7 +4104,7 @@
}
public void assertNoCallback() {
- waitForIdleSerialExecutor(mExecutor, TIMEOUT_MS);
+ HandlerUtilsKt.waitForIdleSerialExecutor(mExecutor, TIMEOUT_MS);
CallbackValue cv = mCallbacks.peek();
assertNull("Unexpected callback: " + cv, cv);
}
diff --git a/tests/net/java/com/android/server/connectivity/tethering/OffloadControllerTest.java b/tests/net/java/com/android/server/connectivity/tethering/OffloadControllerTest.java
index be54b1a..762b76c 100644
--- a/tests/net/java/com/android/server/connectivity/tethering/OffloadControllerTest.java
+++ b/tests/net/java/com/android/server/connectivity/tethering/OffloadControllerTest.java
@@ -51,7 +51,6 @@
import android.net.NetworkStats;
import android.net.RouteInfo;
import android.net.util.SharedLog;
-import android.os.ConditionVariable;
import android.os.Handler;
import android.os.INetworkManagementService;
import android.os.Looper;
@@ -63,6 +62,7 @@
import androidx.test.runner.AndroidJUnit4;
import com.android.internal.util.test.FakeSettingsProvider;
+import com.android.testutils.HandlerUtilsKt;
import org.junit.After;
import org.junit.Before;
@@ -90,6 +90,7 @@
private static final String IPV6_DISCARD_PREFIX = "100::/64";
private static final String USB_PREFIX = "192.168.42.0/24";
private static final String WIFI_PREFIX = "192.168.43.0/24";
+ private static final long WAIT_FOR_IDLE_TIMEOUT = 2 * 1000;
@Mock private OffloadHardwareInterface mHardware;
@Mock private ApplicationInfo mApplicationInfo;
@@ -131,9 +132,7 @@
}
private void waitForIdle() {
- ConditionVariable cv = new ConditionVariable();
- new Handler(Looper.getMainLooper()).post(() -> { cv.open(); });
- cv.block();
+ HandlerUtilsKt.waitForIdle(new Handler(Looper.getMainLooper()), WAIT_FOR_IDLE_TIMEOUT);
}
private OffloadController makeOffloadController() throws Exception {
diff --git a/tests/net/java/com/android/server/net/NetworkStatsObserversTest.java b/tests/net/java/com/android/server/net/NetworkStatsObserversTest.java
index 43a3803..9a47f35 100644
--- a/tests/net/java/com/android/server/net/NetworkStatsObserversTest.java
+++ b/tests/net/java/com/android/server/net/NetworkStatsObserversTest.java
@@ -28,8 +28,6 @@
import static android.net.TrafficStats.MB_IN_BYTES;
import static android.text.format.DateUtils.MINUTE_IN_MILLIS;
-import static com.android.internal.util.TestUtils.waitForIdleHandler;
-
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.any;
@@ -56,6 +54,7 @@
import com.android.internal.net.VpnInfo;
import com.android.server.net.NetworkStatsServiceTest.LatchedHandler;
+import com.android.testutils.HandlerUtilsKt;
import org.junit.Before;
import org.junit.Test;
@@ -457,7 +456,7 @@
}
private void waitForObserverToIdle() {
- waitForIdleHandler(mObserverHandlerThread, WAIT_TIMEOUT_MS);
- waitForIdleHandler(mHandler, WAIT_TIMEOUT_MS);
+ HandlerUtilsKt.waitForIdle(mObserverHandlerThread, WAIT_TIMEOUT_MS);
+ HandlerUtilsKt.waitForIdle(mHandler, WAIT_TIMEOUT_MS);
}
}
diff --git a/tests/net/java/com/android/server/net/NetworkStatsServiceTest.java b/tests/net/java/com/android/server/net/NetworkStatsServiceTest.java
index e35c34a..07b5ba4 100644
--- a/tests/net/java/com/android/server/net/NetworkStatsServiceTest.java
+++ b/tests/net/java/com/android/server/net/NetworkStatsServiceTest.java
@@ -52,7 +52,6 @@
import static android.text.format.DateUtils.MINUTE_IN_MILLIS;
import static android.text.format.DateUtils.WEEK_IN_MILLIS;
-import static com.android.internal.util.TestUtils.waitForIdleHandler;
import static com.android.server.net.NetworkStatsService.ACTION_NETWORK_STATS_POLL;
import static org.junit.Assert.assertEquals;
@@ -105,6 +104,7 @@
import com.android.internal.util.test.BroadcastInterceptingContext;
import com.android.server.net.NetworkStatsService.NetworkStatsSettings;
import com.android.server.net.NetworkStatsService.NetworkStatsSettings.Config;
+import com.android.testutils.HandlerUtilsKt;
import libcore.io.IoUtils;
@@ -1321,8 +1321,6 @@
expectNetworkStatsSummary(buildEmptyStats());
expectNetworkStatsUidDetail(buildEmptyStats());
-
-
// Register and verify request and that binder was called
DataUsageRequest request =
mService.registerUsageCallback(mServiceContext.getOpPackageName(), inputRequest,
@@ -1334,14 +1332,11 @@
// Send dummy message to make sure that any previous message has been handled
mHandler.sendMessage(mHandler.obtainMessage(-1));
- waitForIdleHandler(mHandler, WAIT_TIMEOUT);
-
-
+ HandlerUtilsKt.waitForIdle(mHandler, WAIT_TIMEOUT);
// Make sure that the caller binder gets connected
verify(mBinder).linkToDeath(any(IBinder.DeathRecipient.class), anyInt());
-
// modify some number on wifi, and trigger poll event
// not enough traffic to call data usage callback
incrementCurrentTime(HOUR_IN_MILLIS);
@@ -1674,7 +1669,7 @@
mServiceContext.sendBroadcast(new Intent(ACTION_NETWORK_STATS_POLL));
// Send dummy message to make sure that any previous message has been handled
mHandler.sendMessage(mHandler.obtainMessage(-1));
- waitForIdleHandler(mHandler, WAIT_TIMEOUT);
+ HandlerUtilsKt.waitForIdle(mHandler, WAIT_TIMEOUT);
}
static class LatchedHandler extends Handler {
diff --git a/tests/net/util/java/com/android/internal/util/TestUtils.java b/tests/net/util/java/com/android/internal/util/TestUtils.java
index a99cd47..daa00d2 100644
--- a/tests/net/util/java/com/android/internal/util/TestUtils.java
+++ b/tests/net/util/java/com/android/internal/util/TestUtils.java
@@ -19,57 +19,13 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
-import android.os.ConditionVariable;
-import android.os.Handler;
-import android.os.HandlerThread;
-import android.os.Looper;
import android.os.Parcel;
import android.os.Parcelable;
-import androidx.annotation.NonNull;
-
-import java.util.concurrent.Executor;
-
public final class TestUtils {
private TestUtils() { }
/**
- * Block until the given Handler thread becomes idle, or until timeoutMs has passed.
- */
- public static void waitForIdleHandler(HandlerThread handlerThread, long timeoutMs) {
- waitForIdleLooper(handlerThread.getLooper(), timeoutMs);
- }
-
- /**
- * Block until the given Looper becomes idle, or until timeoutMs has passed.
- */
- public static void waitForIdleLooper(Looper looper, long timeoutMs) {
- waitForIdleHandler(new Handler(looper), timeoutMs);
- }
-
- /**
- * Block until the given Handler becomes idle, or until timeoutMs has passed.
- */
- public static void waitForIdleHandler(Handler handler, long timeoutMs) {
- final ConditionVariable cv = new ConditionVariable();
- handler.post(() -> cv.open());
- if (!cv.block(timeoutMs)) {
- fail(handler.toString() + " did not become idle after " + timeoutMs + " ms");
- }
- }
-
- /**
- * Block until the given Serial Executor becomes idle, or until timeoutMs has passed.
- */
- public static void waitForIdleSerialExecutor(@NonNull Executor executor, long timeoutMs) {
- final ConditionVariable cv = new ConditionVariable();
- executor.execute(() -> cv.open());
- if (!cv.block(timeoutMs)) {
- fail(executor.toString() + " did not become idle after " + timeoutMs + " ms");
- }
- }
-
- /**
* Return a new instance of {@code T} after being parceled then unparceled.
*/
public static <T extends Parcelable> T parcelingRoundTrip(T source) {