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 com.android.car.carlauncher;
18 
19 import android.app.Application;
20 import android.content.BroadcastReceiver;
21 import android.content.Context;
22 import android.content.Intent;
23 import android.content.IntentFilter;
24 
25 import com.android.car.carlauncher.displayarea.CarDisplayAreaController;
26 import com.android.car.carlauncher.displayarea.CarDisplayAreaHealthMonitor;
27 import com.android.car.carlauncher.displayarea.CarDisplayAreaOrganizer;
28 import com.android.car.carlauncher.displayarea.CarDisplayAreaTouchHandler;
29 import com.android.car.internal.common.UserHelperLite;
30 import com.android.wm.shell.common.HandlerExecutor;
31 import com.android.wm.shell.common.ShellExecutor;
32 import com.android.wm.shell.common.SyncTransactionQueue;
33 import com.android.wm.shell.common.TransactionPool;
34 
35 /**
36  * Application layer for launcher.This class is responsible for registering the display areas
37  * defined by {@link com.android.server.wm.CarDisplayAreaPolicyProvider}.
38  */
39 public class CarLauncherApplication extends Application {
40 
41     private ShellExecutor mShellExecutor;
42     private SyncTransactionQueue mSyncTransactionQueue;
43     private TransactionPool mTransactionPool = new TransactionPool();
44 
45     private BroadcastReceiver mReceiver = new BroadcastReceiver() {
46         @Override
47         public void onReceive(Context context, Intent intent) {
48             CarDisplayAreaController carDisplayAreaController =
49                     CarDisplayAreaController.getInstance();
50             carDisplayAreaController.makeForegroundDAFullscreen();
51             carDisplayAreaController.unregister();
52             context.unregisterReceiver(mReceiver);
53         }
54     };
55 
56     @Override
onCreate()57     public void onCreate() {
58         super.onCreate();
59 
60         if (UserHelperLite.isHeadlessSystemUser(getUserId())) {
61             return;
62         }
63 
64         if (CarLauncherUtils.isCustomDisplayPolicyDefined(this)) {
65             mShellExecutor = new HandlerExecutor(getMainThreadHandler());
66             CarDisplayAreaController carDisplayAreaController =
67                     CarDisplayAreaController.getInstance();
68             mSyncTransactionQueue = new SyncTransactionQueue(
69                     mTransactionPool, mShellExecutor);
70             Intent controlBarIntent = new Intent(this, ControlBarActivity.class);
71             controlBarIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
72             CarDisplayAreaTouchHandler handler = new CarDisplayAreaTouchHandler(
73                     new HandlerExecutor(getMainThreadHandler()));
74             CarDisplayAreaOrganizer org = CarDisplayAreaOrganizer.getInstance(mShellExecutor, this,
75                     CarLauncherUtils.getMapsIntent(this),
76                     controlBarIntent, mSyncTransactionQueue);
77             carDisplayAreaController.init(this, mSyncTransactionQueue, org, handler);
78             carDisplayAreaController.register();
79 
80             CarDisplayAreaHealthMonitor monitor = CarDisplayAreaHealthMonitor.getInstance(this,
81                     org);
82             monitor.register();
83 
84             IntentFilter filter = new IntentFilter();
85             filter.addAction(Intent.ACTION_USER_SWITCHED);
86 
87             registerReceiver(mReceiver, filter);
88         }
89     }
90 
getShellExecutor()91     ShellExecutor getShellExecutor() {
92         return mShellExecutor;
93     }
94 
getSyncTransactionQueue()95     SyncTransactionQueue getSyncTransactionQueue() {
96         return mSyncTransactionQueue;
97     }
98 
getTransactionPool()99     TransactionPool getTransactionPool() {
100         return mTransactionPool;
101     }
102 }
103