• 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.util.SerializableParcelWrapper;
33 
34 /**
35  * Event logged when {@link DeviceAdminReceiver#onDisableRequested(Context, Intent)} is called.
36  */
37 public final class DeviceAdminDisableRequestedEvent extends Event {
38 
39     private static final long serialVersionUID = 1;
40 
41     /** Begins a query for {@link DeviceAdminDisableRequestedEvent} events. */
queryPackage(String packageName)42     public static DeviceAdminDisableRequestedEventQuery queryPackage(String packageName) {
43         return new DeviceAdminDisableRequestedEventQuery(packageName);
44     }
45 
46     /** {@link EventLogsQuery} for {@link DeviceAdminDisableRequestedEvent}. */
47     public static final class DeviceAdminDisableRequestedEventQuery
48             extends EventLogsQuery<DeviceAdminDisableRequestedEvent,
49             DeviceAdminDisableRequestedEventQuery> {
50 
51         private static final long serialVersionUID = 1;
52 
53         DeviceAdminReceiverQueryHelper<DeviceAdminDisableRequestedEventQuery> mDeviceAdminReceiver =
54                 new DeviceAdminReceiverQueryHelper<>(this);
55         IntentQueryHelper<DeviceAdminDisableRequestedEventQuery> mIntent =
56                 new IntentQueryHelper<>(this);
57 
DeviceAdminDisableRequestedEventQuery(String packageName)58         private DeviceAdminDisableRequestedEventQuery(String packageName) {
59             super(DeviceAdminDisableRequestedEvent.class, packageName);
60         }
61 
62         /**
63          * Queries {@link Intent} passed into
64          * {@link DeviceAdminReceiver#onDisableRequested(Context, Intent)}.
65          */
66         @CheckResult
whereIntent()67         public IntentQueryHelper<DeviceAdminDisableRequestedEventQuery> whereIntent() {
68             return mIntent;
69         }
70 
71         /** Queries {@link DeviceAdminReceiver}. */
72         @CheckResult
73         public DeviceAdminReceiverQuery<DeviceAdminDisableRequestedEventQuery>
whereDeviceAdminReceiver()74                 whereDeviceAdminReceiver() {
75             return mDeviceAdminReceiver;
76         }
77 
78         @Override
filter(DeviceAdminDisableRequestedEvent event)79         protected boolean filter(DeviceAdminDisableRequestedEvent event) {
80             if (!mIntent.matches(event.mIntent)) {
81                 return false;
82             }
83             if (!mDeviceAdminReceiver.matches(event.mDeviceAdminReceiver)) {
84                 return false;
85             }
86             return true;
87         }
88 
89         @Override
describeQuery(String fieldName)90         public String describeQuery(String fieldName) {
91             return toStringBuilder(DeviceAdminDisableRequestedEvent.class, this)
92                     .field("intent", mIntent)
93                     .field("deviceAdminReceiver", mDeviceAdminReceiver)
94                     .toString();
95         }
96     }
97 
98     /** Begins logging a {@link DeviceAdminDisableRequestedEvent}. */
logger( DeviceAdminReceiver deviceAdminReceiver, Context context, Intent intent)99     public static DeviceAdminDisableRequestedEventLogger logger(
100             DeviceAdminReceiver deviceAdminReceiver, Context context, Intent intent) {
101         return new DeviceAdminDisableRequestedEventLogger(deviceAdminReceiver, context, intent);
102     }
103 
104     /** {@link EventLogger} for {@link DeviceAdminDisableRequestedEvent}. */
105     public static final class DeviceAdminDisableRequestedEventLogger
106             extends EventLogger<DeviceAdminDisableRequestedEvent> {
DeviceAdminDisableRequestedEventLogger( DeviceAdminReceiver deviceAdminReceiver, Context context, Intent intent)107         private DeviceAdminDisableRequestedEventLogger(
108                 DeviceAdminReceiver deviceAdminReceiver, Context context, Intent intent) {
109             super(context, new DeviceAdminDisableRequestedEvent());
110             mEvent.mIntent = new SerializableParcelWrapper<>(intent);
111             setDeviceAdminReceiver(deviceAdminReceiver);
112         }
113 
114         /** Sets the {@link DeviceAdminReceiver} which received this event. */
setDeviceAdminReceiver( DeviceAdminReceiver deviceAdminReceiver)115         public DeviceAdminDisableRequestedEventLogger setDeviceAdminReceiver(
116                 DeviceAdminReceiver deviceAdminReceiver) {
117             mEvent.mDeviceAdminReceiver = new DeviceAdminReceiverInfo(deviceAdminReceiver);
118             return this;
119         }
120 
121         /** Sets the {@link DeviceAdminReceiver} which received this event. */
setDeviceAdminReceiver( Class<? extends DeviceAdminReceiver> deviceAdminReceiverClass)122         public DeviceAdminDisableRequestedEventLogger setDeviceAdminReceiver(
123                 Class<? extends DeviceAdminReceiver> deviceAdminReceiverClass) {
124             mEvent.mDeviceAdminReceiver = new DeviceAdminReceiverInfo(deviceAdminReceiverClass);
125             return this;
126         }
127 
128         /** Sets the {@link DeviceAdminReceiver} which received this event. */
setDeviceAdminReceiver( String deviceAdminReceiverClassName)129         public DeviceAdminDisableRequestedEventLogger setDeviceAdminReceiver(
130                 String deviceAdminReceiverClassName) {
131             mEvent.mDeviceAdminReceiver = new DeviceAdminReceiverInfo(deviceAdminReceiverClassName);
132             return this;
133         }
134 
135         /** Sets the {@link Intent} which was received. */
setIntent(Intent intent)136         public DeviceAdminDisableRequestedEventLogger setIntent(Intent intent) {
137             mEvent.mIntent = new SerializableParcelWrapper<>(intent);
138             return this;
139         }
140     }
141 
142     protected SerializableParcelWrapper<Intent> mIntent;
143     protected DeviceAdminReceiverInfo mDeviceAdminReceiver;
144 
145     /**
146      * The {@link Intent} passed into
147      * {@link DeviceAdminReceiver#onDisableRequested(Context, Intent)}.
148      */
intent()149     public Intent intent() {
150         if (mIntent == null) {
151             return null;
152         }
153         return mIntent.get();
154     }
155 
156     /** Information about the {@link DeviceAdminReceiver} which received the intent. */
deviceAdminReceiver()157     public DeviceAdminReceiverInfo deviceAdminReceiver() {
158         return mDeviceAdminReceiver;
159     }
160 
161     @Override
toString()162     public String toString() {
163         return "DeviceAdminDisableRequestedEvent{"
164                 + " intent=" + intent()
165                 + ", deviceAdminReceiver=" + mDeviceAdminReceiver
166                 + ", packageName='" + mPackageName + "'"
167                 + ", timestamp=" + mTimestamp
168                 + "}";
169     }
170 }
171