• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2019 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 android.car;
18 
19 import android.annotation.NonNull;
20 import android.car.annotation.AddedInOrBefore;
21 import android.car.annotation.OptionalFeature;
22 import android.os.RemoteException;
23 import android.util.ArrayMap;
24 
25 import com.android.internal.annotations.GuardedBy;
26 
27 /**
28  * This class declares all car features which does not have API as {@code String}.
29  *
30  * <p>Note that all {@code Car*Managers'} feature string is their service name
31  * {@code Car.*_SERVICE.}
32  * For features with APIs, subfeature {@code String} will be also defined inside the API.
33  *
34  * <p>To prevent potential conflict in feature / subfeature name, all feature name should use
35  * implementation package name space like {@code com.android.car.user.FeatureA} unless it is
36  * {@code Car.*_SERVICE}.
37  *
38  * <p>To define a subfeature, main feature should be already declared and sub feature name should
39  * have the format of "main_feature/sub_feature_name". Note that feature name cannot use '/' and
40  * should use only alphabet, digit, '_', '-' and '.'.
41  *
42  * @hide
43  */
44 public final class CarFeatures {
45     /**
46      * Service to show initial user notice screen. This feature has no API and thus defined here.
47      * @hide */
48     @OptionalFeature
49     @AddedInOrBefore(majorVersion = 33)
50     public static String FEATURE_CAR_USER_NOTICE_SERVICE =
51             "com.android.car.user.CarUserNoticeService";
52 
53     // Local cache for making feature query fast.
54     // Key: feature name, value: supported or not.
55     @GuardedBy("mCachedFeatures")
56     private final ArrayMap<String, Boolean> mCachedFeatures = new ArrayMap<>();
57 
58     /** @hide */
isFeatureEnabled(@onNull ICar service, @NonNull String featureName)59     boolean isFeatureEnabled(@NonNull ICar service, @NonNull String featureName) {
60         synchronized (mCachedFeatures) {
61             Boolean supported = mCachedFeatures.get(featureName);
62             if (supported != null) {
63                 return supported;
64             }
65         }
66         // Need to fetch from car service. This should happen only once
67         try {
68             boolean supported = service.isFeatureEnabled(featureName);
69             synchronized (mCachedFeatures) {
70                 mCachedFeatures.put(featureName, Boolean.valueOf(supported));
71             }
72             return supported;
73         } catch (RemoteException e) {
74             // car service has crashed. return false.
75         }
76         return false;
77     }
78 
79     /** @hide */
resetCache()80     void resetCache() {
81         synchronized (mCachedFeatures) {
82             mCachedFeatures.clear();
83         }
84     }
85 }
86