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

Commit 6778496a authored by Hani Kazmi's avatar Hani Kazmi Committed by Android (Google) Code Review
Browse files

Merge "[AAPM] Add framework stats atoms for current Advanced Protection state" into main

parents 51389730 7e5054e7
Loading
Loading
Loading
Loading
+31 −0
Original line number Diff line number Diff line
@@ -17,11 +17,13 @@
package com.android.server.security.advancedprotection;

import static android.provider.Settings.Secure.ADVANCED_PROTECTION_MODE;
import static com.android.internal.util.ConcurrentUtils.DIRECT_EXECUTOR;

import android.Manifest;
import android.annotation.EnforcePermission;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.app.StatsManager;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Binder;
@@ -45,6 +47,7 @@ import android.security.advancedprotection.IAdvancedProtectionService;
import android.security.advancedprotection.AdvancedProtectionProtoEnums;
import android.util.ArrayMap;
import android.util.Slog;
import android.util.StatsEvent;

import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.util.DumpUtils;
@@ -137,6 +140,15 @@ public class AdvancedProtectionService extends IAdvancedProtectionService.Stub
        mProviders.add(new DisallowWepAdvancedProtectionProvider());
    }

    private void initLogging() {
        StatsManager statsManager = mContext.getSystemService(StatsManager.class);
        statsManager.setPullAtomCallback(
                FrameworkStatsLog.ADVANCED_PROTECTION_STATE_INFO,
                null, // use default PullAtomMetadata values
                DIRECT_EXECUTOR,
                new AdvancedProtectionStatePullAtomCallback());
    }

    // Only for tests
    @VisibleForTesting
    AdvancedProtectionService(@NonNull Context context, @NonNull AdvancedProtectionStore store,
@@ -399,6 +411,7 @@ public class AdvancedProtectionService extends IAdvancedProtectionService.Stub
                    Slog.i(TAG, "Advanced protection is enabled");
                }
                mService.initFeatures(enabled);
                mService.initLogging();
            }
        }
    }
@@ -500,4 +513,22 @@ public class AdvancedProtectionService extends IAdvancedProtectionService.Stub
            }
        }
    }

    private class AdvancedProtectionStatePullAtomCallback
            implements StatsManager.StatsPullAtomCallback {

        @Override
        public int onPullAtom(int atomTag, List<StatsEvent> data) {
            if (atomTag != FrameworkStatsLog.ADVANCED_PROTECTION_STATE_INFO) {
                return StatsManager.PULL_SKIP;
            }

            data.add(
                    FrameworkStatsLog.buildStatsEvent(
                            FrameworkStatsLog.ADVANCED_PROTECTION_STATE_INFO,
                            /*enabled*/ isAdvancedProtectionEnabledInternal(),
                            /*hours_since_enabled*/ hoursSinceLastChange()));
            return StatsManager.PULL_SUCCESS;
        }
    }
}