Merge "Add a mutability flag to the PendingIntent"
This commit is contained in:
@@ -18,6 +18,7 @@ package com.android.server;
|
|||||||
|
|
||||||
import static android.Manifest.permission.CHANGE_NETWORK_STATE;
|
import static android.Manifest.permission.CHANGE_NETWORK_STATE;
|
||||||
import static android.Manifest.permission.CONNECTIVITY_USE_RESTRICTED_NETWORKS;
|
import static android.Manifest.permission.CONNECTIVITY_USE_RESTRICTED_NETWORKS;
|
||||||
|
import static android.app.PendingIntent.FLAG_IMMUTABLE;
|
||||||
import static android.content.Intent.ACTION_USER_ADDED;
|
import static android.content.Intent.ACTION_USER_ADDED;
|
||||||
import static android.content.Intent.ACTION_USER_REMOVED;
|
import static android.content.Intent.ACTION_USER_REMOVED;
|
||||||
import static android.content.pm.PackageInfo.REQUESTED_PERMISSION_GRANTED;
|
import static android.content.pm.PackageInfo.REQUESTED_PERMISSION_GRANTED;
|
||||||
@@ -2547,7 +2548,8 @@ public class ConnectivityServiceTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNoMutableNetworkRequests() throws Exception {
|
public void testNoMutableNetworkRequests() throws Exception {
|
||||||
PendingIntent pendingIntent = PendingIntent.getBroadcast(mContext, 0, new Intent("a"), 0);
|
final PendingIntent pendingIntent = PendingIntent.getBroadcast(
|
||||||
|
mContext, 0 /* requestCode */, new Intent("a"), FLAG_IMMUTABLE);
|
||||||
NetworkRequest request1 = new NetworkRequest.Builder()
|
NetworkRequest request1 = new NetworkRequest.Builder()
|
||||||
.addCapability(NET_CAPABILITY_VALIDATED)
|
.addCapability(NET_CAPABILITY_VALIDATED)
|
||||||
.build();
|
.build();
|
||||||
@@ -3209,7 +3211,7 @@ public class ConnectivityServiceTest {
|
|||||||
|
|
||||||
assertThrows(SecurityException.class, () ->
|
assertThrows(SecurityException.class, () ->
|
||||||
mCm.registerNetworkCallback(r, PendingIntent.getService(
|
mCm.registerNetworkCallback(r, PendingIntent.getService(
|
||||||
mServiceContext, 0, new Intent(), 0)));
|
mServiceContext, 0 /* requestCode */, new Intent(), FLAG_IMMUTABLE)));
|
||||||
|
|
||||||
// Requesting a Network with signal strength should get IllegalArgumentException.
|
// Requesting a Network with signal strength should get IllegalArgumentException.
|
||||||
assertThrows(IllegalArgumentException.class, () ->
|
assertThrows(IllegalArgumentException.class, () ->
|
||||||
@@ -3217,7 +3219,7 @@ public class ConnectivityServiceTest {
|
|||||||
|
|
||||||
assertThrows(IllegalArgumentException.class, () ->
|
assertThrows(IllegalArgumentException.class, () ->
|
||||||
mCm.requestNetwork(r, PendingIntent.getService(
|
mCm.requestNetwork(r, PendingIntent.getService(
|
||||||
mServiceContext, 0, new Intent(), 0)));
|
mServiceContext, 0 /* requestCode */, new Intent(), FLAG_IMMUTABLE)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -4681,12 +4683,14 @@ public class ConnectivityServiceTest {
|
|||||||
}
|
}
|
||||||
j = 0;
|
j = 0;
|
||||||
while (j++ < INTENTS / 2) {
|
while (j++ < INTENTS / 2) {
|
||||||
PendingIntent pi = PendingIntent.getBroadcast(mContext, 0, new Intent("a" + j), 0);
|
final PendingIntent pi = PendingIntent.getBroadcast(mContext, 0 /* requestCode */,
|
||||||
|
new Intent("a" + j), FLAG_IMMUTABLE);
|
||||||
mCm.requestNetwork(networkRequest, pi);
|
mCm.requestNetwork(networkRequest, pi);
|
||||||
registered.add(pi);
|
registered.add(pi);
|
||||||
}
|
}
|
||||||
while (j++ < INTENTS) {
|
while (j++ < INTENTS) {
|
||||||
PendingIntent pi = PendingIntent.getBroadcast(mContext, 0, new Intent("b" + j), 0);
|
final PendingIntent pi = PendingIntent.getBroadcast(mContext, 0 /* requestCode */,
|
||||||
|
new Intent("b" + j), FLAG_IMMUTABLE);
|
||||||
mCm.registerNetworkCallback(networkRequest, pi);
|
mCm.registerNetworkCallback(networkRequest, pi);
|
||||||
registered.add(pi);
|
registered.add(pi);
|
||||||
}
|
}
|
||||||
@@ -4700,11 +4704,13 @@ public class ConnectivityServiceTest {
|
|||||||
);
|
);
|
||||||
assertThrows(TooManyRequestsException.class, () ->
|
assertThrows(TooManyRequestsException.class, () ->
|
||||||
mCm.requestNetwork(networkRequest,
|
mCm.requestNetwork(networkRequest,
|
||||||
PendingIntent.getBroadcast(mContext, 0, new Intent("c"), 0))
|
PendingIntent.getBroadcast(mContext, 0 /* requestCode */,
|
||||||
|
new Intent("c"), FLAG_IMMUTABLE))
|
||||||
);
|
);
|
||||||
assertThrows(TooManyRequestsException.class, () ->
|
assertThrows(TooManyRequestsException.class, () ->
|
||||||
mCm.registerNetworkCallback(networkRequest,
|
mCm.registerNetworkCallback(networkRequest,
|
||||||
PendingIntent.getBroadcast(mContext, 0, new Intent("d"), 0))
|
PendingIntent.getBroadcast(mContext, 0 /* requestCode */,
|
||||||
|
new Intent("d"), FLAG_IMMUTABLE))
|
||||||
);
|
);
|
||||||
|
|
||||||
for (Object o : registered) {
|
for (Object o : registered) {
|
||||||
@@ -4733,16 +4739,16 @@ public class ConnectivityServiceTest {
|
|||||||
waitForIdle();
|
waitForIdle();
|
||||||
|
|
||||||
for (int i = 0; i < MAX_REQUESTS; i++) {
|
for (int i = 0; i < MAX_REQUESTS; i++) {
|
||||||
PendingIntent pendingIntent =
|
final PendingIntent pendingIntent = PendingIntent.getBroadcast(
|
||||||
PendingIntent.getBroadcast(mContext, 0, new Intent("e" + i), 0);
|
mContext, 0 /* requestCode */, new Intent("e" + i), FLAG_IMMUTABLE);
|
||||||
mCm.requestNetwork(networkRequest, pendingIntent);
|
mCm.requestNetwork(networkRequest, pendingIntent);
|
||||||
mCm.unregisterNetworkCallback(pendingIntent);
|
mCm.unregisterNetworkCallback(pendingIntent);
|
||||||
}
|
}
|
||||||
waitForIdle();
|
waitForIdle();
|
||||||
|
|
||||||
for (int i = 0; i < MAX_REQUESTS; i++) {
|
for (int i = 0; i < MAX_REQUESTS; i++) {
|
||||||
PendingIntent pendingIntent =
|
final PendingIntent pendingIntent = PendingIntent.getBroadcast(
|
||||||
PendingIntent.getBroadcast(mContext, 0, new Intent("f" + i), 0);
|
mContext, 0 /* requestCode */, new Intent("f" + i), FLAG_IMMUTABLE);
|
||||||
mCm.registerNetworkCallback(networkRequest, pendingIntent);
|
mCm.registerNetworkCallback(networkRequest, pendingIntent);
|
||||||
mCm.unregisterNetworkCallback(pendingIntent);
|
mCm.unregisterNetworkCallback(pendingIntent);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user