Search in sources :

Example 16 with AtomicFile

use of com.android.internal.os.AtomicFile in project android_frameworks_base by ParanoidAndroid.

the class TestContext method testAuthorityParsing.

@MediumTest
public void testAuthorityParsing() throws Exception {
    final Account account = new Account("account1", "type1");
    final String authority1 = "auth1";
    final String authority2 = "auth2";
    final String authority3 = "auth3";
    final Bundle extras = new Bundle();
    PeriodicSync sync1 = new PeriodicSync(account, authority1, extras, (long) (60 * 60 * 24));
    PeriodicSync sync2 = new PeriodicSync(account, authority2, extras, (long) (60 * 60 * 24));
    PeriodicSync sync3 = new PeriodicSync(account, authority3, extras, (long) (60 * 60 * 24));
    PeriodicSync sync1s = new PeriodicSync(account, authority1, extras, 1000);
    PeriodicSync sync2s = new PeriodicSync(account, authority2, extras, 1000);
    PeriodicSync sync3s = new PeriodicSync(account, authority3, extras, 1000);
    MockContentResolver mockResolver = new MockContentResolver();
    final TestContext testContext = new TestContext(mockResolver, getContext());
    byte[] accountsFileData = ("<?xml version='1.0' encoding='utf-8' standalone='yes' ?>\n" + "<accounts>\n" + "<authority id=\"0\" user=\"0\" account=\"account1\" type=\"type1\" authority=\"auth1\" />\n" + "<authority id=\"1\" user=\"0\" account=\"account1\" type=\"type1\" authority=\"auth2\" />\n" + "<authority id=\"2\"            account=\"account1\" type=\"type1\" authority=\"auth3\" />\n" + "<authority id=\"3\" user=\"1\" account=\"account1\" type=\"type1\" authority=\"auth3\" />\n" + "</accounts>\n").getBytes();
    File syncDir = getSyncDir();
    syncDir.mkdirs();
    AtomicFile accountInfoFile = new AtomicFile(new File(syncDir, "accounts.xml"));
    FileOutputStream fos = accountInfoFile.startWrite();
    fos.write(accountsFileData);
    accountInfoFile.finishWrite(fos);
    SyncStorageEngine engine = SyncStorageEngine.newTestInstance(testContext);
    List<PeriodicSync> syncs = engine.getPeriodicSyncs(account, 0, authority1);
    assertEquals(1, syncs.size());
    assertEquals(sync1, syncs.get(0));
    syncs = engine.getPeriodicSyncs(account, 0, authority2);
    assertEquals(1, syncs.size());
    assertEquals(sync2, syncs.get(0));
    syncs = engine.getPeriodicSyncs(account, 0, authority3);
    assertEquals(1, syncs.size());
    assertEquals(sync3, syncs.get(0));
    syncs = engine.getPeriodicSyncs(account, 1, authority3);
    assertEquals(1, syncs.size());
    assertEquals(sync3, syncs.get(0));
    accountsFileData = ("<?xml version='1.0' encoding='utf-8' standalone='yes' ?>\n" + "<accounts version=\"2\">\n" + "<authority id=\"0\" account=\"account1\" type=\"type1\" authority=\"auth1\" />\n" + "<authority id=\"1\" account=\"account1\" type=\"type1\" authority=\"auth2\" />\n" + "<authority id=\"2\" account=\"account1\" type=\"type1\" authority=\"auth3\" />\n" + "</accounts>\n").getBytes();
    accountInfoFile = new AtomicFile(new File(syncDir, "accounts.xml"));
    fos = accountInfoFile.startWrite();
    fos.write(accountsFileData);
    accountInfoFile.finishWrite(fos);
    engine.clearAndReadState();
    syncs = engine.getPeriodicSyncs(account, 0, authority1);
    assertEquals(0, syncs.size());
    syncs = engine.getPeriodicSyncs(account, 0, authority2);
    assertEquals(0, syncs.size());
    syncs = engine.getPeriodicSyncs(account, 0, authority3);
    assertEquals(0, syncs.size());
    accountsFileData = ("<?xml version='1.0' encoding='utf-8' standalone='yes' ?>\n" + "<accounts version=\"2\">\n" + "<authority id=\"0\" account=\"account1\" type=\"type1\" authority=\"auth1\">\n" + "<periodicSync period=\"1000\" />\n" + "</authority>" + "<authority id=\"1\" account=\"account1\" type=\"type1\" authority=\"auth2\">\n" + "<periodicSync period=\"1000\" />\n" + "</authority>" + "<authority id=\"2\" account=\"account1\" type=\"type1\" authority=\"auth3\">\n" + "<periodicSync period=\"1000\" />\n" + "</authority>" + "</accounts>\n").getBytes();
    accountInfoFile = new AtomicFile(new File(syncDir, "accounts.xml"));
    fos = accountInfoFile.startWrite();
    fos.write(accountsFileData);
    accountInfoFile.finishWrite(fos);
    engine.clearAndReadState();
    syncs = engine.getPeriodicSyncs(account, 0, authority1);
    assertEquals(1, syncs.size());
    assertEquals(sync1s, syncs.get(0));
    syncs = engine.getPeriodicSyncs(account, 0, authority2);
    assertEquals(1, syncs.size());
    assertEquals(sync2s, syncs.get(0));
    syncs = engine.getPeriodicSyncs(account, 0, authority3);
    assertEquals(1, syncs.size());
    assertEquals(sync3s, syncs.get(0));
}
Also used : Account(android.accounts.Account) AtomicFile(com.android.internal.os.AtomicFile) Bundle(android.os.Bundle) FileOutputStream(java.io.FileOutputStream) PeriodicSync(android.content.PeriodicSync) MockContentResolver(android.test.mock.MockContentResolver) File(java.io.File) AtomicFile(com.android.internal.os.AtomicFile) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Example 17 with AtomicFile

use of com.android.internal.os.AtomicFile in project platform_frameworks_base by android.

the class TestContext method testSyncableMigration.

@SmallTest
public void testSyncableMigration() throws Exception {
    final Account account = new Account("acc", "type");
    MockContentResolver mockResolver = new MockContentResolver();
    final TestContext testContext = new TestContext(mockResolver, getContext());
    byte[] accountsFileData = ("<?xml version='1.0' encoding='utf-8' standalone='yes' ?>\n" + "<accounts>\n" + "<authority id=\"0\" account=\"acc\" authority=\"other1\" />\n" + "<authority id=\"1\" account=\"acc\" type=\"type\" authority=\"other2\" />\n" + "<authority id=\"2\" account=\"acc\" type=\"type\" syncable=\"false\"" + " authority=\"other3\" />\n" + "<authority id=\"3\" account=\"acc\" type=\"type\" syncable=\"true\"" + " authority=\"other4\" />\n" + "</accounts>\n").getBytes();
    File syncDir = new File(new File(testContext.getFilesDir(), "system"), "sync");
    syncDir.mkdirs();
    AtomicFile accountInfoFile = new AtomicFile(new File(syncDir, "accounts.xml"));
    FileOutputStream fos = accountInfoFile.startWrite();
    fos.write(accountsFileData);
    accountInfoFile.finishWrite(fos);
    SyncStorageEngine engine = SyncStorageEngine.newTestInstance(testContext);
    assertEquals(-1, engine.getIsSyncable(account, 0, "other1"));
    assertEquals(1, engine.getIsSyncable(account, 0, "other2"));
    assertEquals(0, engine.getIsSyncable(account, 0, "other3"));
    assertEquals(1, engine.getIsSyncable(account, 0, "other4"));
}
Also used : Account(android.accounts.Account) AtomicFile(com.android.internal.os.AtomicFile) FileOutputStream(java.io.FileOutputStream) MockContentResolver(android.test.mock.MockContentResolver) File(java.io.File) AtomicFile(com.android.internal.os.AtomicFile) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 18 with AtomicFile

use of com.android.internal.os.AtomicFile in project platform_frameworks_base by android.

the class TestContext method testListenForTicklesParsing.

@MediumTest
public void testListenForTicklesParsing() throws Exception {
    byte[] accountsFileData = ("<?xml version='1.0' encoding='utf-8' standalone='yes' ?>\n" + "<accounts>\n" + "<listenForTickles user=\"0\" enabled=\"false\" />" + "<listenForTickles user=\"1\" enabled=\"true\" />" + "<authority id=\"0\" user=\"0\" account=\"account1\" type=\"type1\" authority=\"auth1\" />\n" + "<authority id=\"1\" user=\"1\" account=\"account1\" type=\"type1\" authority=\"auth1\" />\n" + "</accounts>\n").getBytes();
    MockContentResolver mockResolver = new MockContentResolver();
    final TestContext testContext = new TestContext(mockResolver, getContext());
    File syncDir = getSyncDir();
    syncDir.mkdirs();
    AtomicFile accountInfoFile = new AtomicFile(new File(syncDir, "accounts.xml"));
    FileOutputStream fos = accountInfoFile.startWrite();
    fos.write(accountsFileData);
    accountInfoFile.finishWrite(fos);
    SyncStorageEngine engine = SyncStorageEngine.newTestInstance(testContext);
    assertEquals(false, engine.getMasterSyncAutomatically(0));
    assertEquals(true, engine.getMasterSyncAutomatically(1));
    assertEquals(true, engine.getMasterSyncAutomatically(2));
}
Also used : AtomicFile(com.android.internal.os.AtomicFile) FileOutputStream(java.io.FileOutputStream) MockContentResolver(android.test.mock.MockContentResolver) File(java.io.File) AtomicFile(com.android.internal.os.AtomicFile) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Example 19 with AtomicFile

use of com.android.internal.os.AtomicFile in project platform_frameworks_base by android.

the class PackageManagerSettingsTests method writeFile.

private void writeFile(File file, byte[] data) {
    file.mkdirs();
    try {
        AtomicFile aFile = new AtomicFile(file);
        FileOutputStream fos = aFile.startWrite();
        fos.write(data);
        aFile.finishWrite(fos);
    } catch (IOException ioe) {
        Log.e(TAG, "Cannot write file " + file.getPath());
    }
}
Also used : AtomicFile(com.android.internal.os.AtomicFile) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException)

Example 20 with AtomicFile

use of com.android.internal.os.AtomicFile in project android_frameworks_base by ResurrectionRemix.

the class TestContext method testSyncableMigration.

@SmallTest
public void testSyncableMigration() throws Exception {
    final Account account = new Account("acc", "type");
    MockContentResolver mockResolver = new MockContentResolver();
    final TestContext testContext = new TestContext(mockResolver, getContext());
    byte[] accountsFileData = ("<?xml version='1.0' encoding='utf-8' standalone='yes' ?>\n" + "<accounts>\n" + "<authority id=\"0\" account=\"acc\" authority=\"other1\" />\n" + "<authority id=\"1\" account=\"acc\" type=\"type\" authority=\"other2\" />\n" + "<authority id=\"2\" account=\"acc\" type=\"type\" syncable=\"false\"" + " authority=\"other3\" />\n" + "<authority id=\"3\" account=\"acc\" type=\"type\" syncable=\"true\"" + " authority=\"other4\" />\n" + "</accounts>\n").getBytes();
    File syncDir = new File(new File(testContext.getFilesDir(), "system"), "sync");
    syncDir.mkdirs();
    AtomicFile accountInfoFile = new AtomicFile(new File(syncDir, "accounts.xml"));
    FileOutputStream fos = accountInfoFile.startWrite();
    fos.write(accountsFileData);
    accountInfoFile.finishWrite(fos);
    SyncStorageEngine engine = SyncStorageEngine.newTestInstance(testContext);
    assertEquals(-1, engine.getIsSyncable(account, 0, "other1"));
    assertEquals(1, engine.getIsSyncable(account, 0, "other2"));
    assertEquals(0, engine.getIsSyncable(account, 0, "other3"));
    assertEquals(1, engine.getIsSyncable(account, 0, "other4"));
}
Also used : Account(android.accounts.Account) AtomicFile(com.android.internal.os.AtomicFile) FileOutputStream(java.io.FileOutputStream) MockContentResolver(android.test.mock.MockContentResolver) File(java.io.File) AtomicFile(com.android.internal.os.AtomicFile) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Aggregations

AtomicFile (com.android.internal.os.AtomicFile)21 FileOutputStream (java.io.FileOutputStream)21 MockContentResolver (android.test.mock.MockContentResolver)16 File (java.io.File)16 Account (android.accounts.Account)11 MediumTest (android.test.suitebuilder.annotation.MediumTest)11 SmallTest (android.test.suitebuilder.annotation.SmallTest)5 IOException (java.io.IOException)5 PeriodicSync (android.content.PeriodicSync)1 Bundle (android.os.Bundle)1