I have two Android apps : 'A' and 'B'.
When 'B' tries to execute a method 'x','A' must do some pretest, then it decides if 'B' can execute this method or not.
I need a solution that keeps the 'B' app unchanged (without including a method call to 'A').
Example: if 'B' tries to execute a heavy-computational method it needs authorization from 'A' to execute it locally or remotely.
That's not possible. Nor should it be possible.
If this were possible, since you don't want to change "B", then any app could prevent any other app from executing part of their code, whenever they wanted to. That would be a complete breach of the Android security/privileges system.
What you can do is let "B" decide for itself if it should execute this function. And, if it turns out to be very labor-intensive, let "B" run this operation in the background as a Service.
If you are willing to make small changes in "B", it becomes possible. Let "B" send an Intent to "A" asking it to do the pre-test. Then depending on the result it gets from "A", it decides if it will execute the function.