In the NotificationManagerService.java from Android 5.0 framework source code. I don't understand when the uid will be zero.
private static boolean isUidSystem(int uid) {
final int appid = UserHandle.getAppId(uid);
return (appid == Process.SYSTEM_UID || appid == Process.PHONE_UID || uid == 0);
}
Android's
Processclass contains the following definitions (among others):These framework values correspond to kernel
uids for theroot,system, andradiousers. In Android, many system processes run as one of these threeuids.NotificationManagerService uses
isUidSystem()to check if the calling process is owned by one of these users and if so, set the booleanisSystemNotification(it also ends up true if the package name begins withandroid.*).Note that
isSystemUiddoesn't directly compare the callinguidwith the above values, but first runs it throughUserHandle.getAppId(), which takes the kernel value and mods it withUserHandle.PER_USER_RANGE, normally defined as 100000 (i.e.,uid % PER_USER_RANGE). This ends up being the last five digits of the kerneluid, where the first two correspond to theuserIdon multi-user devices.So the
uidandappIdwill be 0 for processes and apps that are running as the root user, andisSystemUid()will returntruein this case. It will also return true whenever the uid is from a caller running as thesystemorradiouser.