Loading services/core/java/com/android/server/stats/StatsCompanionService.java +41 −36 Original line number Diff line number Diff line Loading @@ -174,11 +174,6 @@ public class StatsCompanionService extends IStatsCompanionService.Stub { private final KernelWakelockStats mTmpWakelockStats = new KernelWakelockStats(); private IWifiManager mWifiManager = null; private TelephonyManager mTelephony = null; private final StatFs mStatFsData = new StatFs(Environment.getDataDirectory().getAbsolutePath()); private final StatFs mStatFsSystem = new StatFs(Environment.getRootDirectory().getAbsolutePath()); private final StatFs mStatFsTemp = new StatFs(Environment.getDownloadCacheDirectory().getAbsolutePath()); @GuardedBy("sStatsdLock") private final HashSet<Long> mDeathTimeMillis = new HashSet<>(); @GuardedBy("sStatsdLock") Loading Loading @@ -772,7 +767,7 @@ public class StatsCompanionService extends IStatsCompanionService.Stub { private void pullBluetoothBytesTransfer( int tagId, long elapsedNanos, long wallClockNanos, List<StatsLogEventWrapper> pulledData) { BluetoothActivityEnergyInfo info = pullBluetoothData(); BluetoothActivityEnergyInfo info = fetchBluetoothData(); if (info.getUidTraffic() != null) { for (UidTraffic traffic : info.getUidTraffic()) { StatsLogEventWrapper e = new StatsLogEventWrapper(tagId, elapsedNanos, Loading Loading @@ -884,9 +879,12 @@ public class StatsCompanionService extends IStatsCompanionService.Stub { int tagId, long elapsedNanos, long wallClockNanos, List<StatsLogEventWrapper> pulledData) { long token = Binder.clearCallingIdentity(); synchronized (this) { if (mWifiManager == null) { mWifiManager = IWifiManager.Stub.asInterface(ServiceManager.getService(Context.WIFI_SERVICE)); IWifiManager.Stub.asInterface( ServiceManager.getService(Context.WIFI_SERVICE)); } } if (mWifiManager != null) { try { Loading Loading @@ -916,9 +914,11 @@ public class StatsCompanionService extends IStatsCompanionService.Stub { int tagId, long elapsedNanos, long wallClockNanos, List<StatsLogEventWrapper> pulledData) { long token = Binder.clearCallingIdentity(); synchronized (this) { if (mTelephony == null) { mTelephony = TelephonyManager.from(mContext); } } if (mTelephony != null) { SynchronousResultReceiver modemReceiver = new SynchronousResultReceiver("telephony"); mTelephony.requestModemActivityInfo(modemReceiver); Loading @@ -941,7 +941,7 @@ public class StatsCompanionService extends IStatsCompanionService.Stub { private void pullBluetoothActivityInfo( int tagId, long elapsedNanos, long wallClockNanos, List<StatsLogEventWrapper> pulledData) { BluetoothActivityEnergyInfo info = pullBluetoothData(); BluetoothActivityEnergyInfo info = fetchBluetoothData(); StatsLogEventWrapper e = new StatsLogEventWrapper(tagId, elapsedNanos, wallClockNanos); e.writeLong(info.getTimeStamp()); e.writeInt(info.getBluetoothStackState()); Loading @@ -952,7 +952,7 @@ public class StatsCompanionService extends IStatsCompanionService.Stub { pulledData.add(e); } private synchronized BluetoothActivityEnergyInfo pullBluetoothData() { private synchronized BluetoothActivityEnergyInfo fetchBluetoothData() { final BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); if (adapter != null) { SynchronousResultReceiver bluetoothReceiver = new SynchronousResultReceiver( Loading Loading @@ -1323,6 +1323,7 @@ public class StatsCompanionService extends IStatsCompanionService.Stub { private void pullProcessStats(int section, int tagId, long elapsedNanos, long wallClockNanos, List<StatsLogEventWrapper> pulledData) { synchronized (this) { try { long lastHighWaterMark = readProcStatsHighWaterMark(section); List<ParcelFileDescriptor> statsFiles = new ArrayList<>(); Loading @@ -1331,13 +1332,16 @@ public class StatsCompanionService extends IStatsCompanionService.Stub { if (statsFiles.size() != 1) { return; } InputStream stream = new ParcelFileDescriptor.AutoCloseInputStream(statsFiles.get(0)); InputStream stream = new ParcelFileDescriptor.AutoCloseInputStream( statsFiles.get(0)); int[] len = new int[1]; byte[] stats = readFully(stream, len); StatsLogEventWrapper e = new StatsLogEventWrapper(tagId, elapsedNanos, wallClockNanos); StatsLogEventWrapper e = new StatsLogEventWrapper(tagId, elapsedNanos, wallClockNanos); e.writeStorage(Arrays.copyOf(stats, len[0])); pulledData.add(e); new File(mBaseDir.getAbsolutePath() + "/" + section + "_" + lastHighWaterMark).delete(); new File(mBaseDir.getAbsolutePath() + "/" + section + "_" + lastHighWaterMark).delete(); new File( mBaseDir.getAbsolutePath() + "/" + section + "_" + highWaterMark).createNewFile(); Loading @@ -1349,6 +1353,7 @@ public class StatsCompanionService extends IStatsCompanionService.Stub { Log.e(TAG, "Getting procstats failed: ", e); } } } static byte[] readFully(InputStream stream, int[] outLen) throws IOException { int pos = 0; Loading Loading
services/core/java/com/android/server/stats/StatsCompanionService.java +41 −36 Original line number Diff line number Diff line Loading @@ -174,11 +174,6 @@ public class StatsCompanionService extends IStatsCompanionService.Stub { private final KernelWakelockStats mTmpWakelockStats = new KernelWakelockStats(); private IWifiManager mWifiManager = null; private TelephonyManager mTelephony = null; private final StatFs mStatFsData = new StatFs(Environment.getDataDirectory().getAbsolutePath()); private final StatFs mStatFsSystem = new StatFs(Environment.getRootDirectory().getAbsolutePath()); private final StatFs mStatFsTemp = new StatFs(Environment.getDownloadCacheDirectory().getAbsolutePath()); @GuardedBy("sStatsdLock") private final HashSet<Long> mDeathTimeMillis = new HashSet<>(); @GuardedBy("sStatsdLock") Loading Loading @@ -772,7 +767,7 @@ public class StatsCompanionService extends IStatsCompanionService.Stub { private void pullBluetoothBytesTransfer( int tagId, long elapsedNanos, long wallClockNanos, List<StatsLogEventWrapper> pulledData) { BluetoothActivityEnergyInfo info = pullBluetoothData(); BluetoothActivityEnergyInfo info = fetchBluetoothData(); if (info.getUidTraffic() != null) { for (UidTraffic traffic : info.getUidTraffic()) { StatsLogEventWrapper e = new StatsLogEventWrapper(tagId, elapsedNanos, Loading Loading @@ -884,9 +879,12 @@ public class StatsCompanionService extends IStatsCompanionService.Stub { int tagId, long elapsedNanos, long wallClockNanos, List<StatsLogEventWrapper> pulledData) { long token = Binder.clearCallingIdentity(); synchronized (this) { if (mWifiManager == null) { mWifiManager = IWifiManager.Stub.asInterface(ServiceManager.getService(Context.WIFI_SERVICE)); IWifiManager.Stub.asInterface( ServiceManager.getService(Context.WIFI_SERVICE)); } } if (mWifiManager != null) { try { Loading Loading @@ -916,9 +914,11 @@ public class StatsCompanionService extends IStatsCompanionService.Stub { int tagId, long elapsedNanos, long wallClockNanos, List<StatsLogEventWrapper> pulledData) { long token = Binder.clearCallingIdentity(); synchronized (this) { if (mTelephony == null) { mTelephony = TelephonyManager.from(mContext); } } if (mTelephony != null) { SynchronousResultReceiver modemReceiver = new SynchronousResultReceiver("telephony"); mTelephony.requestModemActivityInfo(modemReceiver); Loading @@ -941,7 +941,7 @@ public class StatsCompanionService extends IStatsCompanionService.Stub { private void pullBluetoothActivityInfo( int tagId, long elapsedNanos, long wallClockNanos, List<StatsLogEventWrapper> pulledData) { BluetoothActivityEnergyInfo info = pullBluetoothData(); BluetoothActivityEnergyInfo info = fetchBluetoothData(); StatsLogEventWrapper e = new StatsLogEventWrapper(tagId, elapsedNanos, wallClockNanos); e.writeLong(info.getTimeStamp()); e.writeInt(info.getBluetoothStackState()); Loading @@ -952,7 +952,7 @@ public class StatsCompanionService extends IStatsCompanionService.Stub { pulledData.add(e); } private synchronized BluetoothActivityEnergyInfo pullBluetoothData() { private synchronized BluetoothActivityEnergyInfo fetchBluetoothData() { final BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); if (adapter != null) { SynchronousResultReceiver bluetoothReceiver = new SynchronousResultReceiver( Loading Loading @@ -1323,6 +1323,7 @@ public class StatsCompanionService extends IStatsCompanionService.Stub { private void pullProcessStats(int section, int tagId, long elapsedNanos, long wallClockNanos, List<StatsLogEventWrapper> pulledData) { synchronized (this) { try { long lastHighWaterMark = readProcStatsHighWaterMark(section); List<ParcelFileDescriptor> statsFiles = new ArrayList<>(); Loading @@ -1331,13 +1332,16 @@ public class StatsCompanionService extends IStatsCompanionService.Stub { if (statsFiles.size() != 1) { return; } InputStream stream = new ParcelFileDescriptor.AutoCloseInputStream(statsFiles.get(0)); InputStream stream = new ParcelFileDescriptor.AutoCloseInputStream( statsFiles.get(0)); int[] len = new int[1]; byte[] stats = readFully(stream, len); StatsLogEventWrapper e = new StatsLogEventWrapper(tagId, elapsedNanos, wallClockNanos); StatsLogEventWrapper e = new StatsLogEventWrapper(tagId, elapsedNanos, wallClockNanos); e.writeStorage(Arrays.copyOf(stats, len[0])); pulledData.add(e); new File(mBaseDir.getAbsolutePath() + "/" + section + "_" + lastHighWaterMark).delete(); new File(mBaseDir.getAbsolutePath() + "/" + section + "_" + lastHighWaterMark).delete(); new File( mBaseDir.getAbsolutePath() + "/" + section + "_" + highWaterMark).createNewFile(); Loading @@ -1349,6 +1353,7 @@ public class StatsCompanionService extends IStatsCompanionService.Stub { Log.e(TAG, "Getting procstats failed: ", e); } } } static byte[] readFully(InputStream stream, int[] outLen) throws IOException { int pos = 0; Loading