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.annotation.NonNull; 22 import android.annotation.Nullable; 23 import android.car.Car; 24 import android.car.CarOccupantZoneManager; 25 import android.content.Context; 26 import android.content.res.Configuration; 27 import android.os.Bundle; 28 import android.os.UserHandle; 29 import android.view.ContextThemeWrapper; 30 import android.view.Display; 31 import android.view.WindowManager; 32 33 import com.android.car.oem.tokens.Token; 34 import com.android.systemui.car.users.CarSystemUIUserUtil; 35 36 /** 37 * Application class for CarSystemUI. 38 */ 39 public class CarSystemUIApplication extends SystemUIApplication { 40 41 private boolean mIsVisibleBackgroundUserSysUI; 42 43 @Override onCreate()44 public void onCreate() { 45 mIsVisibleBackgroundUserSysUI = CarSystemUIUserUtil.isSecondaryMUMDSystemUI(); 46 super.onCreate(); 47 if (mIsVisibleBackgroundUserSysUI) { 48 Car car = Car.createCar(this); 49 if (car == null) { 50 return; 51 } 52 CarOccupantZoneManager manager = (CarOccupantZoneManager) car.getCarManager( 53 Car.CAR_OCCUPANT_ZONE_SERVICE); 54 if (manager != null) { 55 CarOccupantZoneManager.OccupantZoneInfo info = manager.getMyOccupantZone(); 56 if (info != null) { 57 Display display = manager.getDisplayForOccupant(info, DISPLAY_TYPE_MAIN); 58 if (display != null) { 59 updateDisplay(display.getDisplayId()); 60 startSystemUserServicesIfNeeded(); 61 } 62 } 63 } 64 car.disconnect(); 65 } 66 } 67 68 @Override shouldStartSystemUserServices()69 protected boolean shouldStartSystemUserServices() { 70 if (mIsVisibleBackgroundUserSysUI) { 71 // visible background user SystemUI instances should start the same services as the 72 // normal system user SystemUI instance. 73 return true; 74 } 75 return super.shouldStartSystemUserServices(); 76 } 77 78 @Override shouldStartSecondaryUserServices()79 protected boolean shouldStartSecondaryUserServices() { 80 if (mIsVisibleBackgroundUserSysUI) { 81 // visible background user SystemUI instances should start the same services as the 82 // normal system user SystemUI instance - this already includes the secondary user 83 // services. 84 return false; 85 } 86 return super.shouldStartSecondaryUserServices(); 87 } 88 89 @Override attachBaseContext(Context base)90 public void attachBaseContext(Context base) { 91 Context context = Token.createOemStyledContext(base); 92 context.getTheme().applyStyle(R.style.CarSystemUIThemeOverlay, true); 93 super.attachBaseContext(context); 94 } 95 96 @Override createContextAsUser(UserHandle user, @CreatePackageOptions int flags)97 public Context createContextAsUser(UserHandle user, @CreatePackageOptions int flags) { 98 Context context = super.createContextAsUser(user, flags); 99 return new ContextThemeWrapper(context, this.getTheme()); 100 } 101 102 @Override 103 @NonNull createWindowContext(@indowManager.LayoutParams.WindowType int type, @Nullable Bundle options)104 public Context createWindowContext(@WindowManager.LayoutParams.WindowType int type, 105 @Nullable Bundle options) { 106 Context context = super.createWindowContext(type, options); 107 return new ContextThemeWrapper(context, this.getTheme()); 108 } 109 110 @Override createConfigurationContext(Configuration overrideConfiguration)111 public Context createConfigurationContext(Configuration overrideConfiguration) { 112 Context context = super.createConfigurationContext(overrideConfiguration); 113 return new ContextThemeWrapper(context, this.getTheme()); 114 } 115 116 } 117