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