Loading core/java/android/service/notification/NotificationRankingUpdate.java +101 −108 Original line number Diff line number Diff line Loading @@ -23,6 +23,7 @@ import android.os.Parcelable; import android.os.SharedMemory; import android.system.ErrnoException; import android.system.OsConstants; import android.util.Slog; import androidx.annotation.NonNull; import androidx.annotation.Nullable; Loading @@ -39,6 +40,7 @@ import java.util.List; */ @SuppressLint({"ParcelNotFinal", "ParcelCreator"}) public class NotificationRankingUpdate implements Parcelable { private static final String TAG = "NotificationRankingUpdate"; private final NotificationListenerService.RankingMap mRankingMap; // The ranking map is stored in shared memory when parceled, for sending across the binder. Loading @@ -57,7 +59,6 @@ public class NotificationRankingUpdate implements Parcelable { * @hide */ public NotificationRankingUpdate(Parcel in) { if (Flags.rankingUpdateAshmem()) { // Recover the ranking map from the SharedMemory and store it in mapParcel. final Parcel mapParcel = Parcel.obtain(); ByteBuffer buffer = null; Loading Loading @@ -88,8 +89,6 @@ public class NotificationRankingUpdate implements Parcelable { addSmartActionsFromBundleToRankingMap(smartActionsBundle); } catch (ErrnoException e) { // TODO(b/284297289): remove throw when associated flag is moved to droidfood, to // avoid crashes; change to Log.wtf. throw new RuntimeException(e); } finally { mapParcel.recycle(); Loading @@ -98,10 +97,6 @@ public class NotificationRankingUpdate implements Parcelable { mRankingMapFd.close(); } } } else { mRankingMap = in.readParcelable(getClass().getClassLoader(), android.service.notification.NotificationListenerService.RankingMap.class); } } /** Loading Loading @@ -169,7 +164,6 @@ public class NotificationRankingUpdate implements Parcelable { */ @Override public void writeToParcel(@NonNull Parcel out, int flags) { if (Flags.rankingUpdateAshmem()) { final Parcel mapParcel = Parcel.obtain(); ArrayList<NotificationListenerService.Ranking> marshalableRankings = new ArrayList<>(); Bundle smartActionsBundle = new Bundle(); Loading @@ -187,7 +181,7 @@ public class NotificationRankingUpdate implements Parcelable { // smart actions, and we don't want to needlessly store an empty list object, so we // check for null before storing. List<Notification.Action> smartActions = ranking.getSmartActions(); if (!smartActions.isEmpty()) { if (smartActions != null && !smartActions.isEmpty()) { smartActionsBundle.putParcelableList(key, smartActions); } Loading Loading @@ -225,11 +219,13 @@ public class NotificationRankingUpdate implements Parcelable { // Puts the SharedMemory object in the parcel. out.writeParcelable(mRankingMapFd, flags); // Writes the Parceled smartActions separately. if (smartActionsBundle.size() > 0) { out.writeBundle(smartActionsBundle); } else { out.writeBundle(null); } } catch (ErrnoException e) { // TODO(b/284297289): remove throw when associated flag is moved to droidfood, to // avoid crashes; change to Log.wtf. throw new RuntimeException(e); Slog.wtf(TAG, "Failed to write ranking map to shared memory", e); } finally { mapParcel.recycle(); // To prevent memory leaks, we can close the ranking map fd here. Loading @@ -239,9 +235,6 @@ public class NotificationRankingUpdate implements Parcelable { mRankingMapFd.close(); } } } else { out.writeParcelable(mRankingMap, flags); } } /** Loading core/java/android/service/notification/flags.aconfig +0 −7 Original line number Diff line number Diff line Loading @@ -2,13 +2,6 @@ package: "android.service.notification" container: "system" container: "system" flag { name: "ranking_update_ashmem" namespace: "systemui" description: "This flag controls moving ranking update contents into ashmem" bug: "249848655" } flag { name: "redact_sensitive_notifications_from_untrusted_listeners" is_exported: true Loading core/tests/coretests/src/android/service/notification/NotificationRankingUpdateTest.java +4 −32 Original line number Diff line number Diff line Loading @@ -44,6 +44,7 @@ import android.platform.test.flag.junit.SetFlagsRule; import android.testing.TestableContext; import androidx.test.InstrumentationRegistry; import androidx.test.ext.junit.runners.AndroidJUnit4; import androidx.test.filters.SmallTest; import org.junit.Assert; Loading @@ -51,13 +52,12 @@ import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; import java.util.ArrayList; import java.util.List; @SmallTest @RunWith(Parameterized.class) @RunWith(AndroidJUnit4.class) public class NotificationRankingUpdateTest { private static final String NOTIFICATION_CHANNEL_ID = "test_channel_id"; Loading @@ -68,15 +68,6 @@ public class NotificationRankingUpdateTest { @Rule public final SetFlagsRule mSetFlagsRule = new SetFlagsRule(); // TODO(b/284297289): remove this flag set once resolved. @Parameterized.Parameters(name = "rankingUpdateAshmem={0}") public static Boolean[] getRankingUpdateAshmem() { return new Boolean[] { true, false }; } @Parameterized.Parameter public boolean mRankingUpdateAshmem; @Rule public TestableContext mContext = spy(new TestableContext(InstrumentationRegistry.getContext(), null)); Loading Loading @@ -432,12 +423,6 @@ public class NotificationRankingUpdateTest { public void setUp() { mNotificationChannel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, "test channel", NotificationManager.IMPORTANCE_DEFAULT); if (mRankingUpdateAshmem) { mSetFlagsRule.enableFlags(Flags.FLAG_RANKING_UPDATE_ASHMEM); } else { mSetFlagsRule.disableFlags(Flags.FLAG_RANKING_UPDATE_ASHMEM); } } /** Loading Loading @@ -485,15 +470,11 @@ public class NotificationRankingUpdateTest { NotificationRankingUpdate nru = generateUpdate(getContext()); Parcel parcel = Parcel.obtain(); nru.writeToParcel(parcel, 0); if (Flags.rankingUpdateAshmem()) { assertTrue(nru.isFdNotNullAndClosed()); } parcel.setDataPosition(0); NotificationRankingUpdate nru1 = NotificationRankingUpdate.CREATOR.createFromParcel(parcel); // The rankingUpdate file descriptor is only non-null in the new path. if (Flags.rankingUpdateAshmem()) { assertTrue(nru1.isFdNotNullAndClosed()); } detailedAssertEquals(nru, nru1); parcel.recycle(); } Loading Loading @@ -630,9 +611,6 @@ public class NotificationRankingUpdateTest { @Test public void testRankingUpdate_writesSmartActionToParcel() { if (!Flags.rankingUpdateAshmem()) { return; } ArrayList<Notification.Action> actions = new ArrayList<>(); PendingIntent intent = PendingIntent.getBroadcast( getContext(), Loading Loading @@ -668,9 +646,6 @@ public class NotificationRankingUpdateTest { @Test public void testRankingUpdate_handlesEmptySmartActionList() { if (!Flags.rankingUpdateAshmem()) { return; } ArrayList<Notification.Action> actions = new ArrayList<>(); NotificationListenerService.Ranking ranking = createEmptyTestRanking(TEST_KEY, 123, actions); Loading @@ -691,9 +666,6 @@ public class NotificationRankingUpdateTest { @Test public void testRankingUpdate_handlesNullSmartActionList() { if (!Flags.rankingUpdateAshmem()) { return; } NotificationListenerService.Ranking ranking = createEmptyTestRanking(TEST_KEY, 123, null); NotificationRankingUpdate rankingUpdate = new NotificationRankingUpdate( Loading Loading
core/java/android/service/notification/NotificationRankingUpdate.java +101 −108 Original line number Diff line number Diff line Loading @@ -23,6 +23,7 @@ import android.os.Parcelable; import android.os.SharedMemory; import android.system.ErrnoException; import android.system.OsConstants; import android.util.Slog; import androidx.annotation.NonNull; import androidx.annotation.Nullable; Loading @@ -39,6 +40,7 @@ import java.util.List; */ @SuppressLint({"ParcelNotFinal", "ParcelCreator"}) public class NotificationRankingUpdate implements Parcelable { private static final String TAG = "NotificationRankingUpdate"; private final NotificationListenerService.RankingMap mRankingMap; // The ranking map is stored in shared memory when parceled, for sending across the binder. Loading @@ -57,7 +59,6 @@ public class NotificationRankingUpdate implements Parcelable { * @hide */ public NotificationRankingUpdate(Parcel in) { if (Flags.rankingUpdateAshmem()) { // Recover the ranking map from the SharedMemory and store it in mapParcel. final Parcel mapParcel = Parcel.obtain(); ByteBuffer buffer = null; Loading Loading @@ -88,8 +89,6 @@ public class NotificationRankingUpdate implements Parcelable { addSmartActionsFromBundleToRankingMap(smartActionsBundle); } catch (ErrnoException e) { // TODO(b/284297289): remove throw when associated flag is moved to droidfood, to // avoid crashes; change to Log.wtf. throw new RuntimeException(e); } finally { mapParcel.recycle(); Loading @@ -98,10 +97,6 @@ public class NotificationRankingUpdate implements Parcelable { mRankingMapFd.close(); } } } else { mRankingMap = in.readParcelable(getClass().getClassLoader(), android.service.notification.NotificationListenerService.RankingMap.class); } } /** Loading Loading @@ -169,7 +164,6 @@ public class NotificationRankingUpdate implements Parcelable { */ @Override public void writeToParcel(@NonNull Parcel out, int flags) { if (Flags.rankingUpdateAshmem()) { final Parcel mapParcel = Parcel.obtain(); ArrayList<NotificationListenerService.Ranking> marshalableRankings = new ArrayList<>(); Bundle smartActionsBundle = new Bundle(); Loading @@ -187,7 +181,7 @@ public class NotificationRankingUpdate implements Parcelable { // smart actions, and we don't want to needlessly store an empty list object, so we // check for null before storing. List<Notification.Action> smartActions = ranking.getSmartActions(); if (!smartActions.isEmpty()) { if (smartActions != null && !smartActions.isEmpty()) { smartActionsBundle.putParcelableList(key, smartActions); } Loading Loading @@ -225,11 +219,13 @@ public class NotificationRankingUpdate implements Parcelable { // Puts the SharedMemory object in the parcel. out.writeParcelable(mRankingMapFd, flags); // Writes the Parceled smartActions separately. if (smartActionsBundle.size() > 0) { out.writeBundle(smartActionsBundle); } else { out.writeBundle(null); } } catch (ErrnoException e) { // TODO(b/284297289): remove throw when associated flag is moved to droidfood, to // avoid crashes; change to Log.wtf. throw new RuntimeException(e); Slog.wtf(TAG, "Failed to write ranking map to shared memory", e); } finally { mapParcel.recycle(); // To prevent memory leaks, we can close the ranking map fd here. Loading @@ -239,9 +235,6 @@ public class NotificationRankingUpdate implements Parcelable { mRankingMapFd.close(); } } } else { out.writeParcelable(mRankingMap, flags); } } /** Loading
core/java/android/service/notification/flags.aconfig +0 −7 Original line number Diff line number Diff line Loading @@ -2,13 +2,6 @@ package: "android.service.notification" container: "system" container: "system" flag { name: "ranking_update_ashmem" namespace: "systemui" description: "This flag controls moving ranking update contents into ashmem" bug: "249848655" } flag { name: "redact_sensitive_notifications_from_untrusted_listeners" is_exported: true Loading
core/tests/coretests/src/android/service/notification/NotificationRankingUpdateTest.java +4 −32 Original line number Diff line number Diff line Loading @@ -44,6 +44,7 @@ import android.platform.test.flag.junit.SetFlagsRule; import android.testing.TestableContext; import androidx.test.InstrumentationRegistry; import androidx.test.ext.junit.runners.AndroidJUnit4; import androidx.test.filters.SmallTest; import org.junit.Assert; Loading @@ -51,13 +52,12 @@ import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; import java.util.ArrayList; import java.util.List; @SmallTest @RunWith(Parameterized.class) @RunWith(AndroidJUnit4.class) public class NotificationRankingUpdateTest { private static final String NOTIFICATION_CHANNEL_ID = "test_channel_id"; Loading @@ -68,15 +68,6 @@ public class NotificationRankingUpdateTest { @Rule public final SetFlagsRule mSetFlagsRule = new SetFlagsRule(); // TODO(b/284297289): remove this flag set once resolved. @Parameterized.Parameters(name = "rankingUpdateAshmem={0}") public static Boolean[] getRankingUpdateAshmem() { return new Boolean[] { true, false }; } @Parameterized.Parameter public boolean mRankingUpdateAshmem; @Rule public TestableContext mContext = spy(new TestableContext(InstrumentationRegistry.getContext(), null)); Loading Loading @@ -432,12 +423,6 @@ public class NotificationRankingUpdateTest { public void setUp() { mNotificationChannel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, "test channel", NotificationManager.IMPORTANCE_DEFAULT); if (mRankingUpdateAshmem) { mSetFlagsRule.enableFlags(Flags.FLAG_RANKING_UPDATE_ASHMEM); } else { mSetFlagsRule.disableFlags(Flags.FLAG_RANKING_UPDATE_ASHMEM); } } /** Loading Loading @@ -485,15 +470,11 @@ public class NotificationRankingUpdateTest { NotificationRankingUpdate nru = generateUpdate(getContext()); Parcel parcel = Parcel.obtain(); nru.writeToParcel(parcel, 0); if (Flags.rankingUpdateAshmem()) { assertTrue(nru.isFdNotNullAndClosed()); } parcel.setDataPosition(0); NotificationRankingUpdate nru1 = NotificationRankingUpdate.CREATOR.createFromParcel(parcel); // The rankingUpdate file descriptor is only non-null in the new path. if (Flags.rankingUpdateAshmem()) { assertTrue(nru1.isFdNotNullAndClosed()); } detailedAssertEquals(nru, nru1); parcel.recycle(); } Loading Loading @@ -630,9 +611,6 @@ public class NotificationRankingUpdateTest { @Test public void testRankingUpdate_writesSmartActionToParcel() { if (!Flags.rankingUpdateAshmem()) { return; } ArrayList<Notification.Action> actions = new ArrayList<>(); PendingIntent intent = PendingIntent.getBroadcast( getContext(), Loading Loading @@ -668,9 +646,6 @@ public class NotificationRankingUpdateTest { @Test public void testRankingUpdate_handlesEmptySmartActionList() { if (!Flags.rankingUpdateAshmem()) { return; } ArrayList<Notification.Action> actions = new ArrayList<>(); NotificationListenerService.Ranking ranking = createEmptyTestRanking(TEST_KEY, 123, actions); Loading @@ -691,9 +666,6 @@ public class NotificationRankingUpdateTest { @Test public void testRankingUpdate_handlesNullSmartActionList() { if (!Flags.rankingUpdateAshmem()) { return; } NotificationListenerService.Ranking ranking = createEmptyTestRanking(TEST_KEY, 123, null); NotificationRankingUpdate rankingUpdate = new NotificationRankingUpdate( Loading