1 /* 2 * Copyright (C) 2020 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.car.internal.common; 18 19 import static com.android.car.internal.ExcludeFromCodeCoverageGeneratedReport.BOILERPLATE_CODE; 20 21 import android.annotation.Nullable; 22 import android.annotation.UserIdInt; 23 import android.os.UserHandle; 24 import android.os.UserManager; 25 26 import com.android.car.internal.ExcludeFromCodeCoverageGeneratedReport; 27 28 /** 29 * Provides user information related helper methods. 30 * 31 * @hide 32 */ 33 public final class UserHelperLite { 34 35 @ExcludeFromCodeCoverageGeneratedReport(reason = BOILERPLATE_CODE, 36 details = "private constructor") UserHelperLite()37 private UserHelperLite() { 38 throw new UnsupportedOperationException("contains only static methods"); 39 } 40 41 /** 42 * Gets a PII-safe representation of the name. 43 */ 44 @Nullable safeName(@ullable String name)45 public static String safeName(@Nullable String name) { 46 return name == null ? name : name.length() + "_chars"; 47 } 48 49 /** 50 * Checks whether the given user is both {@code SYSTEM} and headless. 51 */ isHeadlessSystemUser(@serIdInt int userId)52 public static boolean isHeadlessSystemUser(@UserIdInt int userId) { 53 return userId == UserHandle.SYSTEM.getIdentifier() 54 && UserManager.isHeadlessSystemUserMode(); 55 } 56 } 57