• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2020 The Android Open Source Project
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #pragma once
16 
17 #include "base/export.h"
18 #include "Features.h"
19 // #include "HWMatching.h"
20 
21 #include <string>
22 #include <vector>
23 
24 namespace android {
25 namespace featurecontrol {
26 
27 // featurecontrol is used to switch on/off advanced features It loads
28 // sdk/emulator/lib/advancedFeatures.ini for default values and
29 // .android/advancedFeatures.ini for user overriden values.  If on canary
30 // update channel, sdk/emulator/lib/advancedFeaturesCanary.ini is used for
31 // default values.
32 // It is expected to be initialized at the beginning of the emulator.
33 // For easier testing, one may also want to pass the override value through
34 // command line and call setEnabledOverride. (Command line override not
35 // implemented yet)
36 //
37 // featurecontrol::isEnabled is thread safe, all other methods are not.
38 //
39 // To add new features, please (1) add it to android/data/advancedFeatures.ini
40 // or android/data/advancedFeaturesCanary.ini and (2) add a new line to
41 // FeatureControlDef.h, in the following format:
42 // FEATURE_CONTROL_ITEM(YOUR_FEATURE_NAME)
43 
44 void initialize();
45 
46 bool isEnabled(Feature feature);
47 AEMU_EXPORT void setEnabledOverride(Feature feature, bool isEnabled);
48 void resetEnabledToDefault(Feature feature);
49 
50 // Queries whether this feature is tied to the guest.
51 bool isGuestFeature(Feature feature);
52 
53 // returns true if the user has specified it in
54 // home directory's user-based advancedFeatures.ini.
55 bool isOverridden(Feature feature);
56 
57 // like setEnabledOverride, except it is a no-op
58 // if isOverridden(feature) == true.
59 void setIfNotOverriden(Feature feature, bool isEnabled);
60 // like setIfNotOverriden, except it is a no-op
61 // if the guest did not enable it too.
62 void setIfNotOverridenOrGuestDisabled(Feature feature, bool isEnabled);
63 
64 Feature stringToFeature(const std::string& str);
65 
66 // For hardware configurations special enough to warrant
67 // disabling or enabling features, we use the concept of
68 // "feature pattern" which consists of properties of hardware
69 // in question and a set of features to force-enable or disable.
70 
71 // applyCachedServerFeaturePatterns() queries host hardware
72 // confiruation, takes current cached patterns, and enables
73 // or disables features based on which patterns match the host.
74 // If there is no cached patterns, no action is taken.
75 void applyCachedServerFeaturePatterns();
76 // asyncUpdateServerFeaturePatterns():
77 // If the current cached feature patterns don't exist or are over 24 hours old,
78 // asyncUpdateServerFeaturePatterns() starts a download of
79 // a protobuf containing the latest feature patterns, replacing
80 // the current cached ones.
81 void asyncUpdateServerFeaturePatterns();
82 
83 // Queries the current set of features in various ways:
84 // - whether the default guest/host/server config has attempted
85 // to enable the feature.
86 // - whether the user has overriden the feature.
87 // - the resulting set of enabled features, which also accounts for
88 // programmatic setting of features.
89 std::vector<Feature> getEnabledNonOverride();
90 std::vector<Feature> getEnabledOverride();
91 std::vector<Feature> getDisabledOverride();
92 std::vector<Feature> getEnabled();
93 
94 } // namespace android
95 } // namespace featurecontrol
96