Merge changes Ifafafcd6,I5802dedc into main
* changes: Fix incorrect nullability annotations Add helper method to enfore a package name belongs to an uid
This commit is contained in:
commit
fbc97d95bb
1 changed files with 75 additions and 29 deletions
|
|
@ -3021,26 +3021,6 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||
return false;
|
||||
}
|
||||
|
||||
private int getAppUid(final String app, final UserHandle user) {
|
||||
final PackageManager pm =
|
||||
mContext.createContextAsUser(user, 0 /* flags */).getPackageManager();
|
||||
final long token = Binder.clearCallingIdentity();
|
||||
try {
|
||||
return pm.getPackageUid(app, 0 /* flags */);
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
return -1;
|
||||
} finally {
|
||||
Binder.restoreCallingIdentity(token);
|
||||
}
|
||||
}
|
||||
|
||||
private void verifyCallingUidAndPackage(String packageName, int callingUid) {
|
||||
final UserHandle user = UserHandle.getUserHandleForUid(callingUid);
|
||||
if (getAppUid(packageName, user) != callingUid) {
|
||||
throw new SecurityException(packageName + " does not belong to uid " + callingUid);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure that a network route exists to deliver traffic to the specified
|
||||
* host via the specified network interface.
|
||||
|
|
@ -3056,7 +3036,8 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||
if (disallowedBecauseSystemCaller()) {
|
||||
return false;
|
||||
}
|
||||
verifyCallingUidAndPackage(callingPackageName, mDeps.getCallingUid());
|
||||
PermissionUtils.enforcePackageNameMatchesUid(
|
||||
mContext, mDeps.getCallingUid(), callingPackageName);
|
||||
enforceChangePermission(callingPackageName, callingAttributionTag);
|
||||
if (mProtectedNetworks.contains(networkType)) {
|
||||
enforceConnectivityRestrictedNetworksPermission(true /* checkUidsAllowedList */);
|
||||
|
|
|
|||
Loading…
Reference in a new issue