Use getProfileParentId() in native permission helper (2/2)

getCredentialOwnerProfile() makes some additional unnecessary checks.

Test: cts-tradefed run cts-dev -m DevicePolicyManager --test
com.android.cts.devicepolicy.ManagedProfileTest#testBluetooth
Bug: 69284968
Change-Id: If9974e1af1e0cc0df29c39d47d3e262552294a85
diff --git a/jni/IUserManager.cc b/jni/IUserManager.cc
index 32c429a..0e36292 100644
--- a/jni/IUserManager.cc
+++ b/jni/IUserManager.cc
@@ -47,6 +47,25 @@
 
     return reply.readInt32();
   }
+
+  virtual int32_t getProfileParentId(int32_t user_handle) {
+    Parcel data, reply;
+    data.writeInterfaceToken(IUserManager::getInterfaceDescriptor());
+    data.writeInt32(user_handle);
+    status_t rc = remote()->transact(GET_PROFILE_PARENT_ID, data, &reply, 0);
+    if (rc != NO_ERROR) {
+      ALOGE("%s: failed (%d)\n", __func__, rc);
+      return -1;
+    }
+
+    int32_t exception = reply.readExceptionCode();
+    if (exception != 0) {
+      ALOGE("%s: got exception (%d)\n", __func__, exception);
+      return -1;
+    }
+
+    return reply.readInt32();
+  }
 };
 
 IMPLEMENT_META_INTERFACE(UserManager, "android.os.IUserManager");
diff --git a/jni/IUserManager.h b/jni/IUserManager.h
index 48bb275..2164d9a 100644
--- a/jni/IUserManager.h
+++ b/jni/IUserManager.h
@@ -33,9 +33,11 @@
   // must be kept in sync with IUserManager.aidl
   enum {
     GET_CREDENTIAL_OWNER_PROFILE = IBinder::FIRST_CALL_TRANSACTION + 0,
+    GET_PROFILE_PARENT_ID,
   };
 
   virtual int32_t getCredentialOwnerProfile(int32_t user_id) = 0;
+  virtual int32_t getProfileParentId(int32_t user_handle) = 0;
 
   DECLARE_META_INTERFACE(UserManager);
 };
diff --git a/jni/permission_helpers.cc b/jni/permission_helpers.cc
index 8fdd943..26a8a89 100644
--- a/jni/permission_helpers.cc
+++ b/jni/permission_helpers.cc
@@ -79,7 +79,7 @@
   if (um != NULL) {
     // Must use Bluetooth process identity when making call to get parent user
     int64_t ident = ipcState->clearCallingIdentity();
-    parentUser = um->getCredentialOwnerProfile(callingUser);
+    parentUser = um->getProfileParentId(callingUser);
     ipcState->restoreCallingIdentity(ident);
   }