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

Commit 3ec64340 authored by Sunny Shao's avatar Sunny Shao
Browse files

[Catalyst] Migrate the Modes > Bedtime screen

NO_IFTTT=Catalyst only

Test: manual
Bug: 410485352
Flag: com.android.settings.flags.device_state
Change-Id: I4c286f89433462c34459804192dae5aefbd0bf10
parent 722a5ea0
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -41,6 +41,7 @@ import com.android.settings.network.NetworkDashboardScreen
import com.android.settings.network.NetworkProviderScreen
import com.android.settings.network.tether.TetherScreen
import com.android.settings.notification.SoundScreen
import com.android.settings.notification.modes.devicestate.ZenModeBedtimeScreen
import com.android.settings.notification.modes.devicestate.ZenModeButtonPreference
import com.android.settings.notification.modes.devicestate.ZenModeDndDisplayScreen
import com.android.settings.notification.modes.devicestate.ZenModeDndScreen
@@ -182,6 +183,11 @@ fun getScreenConfigs() =
            screenKey = ZenModeDndDisplayScreen.KEY,
            category = setOf(DeviceStateCategory.UNCATEGORIZED),
        ),
        PerScreenConfig(
            enabled = true,
            screenKey = ZenModeBedtimeScreen.KEY,
            category = setOf(DeviceStateCategory.UNCATEGORIZED),
        ),
    )

fun getDeviceStateItemList() =
+80 −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.modes.devicestate

import android.app.Flags as AppFlags
import android.content.Context
import android.content.Intent
import android.provider.Settings.EXTRA_AUTOMATIC_ZEN_RULE_ID
import com.android.settings.Settings.ModeSettingsActivity
import com.android.settings.contract.TAG_DEVICE_STATE_SCREEN
import com.android.settings.flags.Flags
import com.android.settingslib.metadata.PreferenceAvailabilityProvider
import com.android.settingslib.metadata.PreferenceMetadata
import com.android.settingslib.metadata.PreferenceSummaryProvider
import com.android.settingslib.metadata.PreferenceTitleProvider
import com.android.settingslib.metadata.ProvidePreferenceScreen
import com.android.settingslib.metadata.preferenceHierarchy
import com.android.settingslib.preference.PreferenceFragment
import com.android.settingslib.preference.PreferenceScreenCreator

/**
 * This Bedtime mode screen is dedicated for device state. It functions via a virtual key and is
 * separate from the current Settings user interface, which it does not affect. Obviously, this is
 * not fully migrated page.
 */
// LINT.IfChange
@ProvidePreferenceScreen(ZenModeBedtimeScreen.KEY)
class ZenModeBedtimeScreen :
    PreferenceScreenCreator,
    PreferenceAvailabilityProvider,
    PreferenceTitleProvider,
    PreferenceSummaryProvider {

    override val key: String
        get() = KEY

    override fun tags(context: Context) = arrayOf(TAG_DEVICE_STATE_SCREEN)

    override fun isFlagEnabled(context: Context) = Flags.deviceState() && AppFlags.modesUi()

    override fun fragmentClass() = PreferenceFragment::class.java

    override fun isAvailable(context: Context) = AppFlags.modesUi() && context.hasBedtimeMode()

    override fun getTitle(context: Context): CharSequence? = context.getBedtimeMode()?.name

    override fun getSummary(context: Context): CharSequence? =
        context.getZenModeScreenSummary(context.getBedtimeMode())

    override fun getLaunchIntent(context: Context, metadata: PreferenceMetadata?): Intent? =
        if (AppFlags.modesUi())
            Intent(context, ModeSettingsActivity::class.java)
                .putExtra(EXTRA_AUTOMATIC_ZEN_RULE_ID, context.getBedtimeMode()?.id)
        else null

    override fun getPreferenceHierarchy(context: Context) = preferenceHierarchy(context, this) {}

    companion object {
        const val KEY = "device_state_bedtime_mode_screen" // only for device state.
    }
}
// LINT.ThenChange(
//     ../ZenModeFragment.java,
//     ../ZenModesListPreferenceController.java,
//     ../ZenModesListItemPreference.java,
// )
+6 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.settings.notification.modes.devicestate

import android.app.AutomaticZenRule.TYPE_BEDTIME
import android.content.Context
import android.service.notification.ZenModeConfig.MANUAL_RULE_ID
import com.android.settings.R
@@ -30,6 +31,11 @@ internal fun Context.hasDndMode() = (getBackend().getMode(MANUAL_RULE_ID) != nul

internal fun Context.getDndMode(): ZenMode? = getBackend().getMode(MANUAL_RULE_ID)

internal fun Context.hasBedtimeMode() = getBackend().modes.any { it.type == TYPE_BEDTIME }

internal fun Context.getBedtimeMode(): ZenMode? =
    getBackend().modes.find { it.type == TYPE_BEDTIME }

internal fun Context.getZenModeScreenSummary(zenMode: ZenMode?): String {
    if (zenMode == null) return ""
    val status = zenMode.status