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 * @hide 28 */ 29 public final class CarSystemProperties { 30 private static final String PROP_BOOT_USER_OVERRIDE_ID = 31 "android.car.systemuser.bootuseroverrideid"; 32 private static final String PROP_USER_HAL_ENABLED = "android.car.user_hal_enabled"; 33 private static final String PROP_USER_HAL_TIMEOUT = "android.car.user_hal_timeout"; 34 private static final String PROP_DEVICE_POLICY_MANAGER_TIMEOUT = 35 "android.car.device_policy_manager_timeout"; 36 CarSystemProperties()37 private CarSystemProperties() { 38 throw new UnsupportedOperationException(); 39 } 40 41 /** Check {@code system/libsysprop/srcs/android/sysprop/CarProperties.sysprop} */ getBootUserOverrideId()42 public static Optional<Integer> getBootUserOverrideId() { 43 return Optional.ofNullable(tryParseInteger(SystemProperties.get( 44 PROP_BOOT_USER_OVERRIDE_ID))); 45 } 46 47 /** Check {@code system/libsysprop/srcs/android/sysprop/CarProperties.sysprop} */ getUserHalEnabled()48 public static Optional<Boolean> getUserHalEnabled() { 49 return Optional.ofNullable(Boolean.valueOf(SystemProperties.get(PROP_USER_HAL_ENABLED))); 50 } 51 52 /** Check {@code system/libsysprop/srcs/android/sysprop/CarProperties.sysprop} */ getUserHalTimeout()53 public static Optional<Integer> getUserHalTimeout() { 54 return Optional.ofNullable(tryParseInteger(SystemProperties.get(PROP_USER_HAL_TIMEOUT))); 55 } 56 57 /** Check {@code system/libsysprop/srcs/android/sysprop/CarProperties.sysprop} */ getDevicePolicyManagerTimeout()58 public static Optional<Integer> getDevicePolicyManagerTimeout() { 59 return Optional.ofNullable(tryParseInteger(SystemProperties.get( 60 PROP_DEVICE_POLICY_MANAGER_TIMEOUT))); 61 } 62 63 @Nullable tryParseInteger(String str)64 private static Integer tryParseInteger(String str) { 65 try { 66 return Integer.valueOf(str); 67 } catch (NumberFormatException e) { 68 return null; 69 } 70 } 71 } 72