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

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

Merge "Add preference for device suggestions" into main

parents 7fa1306b 4b37da0a
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -111,3 +111,10 @@ flag {
  description: "Enables alert indicator on homepage tiles"
  bug: "403326850"
}

flag {
  name: "device_suggestions_preference"
  namespace: "android_settings"
  description: "Add a preference for device suggestions in the media page"
  bug: "415096359"
}
+4 −0
Original line number Diff line number Diff line
@@ -13488,6 +13488,10 @@ Data usage charges may apply.</string>
    <string name="media_controls_hide_player">Hide player</string>
    <!-- Subtext for media settings when the player will be shown [CHAR LIMIT=50] -->
    <string name="media_controls_show_player">Show player</string>
    <!-- Title of setting for device suggestions in the media player [CHAR LIMIT=50]-->
    <string name="media_controls_suggestions_title">Media suggestions</string>
    <!-- Description of setting for device suggestions in the media player [CHAR LIMIT=NONE]-->
    <string name="media_controls_suggestions_description">Provide media suggestions from media apps based on your activity and location.</string>
    <!-- Keywords for the media controls setting [CHAR LIMIT=NONE]-->
    <string name="keywords_media_controls">media</string>
+3 −0
Original line number Diff line number Diff line
@@ -68,6 +68,9 @@ class MediaControlsScreen(context: Context) :
        preferenceHierarchy(context, this) {
            +MediaControlsSwitchPreference(mediaControlsStore)
            +MediaControlsLockscreenSwitchPreference()
            if (Flags.deviceSuggestionsPreference()) {
                +SuggestionsPreference()
            }
        }

    override fun getSummary(context: Context): CharSequence? =
+45 −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.sound

import android.content.Context
import com.android.settings.R
import com.android.settingslib.metadata.PreferenceAvailabilityProvider
import com.android.settingslib.metadata.PreferenceMetadata
import com.android.settingslib.metadata.PreferenceSummaryProvider

/** Preference for media device suggestions. */
class SuggestionsPreference() :
    PreferenceMetadata, PreferenceSummaryProvider, PreferenceAvailabilityProvider {

    override val key
        get() = KEY

    override val title
        get() = R.string.media_controls_suggestions_title

    override fun intent(context: Context) = SuggestionsPreferenceUtils.getSuggestionIntent(context)

    override fun isAvailable(context: Context) = intent(context) != null

    override fun getSummary(context: Context) =
        SuggestionsPreferenceUtils.getSuggestionDescription(context)

    companion object {
        const val KEY = "media_suggestions"
    }
}
+55 −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.sound

import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager
import android.graphics.Typeface
import android.provider.Settings
import android.text.SpannableString
import android.text.SpannableStringBuilder
import android.text.Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
import android.text.style.ForegroundColorSpan
import android.text.style.StyleSpan
import com.android.settingslib.Utils

/** Utilities for populating the suggestion preference content. */
object SuggestionsPreferenceUtils {
    private val SUGGESTION_PROVIDER_TARGET = "media_device_suggestions_target"
    private val SUGGESTION_PROVIDER_DESCRIPTION = "media_device_suggestions_description"

    fun getSuggestionIntent(context: Context): Intent? {
        val targetAction =
            Settings.Secure.getString(context.contentResolver, SUGGESTION_PROVIDER_TARGET)
              ?: return null
        val intent = Intent(targetAction)
        val activityInfo =
            intent.resolveActivityInfo(context.packageManager, PackageManager.MATCH_ALL)
                ?: return null
        if (activityInfo.applicationInfo?.isSystemApp != true) {
            return null
        }
        return intent
    }

    fun getSuggestionDescription(context: Context) =
        Settings.Secure.getString(
            context.contentResolver,
            SUGGESTION_PROVIDER_DESCRIPTION
        )
}