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 android.car.builtin.util; 18 19 import android.annotation.NonNull; 20 import android.annotation.RequiresApi; 21 import android.annotation.SystemApi; 22 import android.annotation.UserIdInt; 23 import android.app.usage.UsageStatsManager; 24 import android.car.builtin.annotation.AddedIn; 25 import android.car.builtin.annotation.PlatformVersion; 26 import android.os.Build; 27 import android.util.Log; 28 29 import java.util.Objects; 30 31 /** 32 * Wrapper for UsageStatsManager. 33 * 34 * @hide 35 */ 36 @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES) 37 public final class UsageStatsManagerHelper { 38 39 private static final String TAG = UsageStatsManagerHelper.class.getSimpleName(); 40 private static final boolean DEBUG = false; 41 UsageStatsManagerHelper()42 private UsageStatsManagerHelper() { 43 throw new UnsupportedOperationException(); 44 } 45 46 /** 47 * Reports user interaction with a given package in the given user. 48 * Check {@link UsageStatsManager#reportUserInteraction(String, int)} 49 * 50 * @param usageStatsManager {@link UsageStatsManager} instance used to report the user 51 * interaction 52 * @param packageName package name reported for the user interaction 53 * @param userId user id of the process 54 */ 55 @RequiresApi(Build.VERSION_CODES.UPSIDE_DOWN_CAKE) 56 @AddedIn(PlatformVersion.UPSIDE_DOWN_CAKE_0) reportUserInteraction(@onNull UsageStatsManager usageStatsManager, @NonNull String packageName, @UserIdInt int userId)57 public static void reportUserInteraction(@NonNull UsageStatsManager usageStatsManager, 58 @NonNull String packageName, @UserIdInt int userId) { 59 if (DEBUG) { 60 Log.d(TAG, "usageStatsManager#reportUserInteraction package=" + packageName 61 + " userId=" + userId); 62 } 63 Objects.requireNonNull(usageStatsManager); 64 Objects.requireNonNull(packageName); 65 usageStatsManager.reportUserInteraction(packageName, userId); 66 } 67 68 } 69