Search in sources :

Example 6 with SQLiteDiskIOException

use of android.database.sqlite.SQLiteDiskIOException in project android_frameworks_base by crdroidandroid.

the class MtpDocumentsProvider method onCreate.

@Override
public boolean onCreate() {
    sSingleton = this;
    mContext = getContext();
    mResources = getContext().getResources();
    mMtpManager = new MtpManager(getContext());
    mResolver = getContext().getContentResolver();
    mDeviceToolkits = new HashMap<Integer, DeviceToolkit>();
    mDatabase = new MtpDatabase(getContext(), MtpDatabaseConstants.FLAG_DATABASE_IN_FILE);
    mRootScanner = new RootScanner(mResolver, mMtpManager, mDatabase);
    mAppFuse = new AppFuse(TAG, new AppFuseCallback());
    mIntentSender = new ServiceIntentSender(getContext());
    // after booting.
    try {
        final int bootCount = Settings.Global.getInt(mResolver, Settings.Global.BOOT_COUNT, -1);
        final int lastBootCount = mDatabase.getLastBootCount();
        if (bootCount != -1 && bootCount != lastBootCount) {
            mDatabase.setLastBootCount(bootCount);
            final List<UriPermission> permissions = mResolver.getOutgoingPersistedUriPermissions();
            final Uri[] uris = new Uri[permissions.size()];
            for (int i = 0; i < permissions.size(); i++) {
                uris[i] = permissions.get(i).getUri();
            }
            mDatabase.cleanDatabase(uris);
        }
    } catch (SQLiteDiskIOException error) {
        // It can happen due to disk shortage.
        Log.e(TAG, "Failed to clean database.", error);
        return false;
    }
    // TODO: Mount AppFuse on demands.
    try {
        mAppFuse.mount(getContext().getSystemService(StorageManager.class));
    } catch (IOException error) {
        Log.e(TAG, "Failed to start app fuse.", error);
        return false;
    }
    resume();
    return true;
}
Also used : StorageManager(android.os.storage.StorageManager) SQLiteDiskIOException(android.database.sqlite.SQLiteDiskIOException) IOException(java.io.IOException) Uri(android.net.Uri) Point(android.graphics.Point) UriPermission(android.content.UriPermission) SQLiteDiskIOException(android.database.sqlite.SQLiteDiskIOException)

Example 7 with SQLiteDiskIOException

use of android.database.sqlite.SQLiteDiskIOException in project android_frameworks_base by ParanoidAndroid.

the class DatabaseErrorHandlerTest method testDatabaseIsCorrupt.

public void testDatabaseIsCorrupt() throws IOException {
    mDatabase.execSQL("create table t (i int);");
    // write junk into the database file
    BufferedWriter writer = new BufferedWriter(new FileWriter(mDatabaseFile.getPath()));
    writer.write("blah");
    writer.close();
    assertTrue(mDatabaseFile.exists());
    // should trigger call to MyDatabaseCorruptionHandler.onCorruption
    try {
        mDatabase.execSQL("select * from t;");
        fail("expected exception");
    } catch (SQLiteDiskIOException e) {
        // expected
        if (mDatabaseFile.exists()) {
            mDatabaseFile.delete();
        }
    } catch (SQLiteException e) {
    }
    // database file should be gone
    assertFalse(mDatabaseFile.exists());
    // after corruption handler is called, the database file should be free of
    // database corruption
    SQLiteDatabase db = SQLiteDatabase.openOrCreateDatabase(mDatabaseFile.getPath(), null, new MyDatabaseCorruptionHandler());
    assertTrue(db.isDatabaseIntegrityOk());
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase) FileWriter(java.io.FileWriter) SQLiteDiskIOException(android.database.sqlite.SQLiteDiskIOException) SQLiteException(android.database.sqlite.SQLiteException) BufferedWriter(java.io.BufferedWriter)

Example 8 with SQLiteDiskIOException

use of android.database.sqlite.SQLiteDiskIOException in project platform_frameworks_base by android.

the class MtpDocumentsProvider method onCreate.

@Override
public boolean onCreate() {
    sSingleton = this;
    mContext = getContext();
    mResources = getContext().getResources();
    mMtpManager = new MtpManager(getContext());
    mResolver = getContext().getContentResolver();
    mDeviceToolkits = new HashMap<Integer, DeviceToolkit>();
    mDatabase = new MtpDatabase(getContext(), MtpDatabaseConstants.FLAG_DATABASE_IN_FILE);
    mRootScanner = new RootScanner(mResolver, mMtpManager, mDatabase);
    mAppFuse = new AppFuse(TAG, new AppFuseCallback());
    mIntentSender = new ServiceIntentSender(getContext());
    // after booting.
    try {
        final int bootCount = Settings.Global.getInt(mResolver, Settings.Global.BOOT_COUNT, -1);
        final int lastBootCount = mDatabase.getLastBootCount();
        if (bootCount != -1 && bootCount != lastBootCount) {
            mDatabase.setLastBootCount(bootCount);
            final List<UriPermission> permissions = mResolver.getOutgoingPersistedUriPermissions();
            final Uri[] uris = new Uri[permissions.size()];
            for (int i = 0; i < permissions.size(); i++) {
                uris[i] = permissions.get(i).getUri();
            }
            mDatabase.cleanDatabase(uris);
        }
    } catch (SQLiteDiskIOException error) {
        // It can happen due to disk shortage.
        Log.e(TAG, "Failed to clean database.", error);
        return false;
    }
    // TODO: Mount AppFuse on demands.
    try {
        mAppFuse.mount(getContext().getSystemService(StorageManager.class));
    } catch (IOException error) {
        Log.e(TAG, "Failed to start app fuse.", error);
        return false;
    }
    resume();
    return true;
}
Also used : StorageManager(android.os.storage.StorageManager) SQLiteDiskIOException(android.database.sqlite.SQLiteDiskIOException) IOException(java.io.IOException) Uri(android.net.Uri) Point(android.graphics.Point) UriPermission(android.content.UriPermission) SQLiteDiskIOException(android.database.sqlite.SQLiteDiskIOException)

Example 9 with SQLiteDiskIOException

use of android.database.sqlite.SQLiteDiskIOException in project android_frameworks_base by DirtyUnicorns.

the class DatabaseErrorHandlerTest method testDatabaseIsCorrupt.

public void testDatabaseIsCorrupt() throws IOException {
    mDatabase.execSQL("create table t (i int);");
    // write junk into the database file
    BufferedWriter writer = new BufferedWriter(new FileWriter(mDatabaseFile.getPath()));
    writer.write("blah");
    writer.close();
    assertTrue(mDatabaseFile.exists());
    // should trigger call to MyDatabaseCorruptionHandler.onCorruption
    try {
        mDatabase.execSQL("select * from t;");
        fail("expected exception");
    } catch (SQLiteDiskIOException e) {
        // expected
        if (mDatabaseFile.exists()) {
            mDatabaseFile.delete();
        }
    } catch (SQLiteException e) {
    }
    // database file should be gone
    assertFalse(mDatabaseFile.exists());
    // after corruption handler is called, the database file should be free of
    // database corruption
    SQLiteDatabase db = SQLiteDatabase.openOrCreateDatabase(mDatabaseFile.getPath(), null, new MyDatabaseCorruptionHandler());
    assertTrue(db.isDatabaseIntegrityOk());
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase) FileWriter(java.io.FileWriter) SQLiteDiskIOException(android.database.sqlite.SQLiteDiskIOException) SQLiteException(android.database.sqlite.SQLiteException) BufferedWriter(java.io.BufferedWriter)

Example 10 with SQLiteDiskIOException

use of android.database.sqlite.SQLiteDiskIOException in project android_frameworks_base by DirtyUnicorns.

the class MtpDocumentsProvider method onCreate.

@Override
public boolean onCreate() {
    sSingleton = this;
    mContext = getContext();
    mResources = getContext().getResources();
    mMtpManager = new MtpManager(getContext());
    mResolver = getContext().getContentResolver();
    mDeviceToolkits = new HashMap<Integer, DeviceToolkit>();
    mDatabase = new MtpDatabase(getContext(), MtpDatabaseConstants.FLAG_DATABASE_IN_FILE);
    mRootScanner = new RootScanner(mResolver, mMtpManager, mDatabase);
    mAppFuse = new AppFuse(TAG, new AppFuseCallback());
    mIntentSender = new ServiceIntentSender(getContext());
    // after booting.
    try {
        final int bootCount = Settings.Global.getInt(mResolver, Settings.Global.BOOT_COUNT, -1);
        final int lastBootCount = mDatabase.getLastBootCount();
        if (bootCount != -1 && bootCount != lastBootCount) {
            mDatabase.setLastBootCount(bootCount);
            final List<UriPermission> permissions = mResolver.getOutgoingPersistedUriPermissions();
            final Uri[] uris = new Uri[permissions.size()];
            for (int i = 0; i < permissions.size(); i++) {
                uris[i] = permissions.get(i).getUri();
            }
            mDatabase.cleanDatabase(uris);
        }
    } catch (SQLiteDiskIOException error) {
        // It can happen due to disk shortage.
        Log.e(TAG, "Failed to clean database.", error);
        return false;
    }
    // TODO: Mount AppFuse on demands.
    try {
        mAppFuse.mount(getContext().getSystemService(StorageManager.class));
    } catch (IOException error) {
        Log.e(TAG, "Failed to start app fuse.", error);
        return false;
    }
    resume();
    return true;
}
Also used : StorageManager(android.os.storage.StorageManager) SQLiteDiskIOException(android.database.sqlite.SQLiteDiskIOException) IOException(java.io.IOException) Uri(android.net.Uri) Point(android.graphics.Point) UriPermission(android.content.UriPermission) SQLiteDiskIOException(android.database.sqlite.SQLiteDiskIOException)

Aggregations

SQLiteDiskIOException (android.database.sqlite.SQLiteDiskIOException)12 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)6 SQLiteException (android.database.sqlite.SQLiteException)6 BufferedWriter (java.io.BufferedWriter)6 FileWriter (java.io.FileWriter)6 UriPermission (android.content.UriPermission)5 Point (android.graphics.Point)5 Uri (android.net.Uri)5 StorageManager (android.os.storage.StorageManager)5 IOException (java.io.IOException)5 IBannerAd (com.abewy.android.ads.IBannerAd)1 Ad (com.google.ads.Ad)1 AdListener (com.google.ads.AdListener)1 ErrorCode (com.google.ads.AdRequest.ErrorCode)1 AdView (com.google.ads.AdView)1