As a student researcher, I would like to know if there is an in app code to root an android kitkat device without the user knowing it(discreetly). If there is any open source app code to root a phone, then that will do the task. I have looked at many rooting apps but could not find any open source code for those.
It's not possible in general. It's normally necessary to unlock the bootloader, which requires the user to acknowledge on-screen that all user data will be deleted. The only way to avoid this is when there's some specific kernel-mode vulnerability to exploit, and of course the method to do so is specific to a particular device and ROM version, and usually doesn't work in later updates after the vulnerability has been fixed. For example, the exynos4 camera driver vulnerability allows "one-click" rooting of some exynos4-based devices, but it's been fixed with OTA updates, so up-to-date devices aren't vulnerable to it.