How to access another application with SQLCipher database, passing the password in the Content Provider?

1

In the code below, I grant access to the database in app1, using Content Provider, which makes use of SQLCipher:

App1

public class StudentsProvider extends ContentProvider {

private SQLiteDatabase db;

@Override
public boolean onCreate() {
    Context context = getContext();
    DatabaseHelper dbHelper = new DatabaseHelper(context);
    SQLiteDatabase.loadLibs(context);
    db = dbHelper.getWritableDatabase("password");
    return db != null;
}

In app2, I query in the app1 database:

App2

static final String PROVIDER_NAME = "com.example.a436236692.myapplication.StudentsProvider";
static final String URL = "content://" + PROVIDER_NAME + "/students";
static final Uri CONTENT_URI = Uri.parse(URL);
private void carregaResultados() {
    ContentResolver cr = getContentResolver();
    Cursor c = cr.query(CONTENT_URI, null, null, null, null);
    if (c.moveToFirst()){
        //reading db...
    }
}

But I want to pass the password through the Content Provider, from app2 to app1 and change that hardcode :

  

db = dbHelper.getWritableDatabase ("password");

What is the best way to do this?

Thank you!

    
asked by anonymous 08.08.2017 / 14:47

1 answer

1
As far as I know this is not possible.

What you should do is set permissions that applications that want to access the provider must have.

In the application's AndroidManifest, declare one or more <permission> elements:

...
<permission android:name="com.example.myapp.permission.DEADLY_ACTIVITY"
    android:label="@string/permlab_deadlyActivity"
    android:description="@string/permdesc_deadlyActivity"
    android:permissionGroup="android.permission-group.COST_MONEY"
    android:protectionLevel="dangerous" />
...

Applications wishing to use the provider will have to declare their <uses-permission> on their AndroidManifest.

References:

08.08.2017 / 15:06