Check system and phone UID in multiple-user-aware way
This CL calls UserHandle.getAppId to make sure the UID check with
Process.SYSTEM_UID and PHONE_UID are multiple-user-aware.
In multiuser context, Process.SYSTEM_UID or PHONE_UID is NOT the UID
of system/phone but the app id. The complete UID is prefixed with
user id (e.g. 1001001 is phone UID for user 10).
Bug: 328511085
Test: atest FrameworksNetCommonTests
Flag: EXEMPT Tiny bug fix
Change-Id: I97bbfcff37374ba367fc8d62400ae140136cd012
diff --git a/service/src/com/android/server/connectivity/ConnectivityNativeService.java b/service/src/com/android/server/connectivity/ConnectivityNativeService.java
index cf6127f..917ad4d 100644
--- a/service/src/com/android/server/connectivity/ConnectivityNativeService.java
+++ b/service/src/com/android/server/connectivity/ConnectivityNativeService.java
@@ -23,6 +23,7 @@
import android.os.Binder;
import android.os.Process;
import android.os.ServiceSpecificException;
+import android.os.UserHandle;
import android.system.ErrnoException;
import android.util.Log;
@@ -67,8 +68,8 @@
}
private void enforceBlockPortPermission() {
- final int uid = Binder.getCallingUid();
- if (uid == Process.ROOT_UID || uid == Process.PHONE_UID) return;
+ final int appId = UserHandle.getAppId(Binder.getCallingUid());
+ if (appId == Process.ROOT_UID || appId == Process.PHONE_UID) return;
PermissionUtils.enforceNetworkStackPermission(mContext);
}