Android frameworks 开发总结之九(Settings)

1.移除Settings首頁所有suggestion項

XXX設備按照客人要求需要移除Settings中所有的suggestion項,比喻:Finish setting up your device,Customize your device等。

修改packages/apps/SettingsIntelligence/src/com/android/settings/intelligence/suggestions/SuggestionParser.java 文件中的getSuggestions方法:

public List getSuggestions() {
        final SuggestionListBuilder suggestionBuilder = new SuggestionListBuilder();

        for (SuggestionCategory category : CATEGORIES) {
            if (category.isExclusive() && !isExclusiveCategoryExpired(category)) {
                // If suggestions from an exclusive category are present, parsing is stopped
                // and only suggestions from that category are displayed. Note that subsequent
                // exclusive categories are also ignored.

                // Read suggestion and force ignoreSuggestionDismissRule to be false so the rule
                // defined from each suggestion itself is used.
                final List exclusiveSuggestions =
                        readSuggestions(category, false /* ignoreDismissRule */);
                exclusiveSuggestions.clear(); // remove all suggestion item
                if (!exclusiveSuggestions.isEmpty()) {
                    suggestionBuilder.addSuggestions(category, exclusiveSuggestions);
                    return suggestionBuilder.build();
                }
            } else {
                // Either the category is not exclusive, or the exclusiveness expired so we should
                // treat it as a normal category.
                final List suggestions =
                        readSuggestions(category, true /* ignoreDismissRule */);
                suggestions.clear(); //remove all suggestion item
                suggestionBuilder.addSuggestions(category, suggestions);
            }
        }
        return suggestionBuilder.build();
    }

2.解決Settings中search results前面的null level

使用settings中的 search功能時,在搜索的結果中最前面多一個null level。修改:packages/apps/SettingsIntelligence/src/com/android/settings/intelligence/search/sitemap/SiteMapManager.java 文件中的buildBreadCrumb 方法.

  public synchronized List buildBreadCrumb(Context context, String clazz,
            String screenTitle) {
        init(context);
        final long startTime = System.currentTimeMillis();
        final List breadcrumbs = new ArrayList<>();
        if (!mInitialized) {
            Log.w(TAG, "SiteMap is not initialized yet, skipping");
            return breadcrumbs;
        }
        breadcrumbs.add(screenTitle);
        String currentClass = clazz;
        String currentTitle = screenTitle;
        // Look up current page's parent, if found add it to breadcrumb string list, and repeat.
        while (true) {
            final SiteMapPair pair = lookUpParent(currentClass, currentTitle);
            //檢測parent title是否爲空,爲空不添加
            if (pair == null || pair.getParentTitle() == null) {
                if (DEBUG_TIMING) {
                    Log.d(TAG, "BreadCrumb timing: " + (System.currentTimeMillis() - startTime));
                }
                return breadcrumbs;
            }
            breadcrumbs.add(0, pair.getParentTitle());
            currentClass = pair.getParentClass();
            currentTitle = pair.getParentTitle();
        }
    }

3.Settings 获取app存储大小

设置里面的app信息里面存储里面的app Size对应stats.codeSize. 读取流程如下:

StorageStatsService.queryStatsForPackage-->StorageStatsService.queryStatsForUid -->Installer.getAppSize -→InstalldNativeService.cpp

frameworks/base/services/usage/java/com/android/server/usage/StorageStatsService.java

frameworks/base/services/core/java/com/android/server/pm/Installer.java

frameworks/native/cmds/installd/InstalldNativeService.cpp

如果想debug InstallNatvieService文件中读取大小的时候是否有错误,则需要enable MEASURE_DEBUG, 打开方式为设定“frameworks/native/cmds/installd/utils.h“文件中的MEASURE_DEBUG为1。

InstalldNativeService文件中的getAppSize方法里面“calculate_tree_size“这个是在” frameworks/native/cmds/installd/utils.cpp”文件中实现.

你可能感兴趣的:(android)