• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.deviceadminreceivers;
18 
19 import android.app.admin.DeviceAdminReceiver;
20 import android.content.Context;
21 import android.content.Intent;
22 
23 import androidx.annotation.CheckResult;
24 
25 import com.android.eventlib.Event;
26 import com.android.eventlib.EventLogger;
27 import com.android.eventlib.EventLogsQuery;
28 import com.android.queryable.info.DeviceAdminReceiverInfo;
29 import com.android.queryable.queries.DeviceAdminReceiverQuery;
30 import com.android.queryable.queries.DeviceAdminReceiverQueryHelper;
31 import com.android.queryable.queries.IntentQueryHelper;
32 import com.android.queryable.queries.StringQuery;
33 import com.android.queryable.queries.StringQueryHelper;
34 import com.android.queryable.util.SerializableParcelWrapper;
35 
36 /**
37  * Event logged when {@link DeviceAdminReceiver#onBugreportShared(Context, Intent, String)}
38  * is called.
39  */
40 public final class DeviceAdminBugreportSharedEvent extends Event {
41 
42     private static final long serialVersionUID = 1;
43 
44     /** Begins a query for {@link DeviceAdminBugreportSharedEvent} events. */
queryPackage(String packageName)45     public static DeviceAdminBugreportSharedEventQuery queryPackage(String packageName) {
46         return new DeviceAdminBugreportSharedEventQuery(packageName);
47     }
48 
49     /** {@link EventLogsQuery} for {@link DeviceAdminBugreportSharedEvent}. */
50     public static final class DeviceAdminBugreportSharedEventQuery
51             extends EventLogsQuery<DeviceAdminBugreportSharedEvent,
52             DeviceAdminBugreportSharedEventQuery> {
53 
54         private static final long serialVersionUID = 1;
55 
56         DeviceAdminReceiverQueryHelper<DeviceAdminBugreportSharedEventQuery> mDeviceAdminReceiver =
57                 new DeviceAdminReceiverQueryHelper<>(this);
58         IntentQueryHelper<DeviceAdminBugreportSharedEventQuery> mIntent =
59                 new IntentQueryHelper<>(this);
60         StringQueryHelper<DeviceAdminBugreportSharedEventQuery> mBugreportHash =
61                 new StringQueryHelper<>(this);
62 
DeviceAdminBugreportSharedEventQuery(String packageName)63         private DeviceAdminBugreportSharedEventQuery(String packageName) {
64             super(DeviceAdminBugreportSharedEvent.class, packageName);
65         }
66 
67         /**
68          * Queries {@link Intent} passed into
69          * {@link DeviceAdminReceiver#onBugreportShared(Context, Intent, String)}.
70          */
71         @CheckResult
whereIntent()72         public IntentQueryHelper<DeviceAdminBugreportSharedEventQuery> whereIntent() {
73             return mIntent;
74         }
75 
76         /** Queries {@link DeviceAdminReceiver}. */
77         @CheckResult
whereDeviceAdminReceiver()78         public DeviceAdminReceiverQuery<DeviceAdminBugreportSharedEventQuery> whereDeviceAdminReceiver() {
79             return mDeviceAdminReceiver;
80         }
81 
82         /** Queries {@code bugReportHash}. */
83         @CheckResult
whereBugreportHash()84         public StringQuery<DeviceAdminBugreportSharedEventQuery> whereBugreportHash() {
85             return mBugreportHash;
86         }
87 
88         @Override
filter(DeviceAdminBugreportSharedEvent event)89         protected boolean filter(DeviceAdminBugreportSharedEvent event) {
90             if (!mIntent.matches(event.mIntent)) {
91                 return false;
92             }
93             if (!mDeviceAdminReceiver.matches(event.mDeviceAdminReceiver)) {
94                 return false;
95             }
96             if (!mBugreportHash.matches(event.mBugreportHash)) {
97                 return false;
98             }
99             return true;
100         }
101 
102         @Override
describeQuery(String fieldName)103         public String describeQuery(String fieldName) {
104             return toStringBuilder(DeviceAdminBugreportSharedEvent.class, this)
105                     .field("intent", mIntent)
106                     .field("deviceAdminReceiver", mDeviceAdminReceiver)
107                     .field("bugReportHash", mBugreportHash)
108                     .toString();
109         }
110     }
111 
112     /** Begins logging a {@link DeviceAdminBugreportSharedEvent}. */
logger( DeviceAdminReceiver deviceAdminReceiver, Context context, Intent intent, String bugreportHash)113     public static DeviceAdminBugreportSharedEventLogger logger(
114             DeviceAdminReceiver deviceAdminReceiver,
115             Context context, Intent intent, String bugreportHash) {
116         return new DeviceAdminBugreportSharedEventLogger(
117                 deviceAdminReceiver, context, intent, bugreportHash);
118     }
119 
120     /** {@link EventLogger} for {@link DeviceAdminBugreportSharedEvent}. */
121     public static final class DeviceAdminBugreportSharedEventLogger
122             extends EventLogger<DeviceAdminBugreportSharedEvent> {
DeviceAdminBugreportSharedEventLogger( DeviceAdminReceiver deviceAdminReceiver, Context context, Intent intent, String bugreportHash)123         private DeviceAdminBugreportSharedEventLogger(
124                 DeviceAdminReceiver deviceAdminReceiver,
125                 Context context, Intent intent, String bugreportHash) {
126             super(context, new DeviceAdminBugreportSharedEvent());
127             mEvent.mIntent = new SerializableParcelWrapper<>(intent);
128             mEvent.mBugreportHash = bugreportHash;
129             setDeviceAdminReceiver(deviceAdminReceiver);
130         }
131 
132         /** Sets the {@link DeviceAdminReceiver} which received this event. */
setDeviceAdminReceiver( DeviceAdminReceiver deviceAdminReceiver)133         public DeviceAdminBugreportSharedEventLogger setDeviceAdminReceiver(
134                 DeviceAdminReceiver deviceAdminReceiver) {
135             mEvent.mDeviceAdminReceiver = new DeviceAdminReceiverInfo(deviceAdminReceiver);
136             return this;
137         }
138 
139         /** Sets the {@link DeviceAdminReceiver} which received this event. */
setDeviceAdminReceiver( Class<? extends DeviceAdminReceiver> deviceAdminReceiverClass)140         public DeviceAdminBugreportSharedEventLogger setDeviceAdminReceiver(
141                 Class<? extends DeviceAdminReceiver> deviceAdminReceiverClass) {
142             mEvent.mDeviceAdminReceiver = new DeviceAdminReceiverInfo(deviceAdminReceiverClass);
143             return this;
144         }
145 
146         /** Sets the {@link DeviceAdminReceiver} which received this event. */
setDeviceAdminReceiver( String deviceAdminReceiverClassName)147         public DeviceAdminBugreportSharedEventLogger setDeviceAdminReceiver(
148                 String deviceAdminReceiverClassName) {
149             mEvent.mDeviceAdminReceiver = new DeviceAdminReceiverInfo(deviceAdminReceiverClassName);
150             return this;
151         }
152 
153         /** Sets the {@link Intent} which was received. */
setIntent(Intent intent)154         public DeviceAdminBugreportSharedEventLogger setIntent(Intent intent) {
155             mEvent.mIntent = new SerializableParcelWrapper<>(intent);
156             return this;
157         }
158 
159         /** Sets the {@code bugreportHash} which was received. */
setBugreportHash(String bugreportHash)160         public DeviceAdminBugreportSharedEventLogger setBugreportHash(String bugreportHash) {
161             mEvent.mBugreportHash = bugreportHash;
162             return this;
163         }
164     }
165 
166     protected SerializableParcelWrapper<Intent> mIntent;
167     protected DeviceAdminReceiverInfo mDeviceAdminReceiver;
168     protected String mBugreportHash;
169 
170     /**
171      * The {@link Intent} passed into
172      * {@link DeviceAdminReceiver#onBugreportShared(Context, Intent, String)}.
173      */
intent()174     public Intent intent() {
175         if (mIntent == null) {
176             return null;
177         }
178         return mIntent.get();
179     }
180 
181     /** Information about the {@link DeviceAdminReceiver} which received the intent. */
deviceAdminReceiver()182     public DeviceAdminReceiverInfo deviceAdminReceiver() {
183         return mDeviceAdminReceiver;
184     }
185 
186     /**
187      * The {@code bugreportHash} passed into
188      * {@link DeviceAdminReceiver#onBugreportShared(Context, Intent, String)}.
189      */
bugreportHash()190     public String bugreportHash() {
191         return mBugreportHash;
192     }
193 
194     @Override
toString()195     public String toString() {
196         return "DeviceAdminBugreportSharedEvent{"
197                 + " intent=" + intent()
198                 + ", bugreportHash=" + mBugreportHash
199                 + ", deviceAdminReceiver=" + mDeviceAdminReceiver
200                 + ", packageName='" + mPackageName + "'"
201                 + ", timestamp=" + mTimestamp
202                 + "}";
203     }
204 }
205