自 2025 年 3 月 27 日起,我们建议您使用 android-latest-release
而非 aosp-main
构建 AOSP 并为其做出贡献。如需了解详情,请参阅 AOSP 的变更。
个性化设置
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
Android 的“设置”应用为 Android 8.0 用户提供了一系列建议。
这些建议通常有助于改进手机功能,而且可以自定义(例如 “设置‘勿扰’时间安排”或“开启 WLAN 通话功能”)。该功能会对建议进行排名(基于任何上下文信号或用户以往的建议采用情况)。
当前的默认 Android 开放源代码项目 (AOSP) 排名模型基于用户以往的建议采用情况;这是一个简单的线性模型,它通过逻辑回归进行训练,从而正确地对互动信号进行加权。 默认实现会使用显示、点击或拒绝的建议作为指标,同时根据这些事件的新近度对建议进行排名,并提高正确预测用户对这些建议的采用情况的概率。
该模型是利用有限的已记录用户数据构建而成的。 设备制造商 (OEM) 可以根据收集的任何数据开发自己的排名模型,并可能会在后期根据上下文信号校准排名。
实现
在 AOSP 中找到默认的 packages/apps/Settings/src/com/android/settings/dashboard/suggestions/SuggestionRanker.java
实现。
此功能由标记 isSmartSuggestionEnabled
进行保护,该标记默认情况下设置为 false。如果启用该功能(设置为 true),则该功能可使用默认 AOSP 实现运行,无需进行其他修改。原始设备制造商 (OEM) 可以使用默认实现或引入自己的实现来启用此功能。
OEM 可以通过实现 platform/packages/apps/Settings/src/com/android/settings/dashboard/suggestions/SuggestionFeatureProvider.java
功能并替换文件的 rankSuggestions
方法来自定义该功能。该方法会获得两个列表,其中包含建议图块及相应的 suggestionId。 该方法应仅根据所需排名得分重新排列相应列表中图块的顺序。suggestionId 可以用于唯一标识建议,并根据排名实现(例如,与此特定建议的互动新近度)提取关于该建议的所需过往信息。
验证
实现者可以通过编写自己的单元测试(类似于 packages/apps/Settings/tests/robotests/src/com/android/settings/dashboard/suggestions/SuggestionRankerTest.java
)来验证排名,从而确保其功能版本能够按预期运行。
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-27。
[null,null,["最后更新时间 (UTC):2025-07-27。"],[],[],null,["# Personalized settings\n\nThe Android Settings app provides a list of suggestions to the users in Android 8.0.\nThese suggestions typically promote features of the phone, and they are customizable\n(e.g., \"Set Do Not Disturb schedule\" or \"Turn on Wi-Fi Calling\"). This feature provides\nranking for suggestions, based on any contextual signal or the user's past interactions\nwith suggestions.\n\n\nThe current default Android Open Source Project (AOSP) ranking model is based on\nuser's previous interactions with the suggestion, which is a simple linear model\ntrained with logistic regression to properly weight the interaction signals. The\ndefault implementation uses suggestions shown, clicked or dismissed as\nindicators along with the recency of these events to rank the suggestions and\nincrease the chance of predicting a user's interaction with these suggestions.\nThis model was built with a limited amount of logged user data. Device manufacturers\n(OEMs) can develop their own ranking model based on any collected data and potentially\ninclude contextual signals and calibrate the ranking.\n\nImplementation\n--------------\n\n\nFind the default `packages/apps/Settings/src/com/android/settings/dashboard/suggestions/SuggestionRanker.java` implementation in AOSP.\n\n\nThis feature is guarded by a flag, `isSmartSuggestionEnabled`, which\nis set to false by default. If enabled (set to true), the feature operates\nwithout additional modification using the default AOSP implementation. OEMs can\neither use the default implementation or introduce their own implementation to\nenable this feature.\n\n\nOEMs may customize the feature by implementing `platform/packages/apps/Settings/src/com/android/settings/dashboard/suggestions/SuggestionFeatureProvider.java\n` feature and Overriding the file's `rankSuggestions` method.\nThis method gets two lists containing suggestion Tiles and the corresponding\nsuggestionIds. This method should reorder the tiles in the list only according\nto the desired ranking score. The suggestionIds can be used to uniquely identify\nsuggestions and extract the required past information about the suggestion,\ndepending on the ranking implementation (e.g., recency of interaction with this\nparticular suggestion).\n\nValidation\n----------\n\n\nImplementers can ensure their version of the feature works as intended by\nwriting their own unit tests similar to `packages/apps/Settings/tests/robotests/src/com/android/settings/dashboard/suggestions/SuggestionRankerTest.java` to verify the ranking."]]