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