Skip to content
This repository has been archived by the owner on Mar 16, 2021. It is now read-only.

android-DirectBoot #133

Open
malangstudio opened this issue Jul 24, 2018 · 3 comments
Open

android-DirectBoot #133

malangstudio opened this issue Jul 24, 2018 · 3 comments

Comments

@malangstudio
Copy link

malangstudio commented Jul 24, 2018

https://android-developers.googleblog.com/2016/04/developing-for-direct-boot.html

Do you support this feature?

@malangstudio
Copy link
Author

TrayContentProvider.java

like this ?

onCreate() >>

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            storageContext = getContext().createDeviceProtectedStorageContext();

            if (storageContext.moveDatabaseFrom(getContext(), TrayDBHelper.DATABASE_NAME)) {
                Log.d("TrayContentProvider", "[TrayDBHelper] TrayDBHelper.DATABASE_NAME.moveDatabaseFrom : true");
            } else {
                Log.d("TrayContentProvider", "[TrayDBHelper] TrayDBHelper.DATABASE_NAME.moveDatabaseFrom : false");
            }

            if (storageContext.moveDatabaseFrom(getContext(), TrayDBHelper.DATABASE_NAME_NO_BACKUP)) {
                Log.d("TrayContentProvider", "[TrayDBHelper] TrayDBHelper.DATABASE_NAME_NO_BACKUP.moveDatabaseFrom : true");
            } else {
                Log.d("TrayContentProvider", "[TrayDBHelper] TrayDBHelper.DATABASE_NAME_NO_BACKUP.moveDatabaseFrom : false");
            }

        } else {
            storageContext = getContext();
        }

        mUserDbHelper = new TrayDBHelper(storageContext, true);
        mDeviceDbHelper = new TrayDBHelper(storageContext, false);

@StefMa
Copy link
Contributor

StefMa commented Jul 26, 2018 via email

@fython
Copy link

fython commented Aug 29, 2018

My project using Tray needs this feature too. But I recommend not to modify TrayContentProvider.java to use Context#createDeviceProtectedStorageContext() like @malangstudio 's #133 (comment) . Users should decide if using device protected storage context or a normal context by themselves.

For example:

final Context storageContext;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
    storageContext = context.createDeviceProtectedStorageContext();
} else {
    storageContext = context;
}
mPreferences = new TrayPreferences(storageContext, PREF_NAME, 1);

However, I found Tray didn't work well with device protected storage context. I got stack trace logs:

E/SQLiteDatabase: Error inserting MIGRATED_KEY=null UPDATED=1535531359059 CREATED=1535531359059 MODULE=screenshot VALUE=true KEY=preview_floating_window
    android.database.sqlite.SQLiteReadOnlyDatabaseException: attempt to write a readonly database (code 1032)
        at android.database.sqlite.SQLiteConnection.nativeExecuteForLastInsertedRowId(Native Method)
        at android.database.sqlite.SQLiteConnection.executeForLastInsertedRowId(SQLiteConnection.java:785)
        at android.database.sqlite.SQLiteSession.executeForLastInsertedRowId(SQLiteSession.java:788)
        at android.database.sqlite.SQLiteStatement.executeInsert(SQLiteStatement.java:86)
        at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1548)
        at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1417)
        at net.grandcentrix.tray.provider.SqliteHelper.insertOrUpdate(SqliteHelper.java:148)
        at net.grandcentrix.tray.provider.TrayContentProvider.insertOrUpdate(TrayContentProvider.java:208)
        at net.grandcentrix.tray.provider.TrayContentProvider.insert(TrayContentProvider.java:188)
        at android.content.ContentProvider$Transport.insert(ContentProvider.java:265)
        at android.content.ContentResolver.insert(ContentResolver.java:1539)
        at net.grandcentrix.tray.provider.TrayProviderHelper.persist(TrayProviderHelper.java:151)
        at net.grandcentrix.tray.provider.ContentProviderStorage.put(ContentProviderStorage.java:260)
        at net.grandcentrix.tray.provider.ContentProviderStorage.put(ContentProviderStorage.java:231)
        at net.grandcentrix.tray.core.Preferences.putData(Preferences.java:310)
        at net.grandcentrix.tray.core.Preferences.put(Preferences.java:171)
        at moe.feng.nevo.decorators.enscreenshot.ScreenshotPreferences.setPreviewInFloatingWindow(ScreenshotPreferences.java:207)

I can guarantee that data can be read and written with device protected storage context. But logs told me the database is readonly. Do you have any idea?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

3 participants