• Home
  • History
  • Annotate
  • 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 import android.net.Uri;
23 
24 import androidx.annotation.CheckResult;
25 
26 import com.android.eventlib.Event;
27 import com.android.eventlib.EventLogger;
28 import com.android.eventlib.EventLogsQuery;
29 import com.android.queryable.info.DeviceAdminReceiverInfo;
30 import com.android.queryable.queries.DeviceAdminReceiverQuery;
31 import com.android.queryable.queries.DeviceAdminReceiverQueryHelper;
32 import com.android.queryable.queries.IntegerQuery;
33 import com.android.queryable.queries.IntegerQueryHelper;
34 import com.android.queryable.queries.IntentQueryHelper;
35 import com.android.queryable.queries.StringQuery;
36 import com.android.queryable.queries.StringQueryHelper;
37 import com.android.queryable.queries.UriQuery;
38 import com.android.queryable.queries.UriQueryHelper;
39 import com.android.queryable.util.SerializableParcelWrapper;
40 
41 /**
42  * Event logged when
43  * {@link DeviceAdminReceiver#onChoosePrivateKeyAlias(Context, Intent, int, Uri, String)} is called.
44  */
45 public final class DeviceAdminChoosePrivateKeyAliasEvent extends Event {
46 
47     private static final long serialVersionUID = 1;
48 
49     /** Begins a query for {@link DeviceAdminChoosePrivateKeyAliasEvent} events. */
queryPackage(String packageName)50     public static DeviceAdminChoosePrivateKeyAliasEventQuery queryPackage(String packageName) {
51         return new DeviceAdminChoosePrivateKeyAliasEventQuery(packageName);
52     }
53 
54     /** {@link EventLogsQuery} for {@link DeviceAdminChoosePrivateKeyAliasEvent}. */
55     public static final class DeviceAdminChoosePrivateKeyAliasEventQuery
56             extends EventLogsQuery<DeviceAdminChoosePrivateKeyAliasEvent,
57             DeviceAdminChoosePrivateKeyAliasEventQuery> {
58 
59         private static final long serialVersionUID = 1;
60 
61         DeviceAdminReceiverQueryHelper<DeviceAdminChoosePrivateKeyAliasEventQuery> mDeviceAdminReceiver =
62                 new DeviceAdminReceiverQueryHelper<>(this);
63         IntentQueryHelper<DeviceAdminChoosePrivateKeyAliasEventQuery> mIntent =
64                 new IntentQueryHelper<>(this);
65         IntegerQueryHelper<DeviceAdminChoosePrivateKeyAliasEventQuery> mUid =
66                 new IntegerQueryHelper<>(this);
67         UriQueryHelper<DeviceAdminChoosePrivateKeyAliasEventQuery> mUri =
68                 new UriQueryHelper<>(this);
69         StringQueryHelper<DeviceAdminChoosePrivateKeyAliasEventQuery> mAlias =
70                 new StringQueryHelper<>(this);
71 
DeviceAdminChoosePrivateKeyAliasEventQuery(String packageName)72         private DeviceAdminChoosePrivateKeyAliasEventQuery(String packageName) {
73             super(DeviceAdminChoosePrivateKeyAliasEvent.class, packageName);
74         }
75 
76         /**
77          * Queries {@link Intent} passed into
78          * {@link DeviceAdminReceiver#onChoosePrivateKeyAlias(Context, Intent, int, Uri, String).
79          */
80         @CheckResult
whereIntent()81         public IntentQueryHelper<DeviceAdminChoosePrivateKeyAliasEventQuery> whereIntent() {
82             return mIntent;
83         }
84 
85         /** Queries {@link DeviceAdminReceiver}. */
86         @CheckResult
whereDeviceAdminReceiver()87         public DeviceAdminReceiverQuery<DeviceAdminChoosePrivateKeyAliasEventQuery> whereDeviceAdminReceiver() {
88             return mDeviceAdminReceiver;
89         }
90 
91         /** Query {@code uid}. */
92         @CheckResult
whereUid()93         public IntegerQuery<DeviceAdminChoosePrivateKeyAliasEventQuery> whereUid() {
94             return mUid;
95         }
96 
97         /** Queries {@link Uri}. */
98         @CheckResult
whereUri()99         public UriQuery<DeviceAdminChoosePrivateKeyAliasEventQuery> whereUri() {
100             return mUri;
101         }
102 
103         /** Query {@code alias}. */
104         @CheckResult
whereAlias()105         public StringQuery<DeviceAdminChoosePrivateKeyAliasEventQuery> whereAlias() {
106             return mAlias;
107         }
108 
109         @Override
filter(DeviceAdminChoosePrivateKeyAliasEvent event)110         protected boolean filter(DeviceAdminChoosePrivateKeyAliasEvent event) {
111             if (!mIntent.matches(event.mIntent)) {
112                 return false;
113             }
114             if (!mDeviceAdminReceiver.matches(event.mDeviceAdminReceiver)) {
115                 return false;
116             }
117             if (!mUid.matches(event.mUid)) {
118                 return false;
119             }
120             if (!mUri.matches(event.mUri)) {
121                 return false;
122             }
123             if (!mAlias.matches(event.mAlias)) {
124                 return false;
125             }
126             return true;
127         }
128 
129         @Override
describeQuery(String fieldName)130         public String describeQuery(String fieldName) {
131             return toStringBuilder(DeviceAdminChoosePrivateKeyAliasEvent.class, this)
132                     .field("intent", mIntent)
133                     .field("deviceAdminReceiver", mDeviceAdminReceiver)
134                     .field("uid", mUid)
135                     .field("uri", mUri)
136                     .field("alias", mAlias)
137                     .toString();
138         }
139     }
140 
141     /** Begins logging a {@link DeviceAdminChoosePrivateKeyAliasEvent}. */
logger( DeviceAdminReceiver deviceAdminReceiver, Context context, Intent intent, int uid, Uri uri, String alias)142     public static DeviceAdminChoosePrivateKeyAliasEventLogger logger(
143             DeviceAdminReceiver deviceAdminReceiver, Context context,
144             Intent intent, int uid, Uri uri, String alias) {
145         return new DeviceAdminChoosePrivateKeyAliasEventLogger(
146                 deviceAdminReceiver, context, intent, uid, uri, alias);
147     }
148 
149     /** {@link EventLogger} for {@link DeviceAdminChoosePrivateKeyAliasEvent}. */
150     public static final class DeviceAdminChoosePrivateKeyAliasEventLogger
151             extends EventLogger<DeviceAdminChoosePrivateKeyAliasEvent> {
DeviceAdminChoosePrivateKeyAliasEventLogger( DeviceAdminReceiver deviceAdminReceiver, Context context, Intent intent, int uid, Uri uri, String alias)152         private DeviceAdminChoosePrivateKeyAliasEventLogger(
153                 DeviceAdminReceiver deviceAdminReceiver, Context context, Intent intent,
154                 int uid, Uri uri, String alias) {
155             super(context, new DeviceAdminChoosePrivateKeyAliasEvent());
156             mEvent.mIntent = new SerializableParcelWrapper<>(intent);
157             mEvent.mUid = uid;
158             mEvent.mUri = new SerializableParcelWrapper<>(uri);
159             mEvent.mAlias = alias;
160             setDeviceAdminReceiver(deviceAdminReceiver);
161         }
162 
163         /** Sets the {@link DeviceAdminReceiver} which received this event. */
setDeviceAdminReceiver( DeviceAdminReceiver deviceAdminReceiver)164         public DeviceAdminChoosePrivateKeyAliasEventLogger setDeviceAdminReceiver(
165                 DeviceAdminReceiver deviceAdminReceiver) {
166             mEvent.mDeviceAdminReceiver = new DeviceAdminReceiverInfo(deviceAdminReceiver);
167             return this;
168         }
169 
170         /** Sets the {@link DeviceAdminReceiver} which received this event. */
setDeviceAdminReceiver( Class<? extends DeviceAdminReceiver> deviceAdminReceiverClass)171         public DeviceAdminChoosePrivateKeyAliasEventLogger setDeviceAdminReceiver(
172                 Class<? extends DeviceAdminReceiver> deviceAdminReceiverClass) {
173             mEvent.mDeviceAdminReceiver = new DeviceAdminReceiverInfo(deviceAdminReceiverClass);
174             return this;
175         }
176 
177         /** Sets the {@link DeviceAdminReceiver} which received this event. */
setDeviceAdminReceiver( String deviceAdminReceiverClassName)178         public DeviceAdminChoosePrivateKeyAliasEventLogger setDeviceAdminReceiver(
179                 String deviceAdminReceiverClassName) {
180             mEvent.mDeviceAdminReceiver = new DeviceAdminReceiverInfo(deviceAdminReceiverClassName);
181             return this;
182         }
183 
184         /** Sets the {@link Intent} which was received. */
setIntent(Intent intent)185         public DeviceAdminChoosePrivateKeyAliasEventLogger setIntent(Intent intent) {
186             mEvent.mIntent = new SerializableParcelWrapper<>(intent);
187             return this;
188         }
189 
190         /** Sets the {@code uid} which was received. */
setUid(int uid)191         public DeviceAdminChoosePrivateKeyAliasEventLogger setUid(int uid) {
192             mEvent.mUid = uid;
193             return this;
194         }
195 
196         /** Sets the {@link Uri} which was received. */
setUri(Uri uri)197         public DeviceAdminChoosePrivateKeyAliasEventLogger setUri(Uri uri) {
198             mEvent.mUri = new SerializableParcelWrapper<>(uri);
199             return this;
200         }
201 
202         /** Sets the {@code alias} which was received. */
setAlias(String alias)203         public DeviceAdminChoosePrivateKeyAliasEventLogger setAlias(String alias) {
204             mEvent.mAlias = alias;
205             return this;
206         }
207     }
208 
209     protected SerializableParcelWrapper<Intent> mIntent;
210     protected DeviceAdminReceiverInfo mDeviceAdminReceiver;
211     protected int mUid;
212     protected SerializableParcelWrapper<Uri> mUri;
213     protected String mAlias;
214 
215     /**
216      * The {@link Intent} passed into
217      * {@link DeviceAdminReceiver#onChoosePrivateKeyAlias(Context, Intent, int, Uri, String)
218      */
intent()219     public Intent intent() {
220         if (mIntent == null) {
221             return null;
222         }
223         return mIntent.get();
224     }
225 
226     /** Information about the {@link DeviceAdminReceiver} which received the intent. */
deviceAdminReceiver()227     public DeviceAdminReceiverInfo deviceAdminReceiver() {
228         return mDeviceAdminReceiver;
229     }
230 
231     /**
232      * The {@code uid} passed into
233      * {@link DeviceAdminReceiver#onChoosePrivateKeyAlias(Context, Intent, int, Uri, String)
234      */
uid()235     public int uid() {
236         return mUid;
237     }
238 
239     /**
240      * The {@link Uri} passed into
241      * {@link DeviceAdminReceiver#onChoosePrivateKeyAlias(Context, Intent, int, Uri, String)
242      */
uri()243     public Uri uri() {
244         if (mUri == null) {
245             return null;
246         }
247         return mUri.get();
248     }
249 
250     /**
251      * The {@code alias} passed into
252      * {@link DeviceAdminReceiver#onChoosePrivateKeyAlias(Context, Intent, int, Uri, String)
253      */
alias()254     public String alias() {
255         return mAlias;
256     }
257 
258     @Override
toString()259     public String toString() {
260         return "DeviceAdminChoosePrivateKeyAliasEvent{"
261                 + " intent=" + intent()
262                 + ", uid=" + mUid
263                 + ", uri=" + uri()
264                 + ", alias=" + mAlias
265                 + ", deviceAdminReceiver=" + mDeviceAdminReceiver
266                 + ", packageName='" + mPackageName + "'"
267                 + ", timestamp=" + mTimestamp
268                 + "}";
269     }
270 }
271