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

Commit 84433db8 authored by Evan Chen's avatar Evan Chen
Browse files

Fix NullPointerException for requestNotification

Also use EnhancedConfirmationManager to detect if the package
is Restricted Settings Allowed instead in V.

Test: cts
Bug: 329718684
Change-Id: Ic503338e92927c78eb02085edfc8c7a909afaeb9
parent 723bced5
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;
        }
    }
}