1 /*
2  * Copyright (C) 2009 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.internal.view;
18 
19 import android.annotation.Nullable;
20 import android.compat.annotation.UnsupportedAppUsage;
21 import android.hardware.input.InputManagerGlobal;
22 import android.os.Bundle;
23 import android.os.ParcelFileDescriptor;
24 import android.os.RemoteException;
25 import android.util.MergedConfiguration;
26 import android.view.DragEvent;
27 import android.view.IScrollCaptureResponseListener;
28 import android.view.IWindow;
29 import android.view.IWindowSession;
30 import android.view.InsetsSourceControl;
31 import android.view.InsetsState;
32 import android.view.PointerIcon;
33 import android.view.ScrollCaptureResponse;
34 import android.view.WindowInsets.Type.InsetsType;
35 import android.view.inputmethod.ImeTracker;
36 import android.window.ClientWindowFrames;
37 
38 import com.android.internal.os.IResultReceiver;
39 
40 import java.io.IOException;
41 
42 public class BaseIWindow extends IWindow.Stub {
43 
44     @UnsupportedAppUsage(maxTargetSdk = android.os.Build.VERSION_CODES.P)
BaseIWindow()45     public BaseIWindow() {}
46 
47     private IWindowSession mSession;
48 
setSession(IWindowSession session)49     public void setSession(IWindowSession session) {
50         mSession = session;
51     }
52 
53     @Override
resized(ClientWindowFrames frames, boolean reportDraw, MergedConfiguration mergedConfiguration, InsetsState insetsState, boolean forceLayout, boolean alwaysConsumeSystemBars, int displayId, int seqId, boolean dragResizing)54     public void resized(ClientWindowFrames frames, boolean reportDraw,
55             MergedConfiguration mergedConfiguration, InsetsState insetsState, boolean forceLayout,
56             boolean alwaysConsumeSystemBars, int displayId, int seqId, boolean dragResizing) {
57         if (reportDraw) {
58             try {
59                 mSession.finishDrawing(this, null /* postDrawTransaction */, seqId);
60             } catch (RemoteException e) {
61             }
62         }
63     }
64 
65     @Override
insetsControlChanged(InsetsState insetsState, InsetsSourceControl[] activeControls)66     public void insetsControlChanged(InsetsState insetsState,
67             InsetsSourceControl[] activeControls) {
68     }
69 
70     @Override
showInsets(@nsetsType int types, boolean fromIme, @Nullable ImeTracker.Token statsToken)71     public void showInsets(@InsetsType int types, boolean fromIme,
72             @Nullable ImeTracker.Token statsToken) {
73     }
74 
75     @Override
hideInsets(@nsetsType int types, boolean fromIme, @Nullable ImeTracker.Token statsToken)76     public void hideInsets(@InsetsType int types, boolean fromIme,
77             @Nullable ImeTracker.Token statsToken) {
78     }
79 
80     @Override
moved(int newX, int newY)81     public void moved(int newX, int newY) {
82     }
83 
84     @Override
dispatchAppVisibility(boolean visible)85     public void dispatchAppVisibility(boolean visible) {
86     }
87 
88     @Override
dispatchGetNewSurface()89     public void dispatchGetNewSurface() {
90     }
91 
92     @Override
executeCommand(String command, String parameters, ParcelFileDescriptor out)93     public void executeCommand(String command, String parameters, ParcelFileDescriptor out) {
94         if (out != null) {
95             try {
96                 out.closeWithError("Unsupported command " + command);
97             } catch (IOException e) {
98                 // Ignore
99             }
100         }
101     }
102 
103     @Override
closeSystemDialogs(String reason)104     public void closeSystemDialogs(String reason) {
105     }
106 
107     @Override
dispatchWallpaperOffsets(float x, float y, float xStep, float yStep, float zoom, boolean sync)108     public void dispatchWallpaperOffsets(float x, float y, float xStep, float yStep, float zoom,
109             boolean sync) {
110         if (sync) {
111             try {
112                 mSession.wallpaperOffsetsComplete(asBinder());
113             } catch (RemoteException e) {
114             }
115         }
116     }
117 
118     @Override
dispatchDragEvent(DragEvent event)119     public void dispatchDragEvent(DragEvent event) {
120         if (event.getAction() == DragEvent.ACTION_DROP) {
121             try {
122                 mSession.reportDropResult(this, false);
123             } catch (RemoteException e) {
124             }
125         }
126     }
127 
128     @Override
updatePointerIcon(float x, float y)129     public void updatePointerIcon(float x, float y) {
130         InputManagerGlobal.getInstance()
131                 .setPointerIconType(PointerIcon.TYPE_NOT_SPECIFIED);
132     }
133 
134     @Override
dispatchWallpaperCommand(String action, int x, int y, int z, Bundle extras, boolean sync)135     public void dispatchWallpaperCommand(String action, int x, int y,
136             int z, Bundle extras, boolean sync) {
137         if (sync) {
138             try {
139                 mSession.wallpaperCommandComplete(asBinder(), null);
140             } catch (RemoteException e) {
141             }
142         }
143     }
144 
145     @Override
dispatchWindowShown()146     public void dispatchWindowShown() {
147     }
148 
149     @Override
requestAppKeyboardShortcuts(IResultReceiver receiver, int deviceId)150     public void requestAppKeyboardShortcuts(IResultReceiver receiver, int deviceId) {
151     }
152 
153     @Override
requestScrollCapture(IScrollCaptureResponseListener listener)154     public void requestScrollCapture(IScrollCaptureResponseListener listener) {
155         try {
156             listener.onScrollCaptureResponse(
157                     new ScrollCaptureResponse.Builder().setDescription("Not Implemented").build());
158 
159         } catch (RemoteException ex) {
160             // ignore
161         }
162     }
163 }
164