Yes, you can, but even then, you can’t be 100.000% certain that that code will get executed. Google, your phone manufacturer, big brother, etc. _could_ detect that you’re running Foo and do Bar instead. Most people shouldn’t worry about that, though. I would be more worried about ‘them’ listening to what you do than about ‘them’ changing what you do (and if they want to, ‘they’ likely can do that easier outside your app or even outside your phone than on it)
As to iOS, if you can get the source, you can build and install apps yourself on iOS, too, with the disadvantage that you will have to reinstall the app every x days (executables signed for debugging have an expiry date), with ‘x’ relatively short (a few weeks, IIRC)