RELAND: NetworkRequest: Embed requestor uid & packageName
Add the requestorUid & requestorPackageName fields to NetworkCapabilities. This is populated by CS when a new network request is received. These 2 requestor fields are also optionally used for network matching. All of the regular app initiated requests will have the requestor uid and package name set by connectivity service. Network agents can optionally set the requestorUid and requestorPackageName to restrict the network created only to the app that requested the network. This will help removing the necessity for the various specifiers to embed the uid & package name info in the specifier for network matching. Note: NetworkSpecifier.assertValidFromUid() is deprecated & removed in favor of setting the uid/package name on the agent to restrict the network to a certain app (useful for wifi peer to peer API & wifi aware). Bug: 144102365 Test: Verified that wifi network request related CTS verifier tests pass. Test: Device boots up and connects to wifi networks Merged-In: I207c446108afdac7ee2c25e6bbcbc37c4e3f6529 Change-Id: I58775e82aa7725aac5aa27ca9d2b5ee8f0be4242
This commit is contained in:
@@ -3746,6 +3746,7 @@ public class ConnectivityManager {
|
|||||||
checkCallbackNotNull(callback);
|
checkCallbackNotNull(callback);
|
||||||
Preconditions.checkArgument(action == REQUEST || need != null, "null NetworkCapabilities");
|
Preconditions.checkArgument(action == REQUEST || need != null, "null NetworkCapabilities");
|
||||||
final NetworkRequest request;
|
final NetworkRequest request;
|
||||||
|
final String callingPackageName = mContext.getOpPackageName();
|
||||||
try {
|
try {
|
||||||
synchronized(sCallbacks) {
|
synchronized(sCallbacks) {
|
||||||
if (callback.networkRequest != null
|
if (callback.networkRequest != null
|
||||||
@@ -3757,10 +3758,11 @@ public class ConnectivityManager {
|
|||||||
Messenger messenger = new Messenger(handler);
|
Messenger messenger = new Messenger(handler);
|
||||||
Binder binder = new Binder();
|
Binder binder = new Binder();
|
||||||
if (action == LISTEN) {
|
if (action == LISTEN) {
|
||||||
request = mService.listenForNetwork(need, messenger, binder);
|
request = mService.listenForNetwork(
|
||||||
|
need, messenger, binder, callingPackageName);
|
||||||
} else {
|
} else {
|
||||||
request = mService.requestNetwork(
|
request = mService.requestNetwork(
|
||||||
need, messenger, timeoutMs, binder, legacyType);
|
need, messenger, timeoutMs, binder, legacyType, callingPackageName);
|
||||||
}
|
}
|
||||||
if (request != null) {
|
if (request != null) {
|
||||||
sCallbacks.put(request, callback);
|
sCallbacks.put(request, callback);
|
||||||
@@ -4033,8 +4035,10 @@ public class ConnectivityManager {
|
|||||||
@NonNull PendingIntent operation) {
|
@NonNull PendingIntent operation) {
|
||||||
printStackTrace();
|
printStackTrace();
|
||||||
checkPendingIntentNotNull(operation);
|
checkPendingIntentNotNull(operation);
|
||||||
|
final String callingPackageName = mContext.getOpPackageName();
|
||||||
try {
|
try {
|
||||||
mService.pendingRequestForNetwork(request.networkCapabilities, operation);
|
mService.pendingRequestForNetwork(
|
||||||
|
request.networkCapabilities, operation, callingPackageName);
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
throw e.rethrowFromSystemServer();
|
throw e.rethrowFromSystemServer();
|
||||||
} catch (ServiceSpecificException e) {
|
} catch (ServiceSpecificException e) {
|
||||||
@@ -4146,8 +4150,10 @@ public class ConnectivityManager {
|
|||||||
@NonNull PendingIntent operation) {
|
@NonNull PendingIntent operation) {
|
||||||
printStackTrace();
|
printStackTrace();
|
||||||
checkPendingIntentNotNull(operation);
|
checkPendingIntentNotNull(operation);
|
||||||
|
final String callingPackageName = mContext.getOpPackageName();
|
||||||
try {
|
try {
|
||||||
mService.pendingListenForNetwork(request.networkCapabilities, operation);
|
mService.pendingListenForNetwork(
|
||||||
|
request.networkCapabilities, operation, callingPackageName);
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
throw e.rethrowFromSystemServer();
|
throw e.rethrowFromSystemServer();
|
||||||
} catch (ServiceSpecificException e) {
|
} catch (ServiceSpecificException e) {
|
||||||
|
|||||||
@@ -166,18 +166,19 @@ interface IConnectivityManager
|
|||||||
in int factorySerialNumber);
|
in int factorySerialNumber);
|
||||||
|
|
||||||
NetworkRequest requestNetwork(in NetworkCapabilities networkCapabilities,
|
NetworkRequest requestNetwork(in NetworkCapabilities networkCapabilities,
|
||||||
in Messenger messenger, int timeoutSec, in IBinder binder, int legacy);
|
in Messenger messenger, int timeoutSec, in IBinder binder, int legacy,
|
||||||
|
String callingPackageName);
|
||||||
|
|
||||||
NetworkRequest pendingRequestForNetwork(in NetworkCapabilities networkCapabilities,
|
NetworkRequest pendingRequestForNetwork(in NetworkCapabilities networkCapabilities,
|
||||||
in PendingIntent operation);
|
in PendingIntent operation, String callingPackageName);
|
||||||
|
|
||||||
void releasePendingNetworkRequest(in PendingIntent operation);
|
void releasePendingNetworkRequest(in PendingIntent operation);
|
||||||
|
|
||||||
NetworkRequest listenForNetwork(in NetworkCapabilities networkCapabilities,
|
NetworkRequest listenForNetwork(in NetworkCapabilities networkCapabilities,
|
||||||
in Messenger messenger, in IBinder binder);
|
in Messenger messenger, in IBinder binder, String callingPackageName);
|
||||||
|
|
||||||
void pendingListenForNetwork(in NetworkCapabilities networkCapabilities,
|
void pendingListenForNetwork(in NetworkCapabilities networkCapabilities,
|
||||||
in PendingIntent operation);
|
in PendingIntent operation, String callingPackageName);
|
||||||
|
|
||||||
void releaseNetworkRequest(in NetworkRequest networkRequest);
|
void releaseNetworkRequest(in NetworkRequest networkRequest);
|
||||||
|
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ import android.os.Build;
|
|||||||
import android.os.Parcel;
|
import android.os.Parcel;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
import android.os.Process;
|
import android.os.Process;
|
||||||
|
import android.text.TextUtils;
|
||||||
import android.util.ArraySet;
|
import android.util.ArraySet;
|
||||||
import android.util.proto.ProtoOutputStream;
|
import android.util.proto.ProtoOutputStream;
|
||||||
|
|
||||||
@@ -63,6 +64,16 @@ public final class NetworkCapabilities implements Parcelable {
|
|||||||
// Set to true when private DNS is broken.
|
// Set to true when private DNS is broken.
|
||||||
private boolean mPrivateDnsBroken;
|
private boolean mPrivateDnsBroken;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Uid of the app making the request.
|
||||||
|
*/
|
||||||
|
private int mRequestorUid;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Package name of the app making the request.
|
||||||
|
*/
|
||||||
|
private String mRequestorPackageName;
|
||||||
|
|
||||||
public NetworkCapabilities() {
|
public NetworkCapabilities() {
|
||||||
clearAll();
|
clearAll();
|
||||||
mNetworkCapabilities = DEFAULT_CAPABILITIES;
|
mNetworkCapabilities = DEFAULT_CAPABILITIES;
|
||||||
@@ -89,6 +100,8 @@ public final class NetworkCapabilities implements Parcelable {
|
|||||||
mOwnerUid = Process.INVALID_UID;
|
mOwnerUid = Process.INVALID_UID;
|
||||||
mSSID = null;
|
mSSID = null;
|
||||||
mPrivateDnsBroken = false;
|
mPrivateDnsBroken = false;
|
||||||
|
mRequestorUid = Process.INVALID_UID;
|
||||||
|
mRequestorPackageName = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -109,6 +122,8 @@ public final class NetworkCapabilities implements Parcelable {
|
|||||||
mUnwantedNetworkCapabilities = nc.mUnwantedNetworkCapabilities;
|
mUnwantedNetworkCapabilities = nc.mUnwantedNetworkCapabilities;
|
||||||
mSSID = nc.mSSID;
|
mSSID = nc.mSSID;
|
||||||
mPrivateDnsBroken = nc.mPrivateDnsBroken;
|
mPrivateDnsBroken = nc.mPrivateDnsBroken;
|
||||||
|
mRequestorUid = nc.mRequestorUid;
|
||||||
|
mRequestorPackageName = nc.mRequestorPackageName;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -810,7 +825,7 @@ public final class NetworkCapabilities implements Parcelable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* UID of the app that owns this network, or INVALID_UID if none/unknown.
|
* UID of the app that owns this network, or Process#INVALID_UID if none/unknown.
|
||||||
*
|
*
|
||||||
* <p>This field keeps track of the UID of the app that created this network and is in charge of
|
* <p>This field keeps track of the UID of the app that created this network and is in charge of
|
||||||
* its lifecycle. This could be the UID of apps such as the Wifi network suggestor, the running
|
* its lifecycle. This could be the UID of apps such as the Wifi network suggestor, the running
|
||||||
@@ -821,8 +836,9 @@ public final class NetworkCapabilities implements Parcelable {
|
|||||||
/**
|
/**
|
||||||
* Set the UID of the owner app.
|
* Set the UID of the owner app.
|
||||||
*/
|
*/
|
||||||
public void setOwnerUid(final int uid) {
|
public @NonNull NetworkCapabilities setOwnerUid(final int uid) {
|
||||||
mOwnerUid = uid;
|
mOwnerUid = uid;
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -865,9 +881,11 @@ public final class NetworkCapabilities implements Parcelable {
|
|||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
@SystemApi
|
@SystemApi
|
||||||
public void setAdministratorUids(@NonNull final List<Integer> administratorUids) {
|
public @NonNull NetworkCapabilities setAdministratorUids(
|
||||||
|
@NonNull final List<Integer> administratorUids) {
|
||||||
mAdministratorUids.clear();
|
mAdministratorUids.clear();
|
||||||
mAdministratorUids.addAll(administratorUids);
|
mAdministratorUids.addAll(administratorUids);
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1385,6 +1403,7 @@ public final class NetworkCapabilities implements Parcelable {
|
|||||||
combineSignalStrength(nc);
|
combineSignalStrength(nc);
|
||||||
combineUids(nc);
|
combineUids(nc);
|
||||||
combineSSIDs(nc);
|
combineSSIDs(nc);
|
||||||
|
combineRequestor(nc);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1404,7 +1423,8 @@ public final class NetworkCapabilities implements Parcelable {
|
|||||||
&& satisfiedBySpecifier(nc)
|
&& satisfiedBySpecifier(nc)
|
||||||
&& (onlyImmutable || satisfiedBySignalStrength(nc))
|
&& (onlyImmutable || satisfiedBySignalStrength(nc))
|
||||||
&& (onlyImmutable || satisfiedByUids(nc))
|
&& (onlyImmutable || satisfiedByUids(nc))
|
||||||
&& (onlyImmutable || satisfiedBySSID(nc)));
|
&& (onlyImmutable || satisfiedBySSID(nc)))
|
||||||
|
&& (onlyImmutable || satisfiedByRequestor(nc));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1488,7 +1508,7 @@ public final class NetworkCapabilities implements Parcelable {
|
|||||||
public boolean equals(@Nullable Object obj) {
|
public boolean equals(@Nullable Object obj) {
|
||||||
if (obj == null || (obj instanceof NetworkCapabilities == false)) return false;
|
if (obj == null || (obj instanceof NetworkCapabilities == false)) return false;
|
||||||
NetworkCapabilities that = (NetworkCapabilities) obj;
|
NetworkCapabilities that = (NetworkCapabilities) obj;
|
||||||
return (equalsNetCapabilities(that)
|
return equalsNetCapabilities(that)
|
||||||
&& equalsTransportTypes(that)
|
&& equalsTransportTypes(that)
|
||||||
&& equalsLinkBandwidths(that)
|
&& equalsLinkBandwidths(that)
|
||||||
&& equalsSignalStrength(that)
|
&& equalsSignalStrength(that)
|
||||||
@@ -1496,7 +1516,8 @@ public final class NetworkCapabilities implements Parcelable {
|
|||||||
&& equalsTransportInfo(that)
|
&& equalsTransportInfo(that)
|
||||||
&& equalsUids(that)
|
&& equalsUids(that)
|
||||||
&& equalsSSID(that)
|
&& equalsSSID(that)
|
||||||
&& equalsPrivateDnsBroken(that));
|
&& equalsPrivateDnsBroken(that)
|
||||||
|
&& equalsRequestor(that);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -1514,7 +1535,9 @@ public final class NetworkCapabilities implements Parcelable {
|
|||||||
+ Objects.hashCode(mUids) * 31
|
+ Objects.hashCode(mUids) * 31
|
||||||
+ Objects.hashCode(mSSID) * 37
|
+ Objects.hashCode(mSSID) * 37
|
||||||
+ Objects.hashCode(mTransportInfo) * 41
|
+ Objects.hashCode(mTransportInfo) * 41
|
||||||
+ Objects.hashCode(mPrivateDnsBroken) * 43;
|
+ Objects.hashCode(mPrivateDnsBroken) * 43
|
||||||
|
+ Objects.hashCode(mRequestorUid) * 47
|
||||||
|
+ Objects.hashCode(mRequestorPackageName) * 53;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -1537,6 +1560,8 @@ public final class NetworkCapabilities implements Parcelable {
|
|||||||
dest.writeBoolean(mPrivateDnsBroken);
|
dest.writeBoolean(mPrivateDnsBroken);
|
||||||
dest.writeList(mAdministratorUids);
|
dest.writeList(mAdministratorUids);
|
||||||
dest.writeInt(mOwnerUid);
|
dest.writeInt(mOwnerUid);
|
||||||
|
dest.writeInt(mRequestorUid);
|
||||||
|
dest.writeString(mRequestorPackageName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final @android.annotation.NonNull Creator<NetworkCapabilities> CREATOR =
|
public static final @android.annotation.NonNull Creator<NetworkCapabilities> CREATOR =
|
||||||
@@ -1559,6 +1584,8 @@ public final class NetworkCapabilities implements Parcelable {
|
|||||||
netCap.mPrivateDnsBroken = in.readBoolean();
|
netCap.mPrivateDnsBroken = in.readBoolean();
|
||||||
netCap.setAdministratorUids(in.readArrayList(null));
|
netCap.setAdministratorUids(in.readArrayList(null));
|
||||||
netCap.mOwnerUid = in.readInt();
|
netCap.mOwnerUid = in.readInt();
|
||||||
|
netCap.mRequestorUid = in.readInt();
|
||||||
|
netCap.mRequestorPackageName = in.readString();
|
||||||
return netCap;
|
return netCap;
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
@@ -1624,6 +1651,9 @@ public final class NetworkCapabilities implements Parcelable {
|
|||||||
sb.append(" Private DNS is broken");
|
sb.append(" Private DNS is broken");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sb.append(" RequestorUid: ").append(mRequestorUid);
|
||||||
|
sb.append(" RequestorPackageName: ").append(mRequestorPackageName);
|
||||||
|
|
||||||
sb.append("]");
|
sb.append("]");
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
@@ -1632,6 +1662,7 @@ public final class NetworkCapabilities implements Parcelable {
|
|||||||
private interface NameOf {
|
private interface NameOf {
|
||||||
String nameOf(int value);
|
String nameOf(int value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
@@ -1799,4 +1830,120 @@ public final class NetworkCapabilities implements Parcelable {
|
|||||||
private boolean equalsPrivateDnsBroken(NetworkCapabilities nc) {
|
private boolean equalsPrivateDnsBroken(NetworkCapabilities nc) {
|
||||||
return mPrivateDnsBroken == nc.mPrivateDnsBroken;
|
return mPrivateDnsBroken == nc.mPrivateDnsBroken;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the uid of the app making the request.
|
||||||
|
*
|
||||||
|
* Note: This works only for {@link NetworkAgent} instances. Any capabilities passed in
|
||||||
|
* via the public {@link ConnectivityManager} API's will have this field overwritten.
|
||||||
|
*
|
||||||
|
* @param uid UID of the app.
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
@SystemApi
|
||||||
|
public @NonNull NetworkCapabilities setRequestorUid(int uid) {
|
||||||
|
mRequestorUid = uid;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the uid of the app making the request.
|
||||||
|
*
|
||||||
|
* Note: This could return {@link Process#INVALID_UID} if the {@link NetworkRequest}
|
||||||
|
* object was not obtained from {@link ConnectivityManager}.
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
public int getRequestorUid() {
|
||||||
|
return mRequestorUid;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the package name of the app making the request.
|
||||||
|
*
|
||||||
|
* Note: This works only for {@link NetworkAgent} instances. Any capabilities passed in
|
||||||
|
* via the public {@link ConnectivityManager} API's will have this field overwritten.
|
||||||
|
*
|
||||||
|
* @param packageName package name of the app.
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
@SystemApi
|
||||||
|
public @NonNull NetworkCapabilities setRequestorPackageName(@NonNull String packageName) {
|
||||||
|
mRequestorPackageName = packageName;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the package name of the app making the request.
|
||||||
|
*
|
||||||
|
* Note: This could return {@code null} if the {@link NetworkRequest} object was not obtained
|
||||||
|
* from {@link ConnectivityManager}.
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
public String getRequestorPackageName() {
|
||||||
|
return mRequestorPackageName;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the uid and package name of the app making the request.
|
||||||
|
*
|
||||||
|
* Note: This is intended to be only invoked from within connectivitiy service.
|
||||||
|
*
|
||||||
|
* @param uid UID of the app.
|
||||||
|
* @param packageName package name of the app.
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
public @NonNull NetworkCapabilities setRequestorUidAndPackageName(
|
||||||
|
int uid, @NonNull String packageName) {
|
||||||
|
return setRequestorUid(uid).setRequestorPackageName(packageName);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test whether the passed NetworkCapabilities satisfies the requestor restrictions of this
|
||||||
|
* capabilities.
|
||||||
|
*
|
||||||
|
* This method is called on the NetworkCapabilities embedded in a request with the
|
||||||
|
* capabilities of an available network. If the available network, sets a specific
|
||||||
|
* requestor (by uid and optionally package name), then this will only match a request from the
|
||||||
|
* same app. If either of the capabilities have an unset uid or package name, then it matches
|
||||||
|
* everything.
|
||||||
|
* <p>
|
||||||
|
* nc is assumed nonnull. Else, NPE.
|
||||||
|
*/
|
||||||
|
private boolean satisfiedByRequestor(NetworkCapabilities nc) {
|
||||||
|
// No uid set, matches everything.
|
||||||
|
if (mRequestorUid == Process.INVALID_UID || nc.mRequestorUid == Process.INVALID_UID) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// uids don't match.
|
||||||
|
if (mRequestorUid != nc.mRequestorUid) return false;
|
||||||
|
// No package names set, matches everything
|
||||||
|
if (null == nc.mRequestorPackageName || null == mRequestorPackageName) return true;
|
||||||
|
// check for package name match.
|
||||||
|
return TextUtils.equals(mRequestorPackageName, nc.mRequestorPackageName);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Combine requestor info of the capabilities.
|
||||||
|
* <p>
|
||||||
|
* This is only legal if either the requestor info of this object is reset, or both info are
|
||||||
|
* equal.
|
||||||
|
* nc is assumed nonnull.
|
||||||
|
*/
|
||||||
|
private void combineRequestor(@NonNull NetworkCapabilities nc) {
|
||||||
|
if (mRequestorUid != Process.INVALID_UID && mRequestorUid != nc.mOwnerUid) {
|
||||||
|
throw new IllegalStateException("Can't combine two uids");
|
||||||
|
}
|
||||||
|
if (mRequestorPackageName != null
|
||||||
|
&& !mRequestorPackageName.equals(nc.mRequestorPackageName)) {
|
||||||
|
throw new IllegalStateException("Can't combine two package names");
|
||||||
|
}
|
||||||
|
setRequestorUid(nc.mRequestorUid);
|
||||||
|
setRequestorPackageName(nc.mRequestorPackageName);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean equalsRequestor(NetworkCapabilities nc) {
|
||||||
|
return mRequestorUid == nc.mRequestorUid
|
||||||
|
&& TextUtils.equals(mRequestorPackageName, nc.mRequestorPackageName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -380,6 +380,7 @@ public class NetworkRequest implements Parcelable {
|
|||||||
dest.writeInt(requestId);
|
dest.writeInt(requestId);
|
||||||
dest.writeString(type.name());
|
dest.writeString(type.name());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final @android.annotation.NonNull Creator<NetworkRequest> CREATOR =
|
public static final @android.annotation.NonNull Creator<NetworkRequest> CREATOR =
|
||||||
new Creator<NetworkRequest>() {
|
new Creator<NetworkRequest>() {
|
||||||
public NetworkRequest createFromParcel(Parcel in) {
|
public NetworkRequest createFromParcel(Parcel in) {
|
||||||
@@ -494,6 +495,31 @@ public class NetworkRequest implements Parcelable {
|
|||||||
return networkCapabilities.getNetworkSpecifier();
|
return networkCapabilities.getNetworkSpecifier();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the uid of the app making the request.
|
||||||
|
*
|
||||||
|
* Note: This could return {@link Process#INVALID_UID} if the {@link NetworkRequest} object was
|
||||||
|
* not obtained from {@link ConnectivityManager}.
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
@SystemApi
|
||||||
|
public int getRequestorUid() {
|
||||||
|
return networkCapabilities.getRequestorUid();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the package name of the app making the request.
|
||||||
|
*
|
||||||
|
* Note: This could return {@code null} if the {@link NetworkRequest} object was not obtained
|
||||||
|
* from {@link ConnectivityManager}.
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
@SystemApi
|
||||||
|
@Nullable
|
||||||
|
public String getRequestorPackageName() {
|
||||||
|
return networkCapabilities.getRequestorPackageName();
|
||||||
|
}
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "NetworkRequest [ " + type + " id=" + requestId +
|
return "NetworkRequest [ " + type + " id=" + requestId +
|
||||||
(legacyType != ConnectivityManager.TYPE_NONE ? ", legacyType=" + legacyType : "") +
|
(legacyType != ConnectivityManager.TYPE_NONE ? ", legacyType=" + legacyType : "") +
|
||||||
|
|||||||
@@ -606,7 +606,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
|
|
||||||
private Set<String> mWolSupportedInterfaces;
|
private Set<String> mWolSupportedInterfaces;
|
||||||
|
|
||||||
private TelephonyManager mTelephonyManager;
|
private final TelephonyManager mTelephonyManager;
|
||||||
private final AppOpsManager mAppOpsManager;
|
private final AppOpsManager mAppOpsManager;
|
||||||
|
|
||||||
private final LocationPermissionChecker mLocationPermissionChecker;
|
private final LocationPermissionChecker mLocationPermissionChecker;
|
||||||
@@ -957,6 +957,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
mDeps = checkNotNull(deps, "missing Dependencies");
|
mDeps = checkNotNull(deps, "missing Dependencies");
|
||||||
mSystemProperties = mDeps.getSystemProperties();
|
mSystemProperties = mDeps.getSystemProperties();
|
||||||
mNetIdManager = mDeps.makeNetIdManager();
|
mNetIdManager = mDeps.makeNetIdManager();
|
||||||
|
mContext = checkNotNull(context, "missing Context");
|
||||||
|
|
||||||
mMetricsLog = logger;
|
mMetricsLog = logger;
|
||||||
mDefaultRequest = createDefaultInternetRequestForTransport(-1, NetworkRequest.Type.REQUEST);
|
mDefaultRequest = createDefaultInternetRequestForTransport(-1, NetworkRequest.Type.REQUEST);
|
||||||
@@ -986,7 +987,6 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
|
|
||||||
mLingerDelayMs = mSystemProperties.getInt(LINGER_DELAY_PROPERTY, DEFAULT_LINGER_DELAY_MS);
|
mLingerDelayMs = mSystemProperties.getInt(LINGER_DELAY_PROPERTY, DEFAULT_LINGER_DELAY_MS);
|
||||||
|
|
||||||
mContext = checkNotNull(context, "missing Context");
|
|
||||||
mNMS = checkNotNull(netManager, "missing INetworkManagementService");
|
mNMS = checkNotNull(netManager, "missing INetworkManagementService");
|
||||||
mStatsService = checkNotNull(statsService, "missing INetworkStatsService");
|
mStatsService = checkNotNull(statsService, "missing INetworkStatsService");
|
||||||
mPolicyManager = checkNotNull(policyManager, "missing INetworkPolicyManager");
|
mPolicyManager = checkNotNull(policyManager, "missing INetworkPolicyManager");
|
||||||
@@ -1166,6 +1166,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
int transportType, NetworkRequest.Type type) {
|
int transportType, NetworkRequest.Type type) {
|
||||||
final NetworkCapabilities netCap = new NetworkCapabilities();
|
final NetworkCapabilities netCap = new NetworkCapabilities();
|
||||||
netCap.addCapability(NET_CAPABILITY_INTERNET);
|
netCap.addCapability(NET_CAPABILITY_INTERNET);
|
||||||
|
netCap.setRequestorUidAndPackageName(Process.myUid(), mContext.getPackageName());
|
||||||
if (transportType > -1) {
|
if (transportType > -1) {
|
||||||
netCap.addTransportType(transportType);
|
netCap.addTransportType(transportType);
|
||||||
}
|
}
|
||||||
@@ -1696,10 +1697,12 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
return newLp;
|
return newLp;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void restrictRequestUidsForCaller(NetworkCapabilities nc) {
|
private void restrictRequestUidsForCallerAndSetRequestorInfo(NetworkCapabilities nc,
|
||||||
|
int callerUid, String callerPackageName) {
|
||||||
if (!checkSettingsPermission()) {
|
if (!checkSettingsPermission()) {
|
||||||
nc.setSingleUid(Binder.getCallingUid());
|
nc.setSingleUid(callerUid);
|
||||||
}
|
}
|
||||||
|
nc.setRequestorUidAndPackageName(callerUid, callerPackageName);
|
||||||
nc.setAdministratorUids(Collections.EMPTY_LIST);
|
nc.setAdministratorUids(Collections.EMPTY_LIST);
|
||||||
|
|
||||||
// Clear owner UID; this can never come from an app.
|
// Clear owner UID; this can never come from an app.
|
||||||
@@ -5304,7 +5307,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
// This checks that the passed capabilities either do not request a
|
// This checks that the passed capabilities either do not request a
|
||||||
// specific SSID/SignalStrength, or the calling app has permission to do so.
|
// specific SSID/SignalStrength, 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, String callerPackageName) {
|
||||||
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");
|
||||||
}
|
}
|
||||||
@@ -5314,6 +5317,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
throw new SecurityException(
|
throw new SecurityException(
|
||||||
"Insufficient permissions to request a specific signal strength");
|
"Insufficient permissions to request a specific signal strength");
|
||||||
}
|
}
|
||||||
|
mAppOpsManager.checkPackage(callerUid, callerPackageName);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ArrayList<Integer> getSignalStrengthThresholds(NetworkAgentInfo nai) {
|
private ArrayList<Integer> getSignalStrengthThresholds(NetworkAgentInfo nai) {
|
||||||
@@ -5360,7 +5364,6 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
MatchAllNetworkSpecifier.checkNotMatchAllNetworkSpecifier(ns);
|
MatchAllNetworkSpecifier.checkNotMatchAllNetworkSpecifier(ns);
|
||||||
ns.assertValidFromUid(Binder.getCallingUid());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ensureValid(NetworkCapabilities nc) {
|
private void ensureValid(NetworkCapabilities nc) {
|
||||||
@@ -5372,7 +5375,9 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NetworkRequest requestNetwork(NetworkCapabilities networkCapabilities,
|
public NetworkRequest requestNetwork(NetworkCapabilities networkCapabilities,
|
||||||
Messenger messenger, int timeoutMs, IBinder binder, int legacyType) {
|
Messenger messenger, int timeoutMs, IBinder binder, int legacyType,
|
||||||
|
@NonNull String callingPackageName) {
|
||||||
|
final int callingUid = Binder.getCallingUid();
|
||||||
final NetworkRequest.Type type = (networkCapabilities == null)
|
final NetworkRequest.Type type = (networkCapabilities == null)
|
||||||
? NetworkRequest.Type.TRACK_DEFAULT
|
? NetworkRequest.Type.TRACK_DEFAULT
|
||||||
: NetworkRequest.Type.REQUEST;
|
: NetworkRequest.Type.REQUEST;
|
||||||
@@ -5380,7 +5385,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
// the default network request. This allows callers to keep track of
|
// the default network request. This allows callers to keep track of
|
||||||
// the system default network.
|
// the system default network.
|
||||||
if (type == NetworkRequest.Type.TRACK_DEFAULT) {
|
if (type == NetworkRequest.Type.TRACK_DEFAULT) {
|
||||||
networkCapabilities = createDefaultNetworkCapabilitiesForUid(Binder.getCallingUid());
|
networkCapabilities = createDefaultNetworkCapabilitiesForUid(callingUid);
|
||||||
enforceAccessPermission();
|
enforceAccessPermission();
|
||||||
} else {
|
} else {
|
||||||
networkCapabilities = new NetworkCapabilities(networkCapabilities);
|
networkCapabilities = new NetworkCapabilities(networkCapabilities);
|
||||||
@@ -5392,13 +5397,14 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
}
|
}
|
||||||
ensureRequestableCapabilities(networkCapabilities);
|
ensureRequestableCapabilities(networkCapabilities);
|
||||||
ensureSufficientPermissionsForRequest(networkCapabilities,
|
ensureSufficientPermissionsForRequest(networkCapabilities,
|
||||||
Binder.getCallingPid(), Binder.getCallingUid());
|
Binder.getCallingPid(), callingUid, callingPackageName);
|
||||||
// Set the UID range for this request to the single UID of the requester, or to an empty
|
// Set the UID range for this request to the single UID of the requester, or to an empty
|
||||||
// set of UIDs if the caller has the appropriate permission and UIDs have not been set.
|
// set of UIDs if the caller has the appropriate permission and UIDs have not been set.
|
||||||
// This will overwrite any allowed UIDs in the requested capabilities. Though there
|
// This will overwrite any allowed UIDs in the requested capabilities. Though there
|
||||||
// are no visible methods to set the UIDs, an app could use reflection to try and get
|
// are no visible methods to set the UIDs, an app could use reflection to try and get
|
||||||
// networks for other apps so it's essential that the UIDs are overwritten.
|
// networks for other apps so it's essential that the UIDs are overwritten.
|
||||||
restrictRequestUidsForCaller(networkCapabilities);
|
restrictRequestUidsForCallerAndSetRequestorInfo(networkCapabilities,
|
||||||
|
callingUid, callingPackageName);
|
||||||
|
|
||||||
if (timeoutMs < 0) {
|
if (timeoutMs < 0) {
|
||||||
throw new IllegalArgumentException("Bad timeout specified");
|
throw new IllegalArgumentException("Bad timeout specified");
|
||||||
@@ -5473,16 +5479,18 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NetworkRequest pendingRequestForNetwork(NetworkCapabilities networkCapabilities,
|
public NetworkRequest pendingRequestForNetwork(NetworkCapabilities networkCapabilities,
|
||||||
PendingIntent operation) {
|
PendingIntent operation, @NonNull String callingPackageName) {
|
||||||
checkNotNull(operation, "PendingIntent cannot be null.");
|
checkNotNull(operation, "PendingIntent cannot be null.");
|
||||||
|
final int callingUid = Binder.getCallingUid();
|
||||||
networkCapabilities = new NetworkCapabilities(networkCapabilities);
|
networkCapabilities = new NetworkCapabilities(networkCapabilities);
|
||||||
enforceNetworkRequestPermissions(networkCapabilities);
|
enforceNetworkRequestPermissions(networkCapabilities);
|
||||||
enforceMeteredApnPolicy(networkCapabilities);
|
enforceMeteredApnPolicy(networkCapabilities);
|
||||||
ensureRequestableCapabilities(networkCapabilities);
|
ensureRequestableCapabilities(networkCapabilities);
|
||||||
ensureSufficientPermissionsForRequest(networkCapabilities,
|
ensureSufficientPermissionsForRequest(networkCapabilities,
|
||||||
Binder.getCallingPid(), Binder.getCallingUid());
|
Binder.getCallingPid(), callingUid, callingPackageName);
|
||||||
ensureValidNetworkSpecifier(networkCapabilities);
|
ensureValidNetworkSpecifier(networkCapabilities);
|
||||||
restrictRequestUidsForCaller(networkCapabilities);
|
restrictRequestUidsForCallerAndSetRequestorInfo(networkCapabilities,
|
||||||
|
callingUid, callingPackageName);
|
||||||
|
|
||||||
NetworkRequest networkRequest = new NetworkRequest(networkCapabilities, TYPE_NONE,
|
NetworkRequest networkRequest = new NetworkRequest(networkCapabilities, TYPE_NONE,
|
||||||
nextNetworkRequestId(), NetworkRequest.Type.REQUEST);
|
nextNetworkRequestId(), NetworkRequest.Type.REQUEST);
|
||||||
@@ -5530,15 +5538,16 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NetworkRequest listenForNetwork(NetworkCapabilities networkCapabilities,
|
public NetworkRequest listenForNetwork(NetworkCapabilities networkCapabilities,
|
||||||
Messenger messenger, IBinder binder) {
|
Messenger messenger, IBinder binder, @NonNull String callingPackageName) {
|
||||||
|
final int callingUid = Binder.getCallingUid();
|
||||||
if (!hasWifiNetworkListenPermission(networkCapabilities)) {
|
if (!hasWifiNetworkListenPermission(networkCapabilities)) {
|
||||||
enforceAccessPermission();
|
enforceAccessPermission();
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkCapabilities nc = new NetworkCapabilities(networkCapabilities);
|
NetworkCapabilities nc = new NetworkCapabilities(networkCapabilities);
|
||||||
ensureSufficientPermissionsForRequest(networkCapabilities,
|
ensureSufficientPermissionsForRequest(networkCapabilities,
|
||||||
Binder.getCallingPid(), Binder.getCallingUid());
|
Binder.getCallingPid(), callingUid, callingPackageName);
|
||||||
restrictRequestUidsForCaller(nc);
|
restrictRequestUidsForCallerAndSetRequestorInfo(nc, callingUid, callingPackageName);
|
||||||
// Apps without the CHANGE_NETWORK_STATE permission can't use background networks, so
|
// Apps without the CHANGE_NETWORK_STATE permission can't use background networks, so
|
||||||
// make all their listens include NET_CAPABILITY_FOREGROUND. That way, they will get
|
// make all their listens include NET_CAPABILITY_FOREGROUND. That way, they will get
|
||||||
// onLost and onAvailable callbacks when networks move in and out of the background.
|
// onLost and onAvailable callbacks when networks move in and out of the background.
|
||||||
@@ -5558,17 +5567,17 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void pendingListenForNetwork(NetworkCapabilities networkCapabilities,
|
public void pendingListenForNetwork(NetworkCapabilities networkCapabilities,
|
||||||
PendingIntent operation) {
|
PendingIntent operation, @NonNull String callingPackageName) {
|
||||||
checkNotNull(operation, "PendingIntent cannot be null.");
|
checkNotNull(operation, "PendingIntent cannot be null.");
|
||||||
|
final int callingUid = Binder.getCallingUid();
|
||||||
if (!hasWifiNetworkListenPermission(networkCapabilities)) {
|
if (!hasWifiNetworkListenPermission(networkCapabilities)) {
|
||||||
enforceAccessPermission();
|
enforceAccessPermission();
|
||||||
}
|
}
|
||||||
ensureValid(networkCapabilities);
|
ensureValid(networkCapabilities);
|
||||||
ensureSufficientPermissionsForRequest(networkCapabilities,
|
ensureSufficientPermissionsForRequest(networkCapabilities,
|
||||||
Binder.getCallingPid(), Binder.getCallingUid());
|
Binder.getCallingPid(), callingUid, callingPackageName);
|
||||||
|
|
||||||
final NetworkCapabilities nc = new NetworkCapabilities(networkCapabilities);
|
final NetworkCapabilities nc = new NetworkCapabilities(networkCapabilities);
|
||||||
restrictRequestUidsForCaller(nc);
|
restrictRequestUidsForCallerAndSetRequestorInfo(nc, callingUid, callingPackageName);
|
||||||
|
|
||||||
NetworkRequest networkRequest = new NetworkRequest(nc, TYPE_NONE, nextNetworkRequestId(),
|
NetworkRequest networkRequest = new NetworkRequest(nc, TYPE_NONE, nextNetworkRequestId(),
|
||||||
NetworkRequest.Type.LISTEN);
|
NetworkRequest.Type.LISTEN);
|
||||||
@@ -7847,12 +7856,13 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
throw new IllegalArgumentException("ConnectivityManager.TYPE_* are deprecated."
|
throw new IllegalArgumentException("ConnectivityManager.TYPE_* are deprecated."
|
||||||
+ " Please use NetworkCapabilities instead.");
|
+ " Please use NetworkCapabilities instead.");
|
||||||
}
|
}
|
||||||
mAppOpsManager.checkPackage(Binder.getCallingUid(), callingPackageName);
|
final int callingUid = Binder.getCallingUid();
|
||||||
|
mAppOpsManager.checkPackage(callingUid, callingPackageName);
|
||||||
|
|
||||||
// This NetworkCapabilities is only used for matching to Networks. Clear out its owner uid
|
// This NetworkCapabilities is only used for matching to Networks. Clear out its owner uid
|
||||||
// and administrator uids to be safe.
|
// and administrator uids to be safe.
|
||||||
final NetworkCapabilities nc = new NetworkCapabilities(request.networkCapabilities);
|
final NetworkCapabilities nc = new NetworkCapabilities(request.networkCapabilities);
|
||||||
restrictRequestUidsForCaller(nc);
|
restrictRequestUidsForCallerAndSetRequestorInfo(nc, callingUid, callingPackageName);
|
||||||
|
|
||||||
final NetworkRequest requestWithId =
|
final NetworkRequest requestWithId =
|
||||||
new NetworkRequest(
|
new NetworkRequest(
|
||||||
|
|||||||
@@ -272,9 +272,23 @@ public class NetworkCapabilitiesTest {
|
|||||||
netCap.setOwnerUid(123);
|
netCap.setOwnerUid(123);
|
||||||
assertParcelingIsLossless(netCap);
|
assertParcelingIsLossless(netCap);
|
||||||
netCap.setSSID(TEST_SSID);
|
netCap.setSSID(TEST_SSID);
|
||||||
assertParcelSane(netCap, 13);
|
assertParcelSane(netCap, 15);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testParcelNetworkCapabilitiesWithRequestorUidAndPackageName() {
|
||||||
|
final NetworkCapabilities netCap = new NetworkCapabilities()
|
||||||
|
.addCapability(NET_CAPABILITY_INTERNET)
|
||||||
|
.setRequestorUid(9304)
|
||||||
|
.setRequestorPackageName("com.android.test")
|
||||||
|
.addCapability(NET_CAPABILITY_EIMS)
|
||||||
|
.addCapability(NET_CAPABILITY_NOT_METERED);
|
||||||
|
assertParcelingIsLossless(netCap);
|
||||||
|
netCap.setSSID(TEST_SSID);
|
||||||
|
assertParcelSane(netCap, 15);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testOemPaid() {
|
public void testOemPaid() {
|
||||||
NetworkCapabilities nc = new NetworkCapabilities();
|
NetworkCapabilities nc = new NetworkCapabilities();
|
||||||
|
|||||||
@@ -212,7 +212,8 @@ public class ConnectivityManagerTest {
|
|||||||
ArgumentCaptor<Messenger> captor = ArgumentCaptor.forClass(Messenger.class);
|
ArgumentCaptor<Messenger> captor = ArgumentCaptor.forClass(Messenger.class);
|
||||||
|
|
||||||
// register callback
|
// register callback
|
||||||
when(mService.requestNetwork(any(), captor.capture(), anyInt(), any(), anyInt()))
|
when(mService.requestNetwork(
|
||||||
|
any(), captor.capture(), anyInt(), any(), anyInt(), any()))
|
||||||
.thenReturn(request);
|
.thenReturn(request);
|
||||||
manager.requestNetwork(request, callback, handler);
|
manager.requestNetwork(request, callback, handler);
|
||||||
|
|
||||||
@@ -240,7 +241,8 @@ public class ConnectivityManagerTest {
|
|||||||
ArgumentCaptor<Messenger> captor = ArgumentCaptor.forClass(Messenger.class);
|
ArgumentCaptor<Messenger> captor = ArgumentCaptor.forClass(Messenger.class);
|
||||||
|
|
||||||
// register callback
|
// register callback
|
||||||
when(mService.requestNetwork(any(), captor.capture(), anyInt(), any(), anyInt()))
|
when(mService.requestNetwork(
|
||||||
|
any(), captor.capture(), anyInt(), any(), anyInt(), any()))
|
||||||
.thenReturn(req1);
|
.thenReturn(req1);
|
||||||
manager.requestNetwork(req1, callback, handler);
|
manager.requestNetwork(req1, callback, handler);
|
||||||
|
|
||||||
@@ -258,7 +260,8 @@ public class ConnectivityManagerTest {
|
|||||||
verify(callback, timeout(100).times(0)).onLosing(any(), anyInt());
|
verify(callback, timeout(100).times(0)).onLosing(any(), anyInt());
|
||||||
|
|
||||||
// callback can be registered again
|
// callback can be registered again
|
||||||
when(mService.requestNetwork(any(), captor.capture(), anyInt(), any(), anyInt()))
|
when(mService.requestNetwork(
|
||||||
|
any(), captor.capture(), anyInt(), any(), anyInt(), any()))
|
||||||
.thenReturn(req2);
|
.thenReturn(req2);
|
||||||
manager.requestNetwork(req2, callback, handler);
|
manager.requestNetwork(req2, callback, handler);
|
||||||
|
|
||||||
@@ -282,7 +285,8 @@ public class ConnectivityManagerTest {
|
|||||||
info.targetSdkVersion = VERSION_CODES.N_MR1 + 1;
|
info.targetSdkVersion = VERSION_CODES.N_MR1 + 1;
|
||||||
|
|
||||||
when(mCtx.getApplicationInfo()).thenReturn(info);
|
when(mCtx.getApplicationInfo()).thenReturn(info);
|
||||||
when(mService.requestNetwork(any(), any(), anyInt(), any(), anyInt())).thenReturn(request);
|
when(mService.requestNetwork(any(), any(), anyInt(), any(), anyInt(), any()))
|
||||||
|
.thenReturn(request);
|
||||||
|
|
||||||
Handler handler = new Handler(Looper.getMainLooper());
|
Handler handler = new Handler(Looper.getMainLooper());
|
||||||
manager.requestNetwork(request, callback, handler);
|
manager.requestNetwork(request, callback, handler);
|
||||||
|
|||||||
@@ -107,6 +107,7 @@ import static org.mockito.Mockito.atLeastOnce;
|
|||||||
import static org.mockito.Mockito.doAnswer;
|
import static org.mockito.Mockito.doAnswer;
|
||||||
import static org.mockito.Mockito.doNothing;
|
import static org.mockito.Mockito.doNothing;
|
||||||
import static org.mockito.Mockito.doReturn;
|
import static org.mockito.Mockito.doReturn;
|
||||||
|
import static org.mockito.Mockito.doThrow;
|
||||||
import static org.mockito.Mockito.inOrder;
|
import static org.mockito.Mockito.inOrder;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.never;
|
import static org.mockito.Mockito.never;
|
||||||
@@ -305,6 +306,7 @@ public class ConnectivityServiceTest {
|
|||||||
private static final String MOBILE_IFNAME = "test_rmnet_data0";
|
private static final String MOBILE_IFNAME = "test_rmnet_data0";
|
||||||
private static final String WIFI_IFNAME = "test_wlan0";
|
private static final String WIFI_IFNAME = "test_wlan0";
|
||||||
private static final String WIFI_WOL_IFNAME = "test_wlan_wol";
|
private static final String WIFI_WOL_IFNAME = "test_wlan_wol";
|
||||||
|
private static final String TEST_PACKAGE_NAME = "com.android.test.package";
|
||||||
private static final String[] EMPTY_STRING_ARRAY = new String[0];
|
private static final String[] EMPTY_STRING_ARRAY = new String[0];
|
||||||
|
|
||||||
private MockContext mServiceContext;
|
private MockContext mServiceContext;
|
||||||
@@ -654,7 +656,7 @@ public class ConnectivityServiceTest {
|
|||||||
|
|
||||||
if (mNmValidationRedirectUrl != null) {
|
if (mNmValidationRedirectUrl != null) {
|
||||||
mNmCallbacks.showProvisioningNotification(
|
mNmCallbacks.showProvisioningNotification(
|
||||||
"test_provisioning_notif_action", "com.android.test.package");
|
"test_provisioning_notif_action", TEST_PACKAGE_NAME);
|
||||||
mNmProvNotificationRequested = true;
|
mNmProvNotificationRequested = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2972,7 +2974,7 @@ public class ConnectivityServiceTest {
|
|||||||
networkCapabilities.addTransportType(TRANSPORT_WIFI)
|
networkCapabilities.addTransportType(TRANSPORT_WIFI)
|
||||||
.setNetworkSpecifier(new MatchAllNetworkSpecifier());
|
.setNetworkSpecifier(new MatchAllNetworkSpecifier());
|
||||||
mService.requestNetwork(networkCapabilities, null, 0, null,
|
mService.requestNetwork(networkCapabilities, null, 0, null,
|
||||||
ConnectivityManager.TYPE_WIFI);
|
ConnectivityManager.TYPE_WIFI, TEST_PACKAGE_NAME);
|
||||||
});
|
});
|
||||||
|
|
||||||
class NonParcelableSpecifier extends NetworkSpecifier {
|
class NonParcelableSpecifier extends NetworkSpecifier {
|
||||||
@@ -3011,31 +3013,12 @@ public class ConnectivityServiceTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNetworkSpecifierUidSpoofSecurityException() throws Exception {
|
public void testNetworkRequestUidSpoofSecurityException() throws Exception {
|
||||||
class UidAwareNetworkSpecifier extends NetworkSpecifier implements Parcelable {
|
|
||||||
@Override
|
|
||||||
public boolean satisfiedBy(NetworkSpecifier other) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void assertValidFromUid(int requestorUid) {
|
|
||||||
throw new SecurityException("failure");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int describeContents() { return 0; }
|
|
||||||
@Override
|
|
||||||
public void writeToParcel(Parcel dest, int flags) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
mWiFiNetworkAgent = new TestNetworkAgentWrapper(TRANSPORT_WIFI);
|
mWiFiNetworkAgent = new TestNetworkAgentWrapper(TRANSPORT_WIFI);
|
||||||
mWiFiNetworkAgent.connect(false);
|
mWiFiNetworkAgent.connect(false);
|
||||||
|
NetworkRequest networkRequest = newWifiRequestBuilder().build();
|
||||||
UidAwareNetworkSpecifier networkSpecifier = new UidAwareNetworkSpecifier();
|
|
||||||
NetworkRequest networkRequest = newWifiRequestBuilder().setNetworkSpecifier(
|
|
||||||
networkSpecifier).build();
|
|
||||||
TestNetworkCallback networkCallback = new TestNetworkCallback();
|
TestNetworkCallback networkCallback = new TestNetworkCallback();
|
||||||
|
doThrow(new SecurityException()).when(mAppOpsManager).checkPackage(anyInt(), anyString());
|
||||||
assertThrows(SecurityException.class, () -> {
|
assertThrows(SecurityException.class, () -> {
|
||||||
mCm.requestNetwork(networkRequest, networkCallback);
|
mCm.requestNetwork(networkRequest, networkCallback);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user