1 /* 2 * Copyright (C) 2023 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.car.systembar; 18 19 import android.annotation.Nullable; 20 import android.content.Context; 21 import android.content.om.OverlayManager; 22 import android.content.res.Configuration; 23 import android.os.Build; 24 import android.os.Handler; 25 import android.os.UserHandle; 26 import android.util.Log; 27 import android.view.WindowManager; 28 29 import com.android.internal.statusbar.IStatusBarService; 30 import com.android.systemui.R; 31 import com.android.systemui.car.CarDeviceProvisionedController; 32 import com.android.systemui.car.displaycompat.ToolbarController; 33 import com.android.systemui.car.users.CarSystemUIUserUtil; 34 import com.android.systemui.dagger.qualifiers.Main; 35 import com.android.systemui.plugins.DarkIconDispatcher; 36 import com.android.systemui.settings.DisplayTracker; 37 import com.android.systemui.settings.UserTracker; 38 import com.android.systemui.statusbar.CommandQueue; 39 import com.android.systemui.statusbar.phone.AutoHideController; 40 import com.android.systemui.statusbar.phone.LightBarController; 41 import com.android.systemui.statusbar.phone.PhoneStatusBarPolicy; 42 import com.android.systemui.statusbar.policy.ConfigurationController; 43 import com.android.systemui.statusbar.policy.KeyguardStateController; 44 import com.android.systemui.util.concurrency.DelayableExecutor; 45 46 import dagger.Lazy; 47 48 /** 49 * Currently because of Bug:b/260206944, RROs are not applied to the secondary user. 50 * This class acts as a Mediator, which toggles the Overlay state of the RRO package, 51 * which in turn triggers onConfigurationChange. Only after this change start the 52 * CarSystemBar with overlaid resources. 53 */ 54 public class MDSystemBarsControllerImpl extends CarSystemBarControllerImpl { 55 56 private static final String TAG = MDSystemBarsControllerImpl.class.getSimpleName(); 57 private static final boolean DEBUG = Build.IS_ENG || Build.IS_USERDEBUG; 58 private final Context mContext; 59 private final OverlayManager mOverlayManager; 60 61 private boolean mInitialized = false; 62 MDSystemBarsControllerImpl( @ain Handler mainHandler, Context context, UserTracker userTracker, CarSystemBarViewFactory carSystemBarViewFactory, SystemBarConfigs systemBarConfigs, LightBarController lightBarController, DarkIconDispatcher darkIconDispatcher, WindowManager windowManager, CarDeviceProvisionedController deviceProvisionedController, CommandQueue commandQueue, AutoHideController autoHideController, ButtonSelectionStateListener buttonSelectionStateListener, @Main DelayableExecutor mainExecutor, IStatusBarService barService, Lazy<KeyguardStateController> keyguardStateControllerLazy, Lazy<PhoneStatusBarPolicy> iconPolicyLazy, ConfigurationController configurationController, CarSystemBarRestartTracker restartTracker, DisplayTracker displayTracker, @Nullable ToolbarController toolbarController)63 public MDSystemBarsControllerImpl( 64 @Main Handler mainHandler, 65 Context context, 66 UserTracker userTracker, 67 CarSystemBarViewFactory carSystemBarViewFactory, 68 SystemBarConfigs systemBarConfigs, 69 // TODO(b/156052638): Should not need to inject LightBarController 70 LightBarController lightBarController, 71 DarkIconDispatcher darkIconDispatcher, 72 WindowManager windowManager, 73 CarDeviceProvisionedController deviceProvisionedController, 74 CommandQueue commandQueue, 75 AutoHideController autoHideController, 76 ButtonSelectionStateListener buttonSelectionStateListener, 77 @Main DelayableExecutor mainExecutor, 78 IStatusBarService barService, 79 Lazy<KeyguardStateController> keyguardStateControllerLazy, 80 Lazy<PhoneStatusBarPolicy> iconPolicyLazy, 81 ConfigurationController configurationController, 82 CarSystemBarRestartTracker restartTracker, 83 DisplayTracker displayTracker, 84 @Nullable ToolbarController toolbarController) { 85 super(context, 86 userTracker, 87 carSystemBarViewFactory, 88 systemBarConfigs, 89 lightBarController, 90 darkIconDispatcher, 91 windowManager, 92 deviceProvisionedController, 93 commandQueue, 94 autoHideController, 95 buttonSelectionStateListener, 96 mainExecutor, 97 barService, 98 keyguardStateControllerLazy, 99 iconPolicyLazy, 100 configurationController, 101 restartTracker, 102 displayTracker, 103 toolbarController, 104 mainHandler); 105 mContext = context; 106 mOverlayManager = context.getSystemService(OverlayManager.class); 107 } 108 109 @Override init()110 public void init() { 111 mInitialized = false; 112 113 String rroPackageName = mContext.getString( 114 R.string.config_secondaryUserSystemUIRROPackageName); 115 if (DEBUG) { 116 Log.d(TAG, "start(), toggle RRO package:" + rroPackageName); 117 } 118 // The RRO must be applied to the user that SystemUI is running as. 119 // MUPAND SystemUI runs as the system user, not the actual user. 120 UserHandle userHandle = CarSystemUIUserUtil.isMUPANDSystemUI() ? UserHandle.SYSTEM 121 : mUserTracker.getUserHandle(); 122 try { 123 // TODO(b/260206944): Can remove this after we have a fix for overlaid resources not 124 // applied. 125 // 126 // Currently because of Bug:b/260206944, RROs are not applied to the secondary user. 127 // This class acts as a Mediator, which toggles the Overlay state of the RRO package, 128 // which in turn triggers onConfigurationChange. Only after this change start the 129 // CarSystemBar with overlaid resources. 130 mOverlayManager.setEnabled(rroPackageName, false, userHandle); 131 mOverlayManager.setEnabled(rroPackageName, true, userHandle); 132 } catch (IllegalArgumentException ex) { 133 Log.w(TAG, "Failed to set overlay package: " + ex); 134 mInitialized = true; 135 super.init(); 136 } 137 } 138 139 @Override onConfigChanged(Configuration newConfig)140 public void onConfigChanged(Configuration newConfig) { 141 if (!mInitialized) { 142 mInitialized = true; 143 super.init(); 144 } else { 145 super.onConfigChanged(newConfig); 146 } 147 } 148 149 @Override createSystemBar()150 protected void createSystemBar() { 151 if (!CarSystemUIUserUtil.isSecondaryMUMDSystemUI()) { 152 super.createSystemBar(); 153 } else { 154 createNavBar(); 155 } 156 } 157 } 158