android 获取当前应用的userid

dumpsys activity | grep ActivityRecord

得到当前应用的包名com.xxx.xxx

dumpsys package com.xxx.xxx  | grep userId=

就会得到该应用的 userId=10138

如果我在内核函数open.cpp中加入了 

int open(const char* pathname, int flags, ...) {
  mode_t mode = 0;

  if (needs_mode(flags)) {
    va_list args;
    va_start(args, flags);
    mode = static_cast<mode_t>(va_arg(args, int));
    va_end(args);
  }
    int uid=getuid();
    if ((uid >= 10000 && uid <= 19999))
     {
    if( DBG==1)
         async_safe_format_log(ANDROID_LOG_WARN, "dp", "native open sssss file: %s getpid(%d), getuid(%d) flags 0x%x", pathname,getpid(), getuid(),flags);
    }
  return __openat(AT_FDCWD, pathname, force_O_LARGEFILE(flags), mode);
}

这时当系统启动后后通logcat来检测应用访问了哪些文件

logcat |grep "10138"

猜你喜欢

转载自blog.csdn.net/babytiger/article/details/119752842
今日推荐