Merge "Rename redactNetworkCapabilitiesForPackage and update its javadoc"
This commit is contained in:
@@ -12,8 +12,8 @@ package android.net {
|
|||||||
method @NonNull @RequiresPermission(anyOf={android.net.NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK, android.Manifest.permission.NETWORK_STACK, android.Manifest.permission.NETWORK_SETTINGS}) public java.util.List<android.net.NetworkStateSnapshot> getAllNetworkStateSnapshots();
|
method @NonNull @RequiresPermission(anyOf={android.net.NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK, android.Manifest.permission.NETWORK_STACK, android.Manifest.permission.NETWORK_SETTINGS}) public java.util.List<android.net.NetworkStateSnapshot> getAllNetworkStateSnapshots();
|
||||||
method @Nullable public android.net.ProxyInfo getGlobalProxy();
|
method @Nullable public android.net.ProxyInfo getGlobalProxy();
|
||||||
method @NonNull public static android.util.Range<java.lang.Integer> getIpSecNetIdRange();
|
method @NonNull public static android.util.Range<java.lang.Integer> getIpSecNetIdRange();
|
||||||
method @Nullable @RequiresPermission(anyOf={android.net.NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK, android.Manifest.permission.NETWORK_STACK, android.Manifest.permission.NETWORK_SETTINGS}) public android.net.LinkProperties redactLinkPropertiesForPackage(@NonNull android.net.LinkProperties, int, @NonNull String);
|
method @Nullable @RequiresPermission(anyOf={android.net.NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK, android.Manifest.permission.NETWORK_STACK, android.Manifest.permission.NETWORK_SETTINGS}) public android.net.LinkProperties getRedactedLinkPropertiesForPackage(@NonNull android.net.LinkProperties, int, @NonNull String);
|
||||||
method @Nullable @RequiresPermission(anyOf={android.net.NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK, android.Manifest.permission.NETWORK_STACK, android.Manifest.permission.NETWORK_SETTINGS}) public android.net.NetworkCapabilities redactNetworkCapabilitiesForPackage(@NonNull android.net.NetworkCapabilities, int, @NonNull String);
|
method @Nullable @RequiresPermission(anyOf={android.net.NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK, android.Manifest.permission.NETWORK_STACK, android.Manifest.permission.NETWORK_SETTINGS}) public android.net.NetworkCapabilities getRedactedNetworkCapabilitiesForPackage(@NonNull android.net.NetworkCapabilities, int, @NonNull String);
|
||||||
method @RequiresPermission(anyOf={android.net.NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK, android.Manifest.permission.NETWORK_SETTINGS}) public void registerDefaultNetworkCallbackForUid(int, @NonNull android.net.ConnectivityManager.NetworkCallback, @NonNull android.os.Handler);
|
method @RequiresPermission(anyOf={android.net.NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK, android.Manifest.permission.NETWORK_SETTINGS}) public void registerDefaultNetworkCallbackForUid(int, @NonNull android.net.ConnectivityManager.NetworkCallback, @NonNull android.os.Handler);
|
||||||
method @RequiresPermission(anyOf={android.net.NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK, android.Manifest.permission.NETWORK_SETTINGS}) public void registerSystemDefaultNetworkCallback(@NonNull android.net.ConnectivityManager.NetworkCallback, @NonNull android.os.Handler);
|
method @RequiresPermission(anyOf={android.net.NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK, android.Manifest.permission.NETWORK_SETTINGS}) public void registerSystemDefaultNetworkCallback(@NonNull android.net.ConnectivityManager.NetworkCallback, @NonNull android.os.Handler);
|
||||||
method @RequiresPermission(anyOf={android.Manifest.permission.NETWORK_SETTINGS, android.Manifest.permission.NETWORK_STACK, android.net.NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK}) public void removeUidFromMeteredNetworkAllowList(int);
|
method @RequiresPermission(anyOf={android.Manifest.permission.NETWORK_SETTINGS, android.Manifest.permission.NETWORK_STACK, android.net.NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK}) public void removeUidFromMeteredNetworkAllowList(int);
|
||||||
|
|||||||
@@ -1643,10 +1643,10 @@ public class ConnectivityManager {
|
|||||||
android.Manifest.permission.NETWORK_SETTINGS})
|
android.Manifest.permission.NETWORK_SETTINGS})
|
||||||
@SystemApi(client = MODULE_LIBRARIES)
|
@SystemApi(client = MODULE_LIBRARIES)
|
||||||
@Nullable
|
@Nullable
|
||||||
public LinkProperties redactLinkPropertiesForPackage(@NonNull LinkProperties lp, int uid,
|
public LinkProperties getRedactedLinkPropertiesForPackage(@NonNull LinkProperties lp, int uid,
|
||||||
@NonNull String packageName) {
|
@NonNull String packageName) {
|
||||||
try {
|
try {
|
||||||
return mService.redactLinkPropertiesForPackage(
|
return mService.getRedactedLinkPropertiesForPackage(
|
||||||
lp, uid, packageName, getAttributionTag());
|
lp, uid, packageName, getAttributionTag());
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
throw e.rethrowFromSystemServer();
|
throw e.rethrowFromSystemServer();
|
||||||
@@ -1683,9 +1683,11 @@ public class ConnectivityManager {
|
|||||||
* Redact {@link NetworkCapabilities} for a given package.
|
* Redact {@link NetworkCapabilities} for a given package.
|
||||||
*
|
*
|
||||||
* Returns an instance of {@link NetworkCapabilities} that is appropriately redacted to send
|
* Returns an instance of {@link NetworkCapabilities} that is appropriately redacted to send
|
||||||
* to the given package, considering its permissions. Calling this method will blame the UID for
|
* to the given package, considering its permissions. If the passed capabilities contain
|
||||||
* retrieving the device location if the passed capabilities contain location-sensitive
|
* location-sensitive information, they will be redacted to the correct degree for the location
|
||||||
* information.
|
* permissions of the app (COARSE or FINE), and will blame the UID accordingly for retrieving
|
||||||
|
* that level of location. If the UID holds no location permission, the returned object will
|
||||||
|
* contain no location-sensitive information and the UID is not blamed.
|
||||||
*
|
*
|
||||||
* @param nc A {@link NetworkCapabilities} instance which will be redacted.
|
* @param nc A {@link NetworkCapabilities} instance which will be redacted.
|
||||||
* @param uid The target uid.
|
* @param uid The target uid.
|
||||||
@@ -1700,11 +1702,11 @@ public class ConnectivityManager {
|
|||||||
android.Manifest.permission.NETWORK_SETTINGS})
|
android.Manifest.permission.NETWORK_SETTINGS})
|
||||||
@SystemApi(client = MODULE_LIBRARIES)
|
@SystemApi(client = MODULE_LIBRARIES)
|
||||||
@Nullable
|
@Nullable
|
||||||
public NetworkCapabilities redactNetworkCapabilitiesForPackage(
|
public NetworkCapabilities getRedactedNetworkCapabilitiesForPackage(
|
||||||
@NonNull NetworkCapabilities nc,
|
@NonNull NetworkCapabilities nc,
|
||||||
int uid, @NonNull String packageName) {
|
int uid, @NonNull String packageName) {
|
||||||
try {
|
try {
|
||||||
return mService.redactNetworkCapabilitiesForPackage(nc, uid, packageName,
|
return mService.getRedactedNetworkCapabilitiesForPackage(nc, uid, packageName,
|
||||||
getAttributionTag());
|
getAttributionTag());
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
throw e.rethrowFromSystemServer();
|
throw e.rethrowFromSystemServer();
|
||||||
|
|||||||
@@ -76,13 +76,13 @@ interface IConnectivityManager
|
|||||||
LinkProperties getActiveLinkProperties();
|
LinkProperties getActiveLinkProperties();
|
||||||
LinkProperties getLinkPropertiesForType(int networkType);
|
LinkProperties getLinkPropertiesForType(int networkType);
|
||||||
LinkProperties getLinkProperties(in Network network);
|
LinkProperties getLinkProperties(in Network network);
|
||||||
LinkProperties redactLinkPropertiesForPackage(in LinkProperties lp, int uid, String packageName,
|
LinkProperties getRedactedLinkPropertiesForPackage(in LinkProperties lp, int uid,
|
||||||
String callingAttributionTag);
|
String packageName, String callingAttributionTag);
|
||||||
|
|
||||||
NetworkCapabilities getNetworkCapabilities(in Network network, String callingPackageName,
|
NetworkCapabilities getNetworkCapabilities(in Network network, String callingPackageName,
|
||||||
String callingAttributionTag);
|
String callingAttributionTag);
|
||||||
|
|
||||||
NetworkCapabilities redactNetworkCapabilitiesForPackage(in NetworkCapabilities nc, int uid,
|
NetworkCapabilities getRedactedNetworkCapabilitiesForPackage(in NetworkCapabilities nc, int uid,
|
||||||
String callingPackageName, String callingAttributionTag);
|
String callingPackageName, String callingAttributionTag);
|
||||||
|
|
||||||
@UnsupportedAppUsage(maxTargetSdk = 30, trackingBug = 170729553)
|
@UnsupportedAppUsage(maxTargetSdk = 30, trackingBug = 170729553)
|
||||||
|
|||||||
@@ -2172,7 +2172,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Nullable
|
@Nullable
|
||||||
public LinkProperties redactLinkPropertiesForPackage(@NonNull LinkProperties lp, int uid,
|
public LinkProperties getRedactedLinkPropertiesForPackage(@NonNull LinkProperties lp, int uid,
|
||||||
@NonNull String packageName, @Nullable String callingAttributionTag) {
|
@NonNull String packageName, @Nullable String callingAttributionTag) {
|
||||||
Objects.requireNonNull(packageName);
|
Objects.requireNonNull(packageName);
|
||||||
Objects.requireNonNull(lp);
|
Objects.requireNonNull(lp);
|
||||||
@@ -2207,8 +2207,9 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NetworkCapabilities redactNetworkCapabilitiesForPackage(@NonNull NetworkCapabilities nc,
|
public NetworkCapabilities getRedactedNetworkCapabilitiesForPackage(
|
||||||
int uid, @NonNull String packageName, @Nullable String callingAttributionTag) {
|
@NonNull NetworkCapabilities nc, int uid, @NonNull String packageName,
|
||||||
|
@Nullable String callingAttributionTag) {
|
||||||
Objects.requireNonNull(nc);
|
Objects.requireNonNull(nc);
|
||||||
Objects.requireNonNull(packageName);
|
Objects.requireNonNull(packageName);
|
||||||
enforceNetworkStackOrSettingsPermission();
|
enforceNetworkStackOrSettingsPermission();
|
||||||
|
|||||||
@@ -591,7 +591,7 @@ public class ConnectivityManagerTest {
|
|||||||
|
|
||||||
@DevSdkIgnoreRule.IgnoreUpTo(SC_V2)
|
@DevSdkIgnoreRule.IgnoreUpTo(SC_V2)
|
||||||
@Test
|
@Test
|
||||||
public void testRedactLinkPropertiesForPackage() throws Exception {
|
public void testGetRedactedLinkPropertiesForPackage() throws Exception {
|
||||||
final String groundedPkg = findPackageByPermissions(
|
final String groundedPkg = findPackageByPermissions(
|
||||||
List.of(), /* requiredPermissions */
|
List.of(), /* requiredPermissions */
|
||||||
List.of(ACCESS_NETWORK_STATE) /* forbiddenPermissions */);
|
List.of(ACCESS_NETWORK_STATE) /* forbiddenPermissions */);
|
||||||
@@ -628,54 +628,55 @@ public class ConnectivityManagerTest {
|
|||||||
// No matter what the given uid is, a SecurityException will be thrown if the caller
|
// No matter what the given uid is, a SecurityException will be thrown if the caller
|
||||||
// doesn't hold the NETWORK_SETTINGS permission.
|
// doesn't hold the NETWORK_SETTINGS permission.
|
||||||
assertThrows(SecurityException.class,
|
assertThrows(SecurityException.class,
|
||||||
() -> mCm.redactLinkPropertiesForPackage(lp, groundedUid, groundedPkg));
|
() -> mCm.getRedactedLinkPropertiesForPackage(lp, groundedUid, groundedPkg));
|
||||||
assertThrows(SecurityException.class,
|
assertThrows(SecurityException.class,
|
||||||
() -> mCm.redactLinkPropertiesForPackage(lp, normalUid, normalPkg));
|
() -> mCm.getRedactedLinkPropertiesForPackage(lp, normalUid, normalPkg));
|
||||||
assertThrows(SecurityException.class,
|
assertThrows(SecurityException.class,
|
||||||
() -> mCm.redactLinkPropertiesForPackage(lp, privilegedUid, privilegedPkg));
|
() -> mCm.getRedactedLinkPropertiesForPackage(lp, privilegedUid, privilegedPkg));
|
||||||
|
|
||||||
runAsShell(NETWORK_SETTINGS, () -> {
|
runAsShell(NETWORK_SETTINGS, () -> {
|
||||||
// No matter what the given uid is, if the given LinkProperties is null, then
|
// No matter what the given uid is, if the given LinkProperties is null, then
|
||||||
// NullPointerException will be thrown.
|
// NullPointerException will be thrown.
|
||||||
assertThrows(NullPointerException.class,
|
assertThrows(NullPointerException.class,
|
||||||
() -> mCm.redactLinkPropertiesForPackage(null, groundedUid, groundedPkg));
|
() -> mCm.getRedactedLinkPropertiesForPackage(null, groundedUid, groundedPkg));
|
||||||
assertThrows(NullPointerException.class,
|
assertThrows(NullPointerException.class,
|
||||||
() -> mCm.redactLinkPropertiesForPackage(null, normalUid, normalPkg));
|
() -> mCm.getRedactedLinkPropertiesForPackage(null, normalUid, normalPkg));
|
||||||
assertThrows(NullPointerException.class,
|
assertThrows(NullPointerException.class,
|
||||||
() -> mCm.redactLinkPropertiesForPackage(null, privilegedUid, privilegedPkg));
|
() -> mCm.getRedactedLinkPropertiesForPackage(
|
||||||
|
null, privilegedUid, privilegedPkg));
|
||||||
|
|
||||||
// Make sure null is returned for a UID without ACCESS_NETWORK_STATE.
|
// Make sure null is returned for a UID without ACCESS_NETWORK_STATE.
|
||||||
assertNull(mCm.redactLinkPropertiesForPackage(lp, groundedUid, groundedPkg));
|
assertNull(mCm.getRedactedLinkPropertiesForPackage(lp, groundedUid, groundedPkg));
|
||||||
|
|
||||||
// CaptivePortalApiUrl & CaptivePortalData will be set to null if given uid doesn't hold
|
// CaptivePortalApiUrl & CaptivePortalData will be set to null if given uid doesn't hold
|
||||||
// the NETWORK_SETTINGS permission.
|
// the NETWORK_SETTINGS permission.
|
||||||
assertNull(mCm.redactLinkPropertiesForPackage(lp, normalUid, normalPkg)
|
assertNull(mCm.getRedactedLinkPropertiesForPackage(lp, normalUid, normalPkg)
|
||||||
.getCaptivePortalApiUrl());
|
.getCaptivePortalApiUrl());
|
||||||
assertNull(mCm.redactLinkPropertiesForPackage(lp, normalUid, normalPkg)
|
assertNull(mCm.getRedactedLinkPropertiesForPackage(lp, normalUid, normalPkg)
|
||||||
.getCaptivePortalData());
|
.getCaptivePortalData());
|
||||||
// MTU is not sensitive and is not redacted.
|
// MTU is not sensitive and is not redacted.
|
||||||
assertEquals(mtu, mCm.redactLinkPropertiesForPackage(lp, normalUid, normalPkg)
|
assertEquals(mtu, mCm.getRedactedLinkPropertiesForPackage(lp, normalUid, normalPkg)
|
||||||
.getMtu());
|
.getMtu());
|
||||||
|
|
||||||
// CaptivePortalApiUrl & CaptivePortalData will be preserved if the given uid holds the
|
// CaptivePortalApiUrl & CaptivePortalData will be preserved if the given uid holds the
|
||||||
// NETWORK_SETTINGS permission.
|
// NETWORK_SETTINGS permission.
|
||||||
assertEquals(capportUrl,
|
assertEquals(capportUrl,
|
||||||
mCm.redactLinkPropertiesForPackage(lp, privilegedUid, privilegedPkg)
|
mCm.getRedactedLinkPropertiesForPackage(lp, privilegedUid, privilegedPkg)
|
||||||
.getCaptivePortalApiUrl());
|
.getCaptivePortalApiUrl());
|
||||||
assertEquals(capportData,
|
assertEquals(capportData,
|
||||||
mCm.redactLinkPropertiesForPackage(lp, privilegedUid, privilegedPkg)
|
mCm.getRedactedLinkPropertiesForPackage(lp, privilegedUid, privilegedPkg)
|
||||||
.getCaptivePortalData());
|
.getCaptivePortalData());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private NetworkCapabilities redactNc(@NonNull final NetworkCapabilities nc, int uid,
|
private NetworkCapabilities redactNc(@NonNull final NetworkCapabilities nc, int uid,
|
||||||
@NonNull String packageName) {
|
@NonNull String packageName) {
|
||||||
return mCm.redactNetworkCapabilitiesForPackage(nc, uid, packageName);
|
return mCm.getRedactedNetworkCapabilitiesForPackage(nc, uid, packageName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@DevSdkIgnoreRule.IgnoreUpTo(SC_V2)
|
@DevSdkIgnoreRule.IgnoreUpTo(SC_V2)
|
||||||
@Test
|
@Test
|
||||||
public void testRedactNetworkCapabilitiesForPackage() throws Exception {
|
public void testGetRedactedNetworkCapabilitiesForPackage() throws Exception {
|
||||||
final String groundedPkg = findPackageByPermissions(
|
final String groundedPkg = findPackageByPermissions(
|
||||||
List.of(), /* requiredPermissions */
|
List.of(), /* requiredPermissions */
|
||||||
List.of(ACCESS_NETWORK_STATE) /* forbiddenPermissions */);
|
List.of(ACCESS_NETWORK_STATE) /* forbiddenPermissions */);
|
||||||
|
|||||||
Reference in New Issue
Block a user