1 /*
2  * Copyright (C) 2023 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.systemui.process;
18 
19 import android.os.Process;
20 import android.os.UserHandle;
21 
22 import javax.inject.Inject;
23 
24 /**
25  * A simple wrapper that provides access to process-related details. This facilitates testing by
26  * providing a mockable target around these details.
27  */
28 public class ProcessWrapper {
29     @Inject
ProcessWrapper()30     public ProcessWrapper() {}
31 
32     /**
33      * Returns {@code true} if System User is running the current process.
34      */
isSystemUser()35     public boolean isSystemUser() {
36         return myUserHandle().isSystem();
37     }
38 
39     /**
40      * Returns {@link UserHandle} as returned statically by {@link Process#myUserHandle()}.
41      *
42      * This should not be used to get the "current" user. This information only applies to the
43      * current process, not the current state of SystemUI. Please use
44      * {@link com.android.systemui.settings.UserTracker} if you want to learn about the currently
45      * active user in SystemUI.
46      */
myUserHandle()47     public UserHandle myUserHandle() {
48         return Process.myUserHandle();
49     }
50 }
51