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

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

Merge "Revoke NLS permission if the last association has been removed" into tm-dev

parents bf97b0b0 c3c33a70
Loading
Loading
Loading
Loading
+21 −0
Original line number Diff line number Diff line
@@ -60,10 +60,12 @@ import android.companion.ICompanionDeviceManager;
import android.companion.IOnAssociationsChangedListener;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManagerInternal;
import android.content.pm.ResolveInfo;
import android.content.pm.UserInfo;
import android.net.MacAddress;
import android.net.NetworkPolicyManager;
@@ -80,6 +82,7 @@ import android.os.ServiceManager;
import android.os.SystemProperties;
import android.os.UserHandle;
import android.os.UserManager;
import android.service.notification.NotificationListenerService;
import android.util.ArraySet;
import android.util.ExceptionUtils;
import android.util.Log;
@@ -336,6 +339,24 @@ public class CompanionDeviceManagerService extends SystemService {
        final String packageName = association.getPackageName();

        if (changeType == AssociationStore.CHANGE_TYPE_REMOVED) {
            // Revoke NLS if the last association has been removed for the package
            Binder.withCleanCallingIdentity(() -> {
                if (mAssociationStore.getAssociationsForPackage(userId, packageName).isEmpty()) {
                    NotificationManager nm = getContext().getSystemService(
                        NotificationManager.class);
                    Intent nlsIntent = new Intent(
                            NotificationListenerService.SERVICE_INTERFACE);
                    List<ResolveInfo> matchedServiceList = getContext().getPackageManager()
                            .queryIntentServicesAsUser(nlsIntent, /* flags */ 0, userId);
                    for (ResolveInfo service : matchedServiceList) {
                        if (service.getComponentInfo().getComponentName().getPackageName()
                                .equals(packageName)) {
                            nm.setNotificationListenerAccessGranted(
                                    service.getComponentInfo().getComponentName(), false);
                        }
                    }
                }
            });
            markIdAsPreviouslyUsedForPackage(id, userId, packageName);
        }