1 /* 2 * Copyright (C) 2022 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.adservices.service.common; 18 19 import android.os.Process; 20 21 import com.android.adservices.service.common.compat.ProcessCompatUtils; 22 23 /** 24 * Utility class to deal with the fact that PPAPI can be called from an app or from the SDK Sandbox. 25 */ 26 public class SdkRuntimeUtil { 27 /** 28 * Utility method to retrieve the UID of the application a PPAPI call has been made for. If the 29 * call has been done using the SDK Sandbox this method will return the UID of the originating 30 * app otherwise it will return {@code callerProcessUid}. 31 * 32 * @param callerProcessUid The UID of the calling process 33 * @return the UID of the Application this call has ben made for 34 */ getCallingAppUid(int callerProcessUid)35 public static int getCallingAppUid(int callerProcessUid) { 36 if (ProcessCompatUtils.isSdkSandboxUid(callerProcessUid)) { 37 return Process.getAppUidForSdkSandboxUid(callerProcessUid); 38 } else { 39 return callerProcessUid; 40 } 41 } 42 } 43