538 private void processAppUsage(SparseArray<UserHandle> asUsers) { 539 final boolean forAllUsers = (asUsers.get(UserHandle.USER_ALL) != null); 540 mStatsPeriod = mTypeBatteryRealtimeUs; 541 542 BatterySipper osSipper = null; 543 final SparseArray<? extends Uid> uidStats = mStats.getUidStats(); 544 final int NU = uidStats.size(); 545 for (int iu = 0; iu < NU; iu++) { 546 final Uid u = uidStats.valueAt(iu); 547 final BatterySipper app = new BatterySipper(BatterySipper.DrainType.APP, u, 0); 548 549 mCpuPowerCalculator.calculateApp(app, u, mRawRealtimeUs, mRawUptimeUs, mStatsType);//获取CPU可以运转到在几种频率之下 550 mWakelockPowerCalculator.calculateApp(app, u, mRawRealtimeUs, mRawUptimeUs, mStatsType); 551 mMobileRadioPowerCalculator.calculateApp(app, u, mRawRealtimeUs, mRawUptimeUs, 552 mStatsType); 553 mWifiPowerCalculator.calculateApp(app, u, mRawRealtimeUs, mRawUptimeUs, mStatsType); 554 mBluetoothPowerCalculator.calculateApp(app, u, mRawRealtimeUs, mRawUptimeUs, 555 mStatsType); 556 mSensorPowerCalculator.calculateApp(app, u, mRawRealtimeUs, mRawUptimeUs, mStatsType); 557 mCameraPowerCalculator.calculateApp(app, u, mRawRealtimeUs, mRawUptimeUs, mStatsType); 558 mFlashlightPowerCalculator.calculateApp(app, u, mRawRealtimeUs, mRawUptimeUs, 559 mStatsType); 560 561 final double totalPower = app.sumPower(); 562 if (DEBUG && totalPower != 0) { 563 Log.d(TAG, String.format("UID %d: total power=%s", u.getUid(), 564 makemAh(totalPower))); 565 } 566 567 // Add the app to the list if it is consuming power. 568 if (totalPower != 0 || u.getUid() == 0) { 569 // 570 // Add the app to the app list, WiFi, Bluetooth, etc, or into "Other Users" list. 571 // 572 final int uid = app.getUid(); 573 final int userId = UserHandle.getUserId(uid); 574 if (uid == Process.WIFI_UID) { 575 mWifiSippers.add(app); 576 } else if (uid == Process.BLUETOOTH_UID) { 577 mBluetoothSippers.add(app); 578 } else if (!forAllUsers && asUsers.get(userId) == null 579 && UserHandle.getAppId(uid) >= Process.FIRST_APPLICATION_UID) { 580 // We are told to just report this user's apps as one large entry. 581 List<BatterySipper> list = mUserSippers.get(userId); 582 if (list == null) { 583 list = new ArrayList<>(); 584 mUserSippers.put(userId, list); 585 } 586 list.add(app); 587 } else { 588 mUsageList.add(app); 589 } 590 591 if (uid == 0) { 592 osSipper = app; 593 } 594 } 595 } 596 597 if (osSipper != null) { 598 // The device has probably been awake for longer than the screen on 599 // time and application wake lock time would account for. Assign 600 // this remainder to the OS, if possible. 601 mWakelockPowerCalculator.calculateRemaining(osSipper, mStats, mRawRealtimeUs, 602 mRawUptimeUs, mStatsType); 603 osSipper.sumPower(); 604 } 605 }
737 private void processMiscUsage() { 738 addUserUsage(); 739 addPhoneUsage(); 740 addScreenUsage(); 741 addWiFiUsage(); 742 addBluetoothUsage(); 743 addMemoryUsage(); 744 addIdleUsage(); // Not including cellular idle power 745 // Don't compute radio usage if it's a wifi-only device 746 if (!mWifiOnly) { 747 addRadioUsage(); 748 } 749 }