1 /* 2 * Copyright (C) 2019 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 android.view; 18 19 import android.annotation.NonNull; 20 import android.os.Parcel; 21 import android.os.Parcelable; 22 import android.os.RemoteException; 23 24 import com.android.internal.util.DataClass; 25 26 /** 27 * An {@code InputMonitor} allows privileged applications and components to monitor streams of 28 * {@link InputEvent}s without having to be the designated recipient for the event. 29 * 30 * For example, focus dispatched events would normally only go to the focused window on the 31 * targeted display, but an {@code InputMonitor} will also receive a copy of that event if they're 32 * registered to monitor that type of event on the targeted display. 33 * 34 * @hide 35 */ 36 @DataClass(genToString = true) 37 public final class InputMonitor implements Parcelable { 38 private static final String TAG = "InputMonitor"; 39 40 private static final boolean DEBUG = false; 41 42 @NonNull 43 private final InputChannel mInputChannel; 44 @NonNull 45 private final IInputMonitorHost mHost; 46 @NonNull 47 private final SurfaceControl mSurface; 48 49 /** 50 * Takes all of the current pointer events streams that are currently being sent to this 51 * monitor and generates appropriate cancellations for the windows that would normally get 52 * them. 53 * 54 * This method should be used with caution as unexpected pilfering can break fundamental user 55 * interactions. 56 */ pilferPointers()57 public void pilferPointers() { 58 try { 59 mHost.pilferPointers(); 60 } catch (RemoteException e) { 61 e.rethrowFromSystemServer(); 62 } 63 } 64 65 /** 66 * Disposes the input monitor. 67 * 68 * Explicitly release all of the resources this monitor is holding on to (e.g. the 69 * InputChannel). Once this method is called, this monitor and any resources it's provided may 70 * no longer be used. 71 */ dispose()72 public void dispose() { 73 mInputChannel.dispose(); 74 mSurface.release(); 75 try { 76 mHost.dispose(); 77 } catch (RemoteException e) { 78 e.rethrowFromSystemServer(); 79 } 80 } 81 82 83 84 // Code below generated by codegen v1.0.23. 85 // 86 // DO NOT MODIFY! 87 // CHECKSTYLE:OFF Generated code 88 // 89 // To regenerate run: 90 // $ codegen $ANDROID_BUILD_TOP/frameworks/base/core/java/android/view/InputMonitor.java 91 // 92 // To exclude the generated code from IntelliJ auto-formatting enable (one-time): 93 // Settings > Editor > Code Style > Formatter Control 94 //@formatter:off 95 96 97 @DataClass.Generated.Member InputMonitor( @onNull InputChannel inputChannel, @NonNull IInputMonitorHost host, @NonNull SurfaceControl surface)98 public InputMonitor( 99 @NonNull InputChannel inputChannel, 100 @NonNull IInputMonitorHost host, 101 @NonNull SurfaceControl surface) { 102 this.mInputChannel = inputChannel; 103 com.android.internal.util.AnnotationValidations.validate( 104 NonNull.class, null, mInputChannel); 105 this.mHost = host; 106 com.android.internal.util.AnnotationValidations.validate( 107 NonNull.class, null, mHost); 108 this.mSurface = surface; 109 com.android.internal.util.AnnotationValidations.validate( 110 NonNull.class, null, mSurface); 111 112 // onConstructed(); // You can define this method to get a callback 113 } 114 115 @DataClass.Generated.Member getInputChannel()116 public @NonNull InputChannel getInputChannel() { 117 return mInputChannel; 118 } 119 120 @DataClass.Generated.Member getHost()121 public @NonNull IInputMonitorHost getHost() { 122 return mHost; 123 } 124 125 @DataClass.Generated.Member getSurface()126 public @NonNull SurfaceControl getSurface() { 127 return mSurface; 128 } 129 130 @Override 131 @DataClass.Generated.Member toString()132 public String toString() { 133 // You can override field toString logic by defining methods like: 134 // String fieldNameToString() { ... } 135 136 return "InputMonitor { " + 137 "inputChannel = " + mInputChannel + ", " + 138 "host = " + mHost + ", " + 139 "surface = " + mSurface + 140 " }"; 141 } 142 143 @Override 144 @DataClass.Generated.Member writeToParcel(@onNull Parcel dest, int flags)145 public void writeToParcel(@NonNull Parcel dest, int flags) { 146 // You can override field parcelling by defining methods like: 147 // void parcelFieldName(Parcel dest, int flags) { ... } 148 149 dest.writeTypedObject(mInputChannel, flags); 150 dest.writeStrongInterface(mHost); 151 dest.writeTypedObject(mSurface, flags); 152 } 153 154 @Override 155 @DataClass.Generated.Member describeContents()156 public int describeContents() { return 0; } 157 158 /** @hide */ 159 @SuppressWarnings({"unchecked", "RedundantCast"}) 160 @DataClass.Generated.Member InputMonitor(@onNull Parcel in)161 /* package-private */ InputMonitor(@NonNull Parcel in) { 162 // You can override field unparcelling by defining methods like: 163 // static FieldType unparcelFieldName(Parcel in) { ... } 164 165 InputChannel inputChannel = (InputChannel) in.readTypedObject(InputChannel.CREATOR); 166 IInputMonitorHost host = IInputMonitorHost.Stub.asInterface(in.readStrongBinder()); 167 SurfaceControl surface = (SurfaceControl) in.readTypedObject(SurfaceControl.CREATOR); 168 169 this.mInputChannel = inputChannel; 170 com.android.internal.util.AnnotationValidations.validate( 171 NonNull.class, null, mInputChannel); 172 this.mHost = host; 173 com.android.internal.util.AnnotationValidations.validate( 174 NonNull.class, null, mHost); 175 this.mSurface = surface; 176 com.android.internal.util.AnnotationValidations.validate( 177 NonNull.class, null, mSurface); 178 179 // onConstructed(); // You can define this method to get a callback 180 } 181 182 @DataClass.Generated.Member 183 public static final @NonNull Parcelable.Creator<InputMonitor> CREATOR 184 = new Parcelable.Creator<InputMonitor>() { 185 @Override 186 public InputMonitor[] newArray(int size) { 187 return new InputMonitor[size]; 188 } 189 190 @Override 191 public InputMonitor createFromParcel(@NonNull Parcel in) { 192 return new InputMonitor(in); 193 } 194 }; 195 196 @DataClass.Generated( 197 time = 1679692514588L, 198 codegenVersion = "1.0.23", 199 sourceFile = "frameworks/base/core/java/android/view/InputMonitor.java", 200 inputSignatures = "private static final java.lang.String TAG\nprivate static final boolean DEBUG\nprivate final @android.annotation.NonNull android.view.InputChannel mInputChannel\nprivate final @android.annotation.NonNull android.view.IInputMonitorHost mHost\nprivate final @android.annotation.NonNull android.view.SurfaceControl mSurface\npublic void pilferPointers()\npublic void dispose()\nclass InputMonitor extends java.lang.Object implements [android.os.Parcelable]\n@com.android.internal.util.DataClass(genToString=true)") 201 @Deprecated __metadata()202 private void __metadata() {} 203 204 205 //@formatter:on 206 // End of generated code 207 208 } 209