Set attributionTag for noteOp(WRITE_SETTINGS) calls

Test: atest FrameworksNetTests TetheringTests:TetheringServiceTest
Bug: 136595429
Merged-In: I33f787644c44d7b0e5ce17a433820cfcd985cdfb
Change-Id: Ic3d937e7bb5141798234ed5b2852c1f768e97495
This commit is contained in:
Philip P. Moltmann
2020-03-26 11:50:35 -07:00
parent c44ca579ad
commit 7bc33dfb89
5 changed files with 84 additions and 28 deletions

View File

@@ -36,6 +36,7 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.ArgumentMatchers.nullable;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.anyBoolean;
import static org.mockito.Mockito.anyInt;
@@ -213,7 +214,7 @@ public class ConnectivityManagerTest {
// register callback
when(mService.requestNetwork(
any(), captor.capture(), anyInt(), any(), anyInt(), any()))
any(), captor.capture(), anyInt(), any(), anyInt(), any(), nullable(String.class)))
.thenReturn(request);
manager.requestNetwork(request, callback, handler);
@@ -242,7 +243,7 @@ public class ConnectivityManagerTest {
// register callback
when(mService.requestNetwork(
any(), captor.capture(), anyInt(), any(), anyInt(), any()))
any(), captor.capture(), anyInt(), any(), anyInt(), any(), nullable(String.class)))
.thenReturn(req1);
manager.requestNetwork(req1, callback, handler);
@@ -261,7 +262,7 @@ public class ConnectivityManagerTest {
// callback can be registered again
when(mService.requestNetwork(
any(), captor.capture(), anyInt(), any(), anyInt(), any()))
any(), captor.capture(), anyInt(), any(), anyInt(), any(), nullable(String.class)))
.thenReturn(req2);
manager.requestNetwork(req2, callback, handler);
@@ -285,8 +286,8 @@ public class ConnectivityManagerTest {
info.targetSdkVersion = VERSION_CODES.N_MR1 + 1;
when(mCtx.getApplicationInfo()).thenReturn(info);
when(mService.requestNetwork(any(), any(), anyInt(), any(), anyInt(), any()))
.thenReturn(request);
when(mService.requestNetwork(any(), any(), anyInt(), any(), anyInt(), any(),
nullable(String.class))).thenReturn(request);
Handler handler = new Handler(Looper.getMainLooper());
manager.requestNetwork(request, callback, handler);

View File

@@ -3049,6 +3049,13 @@ public class ConnectivityServiceTest {
assertNoCallbacks(cEmpty1, cEmpty2, cEmpty3, cEmpty4, cFoo, cBar);
}
/**
* @return the context's attribution tag
*/
private String getAttributionTag() {
return null;
}
@Test
public void testInvalidNetworkSpecifier() {
assertThrows(IllegalArgumentException.class, () -> {
@@ -3061,7 +3068,8 @@ public class ConnectivityServiceTest {
networkCapabilities.addTransportType(TRANSPORT_WIFI)
.setNetworkSpecifier(new MatchAllNetworkSpecifier());
mService.requestNetwork(networkCapabilities, null, 0, null,
ConnectivityManager.TYPE_WIFI, mContext.getPackageName());
ConnectivityManager.TYPE_WIFI, mContext.getPackageName(),
getAttributionTag());
});
class NonParcelableSpecifier extends NetworkSpecifier {