When you import third party APIs (packet dependency injection, generated libraries, source code, etc) in your Android project, you assume they will behave as advertised. Most of the times code is not open source, it is obfuscated or just compiled.
Is there a way to control the access of this APIs to important system resources such as network, contacts, video and audio, location?
The best approach would be to provide a proxy
to them for the system resources. This would have the following benefits:
I have failed to find how one such solution can be implemented since the user's defined activities and services can not control the services of the third party APIs or even prevent them for making direct calls to any Android public interface.
The solution should not require root access, since you do not want to have this control outside the boundaries of your own app.
The content of this question is linked to several questions which address particularities of this broad question (log data of content providers, network requests - that got me to think of this problem while researching an answer for it)
Note: The short answer is no, but one can be creative enough (maybe going for native level hacks may resolve this issue - idk)
Build proxy class for your desired android resource you want to protect in a package named com.myproxies (e.g. MediaRecorder, SensorManager, Camera, java.net.HTTPURLConnection).In the proxy you need to implement all of the public methods of the class you are mocking and you need to implemented logic to allow for access (forward to appropriate method) or deny. One helpful step would be to check the caller of the method.
If you plan to import source code, refactor code to change package to your proxy (proguard can help with this).
If you are using a library, get Jar Jar Links,a utility that makes it easy to repackage Java libraries and embed them into your own distribution, and change the package names internally to that of a class in your package that will serve as a proxy.
If you are using Maven or Gradle package dependency injection, you can also try to import Jar Jar Links and perform the package refactoring at compile time (not very sure it can be done)
Unfortunately it is very easy to break the API, as I experienced myself, and there is a lot of manual labour involved.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With