Merge "Updating logging for possible edge cases of incorrectly updated arrays" into udc-dev

This commit is contained in:
Kunal Malhotra
2023-05-01 19:46:43 +00:00
committed by Android (Google) Code Review

View File

@@ -34,7 +34,7 @@ import android.app.ForegroundServiceDelegationOptions;
import android.content.ComponentName; import android.content.ComponentName;
import android.content.pm.ServiceInfo; import android.content.pm.ServiceInfo;
import android.util.ArrayMap; import android.util.ArrayMap;
import android.util.Log; import android.util.Slog;
import android.util.SparseArray; import android.util.SparseArray;
import com.android.internal.annotations.VisibleForTesting; import com.android.internal.annotations.VisibleForTesting;
@@ -192,13 +192,20 @@ public class ForegroundServiceTypeLoggerModule {
final ArrayList<Integer> apiTypes = convertFgsTypeToApiTypes(record.foregroundServiceType); final ArrayList<Integer> apiTypes = convertFgsTypeToApiTypes(record.foregroundServiceType);
final UidState uidState = mUids.get(uid); final UidState uidState = mUids.get(uid);
if (uidState == null) { if (uidState == null) {
Log.e(TAG, "FGS stop call being logged with no start call for UID " + uid); Slog.wtfStack(TAG, "FGS stop call being logged with no start call for UID for UID "
+ uid
+ " in package " + record.packageName);
return; return;
} }
final ArrayList<Integer> apisFound = new ArrayList<>(); final ArrayList<Integer> apisFound = new ArrayList<>();
final ArrayList<Long> timestampsFound = new ArrayList<>(); final ArrayList<Long> timestampsFound = new ArrayList<>();
for (int i = 0, size = apiTypes.size(); i < size; i++) { for (int i = 0, size = apiTypes.size(); i < size; i++) {
int apiType = apiTypes.get(i); final int apiType = apiTypes.get(i);
if (!uidState.mOpenWithFgsCount.contains(apiType)) {
Slog.wtfStack(TAG, "Logger should be tracking FGS types correctly for UID " + uid
+ " in package " + record.packageName);
continue;
}
// retrieve the eligible closed call // retrieve the eligible closed call
// we only want to log if this is the only // we only want to log if this is the only
// open in flight call. If there are other calls, // open in flight call. If there are other calls,
@@ -215,7 +222,8 @@ public class ForegroundServiceTypeLoggerModule {
final ArrayMap<ComponentName, ServiceRecord> runningFgsOfType = final ArrayMap<ComponentName, ServiceRecord> runningFgsOfType =
uidState.mRunningFgs.get(apiType); uidState.mRunningFgs.get(apiType);
if (runningFgsOfType == null) { if (runningFgsOfType == null) {
Log.w(TAG, "Could not find appropriate running FGS for FGS stop"); Slog.w(TAG, "Could not find appropriate running FGS for FGS stop for UID " + uid
+ " in package " + record.packageName);
continue; continue;
} }
@@ -322,7 +330,7 @@ public class ForegroundServiceTypeLoggerModule {
// it's not related to any FGS // it's not related to any FGS
UidState uidState = mUids.get(uid); UidState uidState = mUids.get(uid);
if (uidState == null) { if (uidState == null) {
Log.w(TAG, "API event end called before start!"); Slog.w(TAG, "API event end called before start!");
return -1; return -1;
} }
if (uidState.mOpenWithFgsCount.contains(apiType)) { if (uidState.mOpenWithFgsCount.contains(apiType)) {