首页 > 其他分享 >在 Android 中如何确定 App(Activity) 的启动者

在 Android 中如何确定 App(Activity) 的启动者

时间:2022-11-09 23:33:07浏览次数:67  
标签:uid App u0 Activity sb Android FIRST append UID


最近在帮忙定位一个问题,涉及到某个应用自动启动了,为了确定是谁调用的,使用如下的日志进行查看(注:为了简单考虑,下面的启动者为launcher)



(pre_release|✔) % adb logcat | grep -E "ActivityManager: START" --color=always
I ActivityManager: START u0 {act=android.intent.action.MAIN
cat=[android.intent.category.HOME] flg=0x10000000 hwFlg=0x10
cmp=com.huawei.android.launcher/.unihome.UniHomeLauncher (has extras)} from uid 10070

我们看最后看到这个​​from uid 10070​​,嗯,基本定位到了是这个uid的应用启动了。

确定 uid 10070 是哪个 App

确定uid不能说明问题,我们至少需要确定是哪个应用,我们尝试使用下面的命令过滤进程有关数据



adb shell ps | grep 10070
没有任何数据输出

然而一无所获。

当然前面说了,示例的启动者是launcher,那我们过滤一下launcher



adb shell ps | grep launcher
u0_a70 2207 620 4979992 156312 0 0 S com.huawei.android.launcher

我们发现了​​u0_a70​​​和​​10070​​貌似有一些关联(至少都含有70)

于是我们使用下面的命令确定id



adb shell id u0_a70
uid=10070(u0_a70) gid=10070(u0_a70) groups=10070(u0_a70), context=u:r:shell:s0

果然,​​u0_a70​​​和​​10070​​ 是有关联的

u0_a70 的含义

  • u0 默认的手机第一个用户(可以通过设置里面的多用户新增和切换)
  • a 代表app
  • 70 代表着第70个应用

转换公式

简单而言,对应的公式是这样

u0_a70 = “u0_” + “a” + (uid(这里是10070) – FIRST_APPLICATION_UID(固定值10000))

具体复杂的转换,请参考这段代码



/**
* Generate a text representation of the uid, breaking out its individual
* components -- user, app, isolated, etc.
* @hide
*/
public static void formatUid(StringBuilder sb, int uid) {
if (uid < Process.FIRST_APPLICATION_UID) {
sb.append(uid);
} else {
sb.append('u');
sb.append(getUserId(uid));
final int appId = getAppId(uid);
if (isIsolated(appId)) {
if (appId > Process.FIRST_ISOLATED_UID) {
sb.append('i');
sb.append(appId - Process.FIRST_ISOLATED_UID);
} else {
sb.append("ai");
sb.append(appId - Process.FIRST_APP_ZYGOTE_ISOLATED_UID);
}
} else if (appId >= Process.FIRST_APPLICATION_UID) {
sb.append('a');
sb.append(appId - Process.FIRST_APPLICATION_UID);
} else {
sb.append('s');
sb.append(appId);
}
}
}

部分常量



/**
* Defines the start of a range of UIDs (and GIDs), going from this
* number to {@link #LAST_APPLICATION_UID} that are reserved for assigning
* to applications.
*/
public static final int FIRST_APPLICATION_UID = 10000;
/**
* Last of application-specific UIDs starting at
* {@link #FIRST_APPLICATION_UID}.
*/
public static final int LAST_APPLICATION_UID = 19999;
/**
* First uid used for fully isolated sandboxed processes (with no permissions of their own)
* @hide
*/
@UnsupportedAppUsage
@TestApi
public static final int FIRST_ISOLATED_UID = 99000;
/**
* First uid used for fully isolated sandboxed processes spawned from an app zygote
* @hide
*/
@TestApi
public static final int FIRST_APP_ZYGOTE_ISOLATED_UID = 90000;

以上。

References

标签:uid,App,u0,Activity,sb,Android,FIRST,append,UID
From: https://blog.51cto.com/u_3987305/5838988

相关文章

  • Android WebView 诊断与排查问题的方法和技巧
    WebView,是安卓中很重要的一个组件,我们的应用中集成WebView后,可能会遇到各种各样的问题,这里简单介绍一些AndroidWebView诊断与排查问题的方法,希望对于大家有这方面的问题的......
  • react在create-react-app中使用hooks常见注意事项
    useState它的作用就是声明状态变量useState注意点:初始参数只在组件的首次渲染的时候使用,再次更新是会被忽略每次通过setXxx修改状态都会引起组件重新渲染useS......
  • Spring Boot:自定义SpringApplication
    自定义SpringApplication如果​​SpringApplication​​​的默认值不满足我们的需求,可以创建​​SpringApplication​​实例并对其进行自定义设置,例如,要关闭横幅:packagecom......
  • uniapp 微信对接地图的三种操作
    这里给大家分享我在网上总结出来的一些知识,希望对大家有所帮助1.uni.getLocation获取当前经维度 先上代码letthat=this//获取用户是否开启......
  • yml 文件的中文注释导致 Failed to load property source from location 'classpath:/
    以前项目可以正常运行。今天重新打开项目运行,出现了下面异常:23:56:12.102[main]DEBUGorg.springframework.boot.context.logging.ClasspathLoggingApplicationListener......
  • Android开发 Ripple涟漪效果
    前言此博客讲解Android5.0版本之后的涟漪效果的使用 简单的使用例子ripple_ic_bg.xml<?xmlversion="1.0"encoding="utf-8"?><ripplexmlns:android="http://......
  • android studio 升级 Android Studio Dolphin | 2021.3.1 Patch 1
    androidstudio升级AndroidStudioDolphin|2021.3.1Patch1后,xml布局预览界面报错一开始以为是那些警告导致的,有很多黄色的xml警告,比如命名的名字不是英文,或者设置......
  • Error:Handshake inactivity timeout
    链接远程数据库时,出现如下错误 解决办法:找到本地sequence.js文件,修改文件中的this._timeout,由原来的参数调整改为确定值:this._timeout=100000 ......
  • uniapp上架ios流程
    上架基本需求资料 1、苹果开发者账号2、开发好的APP 上架AppStore审核分7步进行。 1、安装iOS上架辅助软件Appuploader2、申请iOS发布证书(p12)window操作教程3、......
  • 直播平台怎么搭建,Android与Js互调之传递图片
    直播平台怎么搭建,Android与Js互调之传递图片添加addJavascriptInterface注解方法H5VerificationJavascriptInterface对象映射 publicclassH5VerificationJavascrip......