You can get the foreground app and check for its permissions using the PackageManager
class.
To get the foreground application you can go through this link.
Once you get the foreground app, you can fetch the permissions of that app. Check this link for this functionality.
Later, You can check whether its a system app or not by going through getApplicationInfo
and later & with ApplicationInfo.FLAG_SYSTEM
. You can check this link on how to do that.