File: DreamActivity.java

package info (click to toggle)
android-platform-frameworks-base 1%3A14~beta1-3
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 326,092 kB
  • sloc: java: 2,032,373; xml: 343,016; cpp: 304,181; python: 3,683; ansic: 2,090; sh: 1,871; makefile: 117; sed: 19
file content (77 lines) | stat: -rw-r--r-- 2,959 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*
 * Copyright (C) 2020 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.service.dreams;

import android.annotation.Nullable;
import android.app.Activity;
import android.os.Bundle;
import android.text.TextUtils;

/**
 * The Activity used by the {@link DreamService} to draw screensaver content
 * on the screen. This activity runs in dream application's process, but is started by a
 * specialized method: {@link com.android.server.wm.ActivityTaskManagerService#startDreamActivity}.
 * Hence, it does not have to be declared in the dream application's manifest.
 *
 * We use an activity as the dream canvas, because it interacts easier with other activities on
 * the screen (compared to a hover window). However, the DreamService is in charge of the dream and
 * it receives all Window.Callbacks from its main window. Since a window can have only one callback
 * receiver, the activity will not receive any window callbacks.
 *
 * Prior to the DreamActivity, the DreamService used to work with a hovering window and give the
 * screensaver application control over that window. The DreamActivity is a replacement to that
 * hover window. Using an activity allows for better-defined interactions with the rest of the
 * activities on screen. The switch to DreamActivity should be transparent to the screensaver
 * application, i.e. the application will still use DreamService APIs and not notice that the
 * system is using an activity behind the scenes.
 *
 * @hide
 */
public class DreamActivity extends Activity {
    static final String EXTRA_CALLBACK = "binder";
    static final String EXTRA_DREAM_TITLE = "title";
    @Nullable
    private DreamService.DreamActivityCallbacks mCallback;

    public DreamActivity() {}

    @Override
    public void onCreate(@Nullable Bundle bundle) {
        super.onCreate(bundle);

        final String title = getIntent().getStringExtra(EXTRA_DREAM_TITLE);
        if (!TextUtils.isEmpty(title)) {
            setTitle(title);
        }

        final Bundle extras = getIntent().getExtras();
        mCallback = (DreamService.DreamActivityCallbacks) extras.getBinder(EXTRA_CALLBACK);

        if (mCallback != null) {
            mCallback.onActivityCreated(this);
        }
    }

    @Override
    public void onDestroy() {
        if (mCallback != null) {
            mCallback.onActivityDestroyed();
        }

        super.onDestroy();
    }
}