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

Commit b67f2c68 authored by Varun Shah's avatar Varun Shah
Browse files

Update sync exemptions log to include restriction level.

Bug: 226657057
Test: statsd_testdrive 468
Change-Id: I9a50e5a2e6fdfd736f96998a4bf626954be79025
Merged-In: I9a50e5a2e6fdfd736f96998a4bf626954be79025
(cherry picked from commit 940f964b)
parent 6a45e90f
Loading
Loading
Loading
Loading
+25 −1
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import android.annotation.Nullable;
import android.annotation.RequiresPermission;
import android.annotation.UserIdInt;
import android.app.ActivityManager;
import android.app.ActivityManager.RestrictionLevel;
import android.app.ActivityManagerInternal;
import android.app.AppGlobals;
import android.app.AppOpsManager;
@@ -52,6 +53,7 @@ import android.content.pm.ProviderInfo;
import android.database.IContentObserver;
import android.database.sqlite.SQLiteException;
import android.net.Uri;
import android.os.AppBackgroundRestrictionsInfo;
import android.os.Binder;
import android.os.Build;
import android.os.Bundle;
@@ -1544,7 +1546,8 @@ public final class ContentService extends IContentService.Stub {
        }
        if (procState <= ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND || isUidActive) {
            FrameworkStatsLog.write(FrameworkStatsLog.SYNC_EXEMPTION_OCCURRED,
                    callingUid, getProcStateForStatsd(procState), isUidActive);
                    callingUid, getProcStateForStatsd(procState), isUidActive,
                    getRestrictionLevelForStatsd(ami.getRestrictionLevel(callingUid)));
            return ContentResolver.SYNC_EXEMPTION_PROMOTE_BUCKET;
        }
        return ContentResolver.SYNC_EXEMPTION_NONE;
@@ -1599,6 +1602,27 @@ public final class ContentService extends IContentService.Stub {
        }
    }

    private int getRestrictionLevelForStatsd(@RestrictionLevel int level) {
        switch (level) {
            case ActivityManager.RESTRICTION_LEVEL_UNKNOWN:
                return AppBackgroundRestrictionsInfo.LEVEL_UNKNOWN;
            case ActivityManager.RESTRICTION_LEVEL_UNRESTRICTED:
                return AppBackgroundRestrictionsInfo.LEVEL_UNRESTRICTED;
            case ActivityManager.RESTRICTION_LEVEL_EXEMPTED:
                return AppBackgroundRestrictionsInfo.LEVEL_EXEMPTED;
            case ActivityManager.RESTRICTION_LEVEL_ADAPTIVE_BUCKET:
                return AppBackgroundRestrictionsInfo.LEVEL_ADAPTIVE_BUCKET;
            case ActivityManager.RESTRICTION_LEVEL_RESTRICTED_BUCKET:
                return AppBackgroundRestrictionsInfo.LEVEL_RESTRICTED_BUCKET;
            case ActivityManager.RESTRICTION_LEVEL_BACKGROUND_RESTRICTED:
                return AppBackgroundRestrictionsInfo.LEVEL_BACKGROUND_RESTRICTED;
            case ActivityManager.RESTRICTION_LEVEL_HIBERNATION:
                return AppBackgroundRestrictionsInfo.LEVEL_HIBERNATION;
            default:
                return AppBackgroundRestrictionsInfo.LEVEL_UNKNOWN;
        }
    }

    /** {@hide} */
    @VisibleForTesting
    public static final class ObserverNode {