• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_NUMBER_PRE_CREATED_USERS =
33             "android.car.number_pre_created_users";
34     private static final String PROP_NUMBER_PRE_CREATED_GUESTS =
35             "android.car.number_pre_created_guests";
36     private static final String PROP_USER_HAL_ENABLED = "android.car.user_hal_enabled";
37     private static final String PROP_USER_HAL_TIMEOUT = "android.car.user_hal_timeout";
38     private static final String PROP_DEVICE_POLICY_MANAGER_TIMEOUT =
39             "android.car.device_policy_manager_timeout";
40 
CarSystemProperties()41     private CarSystemProperties() {
42         throw new UnsupportedOperationException();
43     }
44 
45     /** Check {@code system/libsysprop/srcs/android/sysprop/CarProperties.sysprop} */
getBootUserOverrideId()46     public static Optional<Integer> getBootUserOverrideId() {
47         return Optional.ofNullable(tryParseInteger(SystemProperties.get(
48                 PROP_BOOT_USER_OVERRIDE_ID)));
49     }
50 
51     /** Check {@code system/libsysprop/srcs/android/sysprop/CarProperties.sysprop} */
getNumberPreCreatedUsers()52     public static Optional<Integer> getNumberPreCreatedUsers() {
53         return Optional.ofNullable(tryParseInteger(SystemProperties.get(
54                 PROP_NUMBER_PRE_CREATED_USERS)));
55     }
56 
57     /** Check {@code system/libsysprop/srcs/android/sysprop/CarProperties.sysprop} */
getNumberPreCreatedGuests()58     public static Optional<Integer> getNumberPreCreatedGuests() {
59         return Optional.ofNullable(tryParseInteger(SystemProperties.get(
60                 PROP_NUMBER_PRE_CREATED_GUESTS)));
61     }
62 
63 
64     /** Check {@code system/libsysprop/srcs/android/sysprop/CarProperties.sysprop} */
getUserHalEnabled()65     public static Optional<Boolean> getUserHalEnabled() {
66         return Optional.ofNullable(Boolean.valueOf(SystemProperties.get(PROP_USER_HAL_ENABLED)));
67     }
68 
69     /** Check {@code system/libsysprop/srcs/android/sysprop/CarProperties.sysprop} */
getUserHalTimeout()70     public static Optional<Integer> getUserHalTimeout() {
71         return Optional.ofNullable(tryParseInteger(SystemProperties.get(PROP_USER_HAL_TIMEOUT)));
72     }
73 
74     /** Check {@code system/libsysprop/srcs/android/sysprop/CarProperties.sysprop} */
getDevicePolicyManagerTimeout()75     public static Optional<Integer> getDevicePolicyManagerTimeout() {
76         return Optional.ofNullable(tryParseInteger(SystemProperties.get(
77                 PROP_DEVICE_POLICY_MANAGER_TIMEOUT)));
78     }
79 
80     @Nullable
tryParseInteger(String str)81     private static Integer tryParseInteger(String str) {
82         try {
83             return Integer.valueOf(str);
84         } catch (NumberFormatException e) {
85             return null;
86         }
87     }
88 }
89