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

Commit 17879b8c authored by Evan Chen's avatar Evan Chen Committed by Android (Google) Code Review
Browse files

Merge "Fix NullPointerException for requestNotification" into main

parents 1ff72183 84433db8
Loading
Loading
Loading
Loading
+6 −4
Original line number Diff line number Diff line
@@ -720,12 +720,14 @@ public final class CompanionDeviceManager {
            return;
        }
        try {
            IntentSender intentSender = mService
                    .requestNotificationAccess(component, mContext.getUserId())
                    .getIntentSender();
            if (intentSender == null) {
            PendingIntent pendingIntent = mService.requestNotificationAccess(
                    component, mContext.getUserId());

            if (pendingIntent == null) {
                return;
            }
            IntentSender intentSender = pendingIntent.getIntentSender();

            mContext.startIntentSender(intentSender, null, 0, 0, 0,
                    ActivityOptions.makeBasic().setPendingIntentBackgroundActivityStartMode(
                            ActivityOptions.MODE_BACKGROUND_ACTIVITY_START_ALLOWED).toBundle());
+16 −4
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.UserIdInt;
import android.app.AppOpsManager;
import android.app.ecm.EnhancedConfirmationManager;
import android.companion.CompanionDeviceService;
import android.content.ComponentName;
import android.content.Context;
@@ -41,6 +42,7 @@ import android.content.pm.ServiceInfo;
import android.content.pm.Signature;
import android.os.Binder;
import android.os.Process;
import android.permission.flags.Flags;
import android.util.Slog;

import com.android.internal.util.ArrayUtils;
@@ -227,9 +229,19 @@ public final class PackageUtils {
     */
    public static boolean isRestrictedSettingsAllowed(
            Context context, String packageName, int uid) {
        if (Flags.enhancedConfirmationModeApisEnabled()) {
            EnhancedConfirmationManager ecm = context.getSystemService(
                    EnhancedConfirmationManager.class);
            try {
                return !ecm.isRestricted(packageName, AppOpsManager.OPSTR_ACCESS_NOTIFICATIONS);
            } catch (PackageManager.NameNotFoundException e) {
                return true;
            }
        } else {
            final int mode = context.getSystemService(AppOpsManager.class).noteOpNoThrow(
                    AppOpsManager.OP_ACCESS_RESTRICTED_SETTINGS, uid,
                    packageName, /* attributionTag= */ null, /* message= */ null);
            return mode == AppOpsManager.MODE_ALLOWED;
        }
    }
}