1 /* 2 * Copyright (C) 2025 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.server.healthconnect.common; 18 19 import android.os.Binder; 20 import android.os.UserHandle; 21 22 /** 23 * Contains state associated with the current request. 24 * 25 * @hide 26 */ 27 public class RequestContext { 28 private final int mUid; 29 private final int mPid; 30 private final UserHandle mCallingUser; 31 32 /** 33 * Create a new {@code RequestContext}. 34 * 35 * <p>Must be called on the request thread, i.e. the binder thread that is handling the current 36 * request. 37 * 38 * @return A {@code RequestContext} instance. 39 */ create()40 public static RequestContext create() { 41 return new RequestContext( 42 Binder.getCallingUid(), Binder.getCallingPid(), Binder.getCallingUserHandle()); 43 } 44 45 /** The user who owns the process which the current request originated from. */ getCallingUser()46 public UserHandle getCallingUser() { 47 return mCallingUser; 48 } 49 50 /** The process ID of the caller. */ getCallingProcessId()51 public int getCallingProcessId() { 52 return mPid; 53 } 54 55 /** The system assigned UID of the calling application. */ getCallingApplicationUid()56 public int getCallingApplicationUid() { 57 return mUid; 58 } 59 RequestContext(int uid, int pid, UserHandle callingUser)60 private RequestContext(int uid, int pid, UserHandle callingUser) { 61 this.mUid = uid; 62 this.mPid = pid; 63 this.mCallingUser = callingUser; 64 } 65 } 66