/* * Copyright (C) 2023 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.safetycenter.logging; import static android.os.Build.VERSION_CODES.TIRAMISU; import static com.android.permission.PermissionStatsLog.SAFETY_STATE; import android.annotation.UserIdInt; import android.app.StatsManager; import android.app.StatsManager.StatsPullAtomCallback; import android.content.Context; import android.safetycenter.SafetyCenterData; import android.safetycenter.config.SafetySource; import android.safetycenter.config.SafetySourcesGroup; import android.util.Log; import android.util.StatsEvent; import androidx.annotation.RequiresApi; import com.android.internal.annotations.GuardedBy; import com.android.modules.utils.build.SdkLevel; import com.android.permission.PermissionStatsLog; import com.android.safetycenter.ApiLock; import com.android.safetycenter.SafetyCenterConfigReader; import com.android.safetycenter.SafetyCenterDataFactory; import com.android.safetycenter.SafetyCenterFlags; import com.android.safetycenter.SafetySourceKey; import com.android.safetycenter.SafetySources; import com.android.safetycenter.UserProfileGroup; import com.android.safetycenter.data.SafetyCenterDataManager; import java.util.List; /** * A {@link StatsPullAtomCallback} that provides a {@link PermissionStatsLog#SAFETY_STATE} atom that * when requested by the {@link StatsManager}. * *
Whenever that atom, which describes the overall Safety Center, is pulled this class also
* separately writes one {@code SAFETY_SOURCE_STATE_COLLECTED} atom for each active source (per
* profile).
*
* @hide
*/
@RequiresApi(TIRAMISU)
public final class SafetyCenterPullAtomCallback implements StatsPullAtomCallback {
private static final String TAG = "SafetyCenterPullAtom";
private final Context mContext;
private final ApiLock mApiLock;
@GuardedBy("mApiLock")
private final SafetyCenterConfigReader mSafetyCenterConfigReader;
@GuardedBy("mApiLock")
private final SafetyCenterDataFactory mDataFactory;
@GuardedBy("mApiLock")
private final SafetyCenterDataManager mDataManager;
public SafetyCenterPullAtomCallback(
Context context,
ApiLock apiLock,
SafetyCenterConfigReader safetyCenterConfigReader,
SafetyCenterDataFactory dataFactory,
SafetyCenterDataManager dataManager) {
mContext = context;
mApiLock = apiLock;
mSafetyCenterConfigReader = safetyCenterConfigReader;
mDataFactory = dataFactory;
mDataManager = dataManager;
}
@Override
public int onPullAtom(int atomTag, List