Debian Codegraph @

core/java/android/service/dreams/DreamOverlayService.java

raw symbols SCIP
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 android.service.dreams;
18
19 import android.annotation.NonNull;
20 import android.annotation.Nullable;
21 import android.annotation.TestApi;
22 import android.app.Service;
23 import android.content.ComponentName;
24 import android.content.Intent;
25 import android.os.IBinder;
26 import android.os.RemoteException;
27 import android.util.Log;
28 import android.view.WindowManager;
29
30
31 /**
32 * Basic implementation of for {@link IDreamOverlay} for testing.
33 * @hide
34 */
35 @TestApi
36 public abstract class DreamOverlayService extends Service {
37 private static final String TAG = "DreamOverlayService";
38 private static final boolean DEBUG = false;
39 private boolean mShowComplications;
40 private ComponentName mDreamComponent;
41
42 private IDreamOverlay mDreamOverlay = new IDreamOverlay.Stub() {
43 @Override
44 public void startDream(WindowManager.LayoutParams layoutParams,
45 IDreamOverlayCallback callback, String dreamComponent,
46 boolean shouldShowComplications) {
47 mDreamOverlayCallback = callback;
48 mDreamComponent = ComponentName.unflattenFromString(dreamComponent);
49 mShowComplications = shouldShowComplications;
50 onStartDream(layoutParams);
51 }
52
53 @Override
54 public void wakeUp() {
55 onWakeUp(() -> {
56 try {
57 mDreamOverlayCallback.onWakeUpComplete();
58 } catch (RemoteException e) {
59 Log.e(TAG, "Could not notify dream of wakeUp:" + e);
60 }
61 });
62 }
63 };
64
65 IDreamOverlayCallback mDreamOverlayCallback;
66
67 public DreamOverlayService() {
68 }
69
70 @Nullable
71 @Override
72 public final IBinder onBind(@NonNull Intent intent) {
73 return mDreamOverlay.asBinder();
74 }
75
76 /**
77 * This method is overridden by implementations to handle when the dream has started and the
78 * window is ready to be interacted with.
79 * @param layoutParams The {@link android.view.WindowManager.LayoutParams} associated with the
80 * dream window.
81 */
82 public abstract void onStartDream(@NonNull WindowManager.LayoutParams layoutParams);
83
84 /**
85 * This method is overridden by implementations to handle when the dream has been requested
86 * to wakeup. This allows any overlay animations to run.
87 *
88 * @param onCompleteCallback The callback to trigger to notify the dream service that the
89 * overlay has completed waking up.
90 * @hide
91 */
92 public void onWakeUp(@NonNull Runnable onCompleteCallback) {
93 }
94
95 /**
96 * This method is invoked to request the dream exit.
97 */
98 public final void requestExit() {
99 try {
100 mDreamOverlayCallback.onExitRequested();
101 } catch (RemoteException e) {
102 Log.e(TAG, "Could not request exit:" + e);
103 }
104 }
105
106 /**
107 * Returns whether to show complications on the dream overlay.
108 */
109 public final boolean shouldShowComplications() {
110 return mShowComplications;
111 }
112
113 /**
114 * Returns the active dream component.
115 * @hide
116 */
117 public final ComponentName getDreamComponent() {
118 return mDreamComponent;
119 }
120 }