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.settings.users;
18 
19 import android.app.settings.SettingsEnums;
20 import android.content.pm.UserInfo;
21 
22 /**
23  * Utils class for metrics to avoid user characteristics checks in code
24  */
25 public class UserMetricsUtils {
26 
27     /**
28      * Returns relevant remove SettingsEnum key depending on UserInfo
29      * @param userInfo information about user
30      * @return list of RestrictionEntry objects with user-visible text.
31      */
getRemoveUserMetricCategory(UserInfo userInfo)32     public static int getRemoveUserMetricCategory(UserInfo userInfo) {
33         if (userInfo.isGuest()) {
34             return  SettingsEnums.ACTION_REMOVE_GUEST_USER;
35         }
36         if (userInfo.isRestricted()) {
37             return SettingsEnums.ACTION_REMOVE_RESTRICTED_USER;
38         }
39         return SettingsEnums.ACTION_REMOVE_USER;
40     }
41 
42     /**
43      * Returns relevant switch user SettingsEnum key depending on UserInfo
44      * @param userInfo information about user
45      * @return SettingsEnums.
46      */
getSwitchUserMetricCategory(UserInfo userInfo)47     public static int getSwitchUserMetricCategory(UserInfo userInfo) {
48         if (userInfo.isGuest()) {
49             return  SettingsEnums.ACTION_SWITCH_TO_GUEST;
50         }
51         if (userInfo.isRestricted()) {
52             return SettingsEnums.ACTION_SWITCH_TO_RESTRICTED_USER;
53         }
54         return SettingsEnums.ACTION_SWITCH_TO_USER;
55     }
56 }
57