Search in sources :

Example 16 with DropBoxManager

use of android.os.DropBoxManager in project platform_frameworks_base by android.

the class DropBoxTest method testAddEntriesInTheFuture.

public void testAddEntriesInTheFuture() throws Exception {
    File dir = getEmptyDir("testAddEntriesInTheFuture");
    long before = System.currentTimeMillis();
    // Near future: should be allowed to persist
    FileWriter w0 = new FileWriter(new File(dir, "DropBoxTest@" + (before + 5000) + ".txt"));
    w0.write("FUTURE0");
    w0.close();
    // Far future: should be collapsed
    FileWriter w1 = new FileWriter(new File(dir, "DropBoxTest@" + (before + 100000) + ".txt"));
    w1.write("FUTURE1");
    w1.close();
    // Another far future item, this one gzipped
    File f2 = new File(dir, "DropBoxTest@" + (before + 100001) + ".txt.gz");
    GZIPOutputStream gz2 = new GZIPOutputStream(new FileOutputStream(f2));
    gz2.write("FUTURE2".getBytes());
    gz2.close();
    // Tombstone in the far future
    new FileOutputStream(new File(dir, "DropBoxTest@" + (before + 100002) + ".lost")).close();
    DropBoxManagerService service = new DropBoxManagerService(getContext(), dir);
    DropBoxManager dropbox = new DropBoxManager(getContext(), service.getServiceStub());
    // Until a write, the timestamps are taken at face value
    DropBoxManager.Entry e0 = dropbox.getNextEntry(null, before);
    DropBoxManager.Entry e1 = dropbox.getNextEntry(null, e0.getTimeMillis());
    DropBoxManager.Entry e2 = dropbox.getNextEntry(null, e1.getTimeMillis());
    DropBoxManager.Entry e3 = dropbox.getNextEntry(null, e2.getTimeMillis());
    assertTrue(null == dropbox.getNextEntry(null, e3.getTimeMillis()));
    assertEquals("FUTURE0", e0.getText(80));
    assertEquals("FUTURE1", e1.getText(80));
    assertEquals("FUTURE2", e2.getText(80));
    assertEquals(null, e3.getText(80));
    assertEquals(before + 5000, e0.getTimeMillis());
    assertEquals(before + 100000, e1.getTimeMillis());
    assertEquals(before + 100001, e2.getTimeMillis());
    assertEquals(before + 100002, e3.getTimeMillis());
    e0.close();
    e1.close();
    e2.close();
    e3.close();
    // Write something to force a collapse
    dropbox.addText("NotDropBoxTest", "FUTURE");
    e0 = dropbox.getNextEntry(null, before);
    e1 = dropbox.getNextEntry(null, e0.getTimeMillis());
    e2 = dropbox.getNextEntry(null, e1.getTimeMillis());
    e3 = dropbox.getNextEntry(null, e2.getTimeMillis());
    assertTrue(null == dropbox.getNextEntry("DropBoxTest", e3.getTimeMillis()));
    assertEquals("FUTURE0", e0.getText(80));
    assertEquals("FUTURE1", e1.getText(80));
    assertEquals("FUTURE2", e2.getText(80));
    assertEquals(null, e3.getText(80));
    assertEquals(before + 5000, e0.getTimeMillis());
    assertEquals(before + 5001, e1.getTimeMillis());
    assertEquals(before + 5002, e2.getTimeMillis());
    assertEquals(before + 5003, e3.getTimeMillis());
    e0.close();
    e1.close();
    e2.close();
    e3.close();
}
Also used : DropBoxManager(android.os.DropBoxManager) DropBoxManagerService(com.android.server.DropBoxManagerService) GZIPOutputStream(java.util.zip.GZIPOutputStream) FileWriter(java.io.FileWriter) FileOutputStream(java.io.FileOutputStream) File(java.io.File)

Example 17 with DropBoxManager

use of android.os.DropBoxManager in project platform_frameworks_base by android.

the class DropBoxTest method testIsTagEnabled.

public void testIsTagEnabled() throws Exception {
    File dir = getEmptyDir("testIsTagEnabled");
    DropBoxManagerService service = new DropBoxManagerService(getContext(), dir);
    DropBoxManager dropbox = new DropBoxManager(getContext(), service.getServiceStub());
    long before = System.currentTimeMillis();
    dropbox.addText("DropBoxTest", "TEST-ENABLED");
    assertTrue(dropbox.isTagEnabled("DropBoxTest"));
    ContentResolver cr = getContext().getContentResolver();
    Settings.Global.putString(cr, Settings.Global.DROPBOX_TAG_PREFIX + "DropBoxTest", "disabled");
    dropbox.addText("DropBoxTest", "TEST-DISABLED");
    assertFalse(dropbox.isTagEnabled("DropBoxTest"));
    Settings.Global.putString(cr, Settings.Global.DROPBOX_TAG_PREFIX + "DropBoxTest", "");
    dropbox.addText("DropBoxTest", "TEST-ENABLED-AGAIN");
    assertTrue(dropbox.isTagEnabled("DropBoxTest"));
    DropBoxManager.Entry e0 = dropbox.getNextEntry("DropBoxTest", before);
    DropBoxManager.Entry e1 = dropbox.getNextEntry("DropBoxTest", e0.getTimeMillis());
    assertTrue(null == dropbox.getNextEntry("DropBoxTest", e1.getTimeMillis()));
    assertEquals("TEST-ENABLED", e0.getText(80));
    assertEquals("TEST-ENABLED-AGAIN", e1.getText(80));
    e0.close();
    e1.close();
}
Also used : DropBoxManager(android.os.DropBoxManager) DropBoxManagerService(com.android.server.DropBoxManagerService) File(java.io.File) ContentResolver(android.content.ContentResolver)

Example 18 with DropBoxManager

use of android.os.DropBoxManager in project platform_frameworks_base by android.

the class DropBoxTest method testGetNextEntry.

public void testGetNextEntry() throws Exception {
    File dir = getEmptyDir("testGetNextEntry");
    DropBoxManagerService service = new DropBoxManagerService(getContext(), dir);
    DropBoxManager dropbox = new DropBoxManager(getContext(), service.getServiceStub());
    long before = System.currentTimeMillis();
    dropbox.addText("DropBoxTest.A", "A0");
    dropbox.addText("DropBoxTest.B", "B0");
    dropbox.addText("DropBoxTest.A", "A1");
    DropBoxManager.Entry a0 = dropbox.getNextEntry("DropBoxTest.A", before);
    DropBoxManager.Entry a1 = dropbox.getNextEntry("DropBoxTest.A", a0.getTimeMillis());
    assertTrue(null == dropbox.getNextEntry("DropBoxTest.A", a1.getTimeMillis()));
    DropBoxManager.Entry b0 = dropbox.getNextEntry("DropBoxTest.B", before);
    assertTrue(null == dropbox.getNextEntry("DropBoxTest.B", b0.getTimeMillis()));
    DropBoxManager.Entry x0 = dropbox.getNextEntry(null, before);
    DropBoxManager.Entry x1 = dropbox.getNextEntry(null, x0.getTimeMillis());
    DropBoxManager.Entry x2 = dropbox.getNextEntry(null, x1.getTimeMillis());
    assertTrue(null == dropbox.getNextEntry(null, x2.getTimeMillis()));
    assertEquals("DropBoxTest.A", a0.getTag());
    assertEquals("DropBoxTest.A", a1.getTag());
    assertEquals("A0", a0.getText(80));
    assertEquals("A1", a1.getText(80));
    assertEquals("DropBoxTest.B", b0.getTag());
    assertEquals("B0", b0.getText(80));
    assertEquals("DropBoxTest.A", x0.getTag());
    assertEquals("DropBoxTest.B", x1.getTag());
    assertEquals("DropBoxTest.A", x2.getTag());
    assertEquals("A0", x0.getText(80));
    assertEquals("B0", x1.getText(80));
    assertEquals("A1", x2.getText(80));
    a0.close();
    a1.close();
    b0.close();
    x0.close();
    x1.close();
    x2.close();
}
Also used : DropBoxManager(android.os.DropBoxManager) DropBoxManagerService(com.android.server.DropBoxManagerService) File(java.io.File)

Example 19 with DropBoxManager

use of android.os.DropBoxManager in project VirtualApp by asLody.

the class ContextFixer method fixContext.

/**
     * Fuck AppOps
     *
     * @param context Context
     */
public static void fixContext(Context context) {
    try {
        context.getPackageName();
    } catch (Throwable e) {
        return;
    }
    PatchManager.getInstance().checkEnv(GraphicsStatsPatch.class);
    int deep = 0;
    while (context instanceof ContextWrapper) {
        context = ((ContextWrapper) context).getBaseContext();
        deep++;
        if (deep >= 10) {
            return;
        }
    }
    ContextImpl.mPackageManager.set(context, null);
    try {
        context.getPackageManager();
    } catch (Throwable e) {
        e.printStackTrace();
    }
    if (!VirtualCore.get().isVAppProcess()) {
        return;
    }
    DropBoxManager dm = (DropBoxManager) context.getSystemService(Context.DROPBOX_SERVICE);
    HookBinderDelegate boxBinder = PatchManager.getInstance().getHookObject(DropBoxManagerPatch.class);
    if (boxBinder != null) {
        try {
            Reflect.on(dm).set("mService", boxBinder.getProxyInterface());
        } catch (ReflectException e) {
            e.printStackTrace();
        }
    }
    String hostPkg = VirtualCore.get().getHostPkg();
    ContextImpl.mBasePackageName.set(context, hostPkg);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        ContextImplKitkat.mOpPackageName.set(context, hostPkg);
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
        ContentResolverJBMR2.mPackageName.set(context.getContentResolver(), hostPkg);
    }
}
Also used : DropBoxManager(android.os.DropBoxManager) ContextWrapper(android.content.ContextWrapper) ReflectException(com.lody.virtual.helper.utils.ReflectException) HookBinderDelegate(com.lody.virtual.client.hook.base.HookBinderDelegate)

Example 20 with DropBoxManager

use of android.os.DropBoxManager in project android_frameworks_base by DirtyUnicorns.

the class BatteryService method logBatteryStatsLocked.

private void logBatteryStatsLocked() {
    IBinder batteryInfoService = ServiceManager.getService(BatteryStats.SERVICE_NAME);
    if (batteryInfoService == null)
        return;
    DropBoxManager db = (DropBoxManager) mContext.getSystemService(Context.DROPBOX_SERVICE);
    if (db == null || !db.isTagEnabled("BATTERY_DISCHARGE_INFO"))
        return;
    File dumpFile = null;
    FileOutputStream dumpStream = null;
    try {
        // dump the service to a file
        dumpFile = new File(DUMPSYS_DATA_PATH + BatteryStats.SERVICE_NAME + ".dump");
        dumpStream = new FileOutputStream(dumpFile);
        batteryInfoService.dump(dumpStream.getFD(), DUMPSYS_ARGS);
        FileUtils.sync(dumpStream);
        // add dump file to drop box
        db.addFile("BATTERY_DISCHARGE_INFO", dumpFile, DropBoxManager.IS_TEXT);
    } catch (RemoteException e) {
        Slog.e(TAG, "failed to dump battery service", e);
    } catch (IOException e) {
        Slog.e(TAG, "failed to write dumpsys file", e);
    } finally {
        // make sure we clean up
        if (dumpStream != null) {
            try {
                dumpStream.close();
            } catch (IOException e) {
                Slog.e(TAG, "failed to close dumpsys output stream");
            }
        }
        if (dumpFile != null && !dumpFile.delete()) {
            Slog.e(TAG, "failed to delete temporary dumpsys file: " + dumpFile.getAbsolutePath());
        }
    }
}
Also used : DropBoxManager(android.os.DropBoxManager) IBinder(android.os.IBinder) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) RemoteException(android.os.RemoteException) File(java.io.File)

Aggregations

DropBoxManager (android.os.DropBoxManager)81 File (java.io.File)65 DropBoxManagerService (com.android.server.DropBoxManagerService)46 FileOutputStream (java.io.FileOutputStream)21 ContentResolver (android.content.ContentResolver)20 IOException (java.io.IOException)16 FileObserver (android.os.FileObserver)12 StatFs (android.os.StatFs)10 FileWriter (java.io.FileWriter)10 GZIPOutputStream (java.util.zip.GZIPOutputStream)10 ActivityThread (android.app.ActivityThread)8 IApplicationThread (android.app.IApplicationThread)8 IBinder (android.os.IBinder)8 RemoteException (android.os.RemoteException)6 AtomicFile (android.util.AtomicFile)5 HashMap (java.util.HashMap)5 BackgroundThread (com.android.internal.os.BackgroundThread)4 ServiceThread (com.android.server.ServiceThread)4 InputStreamReader (java.io.InputStreamReader)4 Point (android.graphics.Point)2