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

Commit 438931ab authored by Android Build Merger (Role)'s avatar Android Build Merger (Role) Committed by Android (Google) Code Review
Browse files

Merge "Merge "Treat apps that use channels as O apps" into oc-dev am: b0744b82 am: 65c95aab"

parents ec3ca111 036bf8e1
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -2869,7 +2869,8 @@ public class NotificationManagerService extends SystemService {
                                adjustedSbn.getUser(), GroupHelper.AUTOGROUP_KEY,
                                System.currentTimeMillis());
                summaryRecord = new NotificationRecord(getContext(), summarySbn,
                        notificationRecord.getChannel());
                        notificationRecord.getChannel(), mRankingHelper.supportsChannels(
                                summarySbn.getPackageName(), summarySbn.getUid()));
                summaries.put(pkg, summarySbn.getKey());
            }
        }
@@ -3210,7 +3211,8 @@ public class NotificationManagerService extends SystemService {
        final StatusBarNotification n = new StatusBarNotification(
                pkg, opPkg, id, tag, notificationUid, callingPid, notification,
                user, null, System.currentTimeMillis());
        final NotificationRecord r = new NotificationRecord(getContext(), n, channel);
        final NotificationRecord r = new NotificationRecord(getContext(), n, channel,
                mRankingHelper.supportsChannels(pkg, notificationUid));

        if (!checkDisqualifyingFeatures(userId, notificationUid, id,tag, r)) {
            return;
+9 −25
Original line number Diff line number Diff line
@@ -115,7 +115,7 @@ public final class NotificationRecord {
    private int mSuppressedVisualEffects = 0;
    private String mUserExplanation;
    private String mPeopleExplanation;
    private boolean mPreChannelsNotification = true;
    private boolean mSupportsChannels = false;
    private Uri mSound;
    private long[] mVibration;
    private AudioAttributes mAttributes;
@@ -128,7 +128,7 @@ public final class NotificationRecord {

    @VisibleForTesting
    public NotificationRecord(Context context, StatusBarNotification sbn,
            NotificationChannel channel)
            NotificationChannel channel, boolean supportsChannels)
    {
        this.sbn = sbn;
        mOriginalFlags = sbn.getNotification().flags;
@@ -138,7 +138,7 @@ public final class NotificationRecord {
        mContext = context;
        stats = new NotificationUsageStats.SingleNotificationStats();
        mChannel = channel;
        mPreChannelsNotification = isPreChannelsNotification();
        mSupportsChannels = supportsChannels;
        mSound = calculateSound();
        mVibration = calculateVibration();
        mAttributes = calculateAttributes();
@@ -146,27 +146,11 @@ public final class NotificationRecord {
        mLight = calculateLights();
    }

    private boolean isPreChannelsNotification() {
        try {
            if (NotificationChannel.DEFAULT_CHANNEL_ID.equals(getChannel().getId())) {
                  final ApplicationInfo applicationInfo =
                        mContext.getPackageManager().getApplicationInfoAsUser(sbn.getPackageName(),
                                0, UserHandle.getUserId(sbn.getUid()));
                if (applicationInfo.targetSdkVersion <= Build.VERSION_CODES.N_MR1) {
                    return true;
                }
            }
        } catch (NameNotFoundException e) {
            Slog.e(TAG, "Can't find package", e);
        }
        return false;
    }

    private Uri calculateSound() {
        final Notification n = sbn.getNotification();

        Uri sound = mChannel.getSound();
        if (mPreChannelsNotification && (getChannel().getUserLockedFields()
        if (!mSupportsChannels && (getChannel().getUserLockedFields()
                & NotificationChannel.USER_LOCKED_SOUND) == 0) {

            final boolean useDefaultSound = (n.defaults & Notification.DEFAULT_SOUND) != 0;
@@ -191,7 +175,7 @@ public final class NotificationRecord {
                : defaultLightColor;
        Light light = getChannel().shouldShowLights() ? new Light(channelLightColor,
                defaultLightOn, defaultLightOff) : null;
        if (mPreChannelsNotification
        if (!mSupportsChannels
                && (getChannel().getUserLockedFields()
                & NotificationChannel.USER_LOCKED_LIGHTS) == 0) {
            final Notification notification = sbn.getNotification();
@@ -222,7 +206,7 @@ public final class NotificationRecord {
        } else {
            vibration = null;
        }
        if (mPreChannelsNotification
        if (!mSupportsChannels
                && (getChannel().getUserLockedFields()
                & NotificationChannel.USER_LOCKED_VIBRATION) == 0) {
            final Notification notification = sbn.getNotification();
@@ -244,7 +228,7 @@ public final class NotificationRecord {
            attributes = Notification.AUDIO_ATTRIBUTES_DEFAULT;
        }

        if (mPreChannelsNotification
        if (!mSupportsChannels
                && (getChannel().getUserLockedFields()
                & NotificationChannel.USER_LOCKED_SOUND) == 0) {
            if (n.audioAttributes != null) {
@@ -293,7 +277,7 @@ public final class NotificationRecord {
        stats.requestedImportance = requestedImportance;
        stats.isNoisy = mSound != null || mVibration != null;

        if (mPreChannelsNotification
        if (!mSupportsChannels
                && (importance == IMPORTANCE_UNSPECIFIED
                || (getChannel().getUserLockedFields()
                & NotificationChannel.USER_LOCKED_IMPORTANCE) == 0)) {
@@ -460,7 +444,7 @@ public final class NotificationRecord {
        pw.println(prefix + "mVisibleSinceMs=" + mVisibleSinceMs);
        pw.println(prefix + "mUpdateTimeMs=" + mUpdateTimeMs);
        pw.println(prefix + "mSuppressedVisualEffects= " + mSuppressedVisualEffects);
        if (mPreChannelsNotification) {
        if (!mSupportsChannels) {
            pw.println(prefix + String.format("defaults=0x%08x flags=0x%08x",
                    notification.defaults, notification.flags));
            pw.println(prefix + "n.sound=" + notification.sound);
+2 −0
Original line number Diff line number Diff line
@@ -42,4 +42,6 @@ public interface RankingConfig {
    void permanentlyDeleteNotificationChannel(String pkg, int uid, String channelId);
    void permanentlyDeleteNotificationChannels(String pkg, int uid);
    ParceledListSlice<NotificationChannel> getNotificationChannels(String pkg, int uid, boolean includeDeleted);

    boolean supportsChannels(String pkg, int uid);
}
+39 −8
Original line number Diff line number Diff line
@@ -273,8 +273,14 @@ public class RankingHelper implements RankingConfig {
    }

    private boolean shouldHaveDefaultChannel(Record r) throws NameNotFoundException {
        if (supportsChannels(r)) {
            return false;
        }

        final int userId = UserHandle.getUserId(r.uid);
        final ApplicationInfo applicationInfo = mPm.getApplicationInfoAsUser(r.pkg, 0, userId);
        final ApplicationInfo applicationInfo = mPm.getApplicationInfoAsUser(r.pkg,
                PackageManager.MATCH_DIRECT_BOOT_AWARE | PackageManager.MATCH_DIRECT_BOOT_UNAWARE,
                userId);
        if (applicationInfo.targetSdkVersion > Build.VERSION_CODES.N_MR1) {
            // O apps should not have the default channel.
            return false;
@@ -499,6 +505,31 @@ public class RankingHelper implements RankingConfig {
        return getOrCreateRecord(pkg, uid).visibility;
    }

    @Override
    public boolean supportsChannels(String pkg, int uid) {
        Record r = getOrCreateRecord(pkg, uid);

        if (r == null) {
            return false;
        }

        if (r.channels.size() == 1
                && r.channels.containsKey(NotificationChannel.DEFAULT_CHANNEL_ID)) {
            return false;
        }

        return true;
    }

    private boolean supportsChannels(Record r) {
        if (r.channels.size() == 1
                && r.channels.containsKey(NotificationChannel.DEFAULT_CHANNEL_ID)) {
            return false;
        }

        return (r.channels.size() > 0);
    }

    @Override
    public void createNotificationChannelGroup(String pkg, int uid, NotificationChannelGroup group,
            boolean fromTargetApp) {
@@ -571,6 +602,10 @@ public class RankingHelper implements RankingConfig {
        r.channels.put(channel.getId(), channel);
        MetricsLogger.action(getChannelLog(channel, pkg).setType(
                MetricsProto.MetricsEvent.TYPE_OPEN));

        // Remove Default Channel.
        r.channels.remove(NotificationChannel.DEFAULT_CHANNEL_ID);

        updateConfig();
    }

@@ -667,13 +702,7 @@ public class RankingHelper implements RankingConfig {
        if (r == null) {
            return;
        }
        int N = r.channels.size() - 1;
        for (int i = N; i >= 0; i--) {
            String key = r.channels.keyAt(i);
            if (!NotificationChannel.DEFAULT_CHANNEL_ID.equals(key)) {
                r.channels.remove(key);
            }
        }
        r.channels.clear();
        updateConfig();
    }

@@ -1025,6 +1054,8 @@ public class RankingHelper implements RankingConfig {
                final int uid = uidList[i];
                synchronized (mRecords) {
                    mRecords.remove(recordKey(pkg, uid));
                    // reset to default settings and re-add misc channel for pre-O apps
                    getOrCreateRecord(pkg, uid);
                }
                mRestoredWithoutUids.remove(pkg);
                updated = true;
+1 −1
Original line number Diff line number Diff line
@@ -69,7 +69,7 @@ public class BadgeExtractorTest {
        Notification n = builder.build();
        StatusBarNotification sbn = new StatusBarNotification(mPkg, mPkg, mId, mTag, mUid,
                mPid, n, mUser, null, System.currentTimeMillis());
        NotificationRecord r = new NotificationRecord(getContext(), sbn, channel);
        NotificationRecord r = new NotificationRecord(getContext(), sbn, channel, true);
        return r;
    }

Loading