解释一下 private List<DefaultLauncherApp> loadDefaultApps() { List<DefaultLauncherApp> defaultApps = new ArrayList<>(); for (ComponentName defaultComponent : getDefaultRecents()) { ActivityDisplayInfo info = applicationInfoRepo.getActivityDisplayInfo( defaultComponent.getPackageName(), defaultComponent.getClassName()); if (info != null) { DefaultLauncherApp launcherApp = DefaultLauncherApp.from( info.getInfo(), info.getLabel(), launcherIconProvider.getLauncherIconSupplier(info, "defaultApp")); defaultApps.add(launcherApp); continue; } LogUtil.logW( TAG, "Unable to get ActivityDisplayInfo for " + defaultComponent.toShortString() + " attempting to fetch from ResolveInfo"); List<ResolveInfo> resolveInfos = applicationInfoRepo.getResolveInfo(defaultComponent.getPackageName()); if (resolveInfos.isEmpty()) { LogUtil.logW( TAG, "Unable to get ResolveInfo for " + defaultComponent.toShortString() + ", not able to add to default recents"); continue; } ResolveInfo resolveInfo = resolveInfos.get(0); ActivityInfo activityInfo = resolveInfo.activityInfo; DefaultLauncherApp app = DefaultLauncherApp.from( activityInfo, activityInfo.loadLabel(packageManager).toString(), launcherIconProvider.getLauncherIconSupplier(resolveInfo, packageManager)); defaultApps.add(app); // apply the first ResolveInfo to avoid duplicated apps. See b/223960101 if (resolveInfos.size() > 1) { LogUtil.logW( TAG, "Get multiple ResolveInfos, apply the first ResolveInfo for " + defaultComponent.toShortString() + ", to avoid duplication:" + activityInfo); } } if (enableRemovalOfDefaultRecentsProvider.get()) { // Filter based on hidden recent apps. defaultApps.removeIf(defaultApp -> shouldHideDefaultRecent(defaultApp.getActivity())); } return new ArrayList<>(); // return defaultApps; }
时间: 2024-02-15 12:28:23 浏览: 73
List<Bean>转换为List<Map>
这是一个方法,其返回类型为私有的 List<DefaultLauncherApp>。该方法用于加载默认应用程序,并将其添加到一个名为 defaultApps 的 ArrayList 中。该方法首先获取默认最近使用过的应用程序的列表,并通过调用 applicationInfoRepo 的 getActivityDisplayInfo 方法获取每个默认应用程序的 ActivityDisplayInfo。如果能够成功获取 ActivityDisplayInfo,则将其转换为 DefaultLauncherApp 并添加到 defaultApps 中。如果不能成功获取 ActivityDisplayInfo,则通过调用 applicationInfoRepo 的 getResolveInfo 方法获取 ResolveInfo 列表,并使用第一个 ResolveInfo 创建 DefaultLauncherApp 并将其添加到 defaultApps 中。如果在获取 ResolveInfo 时发现列表为空,则将跳过该默认应用程序。如果 enableRemovalOfDefaultRecentsProvider 为 true,则将从 defaultApps 中删除应该隐藏的默认最近使用过的应用程序。最后,该方法将返回一个新的 ArrayList,其中包含 defaultApps 中的所有元素。
阅读全文