android13(T) Settings Suggestion 菜单不显示bug修复

一般来讲需求都是去掉这个 suggestion 菜单,因为这玩意会在设备开机几天后自动出现,很烦人。

但反人类的需求也是有的,为什么之前低版本好用,现在高版本不好用了。靓仔无语

修改清单

packages\apps\Settings\src\com\android\settings\homepage\SettingsHomepageActivity.java
packages\apps\SettingsIntelligence\src\com\android\settings\intelligence\suggestions\model\CandidateSuggestion.java

注释 CONTEXTUAL_HOME FeatureFlags,或者你也可以修改 frameworks\base\core\java\android\util\FeatureFlagUtils.java

默认值 DEFAULT_FLAGS.put(“settings_contextual_home”, “false”); 改为true

packages\apps\Settings\src\com\android\settings\homepage\SettingsHomepageActivity.java

//if (FeatureFlagUtils.isEnabled(this, FeatureFlags.CONTEXTUAL_HOME)) {
    
    
                showFragment(() -> new ContextualCardsFragment(), R.id.contextual_cards_content);
                ((FrameLayout) findViewById(R.id.main_content))
                        .getLayoutTransition().enableTransitionType(LayoutTransition.CHANGING);
            //}

packages\apps\SettingsIntelligence\src\com\android\settings\intelligence\suggestions\model\CandidateSuggestion.java

 builder.setTitle(title)
                .setSummary(summary)
                .setFlags(flags)
                .setIcon(icon)
                .setPendingIntent(PendingIntent
                        // .getActivity(mContext, 0 /* requestCode */, mIntent, 0 /* flags */));
                        .getActivity(mContext, 0 /* requestCode */, mIntent, PendingIntent.FLAG_IMMUTABLE));

下面是异常log

2023-06-12 11:29:40.262 4947-4964/com.android.settings.intelligence D/CompatibilityChangeReporter: Compat change id reported: 160794467; UID 10063; state: ENABLED
2023-06-12 11:29:40.263 4349-4383/com.android.settings W/SuggestionController: Error when calling getSuggestion()
    java.lang.IllegalArgumentException: com.android.settings.intelligence: Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent.
    Strongly consider using FLAG_IMMUTABLE, only use FLAG_MUTABLE if some functionality depends on the PendingIntent being mutable, e.g. if it needs to be used with inline replies or bubbles.
        at android.os.Parcel.createExceptionOrNull(Parcel.java:3015)
        at android.os.Parcel.createException(Parcel.java:2995)
        at android.os.Parcel.readException(Parcel.java:2978)
        at android.os.Parcel.readException(Parcel.java:2920)
        at android.service.settings.suggestions.ISuggestionService$Stub$Proxy.getSuggestions(ISuggestionService.java:162)
        at com.android.settingslib.suggestions.SuggestionController.getSuggestions(SuggestionController.java:107)
        at com.android.settings.homepage.contextualcards.legacysuggestion.LegacySuggestionContextualCardController.lambda$loadSuggestions$0(LegacySuggestionContextualCardController.java:137)
        at com.android.settings.homepage.contextualcards.legacysuggestion.LegacySuggestionContextualCardController.$r8$lambda$kMNe3xSkLHtYjD-i_NdUPytmxDE(Unknown Source:0)
        at com.android.settings.homepage.contextualcards.legacysuggestion.LegacySuggestionContextualCardController$$ExternalSyntheticLambda1.run(Unknown Source:2)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:463)
        at java.util.concurrent.FutureTask.run(FutureTask.java:264)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1137)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:637)
        at java.lang.Thread.run(Thread.java:1012)
2023-06-12 11:29:40.263 4349-4383/com.android.settings D/LegacySuggestCardCtrl: Loaded suggests: null

猜你喜欢

转载自blog.csdn.net/u012932409/article/details/131611020