1 /*
2  * Copyright (C) 2018 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 android.content.Context;
20 import android.content.res.Resources;
21 import android.os.UserHandle;
22 
23 import com.android.systemui.dagger.GlobalRootComponent;
24 import com.android.systemui.dagger.SysUIComponent;
25 import com.android.systemui.dagger.WMComponent;
26 import com.android.systemui.wmshell.CarWMComponent;
27 
28 import java.util.HashSet;
29 import java.util.Optional;
30 import java.util.Set;
31 
32 /**
33  * Class factory to provide car specific SystemUI components.
34  */
35 public class CarSystemUIFactory extends SystemUIFactory {
36     @Override
buildGlobalRootComponent(Context context)37     protected GlobalRootComponent buildGlobalRootComponent(Context context) {
38         return DaggerCarGlobalRootComponent.builder()
39                 .context(context)
40                 .build();
41     }
42 
43     @Override
getSystemUIServiceComponents(Resources resources)44     public String[] getSystemUIServiceComponents(Resources resources) {
45         Set<String> names = new HashSet<>();
46 
47         for (String s : super.getSystemUIServiceComponents(resources)) {
48             names.add(s);
49         }
50 
51         for (String s : resources.getStringArray(R.array.config_systemUIServiceComponentsExclude)) {
52             names.remove(s);
53         }
54 
55         for (String s : resources.getStringArray(R.array.config_systemUIServiceComponentsInclude)) {
56             names.add(s);
57         }
58 
59         String[] finalNames = new String[names.size()];
60         names.toArray(finalNames);
61 
62         return finalNames;
63     }
64 
65     @Override
prepareSysUIComponentBuilder( SysUIComponent.Builder sysUIBuilder, WMComponent wm)66     protected SysUIComponent.Builder prepareSysUIComponentBuilder(
67             SysUIComponent.Builder sysUIBuilder, WMComponent wm) {
68         CarWMComponent carWm = (CarWMComponent) wm;
69         boolean isSystemUser = UserHandle.myUserId() == UserHandle.USER_SYSTEM;
70         return ((CarSysUIComponent.Builder) sysUIBuilder).setRootTaskDisplayAreaOrganizer(
71                 isSystemUser ? Optional.of(carWm.getRootTaskDisplayAreaOrganizer())
72                         : Optional.empty());
73     }
74 }
75