Reputation:
Is is possible to access an android service in the framework out of the Dalvik VM?
I want to make modifications in some classes of the Dalvik VM (e.g. libcore/luni classes) and want to get a result from a service back (with a database and other operations).
Is this possible?
Upvotes: 1
Views: 471
Reputation: 4353
Keep in mind that the framework won't be running / set up in all possible contexts that Dalvik runs in.
That said, as a quick hack you might be able to use reflection to get a hold of framework classes.
The right way, though, would be to define an API in the Dalvik core, consisting of something like an interface and a static method, where the static method registers an instance of the interface for the core library to use. Then, in the framework, add code to call that registration function. Something like this (very simplified here, e.g. you'd want error / permission checks):
In libcore:
public interface TheInterface {
void doSomethingInteresting();
...
}
public class TheRegistrar {
private static TheInterface theOne;
public static void register(TheInterface instance) {
theOne = instance;
}
public static TheInterface get() {
return theOne;
}
}
Then, in the libcore code that wants to use this, have it do a get()
(and be prepared to deal with the case where it's null
).
And in the framework, define something like:
public class FrameworkDoohicky implements TheInterface {
...
}
and register it with a call to TheRegistrar.register()
during framework initialization.
Upvotes: 1