Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 532bd7f1 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Add initial settings for summarization" into main

parents 3aaf1147 50e720b0
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -8847,6 +8847,13 @@
    <!-- App Info > Notifications: Title for section where notifications bundles can be configured [CHAR LIMIT=80]-->
    <string name="notification_bundles">Notification bundles</string>
    <!-- App Info > Notifications: Title for section where notifications summaries can be configured [CHAR LIMIT=80]-->
    <string name="notification_summarization_title">Notification summaries</string>
    <string name="notification_summarization_on">On</string>
    <string name="notification_summarization_off">Off</string>
    <string name="notification_summarization_main_control_title">Use notification summaries</string>
    <string name="notification_summarization_description">Automatically summarize conversation notifications from any app</string>
    <!-- App Info > Notifications: Title for section controlling whether this app may show notifications in a promoted format [CHAR LIMIT=80] -->
    <string name="live_notifications">Live notifications</string>
    <!-- App Info > Notifications: Text on the switch to enable or disable an app from showing notifications in a live/promoted format [CHAR LIMIT=50] -->
@@ -9269,7 +9276,6 @@
    <string name="notification_bundle_main_control_title">Use notification bundling</string>
    <string name="notification_bundle_description">Notifications with similar themes will be silenced and grouped together for a quieter experience. Bundling will override an app\'s own notification settings.</string>
    <!-- Title for managing VR (virtual reality) helper services. [CHAR LIMIT=50] -->
    <string name="vr_listeners_title">VR helper services</string>
+11 −3
Original line number Diff line number Diff line
@@ -25,7 +25,7 @@
        <!-- See all apps button -->
        <Preference
            android:key="all_notifications"
            android:order="10"
            android:order="1"
            android:title="@string/app_notification_field"
            android:summary="@string/app_notification_field_summary"
            android:fragment="com.android.settings.applications.manageapplications.ManageApplications">
@@ -35,7 +35,7 @@
        </Preference>
        <Preference
            android:key="notification_history"
            android:order="11"
            android:order="2"
            android:title="@string/notification_history"
            android:summary="@string/notification_history_summary">
            <intent
@@ -44,11 +44,19 @@
                android:targetClass="com.android.settings.notification.history.NotificationHistoryActivity" />
        </Preference>

        <Preference
            android:fragment="com.android.settings.notification.SummarizationPreferenceFragment"
            android:key="summarization_notifications_preference"
            android:order="3"
            android:persistent="false"
            android:title="@string/notification_summarization_title"
            settings:controller="com.android.settings.notification.SummarizationPreferenceController" />

        <Preference
            android:fragment="com.android.settings.notification.BundlePreferenceFragment"
            android:key="bundle_notifications_preference"
            android:persistent="false"
            android:order="12"
            android:order="4"
            android:title="@string/notification_bundle_title"
            settings:controller="com.android.settings.notification.BundlePreferenceController" />
    </PreferenceCategory>
+39 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
    Copyright (C) 2025 The Android Open Source Project

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

        http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
-->

<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:settings="http://schemas.android.com/apk/res-auto"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:title="@string/notification_summarization_title">

    <com.android.settingslib.widget.IllustrationPreference
        android:key="illustration"
        settings:searchable="false"
        android:selectable="false"
        app:lottie_cacheComposition="false"
        settings:dynamicColor="true"/>

    <com.android.settingslib.widget.TopIntroPreference
        android:key="feature_description"
        settings:searchable="false"
        android:title="@string/notification_summarization_description"/>

    <com.android.settingslib.widget.MainSwitchPreference
        android:key="global_pref"
        android:title="@string/notification_summarization_main_control_title"
        settings:controller="com.android.settings.notification.SummarizationGlobalPreferenceController" />
</PreferenceScreen>
+31 −0
Original line number Diff line number Diff line
@@ -687,6 +687,37 @@ public class NotificationBackend {
        }
    }

    public boolean isNotificationSummarizationSupported() {
        try {
            return !sINM.getUnsupportedAdjustmentTypes().contains(Adjustment.KEY_SUMMARIZATION);
        } catch (Exception e) {
            Log.w(TAG, "Error calling NoMan", e);
        }
        return false;
    }

    public boolean isNotificationSummarizationEnabled(Context context) {
        try {
            return sINM.getAllowedAssistantAdjustments(context.getPackageName())
                    .contains(Adjustment.KEY_SUMMARIZATION);
        } catch (Exception e) {
            Log.w(TAG, "Error calling NoMan", e);
        }
        return false;
    }

    public void setNotificationSummarizationEnabled(boolean enabled) {
        try {
            if (enabled) {
                sINM.allowAssistantAdjustment(Adjustment.KEY_SUMMARIZATION);
            } else {
                sINM.disallowAssistantAdjustment(Adjustment.KEY_SUMMARIZATION);
            }
        } catch (Exception e) {
            Log.w(TAG, "Error calling NoMan", e);
        }
    }

    public boolean isBundleTypeApproved(@Adjustment.Types int type) {
        try {
            int[] approved = sINM.getAllowedAdjustmentKeyTypes();
+62 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2025 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.settings.notification;

import android.app.Flags;
import android.content.Context;

import androidx.annotation.NonNull;

import com.android.settings.widget.SettingsMainSwitchPreferenceController;

public class SummarizationGlobalPreferenceController extends
        SettingsMainSwitchPreferenceController {

    NotificationBackend mBackend;

    public SummarizationGlobalPreferenceController(@NonNull Context context,
            @NonNull String preferenceKey) {
        super(context, preferenceKey);
        mBackend = new NotificationBackend();
    }

    @Override
    public int getAvailabilityStatus() {
        if ((Flags.nmSummarization() || Flags.nmSummarizationUi())
                && mBackend.isNotificationSummarizationSupported()) {
            return AVAILABLE;
        }
        return CONDITIONALLY_UNAVAILABLE;
    }

    @Override
    public boolean isChecked() {
        return mBackend.isNotificationSummarizationEnabled(mContext);
    }

    @Override
    public boolean setChecked(boolean isChecked) {
        mBackend.setNotificationSummarizationEnabled(isChecked);
        return true;
    }

    @Override
    public int getSliceHighlightMenuRes() {
        // not needed since it's not sliceable
        return NO_RES;
    }
}
Loading