Easily Generate and Export Material Design Palletes

For many people, it can be pretty difficult to create a palette of complementary colors. … more

Android One Expanding to Bangladesh, Nepal, and Sri Lanka

At Google I/O 2013, Google proudly announced that the Android operating system was … more

Android 5.0.2 Fixes 2012 Nexus 7! Sony’s Making a Google Glass Competitor? – XDA TV

Android 5.0.2 Lollipop is available for the … more

Early Lollipop Ports for Micromax A116 and A117

It feels like it was only yesterday when Google announced the mysterious Android L.After … more

Welcome to XDA

Search to go directly to your device's forum

Register an account

Unlock full posting privileges

Ask a question

No registration required
Post Reply

Xposed module with sqlite (without context

OP shnapsi

4th September 2014, 04:38 PM   |  #1  
OP Member
Thanks Meter: 0
 
50 posts
Join Date:Joined: Aug 2014
Hi,

I want to use sqlite in my xposed module but i don't have any activity or context to send the database constructor.
Is it possible to overcome this?
I tried to send null as a context, but i'm getting nullPointerException when i try to open the database.

Thanks,
Gidi
5th September 2014, 03:38 AM   |  #2  
GermainZ's Avatar
Forum Moderator / Recognized Developer / XDA Portal Team
Thanks Meter: 7,337
 
5,911 posts
Join Date:Joined: Aug 2012
More
If you can't get a context from the method you're hooking, you could try the AndroidAppHelper.currentApplication method.
5th September 2014, 06:24 PM   |  #3  
Senior Member
Thanks Meter: 608
 
519 posts
Join Date:Joined: Jan 2013
More
Code:
Context ctx = AndroidAppHelper.currentApplication();
Context myCtx = ctx.createPackageContext("com.developer.app");
7th September 2014, 07:26 AM   |  #4  
OP Member
Thanks Meter: 0
 
50 posts
Join Date:Joined: Aug 2014
Quote:
Originally Posted by pyler

Code:
Context ctx = AndroidAppHelper.currentApplication();
Context myCtx = ctx.createPackageContext("com.developer.app");

HI Guys,

I tried the AndroidAppHelper.currentApplication() option, but it returns NULL in my case...
7th September 2014, 07:45 AM   |  #5  
elesbb's Avatar
Senior Member
Thanks Meter: 4,469
 
6,922 posts
Join Date:Joined: Jun 2010
Donate to Me
More
Quote:
Originally Posted by shnapsi

HI Guys,

I tried the AndroidAppHelper.currentApplication() option, but it returns NULL in my case...

If you are editing a database using sqlite and the current process you are hooking as no context reference, you can use root to set the database file to readable, then have your own service running in the background with a file observer tracking changes to a file on the device. Inside xposed module you will write to the file with a command instructing the file observer what to do. Then your service will "hear" the command and execute the changes needed.

I plan on writing up a guide for this. Tomorrow
7th September 2014, 04:45 PM   |  #6  
OP Member
Thanks Meter: 0
 
50 posts
Join Date:Joined: Aug 2014
Quote:
Originally Posted by elesbb

If you are editing a database using sqlite and the current process you are hooking as no context reference, you can use root to set the database file to readable, then have your own service running in the background with a file observer tracking changes to a file on the device. Inside xposed module you will write to the file with a command instructing the file observer what to do. Then your service will "hear" the command and execute the changes needed.

I plan on writing up a guide for this. Tomorrow


Thanks, I'll be happy to read your guide and learn new stuff

Anyway, I read that it's possible to use Sqlite DB without using SQLiteOpenHelper, this way, i don't need context.
the problem is that when i do it i get exception:

android.database.sqlite.SQLiteCantOpenDatabaseExce ption: unknown error (code 14): Could not open database

this is my code:

database = SQLiteDatabase.openOrCreateDatabase(DB_NAME,null);
database.execSQL(CREATE_TABLE);

Thanks.
7th September 2014, 08:58 PM   |  #7  
GermainZ's Avatar
Forum Moderator / Recognized Developer / XDA Portal Team
Thanks Meter: 7,337
 
5,911 posts
Join Date:Joined: Aug 2012
More
Quote:
Originally Posted by shnapsi

Thanks, I'll be happy to read your guide and learn new stuff

Anyway, I read that it's possible to use Sqlite DB without using SQLiteOpenHelper, this way, i don't need context.
the problem is that when i do it i get exception:

android.database.sqlite.SQLiteCantOpenDatabaseExce ption: unknown error (code 14): Could not open database

this is my code:

database = SQLiteDatabase.openOrCreateDatabase(DB_NAME,null);
database.execSQL(CREATE_TABLE);

Thanks.

You probably don't have the required permissions to read/write to that location.
9th September 2014, 07:40 AM   |  #8  
OP Member
Thanks Meter: 0
 
50 posts
Join Date:Joined: Aug 2014
Quote:
Originally Posted by GermainZ

You probably don't have the required permissions to read/write to that location.

Thanks GermainZ,
which permissions do i need?
I tried to do it this way too:

Code:
 File db = new File("/data/data/com.example.mytest/databases/" + DB_NAME);
    	db.setReadable(true);
    	db.setWritable(true);
    	File path = new File("/data/data/com.example.mytest/databases/");
    	path.setReadable(true);
    	path.setWritable(true);
    	path.mkdirs();
    	database = SQLiteDatabase.openOrCreateDatabase(db,null);
Still same result...

Thanks!
9th September 2014, 08:03 AM   |  #9  
GermainZ's Avatar
Forum Moderator / Recognized Developer / XDA Portal Team
Thanks Meter: 7,337
 
5,911 posts
Join Date:Joined: Aug 2012
More
Quote:
Originally Posted by shnapsi

Thanks GermainZ,
which permissions do i need?
I tried to do it this way too:

Code:
 File db = new File("/data/data/com.example.mytest/databases/" + DB_NAME);
    	db.setReadable(true);
    	db.setWritable(true);
    	File path = new File("/data/data/com.example.mytest/databases/");
    	path.setReadable(true);
    	path.setWritable(true);
    	path.mkdirs();
    	database = SQLiteDatabase.openOrCreateDatabase(db,null);
Still same result...

Thanks!

Let's differentiate between two things: your module (normal code) and the hooked process (the Xposed code).

Remember that hooked code runs as the hooked process (that is, the app you're hooking *not* your module), so you won't be able to write to your module's data directory.

I don't know if you can change that. Maybe you could create the database and use Context.MODE_WORLD_WRITABLE (from your module, when it firsts open), but I don't think you'll have any luck creating it from the hooked process directly.
9th September 2014, 08:49 AM   |  #10  
OP Member
Thanks Meter: 0
 
50 posts
Join Date:Joined: Aug 2014
Quote:
Originally Posted by GermainZ

Let's differentiate between two things: your module (normal code) and the hooked process (the Xposed code).

Remember that hooked code runs as the hooked process (that is, the app you're hooking *not* your module), so you won't be able to write to your module's data directory.

I don't know if you can change that. Maybe you could create the database and use Context.MODE_WORLD_WRITABLE (from your module, when it firsts open), but I don't think you'll have any luck creating it from the hooked process directly.

So where is the best place to use AndroidAppHelper.currentApplication(); so it won't return null and i will be able to use it in my hooked method?

Post Reply Subscribe to Thread
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes