Merge "Address leftover comments on 923337 and 930217."

am: 1e97aab6f4

Change-Id: I733160ae51b8f0e80f78ab375cdb0a547b74f68d
This commit is contained in:
Paul Hu
2019-04-02 00:58:18 -07:00
committed by android-build-merger
9 changed files with 97 additions and 28 deletions

View File

@@ -27192,12 +27192,12 @@ package android.net {
public static class ConnectivityManager.NetworkCallback { public static class ConnectivityManager.NetworkCallback {
ctor public ConnectivityManager.NetworkCallback(); ctor public ConnectivityManager.NetworkCallback();
method public void onAvailable(android.net.Network); method public void onAvailable(@NonNull android.net.Network);
method public void onBlockedStatusChanged(@NonNull android.net.Network, boolean); method public void onBlockedStatusChanged(@NonNull android.net.Network, boolean);
method public void onCapabilitiesChanged(android.net.Network, android.net.NetworkCapabilities); method public void onCapabilitiesChanged(@NonNull android.net.Network, @NonNull android.net.NetworkCapabilities);
method public void onLinkPropertiesChanged(android.net.Network, android.net.LinkProperties); method public void onLinkPropertiesChanged(@NonNull android.net.Network, @NonNull android.net.LinkProperties);
method public void onLosing(android.net.Network, int); method public void onLosing(@NonNull android.net.Network, int);
method public void onLost(android.net.Network); method public void onLost(@NonNull android.net.Network);
method public void onUnavailable(); method public void onUnavailable();
} }

View File

@@ -97,6 +97,7 @@ package android {
field public static final String MOVE_PACKAGE = "android.permission.MOVE_PACKAGE"; field public static final String MOVE_PACKAGE = "android.permission.MOVE_PACKAGE";
field public static final String NETWORK_SCAN = "android.permission.NETWORK_SCAN"; field public static final String NETWORK_SCAN = "android.permission.NETWORK_SCAN";
field public static final String NETWORK_SETUP_WIZARD = "android.permission.NETWORK_SETUP_WIZARD"; field public static final String NETWORK_SETUP_WIZARD = "android.permission.NETWORK_SETUP_WIZARD";
field public static final String NETWORK_SIGNAL_STRENGTH_WAKEUP = "android.permission.NETWORK_SIGNAL_STRENGTH_WAKEUP";
field public static final String NOTIFICATION_DURING_SETUP = "android.permission.NOTIFICATION_DURING_SETUP"; field public static final String NOTIFICATION_DURING_SETUP = "android.permission.NOTIFICATION_DURING_SETUP";
field public static final String NOTIFY_TV_INPUTS = "android.permission.NOTIFY_TV_INPUTS"; field public static final String NOTIFY_TV_INPUTS = "android.permission.NOTIFY_TV_INPUTS";
field public static final String OBSERVE_APP_USAGE = "android.permission.OBSERVE_APP_USAGE"; field public static final String OBSERVE_APP_USAGE = "android.permission.OBSERVE_APP_USAGE";
@@ -3202,7 +3203,7 @@ package android.net {
} }
public static class NetworkRequest.Builder { public static class NetworkRequest.Builder {
method @NonNull public android.net.NetworkRequest.Builder setSignalStrength(int); method @NonNull @RequiresPermission(android.Manifest.permission.NETWORK_SIGNAL_STRENGTH_WAKEUP) public android.net.NetworkRequest.Builder setSignalStrength(int);
} }
public class NetworkScoreManager { public class NetworkScoreManager {

View File

@@ -3234,7 +3234,7 @@ public class ConnectivityManager {
* *
* @hide * @hide
*/ */
public void onPreCheck(Network network) {} public void onPreCheck(@NonNull Network network) {}
/** /**
* Called when the framework connects and has declared a new network ready for use. * Called when the framework connects and has declared a new network ready for use.
@@ -3247,8 +3247,9 @@ public class ConnectivityManager {
* @param blocked Whether access to the {@link Network} is blocked due to system policy. * @param blocked Whether access to the {@link Network} is blocked due to system policy.
* @hide * @hide
*/ */
public void onAvailable(Network network, NetworkCapabilities networkCapabilities, public void onAvailable(@NonNull Network network,
LinkProperties linkProperties, boolean blocked) { @NonNull NetworkCapabilities networkCapabilities,
@NonNull LinkProperties linkProperties, boolean blocked) {
// Internally only this method is called when a new network is available, and // Internally only this method is called when a new network is available, and
// it calls the callback in the same way and order that older versions used // it calls the callback in the same way and order that older versions used
// to call so as not to change the behavior. // to call so as not to change the behavior.
@@ -3272,7 +3273,7 @@ public class ConnectivityManager {
* *
* @param network The {@link Network} of the satisfying network. * @param network The {@link Network} of the satisfying network.
*/ */
public void onAvailable(Network network) {} public void onAvailable(@NonNull Network network) {}
/** /**
* Called when the network is about to be disconnected. Often paired with an * Called when the network is about to be disconnected. Often paired with an
@@ -3288,7 +3289,7 @@ public class ConnectivityManager {
* network connected. Note that the network may suffer a * network connected. Note that the network may suffer a
* hard loss at any time. * hard loss at any time.
*/ */
public void onLosing(Network network, int maxMsToLive) {} public void onLosing(@NonNull Network network, int maxMsToLive) {}
/** /**
* Called when the framework has a hard loss of the network or when the * Called when the framework has a hard loss of the network or when the
@@ -3296,7 +3297,7 @@ public class ConnectivityManager {
* *
* @param network The {@link Network} lost. * @param network The {@link Network} lost.
*/ */
public void onLost(Network network) {} public void onLost(@NonNull Network network) {}
/** /**
* Called if no network is found in the timeout time specified in * Called if no network is found in the timeout time specified in
@@ -3316,8 +3317,8 @@ public class ConnectivityManager {
* @param networkCapabilities The new {@link android.net.NetworkCapabilities} for this * @param networkCapabilities The new {@link android.net.NetworkCapabilities} for this
* network. * network.
*/ */
public void onCapabilitiesChanged(Network network, public void onCapabilitiesChanged(@NonNull Network network,
NetworkCapabilities networkCapabilities) {} @NonNull NetworkCapabilities networkCapabilities) {}
/** /**
* Called when the network the framework connected to for this request * Called when the network the framework connected to for this request
@@ -3326,7 +3327,8 @@ public class ConnectivityManager {
* @param network The {@link Network} whose link properties have changed. * @param network The {@link Network} whose link properties have changed.
* @param linkProperties The new {@link LinkProperties} for this network. * @param linkProperties The new {@link LinkProperties} for this network.
*/ */
public void onLinkPropertiesChanged(Network network, LinkProperties linkProperties) {} public void onLinkPropertiesChanged(@NonNull Network network,
@NonNull LinkProperties linkProperties) {}
/** /**
* Called when the network the framework connected to for this request * Called when the network the framework connected to for this request
@@ -3337,7 +3339,7 @@ public class ConnectivityManager {
* a tunnel, etc. * a tunnel, etc.
* @hide * @hide
*/ */
public void onNetworkSuspended(Network network) {} public void onNetworkSuspended(@NonNull Network network) {}
/** /**
* Called when the network the framework connected to for this request * Called when the network the framework connected to for this request
@@ -3345,7 +3347,7 @@ public class ConnectivityManager {
* preceded by a matching {@link NetworkCallback#onNetworkSuspended} call. * preceded by a matching {@link NetworkCallback#onNetworkSuspended} call.
* @hide * @hide
*/ */
public void onNetworkResumed(Network network) {} public void onNetworkResumed(@NonNull Network network) {}
/** /**
* Called when access to the specified network is blocked or unblocked. * Called when access to the specified network is blocked or unblocked.

View File

@@ -316,9 +316,6 @@ public final class LinkProperties implements Parcelable {
@SystemApi @SystemApi
@TestApi @TestApi
public boolean removeLinkAddress(@NonNull LinkAddress toRemove) { public boolean removeLinkAddress(@NonNull LinkAddress toRemove) {
if (toRemove == null) {
return false;
}
int i = findLinkAddressIndex(toRemove); int i = findLinkAddressIndex(toRemove);
if (i >= 0) { if (i >= 0) {
mLinkAddresses.remove(i); mLinkAddresses.remove(i);
@@ -391,10 +388,7 @@ public final class LinkProperties implements Parcelable {
@TestApi @TestApi
@SystemApi @SystemApi
public boolean removeDnsServer(@NonNull InetAddress dnsServer) { public boolean removeDnsServer(@NonNull InetAddress dnsServer) {
if (dnsServer != null) { return mDnses.remove(dnsServer);
return mDnses.remove(dnsServer);
}
return false;
} }
/** /**

View File

@@ -17,6 +17,7 @@
package android.net; package android.net;
import android.annotation.NonNull; import android.annotation.NonNull;
import android.annotation.RequiresPermission;
import android.annotation.SystemApi; import android.annotation.SystemApi;
import android.annotation.UnsupportedAppUsage; import android.annotation.UnsupportedAppUsage;
import android.net.NetworkCapabilities.NetCapability; import android.net.NetworkCapabilities.NetCapability;
@@ -343,10 +344,14 @@ public class NetworkRequest implements Parcelable {
* current value. A value of {@code SIGNAL_STRENGTH_UNSPECIFIED} means no value when * current value. A value of {@code SIGNAL_STRENGTH_UNSPECIFIED} means no value when
* received and has no effect when requesting a callback. * received and has no effect when requesting a callback.
* *
* <p>This method requires the caller to hold the
* {@link android.Manifest.permission#NETWORK_SIGNAL_STRENGTH_WAKEUP} permission
*
* @param signalStrength the bearer-specific signal strength. * @param signalStrength the bearer-specific signal strength.
* @hide * @hide
*/ */
@SystemApi @SystemApi
@RequiresPermission(android.Manifest.permission.NETWORK_SIGNAL_STRENGTH_WAKEUP)
public @NonNull Builder setSignalStrength(int signalStrength) { public @NonNull Builder setSignalStrength(int signalStrength) {
mNetworkCapabilities.setSignalStrength(signalStrength); mNetworkCapabilities.setSignalStrength(signalStrength);
return this; return this;

View File

@@ -50,8 +50,7 @@ public abstract class CaptivePortalProbeSpec {
private final String mEncodedSpec; private final String mEncodedSpec;
private final URL mUrl; private final URL mUrl;
CaptivePortalProbeSpec(@NonNull String encodedSpec, @NonNull URL url) CaptivePortalProbeSpec(@NonNull String encodedSpec, @NonNull URL url) {
throws NullPointerException {
mEncodedSpec = checkNotNull(encodedSpec); mEncodedSpec = checkNotNull(encodedSpec);
mUrl = checkNotNull(url); mUrl = checkNotNull(url);
} }

View File

@@ -1580,6 +1580,12 @@
<permission android:name="android.permission.CONNECTIVITY_USE_RESTRICTED_NETWORKS" <permission android:name="android.permission.CONNECTIVITY_USE_RESTRICTED_NETWORKS"
android:protectionLevel="signature|privileged" /> android:protectionLevel="signature|privileged" />
<!-- @SystemApi Allows an internal user to set signal strength in NetworkRequest. This kind of
request will wake up device when signal strength meets the given value.
@hide -->
<permission android:name="android.permission.NETWORK_SIGNAL_STRENGTH_WAKEUP"
android:protectionLevel="signature|privileged" />
<!-- @SystemApi Allows a system application to access hardware packet offload capabilities. <!-- @SystemApi Allows a system application to access hardware packet offload capabilities.
@hide --> @hide -->
<permission android:name="android.permission.PACKET_KEEPALIVE_OFFLOAD" <permission android:name="android.permission.PACKET_KEEPALIVE_OFFLOAD"

View File

@@ -1892,6 +1892,15 @@ public class ConnectivityService extends IConnectivityManager.Stub
return false; return false;
} }
private boolean checkAnyPermissionOf(int pid, int uid, String... permissions) {
for (String permission : permissions) {
if (mContext.checkPermission(permission, pid, uid) == PERMISSION_GRANTED) {
return true;
}
}
return false;
}
private void enforceAnyPermissionOf(String... permissions) { private void enforceAnyPermissionOf(String... permissions) {
if (!checkAnyPermissionOf(permissions)) { if (!checkAnyPermissionOf(permissions)) {
throw new SecurityException("Requires one of the following permissions: " throw new SecurityException("Requires one of the following permissions: "
@@ -1966,6 +1975,12 @@ public class ConnectivityService extends IConnectivityManager.Stub
NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK); NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK);
} }
private boolean checkNetworkSignalStrengthWakeupPermission(int pid, int uid) {
return checkAnyPermissionOf(pid, uid,
android.Manifest.permission.NETWORK_SIGNAL_STRENGTH_WAKEUP,
NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK);
}
private void enforceConnectivityRestrictedNetworksPermission() { private void enforceConnectivityRestrictedNetworksPermission() {
try { try {
mContext.enforceCallingOrSelfPermission( mContext.enforceCallingOrSelfPermission(
@@ -4959,13 +4974,19 @@ public class ConnectivityService extends IConnectivityManager.Stub
} }
} }
// This checks that the passed capabilities either do not request a specific SSID, or the // This checks that the passed capabilities either do not request a specific SSID/SignalStrength
// calling app has permission to do so. // , or the calling app has permission to do so.
private void ensureSufficientPermissionsForRequest(NetworkCapabilities nc, private void ensureSufficientPermissionsForRequest(NetworkCapabilities nc,
int callerPid, int callerUid) { int callerPid, int callerUid) {
if (null != nc.getSSID() && !checkSettingsPermission(callerPid, callerUid)) { if (null != nc.getSSID() && !checkSettingsPermission(callerPid, callerUid)) {
throw new SecurityException("Insufficient permissions to request a specific SSID"); throw new SecurityException("Insufficient permissions to request a specific SSID");
} }
if (nc.hasSignalStrength()
&& !checkNetworkSignalStrengthWakeupPermission(callerPid, callerUid)) {
throw new SecurityException(
"Insufficient permissions to request a specific signal strength");
}
} }
private ArrayList<Integer> getSignalStrengthThresholds(NetworkAgentInfo nai) { private ArrayList<Integer> getSignalStrengthThresholds(NetworkAgentInfo nai) {

View File

@@ -3046,6 +3046,47 @@ public class ConnectivityServiceTest {
} }
} }
@Test
public void testInvalidSignalStrength() {
NetworkRequest r = new NetworkRequest.Builder()
.addCapability(NET_CAPABILITY_INTERNET)
.addTransportType(TRANSPORT_WIFI)
.setSignalStrength(-75)
.build();
// Registering a NetworkCallback with signal strength but w/o NETWORK_SIGNAL_STRENGTH_WAKEUP
// permission should get SecurityException.
try {
mCm.registerNetworkCallback(r, new NetworkCallback());
fail("Expected SecurityException filing a callback with signal strength");
} catch (SecurityException expected) {
// expected
}
try {
mCm.registerNetworkCallback(r, PendingIntent.getService(
mServiceContext, 0, new Intent(), 0));
fail("Expected SecurityException filing a callback with signal strength");
} catch (SecurityException expected) {
// expected
}
// Requesting a Network with signal strength should get IllegalArgumentException.
try {
mCm.requestNetwork(r, new NetworkCallback());
fail("Expected IllegalArgumentException filing a request with signal strength");
} catch (IllegalArgumentException expected) {
// expected
}
try {
mCm.requestNetwork(r, PendingIntent.getService(
mServiceContext, 0, new Intent(), 0));
fail("Expected IllegalArgumentException filing a request with signal strength");
} catch (IllegalArgumentException expected) {
// expected
}
}
@Test @Test
public void testRegisterDefaultNetworkCallback() throws Exception { public void testRegisterDefaultNetworkCallback() throws Exception {
final TestNetworkCallback defaultNetworkCallback = new TestNetworkCallback(); final TestNetworkCallback defaultNetworkCallback = new TestNetworkCallback();