Android:进程UID定义
来源:互联网 发布:网络运维管理论坛 编辑:程序博客网 时间:2024/06/05 11:29
当在adb shell中查询当前进程情况时(ps),可以看到app应用都分配了一个user属性,
如app_37分配给了自己创建的应用com.andy.androidtest,在不卸载这个应用之前,这个属性是保持不变的。
非系统的应用都是以app开头命名,之后的编号就是uid(确切的说是uid-10000)。
# pspsUSER PID PPID VSIZE RSS WCHAN PC NAMEroot 1 0 312 220 c009b74c 0000ca4c S /initroot 2 0 0 0 c004e72c 00000000 S kthreaddroot 3 2 0 0 c003fdc8 00000000 S ksoftirqd/0root 4 2 0 0 c004b2c4 00000000 S events/0root 5 2 0 0 c004b2c4 00000000 S khelperroot 6 2 0 0 c004b2c4 00000000 S suspendroot 7 2 0 0 c004b2c4 00000000 S kblockd/0root 8 2 0 0 c004b2c4 00000000 S cqueueroot 9 2 0 0 c018179c 00000000 S kseriodroot 10 2 0 0 c004b2c4 00000000 S kmmcdroot 11 2 0 0 c006fc74 00000000 S pdflushroot 12 2 0 0 c006fc74 00000000 S pdflushroot 13 2 0 0 c00744e4 00000000 S kswapd0root 14 2 0 0 c004b2c4 00000000 S aio/0root 22 2 0 0 c017ef48 00000000 S mtdblockdroot 23 2 0 0 c004b2c4 00000000 S kstripedroot 24 2 0 0 c004b2c4 00000000 S hid_compatroot 25 2 0 0 c004b2c4 00000000 S rpciod/0root 26 2 0 0 c019d16c 00000000 S mmcqdroot 27 1 740 220 c0158eb0 afd0d8ac S /system/bin/shsystem 28 1 808 208 c01a94a4 afd0db4c S /system/bin/servicemanagerroot 29 1 3736 492 ffffffff afd0e1bc S /system/bin/voldroot 30 1 3716 460 ffffffff afd0e1bc S /system/bin/netdroot 31 1 668 200 c01b52b4 afd0e4dc S /system/bin/debuggerdradio 32 1 5392 616 ffffffff afd0e1bc S /system/bin/rildroot 33 1 102056 25344 c009b74c afd0dc74 S zygotemedia 34 1 22764 3412 ffffffff afd0db4c S /system/bin/mediaserverroot 35 1 812 276 c02181f4 afd0d8ac S /system/bin/installdkeystore 36 1 1616 336 c01b52b4 afd0e4dc S /system/bin/keystoreroot 37 1 740 224 c003da38 afd0e7bc S /system/bin/shroot 38 1 852 296 c00b8fec afd0e90c S /system/bin/qemudroot 40 1 3396 188 ffffffff 0000ecc4 S /sbin/adbdroot 51 37 796 252 c02181f4 afd0d8ac S /system/bin/qemu-propssystem 59 33 190964 39172 ffffffff afd0db4c S system_serverapp_23 110 33 139004 20216 ffffffff afd0eb08 S jp.co.omronsoft.openwnnradio 114 33 145612 22484 ffffffff afd0eb08 S com.android.phoneapp_25 117 33 150104 24568 ffffffff afd0eb08 S com.android.launchersystem 119 33 137096 18980 ffffffff afd0eb08 S com.android.settingsapp_0 151 33 144956 24500 ffffffff afd0eb08 S android.process.acoreapp_22 162 33 132052 18252 ffffffff afd0eb08 S com.android.musicapp_12 171 33 133680 18712 ffffffff afd0eb08 S com.android.quicksearchboxapp_7 180 33 130900 17920 ffffffff afd0eb08 S com.android.protipsapp_2 189 33 134704 19272 ffffffff afd0eb08 S android.process.mediaapp_9 203 33 131712 18736 ffffffff afd0eb08 S com.android.alarmclockapp_15 214 33 144660 19600 ffffffff afd0eb08 S com.android.mmsroot 222 40 740 228 c003da38 afd0e7bc S /system/bin/shroot 223 222 692 292 c009b74c afd0dc74 S logcatapp_10 232 33 132760 17612 ffffffff afd0eb08 S com.android.defcontainerapp_30 247 33 135192 20036 ffffffff afd0eb08 S com.android.emailapp_28 262 33 130696 17408 ffffffff afd0eb08 S com.svox.picoroot 285 40 740 332 c003da38 afd0e7bc S /system/bin/shapp_37 598 33 132460 19900 ffffffff afd0eb08 S com.andy.androidtestroot 605 285 888 336 00000000 afd0d8ac R ps
通过下面的代码我们可以枚举所有在运行的process的uid等属性:
private RunningAppProcessInfo getForegroundApp(){RunningAppProcessInfo result = null, info = null;if (mActivityManager == null)mActivityManager = (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE);List<RunningAppProcessInfo> l = mActivityManager.getRunningAppProcesses();Iterator<RunningAppProcessInfo> i = l.iterator();while (i.hasNext()){info = i.next();Log.v(TAG,"running app process:"+String.valueOf(info.uid)+" "+info.processName);if (info.importance == RunningAppProcessInfo.IMPORTANCE_FOREGROUND&& !isRunningService(info.processName)){result = info;//Log.v(TAG,"running app:"+info.processName);break;}}return result;}
输出结果:
10-25 08:41:16.766: V/ANDROIDTEST(598): running app process:10037 com.andy.androidtest
10-25 08:41:16.774: V/ANDROIDTEST(598): running app process:10025 com.android.launcher
10-25 08:41:16.774: V/ANDROIDTEST(598): running app process:10028 com.svox.pico
10-25 08:41:16.774: V/ANDROIDTEST(598): running app process:10010 com.android.defcontainer
10-25 08:41:16.774: V/ANDROIDTEST(598): running app process:10002 android.process.media
10-25 08:41:16.774: V/ANDROIDTEST(598): running app process:10012 com.android.quicksearchbox
10-25 08:41:16.774: V/ANDROIDTEST(598): running app process:10022 com.android.music
10-25 08:41:16.774: V/ANDROIDTEST(598): running app process:10007 com.android.protips
10-25 08:41:16.774: V/ANDROIDTEST(598): running app process:10023 jp.co.omronsoft.openwnn
10-25 08:41:16.785: V/ANDROIDTEST(598): running app process:1000 system
10-25 08:41:16.785: V/ANDROIDTEST(598): running app process:1001 com.android.phone
10-25 08:41:16.785: V/ANDROIDTEST(598): running app process:10030 com.android.email
10-25 08:41:16.785: V/ANDROIDTEST(598): running app process:10015 com.android.mms
10-25 08:41:16.795: V/ANDROIDTEST(598): running app process:10009 com.android.alarmclock
10-25 08:41:16.795: V/ANDROIDTEST(598): running app process:10000 android.process.acore
10-25 08:41:16.795: V/ANDROIDTEST(598): running app process:1000 com.android.settings
可以看出,这些应用的process 的 uid是大于10000的,ps显示的结果中app_xx,xx部分就是pid减去10000的结果,是一一对应的关系。
这个10000定义在下列文件中的:AID_APP
android_4.1_src\system\core\include\private\Android_filesystem_config.h
/* * Copyright (C) 2007 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *//* This file is used to define the properties of the filesystem** images generated by build tools (mkbootfs and mkyaffs2image) and** by the device side of adb.*/#ifndef _ANDROID_FILESYSTEM_CONFIG_H_#define _ANDROID_FILESYSTEM_CONFIG_H_#include <string.h>#include <sys/stat.h>#include <sys/types.h>/* This is the master Users and Groups config for the platform.** DO NOT EVER RENUMBER.*/#define AID_ROOT 0 /* traditional unix root user */#define AID_SYSTEM 1000 /* system server */#define AID_RADIO 1001 /* telephony subsystem, RIL */#define AID_BLUETOOTH 1002 /* bluetooth subsystem */#define AID_GRAPHICS 1003 /* graphics devices */#define AID_INPUT 1004 /* input devices */#define AID_AUDIO 1005 /* audio devices */#define AID_CAMERA 1006 /* camera devices */#define AID_LOG 1007 /* log devices */#define AID_COMPASS 1008 /* compass device */#define AID_MOUNT 1009 /* mountd socket */#define AID_WIFI 1010 /* wifi subsystem */#define AID_ADB 1011 /* android debug bridge (adbd) */#define AID_INSTALL 1012 /* group for installing packages */#define AID_MEDIA 1013 /* mediaserver process */#define AID_DHCP 1014 /* dhcp client */#define AID_SDCARD_RW 1015 /* external storage write access */#define AID_VPN 1016 /* vpn system */#define AID_KEYSTORE 1017 /* keystore subsystem */#define AID_USB 1018 /* USB devices */#define AID_DRM 1019 /* DRM server */#define AID_AVAILABLE 1020 /* available for use */#define AID_GPS 1021 /* GPS daemon */#define AID_UNUSED1 1022 /* deprecated, DO NOT USE */#define AID_MEDIA_RW 1023 /* internal media storage write access */#define AID_MTP 1024 /* MTP USB driver access */#define AID_NFC 1025 /* nfc subsystem */#define AID_DRMRPC 1026 /* group for drm rpc */#define AID_SHELL 2000 /* adb and debug shell user */#define AID_CACHE 2001 /* cache access */#define AID_DIAG 2002 /* access to diagnostic resources *//* The 3000 series are intended for use as supplemental group id's only. * They indicate special Android capabilities that the kernel is aware of. */#define AID_NET_BT_ADMIN 3001 /* bluetooth: create any socket */#define AID_NET_BT 3002 /* bluetooth: create sco, rfcomm or l2cap sockets */#define AID_INET 3003 /* can create AF_INET and AF_INET6 sockets */#define AID_NET_RAW 3004 /* can create raw INET sockets */#define AID_NET_ADMIN 3005 /* can configure interfaces and routing tables. */#define AID_NET_BW_STATS 3006 /* read bandwidth statistics */#define AID_NET_BW_ACCT 3007 /* change bandwidth statistics accounting */#define AID_MISC 9998 /* access to misc storage */#define AID_NOBODY 9999#define AID_APP 10000 /* first app user */#if !defined(EXCLUDE_FS_CONFIG_STRUCTURES)struct android_id_info { const char *name; unsigned aid;};static const struct android_id_info android_ids[] = { { "root", AID_ROOT, }, { "system", AID_SYSTEM, }, { "radio", AID_RADIO, }, { "bluetooth", AID_BLUETOOTH, }, { "graphics", AID_GRAPHICS, }, { "input", AID_INPUT, }, { "audio", AID_AUDIO, }, { "camera", AID_CAMERA, }, { "log", AID_LOG, }, { "compass", AID_COMPASS, }, { "mount", AID_MOUNT, }, { "wifi", AID_WIFI, }, { "dhcp", AID_DHCP, }, { "adb", AID_ADB, }, { "install", AID_INSTALL, }, { "media", AID_MEDIA, }, { "drm", AID_DRM, }, { "available", AID_AVAILABLE, }, { "nfc", AID_NFC, }, { "drmrpc", AID_DRMRPC, }, { "shell", AID_SHELL, }, { "cache", AID_CACHE, }, { "diag", AID_DIAG, }, { "net_bt_admin", AID_NET_BT_ADMIN, }, { "net_bt", AID_NET_BT, }, { "sdcard_rw", AID_SDCARD_RW, }, { "media_rw", AID_MEDIA_RW, }, { "vpn", AID_VPN, }, { "keystore", AID_KEYSTORE, }, { "usb", AID_USB, }, { "mtp", AID_MTP, }, { "gps", AID_GPS, }, { "inet", AID_INET, }, { "net_raw", AID_NET_RAW, }, { "net_admin", AID_NET_ADMIN, }, { "net_bw_stats", AID_NET_BW_STATS, }, { "net_bw_acct", AID_NET_BW_ACCT, }, { "misc", AID_MISC, }, { "nobody", AID_NOBODY, },};#define android_id_count \ (sizeof(android_ids) / sizeof(android_ids[0])) struct fs_path_config { unsigned mode; unsigned uid; unsigned gid; const char *prefix;};/* Rules for directories.** These rules are applied based on "first match", so they** should start with the most specific path and work their** way up to the root.*/static struct fs_path_config android_dirs[] = { { 00770, AID_SYSTEM, AID_CACHE, "cache" }, { 00771, AID_SYSTEM, AID_SYSTEM, "data/app" }, { 00771, AID_SYSTEM, AID_SYSTEM, "data/app-private" }, { 00771, AID_SYSTEM, AID_SYSTEM, "data/dalvik-cache" }, { 00771, AID_SYSTEM, AID_SYSTEM, "data/data" }, { 00771, AID_SHELL, AID_SHELL, "data/local/tmp" }, { 00771, AID_SHELL, AID_SHELL, "data/local" }, { 01771, AID_SYSTEM, AID_MISC, "data/misc" }, { 00770, AID_DHCP, AID_DHCP, "data/misc/dhcp" }, { 00775, AID_MEDIA_RW, AID_MEDIA_RW, "data/media" }, { 00775, AID_MEDIA_RW, AID_MEDIA_RW, "data/media/Music" }, { 00771, AID_SYSTEM, AID_SYSTEM, "data" }, { 00750, AID_ROOT, AID_SHELL, "sbin" }, { 00755, AID_ROOT, AID_SHELL, "system/bin" }, { 00755, AID_ROOT, AID_SHELL, "system/vendor" }, { 00755, AID_ROOT, AID_SHELL, "system/xbin" }, { 00755, AID_ROOT, AID_ROOT, "system/etc/ppp" }, { 00777, AID_ROOT, AID_ROOT, "sdcard" }, { 00755, AID_ROOT, AID_ROOT, 0 },};/* Rules for files.** These rules are applied based on "first match", so they** should start with the most specific path and work their** way up to the root. Prefixes ending in * denotes wildcard** and will allow partial matches.*/static struct fs_path_config android_files[] = { { 00440, AID_ROOT, AID_SHELL, "system/etc/init.goldfish.rc" }, { 00550, AID_ROOT, AID_SHELL, "system/etc/init.goldfish.sh" }, { 00440, AID_ROOT, AID_SHELL, "system/etc/init.trout.rc" }, { 00550, AID_ROOT, AID_SHELL, "system/etc/init.ril" }, { 00550, AID_ROOT, AID_SHELL, "system/etc/init.testmenu" }, { 00550, AID_DHCP, AID_SHELL, "system/etc/dhcpcd/dhcpcd-run-hooks" }, { 00440, AID_BLUETOOTH, AID_BLUETOOTH, "system/etc/dbus.conf" }, { 00440, AID_BLUETOOTH, AID_BLUETOOTH, "system/etc/bluetooth/main.conf" }, { 00440, AID_BLUETOOTH, AID_BLUETOOTH, "system/etc/bluetooth/input.conf" }, { 00440, AID_BLUETOOTH, AID_BLUETOOTH, "system/etc/bluetooth/audio.conf" }, { 00440, AID_BLUETOOTH, AID_BLUETOOTH, "system/etc/bluetooth/network.conf" }, { 00444, AID_NET_BT, AID_NET_BT, "system/etc/bluetooth/blacklist.conf" }, { 00640, AID_SYSTEM, AID_SYSTEM, "system/etc/bluetooth/auto_pairing.conf" }, { 00444, AID_RADIO, AID_AUDIO, "system/etc/AudioPara4.csv" }, { 00555, AID_ROOT, AID_ROOT, "system/etc/ppp/*" }, { 00555, AID_ROOT, AID_ROOT, "system/etc/rc.*" }, { 00644, AID_SYSTEM, AID_SYSTEM, "data/app/*" }, { 00644, AID_MEDIA_RW, AID_MEDIA_RW, "data/media/*" }, { 00644, AID_SYSTEM, AID_SYSTEM, "data/app-private/*" }, { 00644, AID_APP, AID_APP, "data/data/*" }, /* the following two files are INTENTIONALLY set-gid and not set-uid. * Do not change. */ { 02755, AID_ROOT, AID_NET_RAW, "system/bin/ping" }, { 02750, AID_ROOT, AID_INET, "system/bin/netcfg" }, /* the following five files are INTENTIONALLY set-uid, but they * are NOT included on user builds. */ { 06755, AID_ROOT, AID_ROOT, "system/xbin/su" }, { 06755, AID_ROOT, AID_ROOT, "system/xbin/librank" }, { 06755, AID_ROOT, AID_ROOT, "system/xbin/procrank" }, { 06755, AID_ROOT, AID_ROOT, "system/xbin/procmem" }, { 06755, AID_ROOT, AID_ROOT, "system/xbin/tcpdump" }, { 04770, AID_ROOT, AID_RADIO, "system/bin/pppd-ril" },/* the following file is INTENTIONALLY set-uid, and IS included * in user builds. */ { 06750, AID_ROOT, AID_SHELL, "system/bin/run-as" }, { 00755, AID_ROOT, AID_SHELL, "system/bin/*" }, { 00755, AID_ROOT, AID_ROOT, "system/lib/valgrind/*" }, { 00755, AID_ROOT, AID_SHELL, "system/xbin/*" }, { 00755, AID_ROOT, AID_SHELL, "system/vendor/bin/*" }, { 00750, AID_ROOT, AID_SHELL, "sbin/*" }, { 00755, AID_ROOT, AID_ROOT, "bin/*" }, { 00750, AID_ROOT, AID_SHELL, "init*" }, { 00750, AID_ROOT, AID_SHELL, "charger*" }, { 00644, AID_ROOT, AID_ROOT, 0 },};static inline void fs_config(const char *path, int dir, unsigned *uid, unsigned *gid, unsigned *mode){ struct fs_path_config *pc; int plen; pc = dir ? android_dirs : android_files; plen = strlen(path); for(; pc->prefix; pc++){ int len = strlen(pc->prefix); if (dir) { if(plen < len) continue; if(!strncmp(pc->prefix, path, len)) break; continue; } /* If name ends in * then allow partial matches. */ if (pc->prefix[len -1] == '*') { if(!strncmp(pc->prefix, path, len - 1)) break; } else if (plen == len){ if(!strncmp(pc->prefix, path, len)) break; } } *uid = pc->uid; *gid = pc->gid; *mode = (*mode & (~07777)) | pc->mode; #if 0 fprintf(stderr,"< '%s' '%s' %d %d %o >\n", path, pc->prefix ? pc->prefix : "", *uid, *gid, *mode);#endif}#endif#endif
- Android:进程UID定义
- android系统UID定义
- android uid 的定义
- Android 定义uid权限
- Android中UID机制和共享进程
- Android中UID机制和共享进程
- Android中UID机制和共享进程
- Android中UID机制和共享进程
- Android中UID机制和共享进程
- Android中UID机制和共享进程
- 关于android uid 与进程的关系
- Android中UID机制和共享进程
- Android中UID机制和共享进程
- Android 进程和文件的UID/GID
- Android 进程和文件的UID/GID
- PID,UID,sharedUserId以及Android开启多进程模式
- 进程UID : 父进程(UID/setUID) / 加载文件的SUID
- 进程pid,ppid;进程uid,euid;用户uid,guid
- UML用例图
- 哈夫曼编码简介
- 9-2 个人所得税计算器
- 城市新56个漂泊族 你是哪漂泊一族?
- 设置SharePoint2010列表的项目级权限
- Android:进程UID定义
- Safe Alert Request Error step 的解决办法
- 寄存器使用结构体进行空间地址的映射
- Activity LaunchMode & TaskAffinity
- 控件(CMSComm)进行串口编程
- asp.net 数组
- 10-25带条件查询
- iPhone应用程序编程指南---事件处理
- cout格式控制