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

Commit 3fe6962d authored by Julia Reynolds's avatar Julia Reynolds Committed by Android (Google) Code Review
Browse files

Merge "Don't crash apps on binder errors" into main

parents 49219903 1927aa3d
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -42,6 +42,7 @@ import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.Icon;
import android.os.BadParcelableException;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
@@ -1056,7 +1057,7 @@ public abstract class NotificationListenerService extends Service {
            ParceledListSlice<StatusBarNotification> parceledList = getNotificationInterface()
                    .getActiveNotificationsFromListener(mWrapper, keys, trim);
            return cleanUpNotificationList(parceledList);
        } catch (android.os.RemoteException ex) {
        } catch (android.os.RemoteException | BadParcelableException ex) {
            Log.v(TAG, "Unable to contact notification manager", ex);
        }
        return null;
+16 −0
Original line number Diff line number Diff line
@@ -44,8 +44,10 @@ import android.content.pm.ParceledListSlice;
import android.content.pm.ShortcutInfo;
import android.graphics.Bitmap;
import android.graphics.drawable.Icon;
import android.os.BadParcelableException;
import android.os.Binder;
import android.os.Build;
import android.os.DeadObjectException;
import android.os.IBinder;
import android.os.RemoteException;
import android.os.UserHandle;
@@ -98,6 +100,20 @@ public class NotificationListenerServiceTest extends UiServiceTestCase {
                new String[0], NotificationListenerService.TRIM_LIGHT));
    }

    @Test
    public void testGetActiveNotifications_handlesBinderErrors() throws RemoteException {
        TestListenerService service = new TestListenerService();
        INotificationManager noMan = service.getNoMan();
        when(noMan.getActiveNotificationsFromListener(any(), any(), anyInt()))
                .thenThrow(new BadParcelableException("oops", new DeadObjectException("")));

        assertNotNull(service.getActiveNotifications());
        assertNotNull(service.getActiveNotifications(NotificationListenerService.TRIM_FULL));
        assertNotNull(service.getActiveNotifications(new String[0]));
        assertNull(service.getActiveNotifications(
                new String[0], NotificationListenerService.TRIM_LIGHT));
    }

    @Test
    public void testGetActiveNotifications_preP_mapsExtraPeople() throws RemoteException {
        TestListenerService service = new TestListenerService();