android 11系统源码在compatibilityinfo.java判断当前返回主桌面
时间: 2023-12-06 14:45:31 浏览: 180
在Android 11系统源码中,判断当前返回主桌面的逻辑是在`CompatibilityInfo.java`文件中进行的。具体来说,可以在`getPackageCompatibilityInfo(Package pkg)`方法中找到相关的代码。
在该方法中,会首先判断当前应用是否为桌面应用,如果是,则直接返回默认的`CompatibilityInfo`对象。如果不是,则会进一步判断当前是否返回到了主桌面。这里是通过判断当前Activity的Intent是否包含`CATEGORY_HOME`来实现的。如果包含,则说明已经返回到了主桌面,此时也会返回默认的`CompatibilityInfo`对象。否则,会根据当前的系统版本和硬件设备信息,返回对应的`CompatibilityInfo`对象。
以下是相关的代码片段:
```java
private static final int ALWAYS_NEEDS_COMPAT = (1 << 0);
private static final int NEVER_NEEDS_COMPAT = (1 << 1);
private static final int DONT_ASK_ABOUT_GL_ERRORS = (1 << 2);
public CompatibilityInfo getPackageCompatibilityInfo(Package pkg) {
...
// Check if the package is a system package or a pre-installed app
boolean isPreInstalledApp = isPreInstalledApp(pkg);
boolean isSystemApp = (pkg.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0;
if (!isSystemApp && !isPreInstalledApp) {
// Check if the activity is returning to the home screen
boolean isReturningToHomeScreen = activityIntent != null &&
activityIntent.hasCategory(Intent.CATEGORY_HOME);
if (isReturningToHomeScreen) {
return DEFAULT_COMPATIBILITY_INFO;
}
// Check if the package has a preferred density
int prefDensity = pkg.applicationInfo.preferredDensity;
if (prefDensity != 0) {
return new CompatibilityInfo(null, prefDensity);
}
...
}
// Return the default compatibility info for system packages or pre-installed apps
return DEFAULT_COMPATIBILITY_INFO;
}
```
阅读全文