Use correct user id for permission check for instant foreground service

Test: cts-tradefed run cts-dev -m CtsAppSecurityHostTestCases
          -t android.appsecurity.cts.EphemeralTest#testStartForegrondService

bug: 68275646
Bug: 71366502

Change-Id: I196522c49ae8a7e0ec07bf631f04bae51e96db5b

cherry pick from: https://android-review.googlesource.com/c/platform/frameworks/base/+/559340
(cherry picked from commit e32c238ce76151dd6221e6762f841c8f721c45f7)

Change-Id: Idfeae038d42b9dee9f6f57203f2bdb0764f51877
(cherry picked from commit d967610fb865ce2ac5f8c379a13e21feee98fbe0)
diff --git a/services/core/java/com/android/server/am/ActiveServices.java b/services/core/java/com/android/server/am/ActiveServices.java
index 90ad8a5..9d823a7 100644
--- a/services/core/java/com/android/server/am/ActiveServices.java
+++ b/services/core/java/com/android/server/am/ActiveServices.java
@@ -1043,8 +1043,8 @@
                         try {
                             if (AppGlobals.getPackageManager().checkPermission(
                                     android.Manifest.permission.INSTANT_APP_FOREGROUND_SERVICE,
-                                    r.appInfo.packageName,
-                                    r.appInfo.uid) != PackageManager.PERMISSION_GRANTED) {
+                                    r.appInfo.packageName, UserHandle.getUserId(r.appInfo.uid))
+                                            != PackageManager.PERMISSION_GRANTED) {
                                 throw new SecurityException("Instant app " + r.appInfo.packageName
                                         + " does not have permission to create foreground"
                                         + "services");