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

Commit 1927aa3d authored by Julia Reynolds's avatar Julia Reynolds
Browse files

Don't crash apps on binder errors

Log and return null/empty list instead like the rest of the
RemoteExceptions.

Test: NotificationListenerServiceTest
Fixes: 301554465
Change-Id: I19bae8bee801d3df4357c1411b2601cf6ad64820
parent 21856634
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();