System application in Android

1.9k Views Asked by At

How exactly Android determines if an application is a system application with root privilege?

I know that for such applications, ApplicationInfo.FLAG_SYSTEM will be enabled, and those applications must declare shared user id as "android.uid.system" in their Manifest file. Along with that there is another criteria, where an application located in /system/app should also be treated as System application.

I searched the source code for PackageMangerService.java in AOSP where I observed that if shared user id is android.uid.system then the application is assigned the flag as FLAG_SYSTEM.

But I guess, the applications which are available in /system/app do not contain the shared user id as android.uid.system then how do they get this flag FLAG_SYSTEM enabled for them?

3

There are 3 best solutions below

0
Marcin Orlowski On

if an application is a 'system application' with root privilege

It must be signed with right, system certificate.

0
Jordi Castilla On

The apps in Android devices can be System apps or User apps, this is only based on their installation location.

  • User apps are placed in the /data partition of your Android phone, which is the part of the internal memory made available for user data and apps.
  • System apps are those installed in /system partition.

Wow... that's all? Great! Sound easy... how can I do it?

May sound easy, but it is not, you will need to:

  • Root you phone
  • Add valid signed secure cert
  • Give permissions
  • And more headaches...

But is not impossible either, check this tutorial.

0
Qian On

Ah ha, I had read the code in PackageManagerService.java before. It has a observer to check if any files in /system/priv-app/ directory has changed. And it will install the app if there is a new apk file. Then the system will set the pkgFlags with ApplicationInfo.FLAG_PRIVILEGED

the following is the code in PackageManagerService in Android 5.0:

private PackageParser.Package scanPackageLI(File scanFile, int parseFlags, int scanFlags,
        long currentTime, UserHandle user) {
    ....
    if (locationIsPrivileged(scanFile)) {
        updatedPkg.pkgFlags |= ApplicationInfo.FLAG_PRIVILEGED;
    }
    ....
}