• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 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.systemui;
18 
19 import static android.car.CarOccupantZoneManager.DISPLAY_TYPE_MAIN;
20 
21 import android.car.Car;
22 import android.car.CarOccupantZoneManager;
23 import android.view.Display;
24 
25 import com.android.systemui.car.users.CarSystemUIUserUtil;
26 
27 /**
28  * Application class for CarSystemUI.
29  */
30 public class CarSystemUIApplication extends SystemUIApplication {
31 
32     private boolean mIsVisibleBackgroundUserSysUI;
33 
34     @Override
onCreate()35     public void onCreate() {
36         mIsVisibleBackgroundUserSysUI = CarSystemUIUserUtil.isSecondaryMUMDSystemUI();
37         super.onCreate();
38         if (mIsVisibleBackgroundUserSysUI) {
39             Car car = Car.createCar(this);
40             if (car == null) {
41                 return;
42             }
43             CarOccupantZoneManager manager = (CarOccupantZoneManager) car.getCarManager(
44                     Car.CAR_OCCUPANT_ZONE_SERVICE);
45             if (manager != null) {
46                 CarOccupantZoneManager.OccupantZoneInfo info = manager.getMyOccupantZone();
47                 if (info != null) {
48                     Display display = manager.getDisplayForOccupant(info, DISPLAY_TYPE_MAIN);
49                     if (display != null) {
50                         updateDisplay(display.getDisplayId());
51                         startSystemUserServicesIfNeeded();
52                     }
53                 }
54             }
55             car.disconnect();
56         }
57     }
58 
59     @Override
shouldStartSystemUserServices()60     protected boolean shouldStartSystemUserServices() {
61         if (mIsVisibleBackgroundUserSysUI) {
62             // visible background user SystemUI instances should start the same services as the
63             // normal system user SystemUI instance.
64             return true;
65         }
66         return super.shouldStartSystemUserServices();
67     }
68 
69     @Override
shouldStartSecondaryUserServices()70     protected boolean shouldStartSecondaryUserServices() {
71         if (mIsVisibleBackgroundUserSysUI) {
72             // visible background user SystemUI instances should start the same services as the
73             // normal system user SystemUI instance - this already includes the secondary user
74             // services.
75             return false;
76         }
77         return super.shouldStartSecondaryUserServices();
78     }
79 }
80