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