• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 android.health.connect;
18 
19 import static com.google.common.truth.Truth.assertThat;
20 
21 import android.os.Binder;
22 
23 import androidx.test.ext.junit.runners.AndroidJUnit4;
24 
25 import com.android.server.healthconnect.common.RequestContext;
26 
27 import org.junit.Test;
28 import org.junit.runner.RunWith;
29 
30 @RunWith(AndroidJUnit4.class)
31 public class RequestContextTest {
32 
33     @Test
getCallingApplicationUid_equalToBinderCallingUid()34     public void getCallingApplicationUid_equalToBinderCallingUid() {
35         RequestContext requestContext = RequestContext.create();
36 
37         // Note: since we're not executing this in a binder thread, it just returns the current
38         // (test app) application's UID. This is not therefore a realistic test, but at least
39         // verifies that a value has been set. CTS tests will exercise this realistically.
40         // The same applies to subsequent tests that rely on binder state.
41         assertThat(requestContext.getCallingApplicationUid()).isEqualTo(Binder.getCallingUid());
42     }
43 
44     @Test
getCallingUser_equalToBinderCallingUser()45     public void getCallingUser_equalToBinderCallingUser() {
46         RequestContext requestContext = RequestContext.create();
47 
48         assertThat(requestContext.getCallingUser()).isEqualTo(Binder.getCallingUserHandle());
49     }
50 
51     @Test
getCallingProcessId_equalToBinderCallingPid()52     public void getCallingProcessId_equalToBinderCallingPid() {
53         RequestContext requestContext = RequestContext.create();
54 
55         assertThat(requestContext.getCallingProcessId()).isEqualTo(Binder.getCallingPid());
56     }
57 }
58