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

Commit 477472fe authored by Android Build Coastguard Worker's avatar Android Build Coastguard Worker
Browse files

Snap for 11975806 from 68953d33 to 24Q3-release

Change-Id: Id6a9a45d499fba55afc50c12eae2b1e8556eaccf
parents 78628b03 68953d33
Loading
Loading
Loading
Loading
+7 −4
Original line number Diff line number Diff line
@@ -7906,7 +7906,7 @@
    <!-- Sound: Footer hyperlink text to launch the Connected devices settings page. [CHAR LIMIT=NONE]-->
    <string name="spatial_audio_footer_learn_more_text">Connected devices settings</string>
    <!-- Sound: Summary for the Do not Disturb option that describes how many automatic rules (schedules) are enabled [CHAR LIMIT=NONE]-->
    <!-- Zen Modes: Summary for the Do not Disturb option that describes how many automatic rules (schedules) are enabled [CHAR LIMIT=NONE]-->
    <string name="zen_mode_settings_schedules_summary">
        {count, plural,
            =0    {None}
@@ -7915,13 +7915,16 @@
        }
    </string>
    <!-- Sound: Title for the Do not Disturb option and associated settings page. [CHAR LIMIT=50]-->
    <!-- Zen Modes: Title for the Do not Disturb option and associated settings page. [CHAR LIMIT=50]-->
    <string name="zen_mode_settings_title">Do Not Disturb</string>
    <!-- Sound: Title for the Modes option and associated settings page. [CHAR LIMIT=50]-->
    <!-- Zen Modes: Title for the Modes option and associated settings page. [CHAR LIMIT=50]-->
    <string name="zen_modes_list_title">Priority Modes</string>
    <!-- Sound: Summary for the Do not Disturb option and associated settings page. [CHAR LIMIT=240]-->
    <!-- Zen Modes: Caption of the "add a mode" item in the modes list -->
    <string name="zen_modes_add_mode">Add a mode</string>
    <!-- Zen Modes: Summary for the Do not Disturb option and associated settings page. [CHAR LIMIT=240]-->
    <string name="zen_mode_settings_summary">Only get notified by important people and apps</string>
    <!-- Subtitle for the Do not Disturb slice. [CHAR LIMIT=50]-->
+10 −2
Original line number Diff line number Diff line
@@ -15,7 +15,9 @@
  ~ limitations under the License.
  -->

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

    <!-- TODO: b/333682392 - add strings for summary as appropriate -->
@@ -25,4 +27,10 @@
        <!-- Preferences leading to rules are added in this PreferenceCategory. -->
    </PreferenceCategory>

    <Preference
        android:key="add_mode"
        android:title="@string/zen_modes_add_mode"
        android:icon="@drawable/ic_add_24dp"
        settings:allowDividerAbove="false"/>

</PreferenceScreen>
+30 −0
Original line number Diff line number Diff line
@@ -30,6 +30,8 @@ import android.provider.ContactsContract;
import android.provider.Settings;
import android.service.notification.Condition;
import android.service.notification.ConversationChannelWrapper;
import android.service.notification.SystemZenRules;
import android.service.notification.ZenAdapters;
import android.service.notification.ZenModeConfig;
import android.util.Log;

@@ -242,4 +244,32 @@ class ZenModesBackend {
        }
        mNotificationManager.removeAutomaticZenRule(mode.getId(), /* fromUser= */ true);
    }

    /**
     * Creates a new custom mode with the provided {@code name}. The mode will be "manual" (i.e.
     * not have a schedule), this can be later updated by the user in the mode settings page.
     *
     * @return the created mode. Only {@code null} if creation failed due to an internal error
     */
    @Nullable
    ZenMode addCustomMode(String name) {
        ZenModeConfig.ScheduleInfo schedule = new ZenModeConfig.ScheduleInfo();
        schedule.days = ZenModeConfig.ALL_DAYS;
        schedule.startHour = 22;
        schedule.endHour = 7;

        // TODO: b/326442408 - Create as "manual" (i.e. no trigger) instead of schedule-time.
        AutomaticZenRule rule = new AutomaticZenRule.Builder(name,
                ZenModeConfig.toScheduleConditionId(schedule))
                .setPackage(ZenModeConfig.getScheduleConditionProvider().getPackageName())
                .setType(AutomaticZenRule.TYPE_SCHEDULE_CALENDAR)
                .setOwner(ZenModeConfig.getScheduleConditionProvider())
                .setTriggerDescription(SystemZenRules.getTriggerDescriptionForScheduleTime(
                        mContext, schedule))
                .setManualInvocationAllowed(true)
                .build();

        String ruleId = mNotificationManager.addAutomaticZenRule(rule);
        return getMode(ruleId);
    }
}
+61 −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.content.Context;

import androidx.preference.Preference;

import com.android.settings.utils.ZenServiceListing;
import com.android.settingslib.core.AbstractPreferenceController;

import java.util.Random;

class ZenModesListAddModePreferenceController extends AbstractPreferenceController {

    private final ZenModesBackend mBackend;
    private final ZenServiceListing mServiceListing;

    ZenModesListAddModePreferenceController(Context context, ZenModesBackend backend,
            ZenServiceListing serviceListing) {
        super(context);
        mBackend = backend;
        mServiceListing = serviceListing;
    }

    @Override
    public boolean isAvailable() {
        return true;
    }

    @Override
    public String getPreferenceKey() {
        return "add_mode";
    }

    @Override
    public void updateState(Preference preference) {
        preference.setOnPreferenceClickListener(pref -> {
            // TODO: b/326442408 - Launch the proper mode creation flow (using mServiceListing).
            ZenMode mode = mBackend.addCustomMode("New mode #" + new Random().nextInt(1000));
            if (mode != null) {
                ZenSubSettingLauncher.forMode(mContext, mode.getId()).launch();
            }
            return true;
        });
    }
}
+9 −11
Original line number Diff line number Diff line
@@ -31,12 +31,14 @@ import com.android.settings.utils.ZenServiceListing;
import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settingslib.search.SearchIndexable;

import java.util.ArrayList;
import com.google.common.collect.ImmutableList;

import java.util.List;

@SearchIndexable
public class ZenModesListFragment extends ZenModesFragmentBase {
    protected final ManagedServiceSettings.Config CONFIG = getConditionProviderConfig();

    private static final ManagedServiceSettings.Config CONFIG = getConditionProviderConfig();

    @Override
    protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
@@ -50,13 +52,11 @@ public class ZenModesListFragment extends ZenModesFragmentBase {
        // We need to redefine ZenModesBackend here even though mBackend exists so that this method
        // can be static; it must be static to be able to be used in SEARCH_INDEX_DATA_PROVIDER.
        ZenModesBackend backend = ZenModesBackend.getInstance(context);
        List<AbstractPreferenceController> controllers = new ArrayList<>();
        controllers.add(new ZenModesListPreferenceController(
                context, parent, backend));

        // TODO: b/326442408 - Add controller for "Add Mode" preference/flow, which is what uses
        //                     the ZenServiceListing.
        return controllers;
        return ImmutableList.of(
                new ZenModesListPreferenceController(context, parent, backend),
                new ZenModesListAddModePreferenceController(context, backend, serviceListing)
        );
    }

    @Override
@@ -77,7 +77,7 @@ public class ZenModesListFragment extends ZenModesFragmentBase {
        return SettingsEnums.NOTIFICATION_ZEN_MODE_AUTOMATION;
    }

    protected static ManagedServiceSettings.Config getConditionProviderConfig() {
    private static ManagedServiceSettings.Config getConditionProviderConfig() {
        return new ManagedServiceSettings.Config.Builder()
                .setTag(TAG)
                .setIntentAction(ConditionProviderService.SERVICE_INTERFACE)
@@ -87,8 +87,6 @@ public class ZenModesListFragment extends ZenModesFragmentBase {
                .build();
    }

    // TODO: b/322373473 - Add 3-dot options menu with capability to delete modes.

    /**
     * For Search.
     */
Loading