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

Commit 86af40a0 authored by Michael Wright's avatar Michael Wright Committed by Automerger Merge Worker
Browse files

Merge "Revert^3 "Fix binder error when an app has many channels"" into tm-qpr-dev am: 0b75242b

parents 1aa76fe2 0b75242b
Loading
Loading
Loading
Loading
+13 −8
Original line number Diff line number Diff line
@@ -20,7 +20,6 @@ import android.annotation.SystemApi;
import android.annotation.TestApi;
import android.compat.annotation.UnsupportedAppUsage;
import android.content.Intent;
import android.content.pm.ParceledListSlice;
import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;
@@ -68,7 +67,7 @@ public final class NotificationChannelGroup implements Parcelable {
    private CharSequence mName;
    private String mDescription;
    private boolean mBlocked;
    private ParceledListSlice<NotificationChannel> mChannels;
    private List<NotificationChannel> mChannels = new ArrayList<>();
    // Bitwise representation of fields that have been changed by the user
    private int mUserLockedFields;

@@ -103,8 +102,7 @@ public final class NotificationChannelGroup implements Parcelable {
        } else {
            mDescription = null;
        }
        mChannels = in.readParcelable(
                NotificationChannelGroup.class.getClassLoader(), ParceledListSlice.class);
        in.readParcelableList(mChannels, NotificationChannel.class.getClassLoader(), android.app.NotificationChannel.class);
        mBlocked = in.readBoolean();
        mUserLockedFields = in.readInt();
    }
@@ -131,7 +129,7 @@ public final class NotificationChannelGroup implements Parcelable {
        } else {
            dest.writeByte((byte) 0);
        }
        dest.writeParcelable(mChannels, flags);
        dest.writeParcelableList(mChannels, flags);
        dest.writeBoolean(mBlocked);
        dest.writeInt(mUserLockedFields);
    }
@@ -161,7 +159,7 @@ public final class NotificationChannelGroup implements Parcelable {
     * Returns the list of channels that belong to this group
     */
    public List<NotificationChannel> getChannels() {
        return mChannels == null ? new ArrayList<>() : mChannels.getList();
        return mChannels;
    }

    /**
@@ -192,11 +190,18 @@ public final class NotificationChannelGroup implements Parcelable {
        mBlocked = blocked;
    }

    /**
     * @hide
     */
    public void addChannel(NotificationChannel channel) {
        mChannels.add(channel);
    }

    /**
     * @hide
     */
    public void setChannels(List<NotificationChannel> channels) {
        mChannels = new ParceledListSlice<>(channels);
        mChannels = channels;
    }

    /**
@@ -331,7 +336,7 @@ public final class NotificationChannelGroup implements Parcelable {
        proto.write(NotificationChannelGroupProto.NAME, mName.toString());
        proto.write(NotificationChannelGroupProto.DESCRIPTION, mDescription);
        proto.write(NotificationChannelGroupProto.IS_BLOCKED, mBlocked);
        for (NotificationChannel channel : mChannels.getList()) {
        for (NotificationChannel channel : mChannels) {
            channel.dumpDebug(proto, NotificationChannelGroupProto.CHANNELS);
        }
        proto.end(token);
+1 −1
Original line number Diff line number Diff line
@@ -98,7 +98,7 @@ class ChannelEditorDialogControllerTest : SysuiTestCase() {

    @Test
    fun testPrepareDialogForApp_onlyDefaultChannel() {
        group.channels = listOf(channelDefault)
        group.addChannel(channelDefault)

        controller.prepareDialogForApp(TEST_APP_NAME, TEST_PACKAGE_NAME, TEST_UID,
                setOf(channelDefault), appIcon, clickListener)
+23 −32
Original line number Diff line number Diff line
@@ -86,7 +86,6 @@ import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
@@ -1328,17 +1327,16 @@ public class PreferencesHelper implements RankingConfig {
                return null;
            }
            NotificationChannelGroup group = r.groups.get(groupId).clone();
            ArrayList channels = new ArrayList();
            group.setChannels(new ArrayList<>());
            int N = r.channels.size();
            for (int i = 0; i < N; i++) {
                final NotificationChannel nc = r.channels.valueAt(i);
                if (includeDeleted || !nc.isDeleted()) {
                    if (groupId.equals(nc.getGroup())) {
                        channels.add(nc);
                        group.addChannel(nc);
                    }
                }
            }
            group.setChannels(channels);
            return group;
        }
    }
@@ -1351,10 +1349,7 @@ public class PreferencesHelper implements RankingConfig {
            if (r == null) {
                return null;
            }
            if (r.groups.get(groupId) != null) {
                 return r.groups.get(groupId).clone();
            }
            return null;
            return r.groups.get(groupId);
        }
    }

@@ -1362,48 +1357,44 @@ public class PreferencesHelper implements RankingConfig {
    public ParceledListSlice<NotificationChannelGroup> getNotificationChannelGroups(String pkg,
            int uid, boolean includeDeleted, boolean includeNonGrouped, boolean includeEmpty) {
        Objects.requireNonNull(pkg);
        List<NotificationChannelGroup> groups = new ArrayList<>();
        Map<String, NotificationChannelGroup> groups = new ArrayMap<>();
        synchronized (mPackagePreferences) {
            PackagePreferences r = getPackagePreferencesLocked(pkg, uid);
            if (r == null) {
                return ParceledListSlice.emptyList();
            }
            Map<String, ArrayList<NotificationChannel>> groupedChannels = new HashMap();
            NotificationChannelGroup nonGrouped = new NotificationChannelGroup(null, null);
            int N = r.channels.size();
            for (int i = 0; i < N; i++) {
                final NotificationChannel nc = r.channels.valueAt(i);
                if (includeDeleted || !nc.isDeleted()) {
                    if (nc.getGroup() != null) {
                        if (r.groups.get(nc.getGroup()) != null) {
                            ArrayList<NotificationChannel> channels = groupedChannels.getOrDefault(
                                    nc.getGroup(), new ArrayList<>());
                            channels.add(nc);
                            groupedChannels.put(nc.getGroup(), channels);
                            NotificationChannelGroup ncg = groups.get(nc.getGroup());
                            if (ncg == null) {
                                ncg = r.groups.get(nc.getGroup()).clone();
                                ncg.setChannels(new ArrayList<>());
                                groups.put(nc.getGroup(), ncg);

                            }
                            ncg.addChannel(nc);
                        }
                    } else {
                        ArrayList<NotificationChannel> channels = groupedChannels.getOrDefault(
                            null, new ArrayList<>());
                        channels.add(nc);
                        groupedChannels.put(null, channels);
                        nonGrouped.addChannel(nc);
                    }
                }
            }
            if (includeNonGrouped && nonGrouped.getChannels().size() > 0) {
                groups.put(null, nonGrouped);
            }
            if (includeEmpty) {
                for (NotificationChannelGroup group : r.groups.values()) {
                ArrayList<NotificationChannel> channels =
                        groupedChannels.getOrDefault(group.getId(), new ArrayList<>());
                if (includeEmpty || !channels.isEmpty()) {
                    NotificationChannelGroup clone = group.clone();
                    clone.setChannels(channels);
                    groups.add(clone);
                    if (!groups.containsKey(group.getId())) {
                        groups.put(group.getId(), group);
                    }
                }

            if (includeNonGrouped && groupedChannels.containsKey(null)) {
                NotificationChannelGroup nonGrouped = new NotificationChannelGroup(null, null);
                nonGrouped.setChannels(groupedChannels.get(null));
                groups.add(nonGrouped);
            }
            return new ParceledListSlice<>(groups);
            return new ParceledListSlice<>(new ArrayList<>(groups.values()));
        }
    }

+0 −30
Original line number Diff line number Diff line
@@ -93,7 +93,6 @@ import android.net.Uri;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.os.Parcel;
import android.os.RemoteCallback;
import android.os.RemoteException;
import android.os.UserHandle;
@@ -2447,35 +2446,6 @@ public class PreferencesHelperTest extends UiServiceTestCase {
                mLogger.get(6).event);  // Final log is the deletion of the channel.
    }

    @Test
    public void testGetNotificationChannelGroup() throws Exception {
        NotificationChannelGroup notDeleted = new NotificationChannelGroup("not", "deleted");
        NotificationChannel base =
                new NotificationChannel("not deleted", "belongs to notDeleted", IMPORTANCE_DEFAULT);
        base.setGroup("not");
        NotificationChannel convo =
                new NotificationChannel("convo", "belongs to notDeleted", IMPORTANCE_DEFAULT);
        convo.setGroup("not");
        convo.setConversationId("not deleted", "banana");

        mHelper.createNotificationChannelGroup(PKG_N_MR1, UID_N_MR1, notDeleted, true);
        mHelper.createNotificationChannel(PKG_N_MR1, UID_N_MR1, base, true, false);
        mHelper.createNotificationChannel(PKG_N_MR1, UID_N_MR1, convo, true, false);
        mHelper.createNotificationChannelGroup(PKG_N_MR1, UID_N_MR1, notDeleted, true);

        NotificationChannelGroup g
                = mHelper.getNotificationChannelGroup(notDeleted.getId(), PKG_N_MR1, UID_N_MR1);
        Parcel parcel = Parcel.obtain();
        g.writeToParcel(parcel, 0);
        parcel.setDataPosition(0);

        NotificationChannelGroup g2
                = mHelper.getNotificationChannelGroup(notDeleted.getId(), PKG_N_MR1, UID_N_MR1);
        Parcel parcel2 = Parcel.obtain();
        g2.writeToParcel(parcel2, 0);
        parcel2.setDataPosition(0);
    }

    @Test
    public void testOnUserRemoved() throws Exception {
        int[] user0Uids = {98, 235, 16, 3782};