Debian Codegraph @

core/java/android/service/dreams/DreamActivity.java

raw symbols SCIP
1 /*
2 * Copyright (C) 2020 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.Nullable;
20 import android.app.Activity;
21 import android.os.Bundle;
22 import android.text.TextUtils;
23
24 /**
25 * The Activity used by the {@link DreamService} to draw screensaver content
26 * on the screen. This activity runs in dream application's process, but is started by a
27 * specialized method: {@link com.android.server.wm.ActivityTaskManagerService#startDreamActivity}.
28 * Hence, it does not have to be declared in the dream application's manifest.
29 *
30 * We use an activity as the dream canvas, because it interacts easier with other activities on
31 * the screen (compared to a hover window). However, the DreamService is in charge of the dream and
32 * it receives all Window.Callbacks from its main window. Since a window can have only one callback
33 * receiver, the activity will not receive any window callbacks.
34 *
35 * Prior to the DreamActivity, the DreamService used to work with a hovering window and give the
36 * screensaver application control over that window. The DreamActivity is a replacement to that
37 * hover window. Using an activity allows for better-defined interactions with the rest of the
38 * activities on screen. The switch to DreamActivity should be transparent to the screensaver
39 * application, i.e. the application will still use DreamService APIs and not notice that the
40 * system is using an activity behind the scenes.
41 *
42 * @hide
43 */
44 public class DreamActivity extends Activity {
45 static final String EXTRA_CALLBACK = "binder";
46 static final String EXTRA_DREAM_TITLE = "title";
47 @Nullable
48 private DreamService.DreamActivityCallbacks mCallback;
49
50 public DreamActivity() {}
51
52 @Override
53 public void onCreate(@Nullable Bundle bundle) {
54 super.onCreate(bundle);
55
56 final String title = getIntent().getStringExtra(EXTRA_DREAM_TITLE);
57 if (!TextUtils.isEmpty(title)) {
58 setTitle(title);
59 }
60
61 final Bundle extras = getIntent().getExtras();
62 mCallback = (DreamService.DreamActivityCallbacks) extras.getBinder(EXTRA_CALLBACK);
63
64 if (mCallback != null) {
65 mCallback.onActivityCreated(this);
66 }
67 }
68
69 @Override
70 public void onDestroy() {
71 if (mCallback != null) {
72 mCallback.onActivityDestroyed();
73 }
74
75 super.onDestroy();
76 }
77 }