[Android S] statsd 统计log信息流程

[Android S] statsd 统计log信息流程

参考文档:
https://source.android.google.cn/devices/architecture/modular-system/statsd
https://www.dazhuanlan.com/ostrichmyself/topics/1301914
移动端 Statsd In android 9 (1)
https://blog.csdn.net/ho_mgx/article/details/113486753
Android中的StatsLog


执行如下命令:
run cts -m CtsAppSecurityHostTestCases
-t android.appsecurity.cts.StatsdAppSecurityAtomTest#testRoleHolder

Demo:
统计FrameworkStatsLog.ROLE_HOLDER信息log 代码流程
frameworks/base/services/core/java/com/android/server/stats/pull/StatsPullAtomService.java
public void onBootPhase(int phase)
registerPullers();

frameworks/base/services/core/java/com/android/server/stats/pull/StatsPullAtomService.java
     // Add a RoleHolder atom for each package that holds a role.
3208      int pullRoleHolderLocked(int atomTag, List<StatsEvent> pulledData) {
3209          final long callingToken = Binder.clearCallingIdentity();
3210          try {
3211              PackageManager pm = mContext.getPackageManager();
3212              RoleManagerLocal roleManagerLocal = LocalManagerRegistry.getManager(
3213                      RoleManagerLocal.class);
3214  
3215              List<UserInfo> users = mContext.getSystemService(UserManager.class).getUsers();
3216  
3217              int numUsers = users.size();
3218              for (int userNum = 0; userNum < numUsers; userNum++) {
3219                  int userId = users.get(userNum).getUserHandle().getIdentifier();
3220  
3221                  Map<String, Set<String>> roles = roleManagerLocal.getRolesAndHolders(userId);
3222  
3223                  for (Map.Entry<String, Set<String>> roleEntry : roles.entrySet()) {
3224                      String roleName = roleEntry.getKey();
3225                      Set<String> packageNames = roleEntry.getValue();
3226  
3227                      for (String packageName : packageNames) {
3228                          PackageInfo pkg;
3229                          try {
3230                              pkg = pm.getPackageInfoAsUser(packageName, 0, userId);
3231                          } catch (PackageManager.NameNotFoundException e) {
3232                              Slog.w(TAG, "Role holder " + packageName + " not found");
3233                              return StatsManager.PULL_SKIP;
3234                          }
3235
+                        Slog.d(TAG, "  ======  "
+                            + " pkg: " + pkg
+                            + " atomTag: " + atomTag
+                            + " packageName: " + packageName
+                            + " roleName: " + roleName
+                            );

3236                          pulledData.add(FrameworkStatsLog.buildStatsEvent(
3237                                  atomTag, pkg.applicationInfo.uid, packageName, roleName));
3238                      }
3239                  }
3240              }
3241          } finally {
3242              Binder.restoreCallingIdentity(callingToken);
3243          }
3244          return StatsManager.PULL_SUCCESS;
3245      }

你可能感兴趣的:(Android,Framework,Android,android,framework)