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

Commit c512046e authored by Alexander Roederer's avatar Alexander Roederer
Browse files

Adds modes settings page for bypassing apps

Adds the settings page that a user will reach from a mode settings page
when they tap on "App," to allow  them to select whether all, none, or
priority modes can break through and send notifications.

Bug: 308819928
Bug: 331267485
Flag: android.app.modes_ui DEVELOPMENT
Test: build and test, controller unit tests
Change-Id: I5bcebfca0fc2882f839afdced8d2b817dad14e6c
parent aa6eb398
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -7994,6 +7994,7 @@
        }
    </string>
    <!-- Do not disturb: restrict notifications settings title [CHAR LIMIT=80] -->
    <string name="zen_mode_restrict_notifications_title">Display options for filtered
        notifications</string>
@@ -9155,6 +9156,17 @@
    <!-- [CHAR LIMIT=50] Zen mode settings: Events (ie: calendar events) category in a list of sounds when events is the first or only element in the list. For example “Events can interrupt" or “Events and touch sounds can interrupt" -->
    <string name="zen_mode_events_list_first">Events</string>
    <!-- [CHAR LIMIT=80] Zen mode settings: Title for page to select which apps allowed to interrupt dnd -->
    <string name="zen_mode_apps_title">Apps</string>
    <!-- [CHAR LIMIT=100] Zen mode settings: subtitle for page to select which apps allowed to interrupt dnd -->
    <string name="zen_mode_apps_category">Apps that can interrupt</string>
    <!-- [CHAR LIMIT=60] Zen mode settings: selected apps will be able to bypass dnd -->
    <string name="zen_mode_apps_priority_apps">Selected apps</string>
    <!-- [CHAR LIMIT=60] Zen mode settings: no apps will be able to bypass dnd -->
    <string name="zen_mode_apps_none_apps">None</string>
    <!-- [CHAR LIMIT=60] Zen mode settings: all apps will be able to bypass dnd -->
    <string name="zen_mode_apps_all_apps">All</string>
    <!-- [CHAR LIMIT=100] Zen mode settings: Allow apps to bypass DND -->
    <string name="zen_mode_bypassing_apps">Allow apps to override</string>
    <!-- [CHAR LIMIT=100] Zen mode settings: Allow apps to bypass DND header -->
+4 −0
Original line number Diff line number Diff line
@@ -29,6 +29,10 @@
                android:key="zen_mode_people"
                android:title="@string/zen_category_people"/>

        <Preference
            android:key="zen_mode_apps"
            android:title="@string/zen_category_apps" />

        <Preference
                android:key="zen_other_settings"
                android:title="@string/zen_category_exceptions" />
+44 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
     Copyright (C) 2024 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"
    android:title="@string/zen_mode_apps_title" >

    <PreferenceCategory
        android:key="zen_mode_apps_category"
        android:title="@string/zen_mode_apps_category">

        <com.android.settingslib.widget.SelectorWithWidgetPreference
            android:key="zen_mode_apps_priority"
            android:title="@string/zen_mode_apps_priority_apps"
            settings:searchable="false"/>

        <com.android.settingslib.widget.SelectorWithWidgetPreference
            android:key="zen_mode_apps_none"
            android:title="@string/zen_mode_apps_none_apps"
            settings:searchable="false"/>

        <com.android.settingslib.widget.SelectorWithWidgetPreference
            android:key="zen_mode_apps_all"
            android:title="@string/zen_mode_apps_all_apps"
            settings:searchable="false"/>

    </PreferenceCategory>

</PreferenceScreen>
 No newline at end of file
+57 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 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.modes;

import android.app.settings.SettingsEnums;
import android.content.Context;

import com.android.settings.R;
import com.android.settingslib.core.AbstractPreferenceController;

import java.util.ArrayList;
import java.util.List;

/**
 * Mode >  Apps
 */
public class ZenModeAppsFragment extends ZenModeFragmentBase {

    @Override
    protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
        List<AbstractPreferenceController> controllers = new ArrayList<>();
        controllers.add(new ZenModeAppsPreferenceController(
                context, ZenModeAppsPreferenceController.KEY_PRIORITY, mBackend));
        controllers.add(new ZenModeAppsPreferenceController(
                context, ZenModeAppsPreferenceController.KEY_NONE, mBackend));
        // TODO: b/308819928 - The manual DND mode cannot have the ALL type;
        // unify the controllers into one and only create a preference if isManualDnd is false.
        controllers.add(new ZenModeAppsPreferenceController(
                context, ZenModeAppsPreferenceController.KEY_ALL, mBackend));
        return controllers;
    }

    @Override
    protected int getPreferenceScreenResId() {
        return R.xml.zen_mode_apps_settings;
    }

    @Override
    public int getMetricsCategory() {
        // TODO: b/332937635 - make this the correct metrics category
        return SettingsEnums.NOTIFICATION_ZEN_MODE_PRIORITY;
    }
}
+54 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 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.modes;

import static com.android.settings.notification.modes.ZenModeFragmentBase.MODE_ID;

import android.content.Context;
import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.preference.Preference;

import com.android.settings.core.SubSettingLauncher;

/**
 * Preference with a link and summary about what apps can break through the mode
 */
public class ZenModeAppsLinkPreferenceController extends AbstractZenModePreferenceController {

    private final ZenModeSummaryHelper mSummaryHelper;

    public ZenModeAppsLinkPreferenceController(Context context, String key,
            ZenModesBackend backend) {
        super(context, key, backend);
        mSummaryHelper = new ZenModeSummaryHelper(mContext, mBackend);
    }

    @Override
    public void updateState(Preference preference, @NonNull ZenMode zenMode) {
        Bundle bundle = new Bundle();
        bundle.putString(MODE_ID, zenMode.getId());
        // TODO(b/332937635): Update metrics category
        preference.setIntent(new SubSettingLauncher(mContext)
                .setDestination(ZenModeAppsFragment.class.getName())
                .setSourceMetricsCategory(0)
                .setArguments(bundle)
                .toIntent());
        preference.setSummary(mSummaryHelper.getAppsSummary(zenMode));
    }
}
Loading