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

Commit 3ec6c76d authored by Steven Lee's avatar Steven Lee Committed by Android (Google) Code Review
Browse files

Merge changes from topics "Add_TakeBugreportWithPersistentConsent_Logic",...

Merge changes from topics "Add_TakeBugreportWithPersistentConsent_Logic", "Add_TakeBugreportWithPersistentConsent_Settings"

* changes:
  Make TogglePermissionAppListModel, AppInfoPage and Footer could support using AnnotatedString for the permission description.
  Implement consentless bugreport mechanism
parents ffd7f45e 8071dcee
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -10047,6 +10047,7 @@ package android.os {
    method @RequiresPermission(allOf={android.Manifest.permission.DUMP, android.Manifest.permission.PACKAGE_USAGE_STATS}) public void reportIncident(android.os.IncidentReportArgs);
    method @RequiresPermission(allOf={android.Manifest.permission.DUMP, android.Manifest.permission.PACKAGE_USAGE_STATS}) public void reportIncident(android.os.IncidentReportArgs);
    method @RequiresPermission("android.permission.REQUEST_INCIDENT_REPORT_APPROVAL") public void requestAuthorization(int, String, int, android.os.IncidentManager.AuthListener);
    method @RequiresPermission("android.permission.REQUEST_INCIDENT_REPORT_APPROVAL") public void requestAuthorization(int, String, int, android.os.IncidentManager.AuthListener);
    method public void unregisterSection(int);
    method public void unregisterSection(int);
    field public static final int FLAG_ALLOW_CONSENTLESS_BUGREPORT = 2; // 0x2
    field public static final int FLAG_CONFIRMATION_DIALOG = 1; // 0x1
    field public static final int FLAG_CONFIRMATION_DIALOG = 1; // 0x1
    field public static final int PRIVACY_POLICY_AUTO = 200; // 0xc8
    field public static final int PRIVACY_POLICY_AUTO = 200; // 0xc8
    field public static final int PRIVACY_POLICY_EXPLICIT = 100; // 0x64
    field public static final int PRIVACY_POLICY_EXPLICIT = 100; // 0x64
+15 −1
Original line number Original line Diff line number Diff line
@@ -118,6 +118,19 @@ public class IncidentManager {
     */
     */
    public static final int FLAG_CONFIRMATION_DIALOG = 0x1;
    public static final int FLAG_CONFIRMATION_DIALOG = 0x1;


    /**
     * Flag marking whether corresponding pending report allows consentless bugreport.
     */
    public static final int FLAG_ALLOW_CONSENTLESS_BUGREPORT = 0x2;

    /** @hide */
    @IntDef(flag = true, prefix = { "FLAG_" }, value = {
            FLAG_CONFIRMATION_DIALOG,
            FLAG_ALLOW_CONSENTLESS_BUGREPORT,
    })
    @Retention(RetentionPolicy.SOURCE)
    public @interface PendingReportFlags {}

    /**
    /**
     * Flag marking fields and incident reports than can be taken
     * Flag marking fields and incident reports than can be taken
     * off the device only via adb.
     * off the device only via adb.
@@ -220,8 +233,9 @@ public class IncidentManager {
        /**
        /**
         * Get the flags requested for this pending report.
         * Get the flags requested for this pending report.
         *
         *
         * @see #FLAG_CONFIRMATION_DIALOG
         * @see PendingReportFlags
         */
         */
        @PendingReportFlags
        public int getFlags() {
        public int getFlags() {
            return mFlags;
            return mFlags;
        }
        }
+120 −0
Original line number Original line Diff line number Diff line
/*
 * Copyright (C) 2023 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.settingslib.spa.framework.util

import android.content.res.Resources
import android.graphics.Typeface
import android.text.Spanned
import android.text.style.StyleSpan
import android.text.style.URLSpan
import androidx.annotation.StringRes
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.SpanStyle
import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.text.font.FontStyle
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.Density

const val URLSPAN_TAG = "URLSPAN_TAG"

@Composable
fun annotatedStringResource(@StringRes id: Int, urlSpanColor: Color): AnnotatedString {
    LocalConfiguration.current
    val resources = LocalContext.current.resources
    val density = LocalDensity.current
    return remember(id) {
        val text = resources.getText(id)
        spannableStringToAnnotatedString(text, density, urlSpanColor)
    }
}

private fun spannableStringToAnnotatedString(text: CharSequence, density: Density, urlSpanColor: Color): AnnotatedString {
    return if (text is Spanned) {
        with(density) {
            buildAnnotatedString {
                append((text.toString()))
                text.getSpans(0, text.length, Any::class.java).forEach {
                    val start = text.getSpanStart(it)
                    val end = text.getSpanEnd(it)
                    when (it) {
                        is StyleSpan ->
                            when (it.style) {
                                Typeface.NORMAL -> addStyle(
                                        SpanStyle(
                                                fontWeight = FontWeight.Normal,
                                                fontStyle = FontStyle.Normal
                                        ),
                                        start,
                                        end
                                )
                                Typeface.BOLD -> addStyle(
                                        SpanStyle(
                                                fontWeight = FontWeight.Bold,
                                                fontStyle = FontStyle.Normal
                                        ),
                                        start,
                                        end
                                )
                                Typeface.ITALIC -> addStyle(
                                        SpanStyle(
                                                fontWeight = FontWeight.Normal,
                                                fontStyle = FontStyle.Italic
                                        ),
                                        start,
                                        end
                                )
                                Typeface.BOLD_ITALIC -> addStyle(
                                        SpanStyle(
                                                fontWeight = FontWeight.Bold,
                                                fontStyle = FontStyle.Italic
                                        ),
                                        start,
                                        end
                                )
                            }
                        is URLSpan -> {
                            addStyle(
                                    SpanStyle(
                                            color = urlSpanColor,
                                    ),
                                    start,
                                    end
                            )
                            if (!it.url.isNullOrEmpty()) {
                                addStringAnnotation(
                                        URLSPAN_TAG,
                                        it.url,
                                        start,
                                        end
                                )
                            }
                        }
                        else -> addStyle(SpanStyle(), start, end)
                    }
                }
            }
        }
    } else {
        AnnotatedString(text.toString())
    }
}
+12 −5
Original line number Original line Diff line number Diff line
@@ -34,6 +34,13 @@ import com.android.settingslib.spa.framework.theme.SettingsTheme
@Composable
@Composable
fun Footer(footerText: String) {
fun Footer(footerText: String) {
    if (footerText.isEmpty()) return
    if (footerText.isEmpty()) return
    Footer {
        SettingsBody(footerText)
    }
}

@Composable
fun Footer(content: @Composable () -> Unit) {
    Column(Modifier.padding(SettingsDimension.itemPadding)) {
    Column(Modifier.padding(SettingsDimension.itemPadding)) {
        Icon(
        Icon(
                imageVector = Icons.Outlined.Info,
                imageVector = Icons.Outlined.Info,
@@ -42,7 +49,7 @@ fun Footer(footerText: String) {
                tint = MaterialTheme.colorScheme.onSurfaceVariant,
                tint = MaterialTheme.colorScheme.onSurfaceVariant,
        )
        )
        Spacer(modifier = Modifier.height(SettingsDimension.itemPaddingVertical))
        Spacer(modifier = Modifier.height(SettingsDimension.itemPaddingVertical))
        SettingsBody(footerText)
        content()
    }
    }
}
}


+2 −0
Original line number Original line Diff line number Diff line
@@ -25,4 +25,6 @@
        =1    {There is one song found in {place}.}
        =1    {There is one song found in {place}.}
        other {There are # songs found in {place}.}
        other {There are # songs found in {place}.}
    }</string>
    }</string>

    <string name="test_annotated_string_resource">Annotated string with <b>bold</b> and <a href="https://www.google.com/">link</a>.</string>
</resources>
</resources>
Loading