1 /* 2 * Copyright (C) 2023 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.server; 18 19 import static com.android.internal.util.ConcurrentUtils.DIRECT_EXECUTOR; 20 21 import android.app.StatsManager; 22 import android.content.Context; 23 import android.util.StatsEvent; 24 25 import com.android.internal.os.Zygote; 26 import com.android.internal.util.FrameworkStatsLog; 27 28 import java.util.List; 29 30 public class LogMteState { register(Context context)31 public static void register(Context context) { 32 context.getSystemService(StatsManager.class) 33 .setPullAtomCallback( 34 FrameworkStatsLog.MTE_STATE, 35 null, // use default PullAtomMetadata values 36 DIRECT_EXECUTOR, 37 new StatsManager.StatsPullAtomCallback() { 38 @Override 39 public int onPullAtom(int atomTag, List<StatsEvent> data) { 40 if (atomTag != FrameworkStatsLog.MTE_STATE) { 41 throw new UnsupportedOperationException( 42 "Unknown tagId=" + atomTag); 43 } 44 data.add( 45 FrameworkStatsLog.buildStatsEvent( 46 FrameworkStatsLog.MTE_STATE, 47 Zygote.nativeSupportsMemoryTagging() 48 ? FrameworkStatsLog.MTE_STATE__STATE__ON 49 : FrameworkStatsLog.MTE_STATE__STATE__OFF)); 50 return StatsManager.PULL_SUCCESS; 51 } 52 }); 53 } 54 } 55