Skip to content

SQLiteContentHelper.getBlobColumnAsAssetFile should return AssetFileDescriptor? #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
tandanil opened this issue Sep 1, 2011 · 10 comments

Comments

@tandanil
Copy link

tandanil commented Sep 1, 2011

I am looking at an error in my build and found that SQLCipher's implementation of SQLiteContentHelper.getBlobColumnAsAssetFile is returning a MemoryFile instead of AssetFileDescriptor.
I have googled this and all the src I've seen return AssetFileDescriptor.

@karanfp
Copy link

karanfp commented Sep 19, 2011

You can convert a MemoryFile to AssetFileDescriptor using :

ParcelFileDescriptor fd = memoryFile.getParcelFileDescriptor();
AssetFileDescriptor mFD = new AssetFileDescriptor(fd, 0, memoryFile.length());

@tandanil
Copy link
Author

Hi Karan

Yes, I know I can do that. But by definition getBlobColumnAsAssetFile is supposed to return AssetFileDescriptor. Is there any reason why this was changed for sqlcipher?

Thx

Danilo

-----Original Message-----
From: Karan Popali [mailto:reply@reply.github.com]
Sent: Monday, September 19, 2011 6:51 AM
To: Tan, Danilo
Subject: Re: [android-database-sqlcipher] SQLiteContentHelper.getBlobColumnAsAssetFile should return AssetFileDescriptor? (#7)

You can convert a MemoryFile to AssetFileDescriptor using :

ParcelFileDescriptor fd = memoryFile.getParcelFileDescriptor();
AssetFileDescriptor mFD = new AssetFileDescriptor(fd, 0, memoryFile.length());

Reply to this email directly or view it on GitHub:
https://github.com/guardianproject/android-database-sqlcipher/issues/7#issuecomment-2132377

@n8fr8
Copy link
Collaborator

n8fr8 commented Oct 31, 2011

Danilo:

Please test out our Developer Preview 3 release, and see if this has resolved your concern:
https://github.com/downloads/guardianproject/android-database-sqlcipher/SQLCipherForAndroid-SDK-0.0.6-BETA-DP3.tar.gz

In many cases before, we were reimplementing core pieces of the android.database.* API. However, we have been trying to reuse or just build upon existing code in android.database.* where and when we can. Our goal is as close to 100% API compatibility when we can get it, but we cannot always.

Thanks.

@tandanil
Copy link
Author

ok. will give it a go and let you know.

thx

dt
On 10/30/2011 10:23 PM, n8fr8 wrote:

Danilo:

Please test out our Developer Preview 3 release, and see if this has resolved your concern:
https://github.com/downloads/guardianproject/android-database-sqlcipher/SQLCipherForAndroid-SDK-0.0.6-BETA-DP3.tar.gz

In many cases before, we were reimplementing core pieces of the android.database.* API. However, we have been trying to reuse or just build upon existing code in android.database.* where and when we can. Our goal is as close to 100% API compatibility when we can get it, but we cannot always.

Thanks.

@tandanil
Copy link
Author

tandanil commented Nov 1, 2011

Hi Nathan

I checked the SQLiteContentHelper.java and the method getBlobColumnAsAssetFile is still returning a MemoryFile instead of the normal AssetFileDescriptor.

thx

Danilo

@tandanil
Copy link
Author

tandanil commented Nov 1, 2011

Btw, this is what i did for getBlobColumnAsAssetFile to keep the API consistent...

public static AssetFileDescriptor getBlobColumnAsAssetFile(SQLiteDatabase db, String sql,
        String[] selectionArgs) throws FileNotFoundException {
    android.os.ParcelFileDescriptor fd = null;

    try {
        MemoryFile file = simpleQueryForBlobMemoryFile(db, sql, selectionArgs);
        if (file == null) {
            throw new FileNotFoundException("No results.");
        }
        Class c = file.getClass();
        try {
            java.lang.reflect.Method m = c.getDeclaredMethod("getParcelFileDescriptor");
            m.setAccessible(true);
            fd = (android.os.ParcelFileDescriptor)m.invoke(file);
        } catch (Exception e) {
            android.util.Log.i("SQLiteContentHelper", "SQLiteCursor.java: " + e);
        }       
        AssetFileDescriptor afd = new AssetFileDescriptor(fd, 0, file.length());
        return afd;
    } catch (IOException ex) {
        throw new FileNotFoundException(ex.toString());
    }
}

@n8fr8
Copy link
Collaborator

n8fr8 commented Nov 2, 2011

Ah right. Just digging into this more, and the reason we couldn't return the AssetFileDescriptor, as you realized, was that the needed method was within the "hidden" android.os package. Your use of reflection does seem to solve it.

Will consider integration.

@n8fr8
Copy link
Collaborator

n8fr8 commented Nov 2, 2011

Your code has been included and committed. Thanks for the fix!

guardianproject/android-database-sqlcipher@b5ecbd0

@n8fr8 n8fr8 closed this as completed Nov 2, 2011
@tandanil
Copy link
Author

tandanil commented Nov 2, 2011

Great! Glad to help.

Btw, something you may want to consider as well.

I had replaced all references to SQLiteException to use the android
version instead of the guardianproject one.

The reason is I hit a case where the framework (I forget which one)
returned an android.database.sqlite.SQLiteException and I did not catch
it as I was looking for guardianproject.

Anyway, since the sqlcipher version of the exception is the same (except
for package name) as the android one, maybe it would be good to just
have sqlcipher use the android exception?

thx

dt

On 11/02/2011 11:11 AM, n8fr8 wrote:

Your code has been included and committed. Thanks for the fix!

guardianproject/android-database-sqlcipher@b5ecbd0

@n8fr8
Copy link
Collaborator

n8fr8 commented Nov 2, 2011

Yes, we are slowly figuring out which redundant classes we should remove. Seems like SQLiteException might be a good candidate.

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

No branches or pull requests

3 participants