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