Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8fd93925 authored by Jing Ji's avatar Jing Ji Committed by Automerger Merge Worker
Browse files

Merge "Add other tracker info in the bg restriction metrics" into tm-dev am:...

Merge "Add other tracker info in the bg restriction metrics" into tm-dev am: 839f3298 am: 546ed925 am: e8567d64

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/17924962



Change-Id: Idc9542030c92971ecb871fefa67210fa074619f6
Ignore-AOSP-First: this is an automerge
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents df457ea1 e8567d64
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -287,7 +287,10 @@ final class AppBatteryTracker extends BaseAppStateTracker<AppBatteryPolicy>
     */
    @Override
    byte[] getTrackerInfoForStatsd(int uid) {
        final ImmutableBatteryUsage temp = mUidBatteryUsageInWindow.get(uid);
        final ImmutableBatteryUsage temp;
        synchronized (mLock) {
            temp = mUidBatteryUsageInWindow.get(uid);
        }
        if (temp == null) {
            return null;
        }
+19 −0
Original line number Diff line number Diff line
@@ -24,6 +24,9 @@ import static com.android.server.am.BaseAppStateTracker.ONE_DAY;
import android.annotation.NonNull;
import android.app.ActivityManagerInternal.BindServiceEventListener;
import android.content.Context;
import android.os.AppBackgroundRestrictionsInfo;
import android.os.SystemClock;
import android.util.proto.ProtoOutputStream;

import com.android.server.am.AppBindServiceEventsTracker.AppBindServiceEventsPolicy;
import com.android.server.am.AppRestrictionController.TrackerType;
@@ -81,6 +84,22 @@ final class AppBindServiceEventsTracker extends BaseAppStateTimeSlotEventsTracke
        return new SimpleAppStateTimeslotEvents(other);
    }

    @Override
    byte[] getTrackerInfoForStatsd(int uid) {
        final long now = SystemClock.elapsedRealtime();
        final int numOfBindRequests = getTotalEventsLocked(uid, now);
        if (numOfBindRequests == 0) {
            // Not interested.
            return null;
        }
        final ProtoOutputStream proto = new ProtoOutputStream();
        proto.write(
                AppBackgroundRestrictionsInfo.BindServiceEventsTrackerInfo.BIND_SERVICE_REQUESTS,
                numOfBindRequests);
        proto.flush();
        return proto.getBytes();
    }

    @Override
    void dump(PrintWriter pw, String prefix) {
        pw.print(prefix);
+18 −0
Original line number Diff line number Diff line
@@ -24,6 +24,9 @@ import static com.android.server.am.BaseAppStateTracker.ONE_DAY;
import android.annotation.NonNull;
import android.app.ActivityManagerInternal.BroadcastEventListener;
import android.content.Context;
import android.os.AppBackgroundRestrictionsInfo;
import android.os.SystemClock;
import android.util.proto.ProtoOutputStream;

import com.android.server.am.AppBroadcastEventsTracker.AppBroadcastEventsPolicy;
import com.android.server.am.AppRestrictionController.TrackerType;
@@ -80,6 +83,21 @@ final class AppBroadcastEventsTracker extends BaseAppStateTimeSlotEventsTracker
        return new SimpleAppStateTimeslotEvents(other);
    }

    @Override
    byte[] getTrackerInfoForStatsd(int uid) {
        final long now = SystemClock.elapsedRealtime();
        final int numOfBroadcasts = getTotalEventsLocked(uid, now);
        if (numOfBroadcasts == 0) {
            // Not interested.
            return null;
        }
        final ProtoOutputStream proto = new ProtoOutputStream();
        proto.write(AppBackgroundRestrictionsInfo.BroadcastEventsTrackerInfo.BROADCASTS_SENT,
                numOfBroadcasts);
        proto.flush();
        return proto.getBytes();
    }

    @Override
    void dump(PrintWriter pw, String prefix) {
        pw.print(prefix);
+23 −0
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ import android.app.IProcessObserver;
import android.content.ComponentName;
import android.content.Context;
import android.content.pm.ServiceInfo.ForegroundServiceType;
import android.os.AppBackgroundRestrictionsInfo;
import android.os.Handler;
import android.os.Message;
import android.os.PowerExemptionManager.ReasonCode;
@@ -49,6 +50,7 @@ import android.util.Slog;
import android.util.SparseArray;
import android.util.SparseBooleanArray;
import android.util.TimeUtils;
import android.util.proto.ProtoOutputStream;

import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.VisibleForTesting;
@@ -516,6 +518,12 @@ final class AppFGSTracker extends BaseAppStateDurationsTracker<AppFGSPolicy, Pac
                foregroundServiceTypeToIndex(FOREGROUND_SERVICE_TYPE_NONE));
    }

    @Override
    long getTotalDurations(int uid, long now) {
        return getTotalDurations(uid, now,
                foregroundServiceTypeToIndex(FOREGROUND_SERVICE_TYPE_NONE));
    }

    boolean hasForegroundServices(String packageName, int uid) {
        synchronized (mLock) {
            final PackageDurations pkg = mPkgEvents.get(uid, packageName);
@@ -561,6 +569,21 @@ final class AppFGSTracker extends BaseAppStateDurationsTracker<AppFGSPolicy, Pac
        return false;
    }

    @Override
    byte[] getTrackerInfoForStatsd(int uid) {
        final long fgsDurations = getTotalDurations(uid, SystemClock.elapsedRealtime());
        if (fgsDurations == 0L) {
            // Not interested
            return null;
        }
        final ProtoOutputStream proto = new ProtoOutputStream();
        proto.write(AppBackgroundRestrictionsInfo.FgsTrackerInfo.FGS_NOTIFICATION_VISIBLE,
                hasForegroundServiceNotifications(uid));
        proto.write(AppBackgroundRestrictionsInfo.FgsTrackerInfo.FGS_DURATION, fgsDurations);
        proto.flush();
        return proto.getBytes();
    }

    @Override
    void dump(PrintWriter pw, String prefix) {
        pw.print(prefix);
+15 −0
Original line number Diff line number Diff line
@@ -2435,6 +2435,21 @@ public final class AppRestrictionController {
        }

        void postLongRunningFgsIfNecessary(String packageName, int uid) {
            // Log the event in statsd.
            FrameworkStatsLog.write(FrameworkStatsLog.APP_BACKGROUND_RESTRICTIONS_INFO,
                    uid,
                    mBgController.getRestrictionLevel(uid),
                    AppBackgroundRestrictionsInfo.THRESHOLD_UNKNOWN,
                    AppBackgroundRestrictionsInfo.FGS_TRACKER,
                    mInjector.getAppFGSTracker().getTrackerInfoForStatsd(uid),
                    null, // BatteryTrackerInfo
                    null, // BroadcastEventsTrackerInfo
                    null, // BindServiceEventsTrackerInfo
                    getExemptionReasonForStatsd(
                            mBgController.getBackgroundRestrictionExemptionReason(uid)),
                    AppBackgroundRestrictionsInfo.UNKNOWN, // OptimizationLevel
                    AppBackgroundRestrictionsInfo.SDK_UNKNOWN, // TargetSdk
                    ActivityManager.isLowRamDeviceStatic());
            PendingIntent pendingIntent;
            if (!mBgController.mConstantsObserver.mBgPromptFgsWithNotiOnLongRunning
                    && mBgController.hasForegroundServiceNotifications(packageName, uid)) {
Loading