1 /* 2 * Copyright (C) 2021 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 import android.content.pm.UserInfo; 18 import android.os.UserHandle; 19 20 import java.util.ArrayList; 21 import java.util.List; 22 23 public class UserInfoCompat { 24 UserInfo mUserInfo; 25 public int id; 26 public int restrictedProfileParentId; 27 public static final int NO_PROFILE_GROUP_ID = UserInfo.NO_PROFILE_GROUP_ID; 28 29 getUserHandle()30 public UserHandle getUserHandle() { 31 return mUserInfo.getUserHandle(); 32 } 33 UserInfoCompat(UserInfo userInfo)34 UserInfoCompat(UserInfo userInfo) { 35 mUserInfo = userInfo; 36 id = mUserInfo.id; 37 restrictedProfileParentId = userInfo.restrictedProfileParentId; 38 } 39 getId()40 public int getId() { 41 return mUserInfo.id; 42 } 43 isManagedProfile()44 public boolean isManagedProfile() { 45 return mUserInfo.isManagedProfile(); 46 } 47 isRestricted()48 public boolean isRestricted() { 49 return mUserInfo.isRestricted(); 50 } 51 isAdmin()52 public boolean isAdmin() { 53 return mUserInfo.isAdmin(); 54 } 55 convert(List<UserInfo> infos)56 static List<UserInfoCompat> convert(List<UserInfo> infos) { 57 List<UserInfoCompat> list = new ArrayList<>(); 58 for (UserInfo info : infos) { 59 list.add(new UserInfoCompat(info)); 60 } 61 return list; 62 } 63 } 64