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

Commit e6fb44f9 authored by Julia Reynolds's avatar Julia Reynolds Committed by android-build-merger
Browse files

Merge "Only tag foreground notifications" into pi-dev

am: 59831cbe

Change-Id: Ia986859e678cdb7bd58664dbb4eaeb1b9260b423
parents cf46c7d6 59831cbe
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -73,7 +73,7 @@ public interface ForegroundServiceController {
    void onAppOpChanged(int code, int uid, String packageName, boolean active);

    /**
     * Gets active app ops for this user and package.
     * Gets active app ops for this user and package
     */
    @Nullable ArraySet<Integer> getAppOps(int userId, String packageName);
}
+1 −1
Original line number Diff line number Diff line
@@ -62,7 +62,7 @@ public class AppOpsListener implements AppOpsManager.OnOpActiveChangedListener {
    public void onOpActiveChanged(int code, int uid, String packageName, boolean active) {
        mFsc.onAppOpChanged(code, uid, packageName, active);
        mPresenter.getHandler().post(() -> {
          mEntryManager.updateNotificationsForAppOps(code, uid, packageName, active);
          mEntryManager.updateNotificationsForAppOp(code, uid, packageName, active);
        });
    }
}
+3 −16
Original line number Diff line number Diff line
@@ -383,8 +383,6 @@ public class NotificationData {
        }
        mGroupManager.onEntryAdded(entry);

        updateAppOps(entry);

        updateRankingAndSort(mRankingMap);
    }

@@ -403,25 +401,14 @@ public class NotificationData {
        updateRankingAndSort(ranking);
    }

    private void updateAppOps(Entry entry) {
        final int uid = entry.notification.getUid();
        final String pkg = entry.notification.getPackageName();
        ArraySet<Integer> activeOps = mFsc.getAppOps(entry.notification.getUserId(), pkg);
        if (activeOps != null) {
            int N = activeOps.size();
            for (int i = 0; i < N; i++) {
                updateAppOp(activeOps.valueAt(i), uid, pkg, true);
            }
        }
    }

    public void updateAppOp(int appOp, int uid, String pkg, boolean showIcon) {
    public void updateAppOp(int appOp, int uid, String pkg, String key, boolean showIcon) {
        synchronized (mEntries) {
            final int N = mEntries.size();
            for (int i = 0; i < N; i++) {
                Entry entry = mEntries.valueAt(i);
                if (uid == entry.notification.getUid()
                    && pkg.equals(entry.notification.getPackageName())) {
                        && pkg.equals(entry.notification.getPackageName())
                        && key.equals(entry.key)) {
                    if (showIcon) {
                        entry.mActiveAppOps.add(appOp);
                    } else {
+20 −4
Original line number Diff line number Diff line
@@ -43,6 +43,7 @@ import android.util.Log;
import android.view.View;
import android.view.ViewGroup;

import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.logging.MetricsLogger;
import com.android.internal.statusbar.IStatusBarService;
import com.android.internal.util.NotificationMessagingUtil;
@@ -665,6 +666,7 @@ public class NotificationEntryManager implements Dumpable, NotificationInflater.
        }
        // Add the expanded view and icon.
        mNotificationData.add(entry);
        tagForeground(entry.notification);
        updateNotifications();
    }

@@ -726,6 +728,19 @@ public class NotificationEntryManager implements Dumpable, NotificationInflater.
        mPendingNotifications.put(key, shadeEntry);
    }

    @VisibleForTesting
    protected void tagForeground(StatusBarNotification notification) {
        ArraySet<Integer> activeOps = mForegroundServiceController.getAppOps(
                notification.getUserId(), notification.getPackageName());
        if (activeOps != null) {
            int N = activeOps.size();
            for (int i = 0; i < N; i++) {
                updateNotificationsForAppOp(activeOps.valueAt(i), notification.getUid(),
                        notification.getPackageName(), true);
            }
        }
    }

    @Override
    public void addNotification(StatusBarNotification notification,
            NotificationListenerService.RankingMap ranking) {
@@ -736,10 +751,11 @@ public class NotificationEntryManager implements Dumpable, NotificationInflater.
        }
    }

    public void updateNotificationsForAppOps(int appOp, int uid, String pkg, boolean showIcon) {
        if (mForegroundServiceController.getStandardLayoutKey(
                UserHandle.getUserId(uid), pkg) != null) {
            mNotificationData.updateAppOp(appOp, uid, pkg, showIcon);
    public void updateNotificationsForAppOp(int appOp, int uid, String pkg, boolean showIcon) {
        String foregroundKey = mForegroundServiceController.getStandardLayoutKey(
                UserHandle.getUserId(uid), pkg);
        if (foregroundKey != null) {
            mNotificationData.updateAppOp(appOp, uid, pkg, foregroundKey, showIcon);
            updateNotifications();
        }
    }
+1 −1
Original line number Diff line number Diff line
@@ -86,7 +86,7 @@ public class AppOpsListenerTest extends SysuiTestCase {
        mListener.onOpActiveChanged(
                AppOpsManager.OP_RECORD_AUDIO, TEST_UID, TEST_PACKAGE_NAME, true);
        waitForIdleSync(mHandler);
        verify(mEntryManager, times(1)).updateNotificationsForAppOps(
        verify(mEntryManager, times(1)).updateNotificationsForAppOp(
                AppOpsManager.OP_RECORD_AUDIO, TEST_UID, TEST_PACKAGE_NAME, true);
    }

Loading