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 "aemu/base/export.h" 18 #include "Features.h" 19 // #include "HWMatching.h" 20 21 #include <functional> 22 #include <string> 23 #include <vector> 24 #include <ostream> 25 26 namespace android { 27 namespace featurecontrol { 28 29 // featurecontrol is used to switch on/off advanced features It loads 30 // sdk/emulator/lib/advancedFeatures.ini for default values and 31 // .android/advancedFeatures.ini for user overriden values. If on canary 32 // update channel, sdk/emulator/lib/advancedFeaturesCanary.ini is used for 33 // default values. 34 // It is expected to be initialized at the beginning of the emulator. 35 // For easier testing, one may also want to pass the override value through 36 // command line and call setEnabledOverride. (Command line override not 37 // implemented yet) 38 // 39 // featurecontrol::isEnabled is thread safe, all other methods are not. 40 // 41 // To add new features, please (1) add it to android/data/advancedFeatures.ini 42 // or android/data/advancedFeaturesCanary.ini and (2) add a new line to 43 // FeatureControlDef.h, in the following format: 44 // FEATURE_CONTROL_ITEM(YOUR_FEATURE_NAME) 45 46 void initialize(); 47 48 bool isEnabled(Feature feature); 49 bool isEnabledByGuest(Feature feature); 50 AEMU_EXPORT void setEnabledOverride(Feature feature, bool isEnabled); 51 void resetEnabledToDefault(Feature feature); 52 53 // Queries whether this feature is tied to the guest. 54 bool isGuestFeature(Feature feature); 55 56 // returns true if the user has specified it in 57 // home directory's user-based advancedFeatures.ini. 58 bool isOverridden(Feature feature); 59 60 // like setEnabledOverride, except it is a no-op 61 // if isOverridden(feature) == true. 62 void setIfNotOverriden(Feature feature, bool isEnabled); 63 // like setIfNotOverriden, except it is a no-op 64 // if the guest did not enable it too. 65 void setIfNotOverridenOrGuestDisabled(Feature feature, bool isEnabled); 66 67 Feature stringToFeature(const std::string& str); 68 69 // For hardware configurations special enough to warrant 70 // disabling or enabling features, we use the concept of 71 // "feature pattern" which consists of properties of hardware 72 // in question and a set of features to force-enable or disable. 73 74 // applyCachedServerFeaturePatterns() queries host hardware 75 // confiruation, takes current cached patterns, and enables 76 // or disables features based on which patterns match the host. 77 // If there is no cached patterns, no action is taken. 78 void applyCachedServerFeaturePatterns(); 79 // asyncUpdateServerFeaturePatterns(): 80 // If the current cached feature patterns don't exist or are over 24 hours old, 81 // asyncUpdateServerFeaturePatterns() starts a download of 82 // a protobuf containing the latest feature patterns, replacing 83 // the current cached ones. 84 void asyncUpdateServerFeaturePatterns(); 85 86 // Queries the current set of features in various ways: 87 // - whether the default guest/host/server config has attempted 88 // to enable the feature. 89 // - whether the user has overriden the feature. 90 // - the resulting set of enabled features, which also accounts for 91 // programmatic setting of features. 92 std::vector<Feature> getEnabledNonOverride(); 93 std::vector<Feature> getEnabledOverride(); 94 std::vector<Feature> getDisabledOverride(); 95 std::vector<Feature> getEnabled(); 96 void writeFeaturesToStream(std::ostream& os); 97 98 // Overrides feature_is_enabled function above to use a user-provided callback 99 // instead. 100 void setFeatureEnabledCallback(std::function<bool(Feature)> cb); 101 102 // Customization point for the client to inject feature override calls. 103 void productFeatureOverride(); 104 } // namespace android 105 } // namespace featurecontrol 106