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
Process
class contains the following definitions (among others):These framework values correspond to kernel
uid
s for theroot
,system
, andradio
users. In Android, many system processes run as one of these threeuid
s.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
isSystemUid
doesn't directly compare the callinguid
with 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 theuserId
on multi-user devices.So the
uid
andappId
will be 0 for processes and apps that are running as the root user, andisSystemUid()
will returntrue
in this case. It will also return true whenever the uid is from a caller running as thesystem
orradio
user.