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

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

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

am: 65c95aab

Change-Id: I7c71490236b10229b9592e57511a8f7e4679be49
parents 4078f993 65c95aab
Loading
Loading
Loading
Loading
+4 −2
Original line number Original line Diff line number Diff line
@@ -2869,7 +2869,8 @@ public class NotificationManagerService extends SystemService {
                                adjustedSbn.getUser(), GroupHelper.AUTOGROUP_KEY,
                                adjustedSbn.getUser(), GroupHelper.AUTOGROUP_KEY,
                                System.currentTimeMillis());
                                System.currentTimeMillis());
                summaryRecord = new NotificationRecord(getContext(), summarySbn,
                summaryRecord = new NotificationRecord(getContext(), summarySbn,
                        notificationRecord.getChannel());
                        notificationRecord.getChannel(), mRankingHelper.supportsChannels(
                                summarySbn.getPackageName(), summarySbn.getUid()));
                summaries.put(pkg, summarySbn.getKey());
                summaries.put(pkg, summarySbn.getKey());
            }
            }
        }
        }
@@ -3210,7 +3211,8 @@ public class NotificationManagerService extends SystemService {
        final StatusBarNotification n = new StatusBarNotification(
        final StatusBarNotification n = new StatusBarNotification(
                pkg, opPkg, id, tag, notificationUid, callingPid, notification,
                pkg, opPkg, id, tag, notificationUid, callingPid, notification,
                user, null, System.currentTimeMillis());
                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)) {
        if (!checkDisqualifyingFeatures(userId, notificationUid, id,tag, r)) {
            return;
            return;
+9 −25
Original line number Original line Diff line number Diff line
@@ -115,7 +115,7 @@ public final class NotificationRecord {
    private int mSuppressedVisualEffects = 0;
    private int mSuppressedVisualEffects = 0;
    private String mUserExplanation;
    private String mUserExplanation;
    private String mPeopleExplanation;
    private String mPeopleExplanation;
    private boolean mPreChannelsNotification = true;
    private boolean mSupportsChannels = false;
    private Uri mSound;
    private Uri mSound;
    private long[] mVibration;
    private long[] mVibration;
    private AudioAttributes mAttributes;
    private AudioAttributes mAttributes;
@@ -128,7 +128,7 @@ public final class NotificationRecord {


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


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


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


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


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

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


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

        final int userId = UserHandle.getUserId(r.uid);
        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) {
        if (applicationInfo.targetSdkVersion > Build.VERSION_CODES.N_MR1) {
            // O apps should not have the default channel.
            // O apps should not have the default channel.
            return false;
            return false;
@@ -499,6 +505,31 @@ public class RankingHelper implements RankingConfig {
        return getOrCreateRecord(pkg, uid).visibility;
        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
    @Override
    public void createNotificationChannelGroup(String pkg, int uid, NotificationChannelGroup group,
    public void createNotificationChannelGroup(String pkg, int uid, NotificationChannelGroup group,
            boolean fromTargetApp) {
            boolean fromTargetApp) {
@@ -571,6 +602,10 @@ public class RankingHelper implements RankingConfig {
        r.channels.put(channel.getId(), channel);
        r.channels.put(channel.getId(), channel);
        MetricsLogger.action(getChannelLog(channel, pkg).setType(
        MetricsLogger.action(getChannelLog(channel, pkg).setType(
                MetricsProto.MetricsEvent.TYPE_OPEN));
                MetricsProto.MetricsEvent.TYPE_OPEN));

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

        updateConfig();
        updateConfig();
    }
    }


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


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


Loading