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

Commit 013fbe1b authored by Alison Cichowlas's avatar Alison Cichowlas
Browse files

Only show the promoted toggle if permission requested.

Update copy to match UXW guidance.

Flag: android.app.api_rich_ongoing_permission
Test: CTS tests in topic
Bug: 410619264
Change-Id: Ie485ab5734527b5a5954dad9ad252f194d7b2835
parent 2fd74269
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -9085,9 +9085,9 @@ Data usage charges may apply.</string>
    <!-- App Info > Notifications: Title for section controlling whether this app may show notifications in a promoted format [CHAR LIMIT=80] -->
    <string name="live_notifications">Live notifications</string>
    <!-- App Info > Notifications: Text on the switch to enable or disable an app from showing notifications in a live/promoted format [CHAR LIMIT=50] -->
    <string name="live_notifications_switch">Show live info</string>
    <string name="live_notifications_switch">Live updates</string>
    <!-- App Info > Notifications: Text accompanying the "Show live info" switch explaining the purpose of the setting -->
    <string name="live_notifications_desc">Pinned notifications display live info from apps, and always appear on the status bar and lock screen</string>
    <string name="live_notifications_desc">Display ongoing, time-sensitive notifications on the status bar and lock screen</string>
    <!-- Configure Notifications: Title for the notification bubbles option. [CHAR LIMIT=60] -->
    <string name="notification_bubbles_title">Bubbles</string>
+30 −1
Original line number Diff line number Diff line
@@ -15,8 +15,12 @@
 */
package com.android.settings.notification.app;

import android.Manifest;
import android.app.Flags;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.util.Log;

import androidx.annotation.NonNull;
import androidx.preference.Preference;
@@ -24,9 +28,11 @@ import androidx.preference.Preference;
import com.android.settings.notification.NotificationBackend;
import com.android.settingslib.RestrictedSwitchPreference;


public class PromotedNotificationsPreferenceController extends
        NotificationPreferenceController implements Preference.OnPreferenceChangeListener {
    protected static final String KEY_PROMOTED_SWITCH = "promoted_switch";
    private static final String TAG = "PromotedNotiPrefCon";

    public PromotedNotificationsPreferenceController(@NonNull Context context,
            @NonNull NotificationBackend backend) {
@@ -44,9 +50,32 @@ public class PromotedNotificationsPreferenceController extends
        if (!Flags.uiRichOngoing()) {
            return false;
        }
        return super.isAvailable();
        return isPermissionRequested() && super.isAvailable();
    }

    private boolean isPermissionRequested() {

        if (!Flags.apiRichOngoingPermission()) {
            return true;
        }

        try {
            PackageInfo packageInfo = mPm.getPackageInfo(
                    mAppRow.pkg, PackageManager.GET_PERMISSIONS);

            for (String requestedPermission : packageInfo.requestedPermissions) {
                if (Manifest.permission.POST_PROMOTED_NOTIFICATIONS.equals(requestedPermission)) {
                    return true;
                }
            }
        } catch (PackageManager.NameNotFoundException e) {
            Log.e(TAG, "isPermissionRequested failed", e);
        }

        return false;
    }


    @Override
    boolean isIncludedInFilter() {
        // not a channel-specific preference; only at the app level