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 package com.android.car.internal.os; 18 19 import android.annotation.Nullable; 20 import android.os.SystemProperties; 21 22 import java.util.Optional; 23 24 /** 25 * Replacement for {@code android.sysprop.CarProperties}. This should be manually updated. 26 */ 27 public final class CarSystemProperties { 28 private static final String PROP_BOOT_USER_OVERRIDE_ID = 29 "android.car.systemuser.bootuseroverrideid"; 30 private static final String PROP_USER_HAL_ENABLED = "android.car.user_hal_enabled"; 31 private static final String PROP_USER_HAL_TIMEOUT = "android.car.user_hal_timeout"; 32 private static final String PROP_DEVICE_POLICY_MANAGER_TIMEOUT = 33 "android.car.device_policy_manager_timeout"; 34 CarSystemProperties()35 private CarSystemProperties() { 36 throw new UnsupportedOperationException(); 37 } 38 39 /** Check {@code system/libsysprop/srcs/android/sysprop/CarProperties.sysprop} */ getBootUserOverrideId()40 public static Optional<Integer> getBootUserOverrideId() { 41 return Optional.ofNullable(tryParseInteger(SystemProperties.get( 42 PROP_BOOT_USER_OVERRIDE_ID))); 43 } 44 45 /** Check {@code system/libsysprop/srcs/android/sysprop/CarProperties.sysprop} */ getUserHalEnabled()46 public static Optional<Boolean> getUserHalEnabled() { 47 return Optional.ofNullable(Boolean.valueOf(SystemProperties.get(PROP_USER_HAL_ENABLED))); 48 } 49 50 /** Check {@code system/libsysprop/srcs/android/sysprop/CarProperties.sysprop} */ getUserHalTimeout()51 public static Optional<Integer> getUserHalTimeout() { 52 return Optional.ofNullable(tryParseInteger(SystemProperties.get(PROP_USER_HAL_TIMEOUT))); 53 } 54 55 /** Check {@code system/libsysprop/srcs/android/sysprop/CarProperties.sysprop} */ getDevicePolicyManagerTimeout()56 public static Optional<Integer> getDevicePolicyManagerTimeout() { 57 return Optional.ofNullable(tryParseInteger(SystemProperties.get( 58 PROP_DEVICE_POLICY_MANAGER_TIMEOUT))); 59 } 60 61 @Nullable tryParseInteger(String str)62 private static Integer tryParseInteger(String str) { 63 try { 64 return Integer.valueOf(str); 65 } catch (NumberFormatException e) { 66 return null; 67 } 68 } 69 } 70