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

Commit b8e8a91f authored by Jeff Sharkey's avatar Jeff Sharkey
Browse files

Log when pre-N apps send too much to DropBox.

Once they target N, they'll start getting exceptions, which is
intended to make sure they pay attention to data that would have
otherwise been dropped on the floor.

Bug: 27571535
Change-Id: I49163679c629cd0788327d2c3a654e757ecdcb99
parent 265551de
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -3722,10 +3722,9 @@ public final class ActivityThread {
            } catch (RemoteException ex) {
                if (ex instanceof TransactionTooLargeException
                        && activity.packageInfo.getTargetSdkVersion() < Build.VERSION_CODES.N) {
                    Log.e(TAG, "App tried sending too much data in instance state", ex);
                    Log.e(TAG, "App sent too much data in instance state, so it was ignored", ex);
                    return;
                }

                throw ex.rethrowFromSystemServer();
            }
        }
+3 −3
Original line number Diff line number Diff line
@@ -271,9 +271,9 @@ final class SystemServiceRegistry {
            }});

        registerService(Context.DROPBOX_SERVICE, DropBoxManager.class,
                new StaticServiceFetcher<DropBoxManager>() {
                new CachedServiceFetcher<DropBoxManager>() {
            @Override
            public DropBoxManager createService() {
            public DropBoxManager createService(ContextImpl ctx) {
                IBinder b = ServiceManager.getService(Context.DROPBOX_SERVICE);
                IDropBoxManagerService service = IDropBoxManagerService.Stub.asInterface(b);
                if (service == null) {
@@ -283,7 +283,7 @@ final class SystemServiceRegistry {
                    // DROPBOX_SERVICE is registered.
                    return null;
                }
                return new DropBoxManager(service);
                return new DropBoxManager(ctx, service);
            }});

        registerService(Context.INPUT_SERVICE, InputManager.class,
+23 −2
Original line number Diff line number Diff line
@@ -16,6 +16,9 @@

package android.os;

import android.content.Context;
import android.util.Log;

import com.android.internal.os.IDropBoxManagerService;

import java.io.ByteArrayInputStream;
@@ -40,6 +43,8 @@ import java.util.zip.GZIPInputStream;
 */
public class DropBoxManager {
    private static final String TAG = "DropBoxManager";

    private final Context mContext;
    private final IDropBoxManagerService mService;

    /** Flag value: Entry's content was deleted to save space. */
@@ -249,14 +254,20 @@ public class DropBoxManager {
    }

    /** {@hide} */
    public DropBoxManager(IDropBoxManagerService service) { mService = service; }
    public DropBoxManager(Context context, IDropBoxManagerService service) {
        mContext = context;
        mService = service;
    }

    /**
     * Create a dummy instance for testing.  All methods will fail unless
     * overridden with an appropriate mock implementation.  To obtain a
     * functional instance, use {@link android.content.Context#getSystemService}.
     */
    protected DropBoxManager() { mService = null; }
    protected DropBoxManager() {
        mContext = null;
        mService = null;
    }

    /**
     * Stores human-readable text.  The data may be discarded eventually (or even
@@ -270,6 +281,11 @@ public class DropBoxManager {
        try {
            mService.add(new Entry(tag, 0, data));
        } catch (RemoteException e) {
            if (e instanceof TransactionTooLargeException
                    && mContext.getApplicationInfo().targetSdkVersion < Build.VERSION_CODES.N) {
                Log.e(TAG, "App sent too much data, so it was ignored", e);
                return;
            }
            throw e.rethrowFromSystemServer();
        }
    }
@@ -286,6 +302,11 @@ public class DropBoxManager {
        try {
            mService.add(new Entry(tag, 0, data, flags));
        } catch (RemoteException e) {
            if (e instanceof TransactionTooLargeException
                    && mContext.getApplicationInfo().targetSdkVersion < Build.VERSION_CODES.N) {
                Log.e(TAG, "App sent too much data, so it was ignored", e);
                return;
            }
            throw e.rethrowFromSystemServer();
        }
    }
+10 −10
Original line number Diff line number Diff line
@@ -54,7 +54,7 @@ public class DropBoxTest extends AndroidTestCase {
    public void testAddText() throws Exception {
        File dir = getEmptyDir("testAddText");
        DropBoxManagerService service = new DropBoxManagerService(getContext(), dir);
        DropBoxManager dropbox = new DropBoxManager(service.getServiceStub());
        DropBoxManager dropbox = new DropBoxManager(getContext(), service.getServiceStub());

        long before = System.currentTimeMillis();
        Thread.sleep(5);
@@ -90,7 +90,7 @@ public class DropBoxTest extends AndroidTestCase {
    public void testAddData() throws Exception {
        File dir = getEmptyDir("testAddData");
        DropBoxManagerService service = new DropBoxManagerService(getContext(), dir);
        DropBoxManager dropbox = new DropBoxManager(service.getServiceStub());
        DropBoxManager dropbox = new DropBoxManager(getContext(), service.getServiceStub());

        long before = System.currentTimeMillis();
        dropbox.addData("DropBoxTest", "TEST".getBytes(), 0);
@@ -135,7 +135,7 @@ public class DropBoxTest extends AndroidTestCase {
        gz3.close();

        DropBoxManagerService service = new DropBoxManagerService(getContext(), dir);
        DropBoxManager dropbox = new DropBoxManager(service.getServiceStub());
        DropBoxManager dropbox = new DropBoxManager(getContext(), service.getServiceStub());

        dropbox.addFile("DropBoxTest", f0, DropBoxManager.IS_TEXT);
        dropbox.addFile("DropBoxTest", f1, DropBoxManager.IS_TEXT | DropBoxManager.IS_GZIPPED);
@@ -201,7 +201,7 @@ public class DropBoxTest extends AndroidTestCase {
        new FileOutputStream(new File(dir, "DropBoxTest@" + (before + 100002) + ".lost")).close();

        DropBoxManagerService service = new DropBoxManagerService(getContext(), dir);
        DropBoxManager dropbox = new DropBoxManager(service.getServiceStub());
        DropBoxManager dropbox = new DropBoxManager(getContext(), service.getServiceStub());

        // Until a write, the timestamps are taken at face value
        DropBoxManager.Entry e0 = dropbox.getNextEntry(null, before);
@@ -252,7 +252,7 @@ public class DropBoxTest extends AndroidTestCase {
    public void testIsTagEnabled() throws Exception {
        File dir = getEmptyDir("testIsTagEnabled");
        DropBoxManagerService service = new DropBoxManagerService(getContext(), dir);
        DropBoxManager dropbox = new DropBoxManager(service.getServiceStub());
        DropBoxManager dropbox = new DropBoxManager(getContext(), service.getServiceStub());

        long before = System.currentTimeMillis();
        dropbox.addText("DropBoxTest", "TEST-ENABLED");
@@ -285,7 +285,7 @@ public class DropBoxTest extends AndroidTestCase {
    public void testGetNextEntry() throws Exception {
        File dir = getEmptyDir("testGetNextEntry");
        DropBoxManagerService service = new DropBoxManagerService(getContext(), dir);
        DropBoxManager dropbox = new DropBoxManager(service.getServiceStub());
        DropBoxManager dropbox = new DropBoxManager(getContext(), service.getServiceStub());

        long before = System.currentTimeMillis();
        dropbox.addText("DropBoxTest.A", "A0");
@@ -347,7 +347,7 @@ public class DropBoxTest extends AndroidTestCase {
        final int overhead = 64;
        long before = System.currentTimeMillis();
        DropBoxManagerService service = new DropBoxManagerService(getContext(), dir);
        DropBoxManager dropbox = new DropBoxManager(service.getServiceStub());
        DropBoxManager dropbox = new DropBoxManager(getContext(), service.getServiceStub());

        addRandomEntry(dropbox, "DropBoxTest0", blockSize - overhead);
        addRandomEntry(dropbox, "DropBoxTest0", blockSize - overhead);
@@ -441,7 +441,7 @@ public class DropBoxTest extends AndroidTestCase {
        // Write one normal entry and another so big that it is instantly tombstoned
        long before = System.currentTimeMillis();
        DropBoxManagerService service = new DropBoxManagerService(getContext(), dir);
        DropBoxManager dropbox = new DropBoxManager(service.getServiceStub());
        DropBoxManager dropbox = new DropBoxManager(getContext(), service.getServiceStub());

        dropbox.addText("DropBoxTest", "TEST");
        addRandomEntry(dropbox, "DropBoxTest", blockSize * 20);
@@ -472,7 +472,7 @@ public class DropBoxTest extends AndroidTestCase {
        File dir = getEmptyDir("testFileCountLimits");

        DropBoxManagerService service = new DropBoxManagerService(getContext(), dir);
        DropBoxManager dropbox = new DropBoxManager(service.getServiceStub());
        DropBoxManager dropbox = new DropBoxManager(getContext(), service.getServiceStub());
        dropbox.addText("DropBoxTest", "TEST0");
        dropbox.addText("DropBoxTest", "TEST1");
        dropbox.addText("DropBoxTest", "TEST2");
@@ -525,7 +525,7 @@ public class DropBoxTest extends AndroidTestCase {
        File dir = new File(getEmptyDir("testCreateDropBoxManagerWith"), "InvalidDirectory");
        new FileOutputStream(dir).close();  // Create an empty file
        DropBoxManagerService service = new DropBoxManagerService(getContext(), dir);
        DropBoxManager dropbox = new DropBoxManager(service.getServiceStub());
        DropBoxManager dropbox = new DropBoxManager(getContext(), service.getServiceStub());

        dropbox.addText("DropBoxTest", "should be ignored");
        dropbox.addData("DropBoxTest", "should be ignored".getBytes(), 0);