1 /* 2 * Copyright (C) 2021 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.eventlib.events.activities; 18 19 import android.app.Activity; 20 21 import androidx.annotation.CheckResult; 22 23 import com.android.eventlib.Event; 24 import com.android.eventlib.EventLogger; 25 import com.android.eventlib.EventLogsQuery; 26 import com.android.queryable.info.ActivityInfo; 27 import com.android.queryable.queries.ActivityQuery; 28 import com.android.queryable.queries.ActivityQueryHelper; 29 30 /** 31 * Event logged when {@link Activity#onResume()}} is called. 32 */ 33 public final class ActivityResumedEvent extends Event { 34 35 /** Begin a query for {@link ActivityResumedEvent} events. */ queryPackage(String packageName)36 public static ActivityResumedEventQuery queryPackage(String packageName) { 37 return new ActivityResumedEventQuery(packageName); 38 } 39 40 /** {@link EventLogsQuery} for {@link ActivityResumedEvent}. */ 41 public static final class ActivityResumedEventQuery 42 extends EventLogsQuery<ActivityResumedEvent, ActivityResumedEventQuery> { 43 ActivityQueryHelper<ActivityResumedEventQuery> mActivity = 44 new ActivityQueryHelper<>(this); 45 ActivityResumedEventQuery(String packageName)46 private ActivityResumedEventQuery(String packageName) { 47 super(ActivityResumedEvent.class, packageName); 48 } 49 50 /** Query {@link Activity}. */ 51 @CheckResult whereActivity()52 public ActivityQuery<ActivityResumedEventQuery> whereActivity() { 53 return mActivity; 54 } 55 56 @Override filter(ActivityResumedEvent event)57 protected boolean filter(ActivityResumedEvent event) { 58 if (!mActivity.matches(event.mActivity)) { 59 return false; 60 } 61 return true; 62 } 63 } 64 65 /** Begin logging a {@link ActivityResumedEvent}. */ logger(Activity activity, android.content.pm.ActivityInfo activityInfo)66 public static ActivityResumedEventLogger logger(Activity activity, android.content.pm.ActivityInfo activityInfo) { 67 return new ActivityResumedEventLogger(activity, activityInfo); 68 } 69 70 /** {@link EventLogger} for {@link ActivityResumedEvent}. */ 71 public static final class ActivityResumedEventLogger 72 extends EventLogger<ActivityResumedEvent> { ActivityResumedEventLogger(Activity activity, android.content.pm.ActivityInfo activityInfo)73 private ActivityResumedEventLogger(Activity activity, android.content.pm.ActivityInfo activityInfo) { 74 super(activity, new ActivityResumedEvent()); 75 setActivity(activityInfo); 76 } 77 78 /** Set the {@link Activity} being destroyed. */ setActivity(android.content.pm.ActivityInfo activity)79 public ActivityResumedEventLogger setActivity(android.content.pm.ActivityInfo activity) { 80 mEvent.mActivity = ActivityInfo.builder(activity).build(); 81 return this; 82 } 83 } 84 85 protected ActivityInfo mActivity; 86 87 /** Information about the {@link Activity} destroyed. */ activity()88 public ActivityInfo activity() { 89 return mActivity; 90 } 91 92 @Override toString()93 public String toString() { 94 return "ActivityResumedEvent{" 95 + ", activity=" + mActivity 96 + ", packageName='" + mPackageName + "'" 97 + ", timestamp=" + mTimestamp 98 + "}"; 99 } 100 } 101