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.car.displayarea; 18 19 import android.content.BroadcastReceiver; 20 import android.content.Context; 21 import android.content.Intent; 22 import android.content.IntentFilter; 23 import android.os.Build; 24 import android.os.Handler; 25 import android.os.Looper; 26 import android.util.Log; 27 28 import com.android.systemui.CoreStartable; 29 import com.android.systemui.dagger.SysUISingleton; 30 31 import javax.inject.Inject; 32 33 /** 34 * Dagger Subcomponent for DisplayAreas within SysUI. 35 */ 36 @SysUISingleton 37 public class DisplayAreaComponent implements CoreStartable { 38 public static final String TAG = "DisplayAreaComponent"; 39 // action name for the intent when to update the foreground DA visibility 40 public static final String DISPLAY_AREA_VISIBILITY_CHANGED = 41 "DISPLAY_AREA_VISIBILITY_CHANGED"; 42 // key name for the intent's extra that tells the DA's visibility status 43 public static final String INTENT_EXTRA_IS_DISPLAY_AREA_VISIBLE = 44 "EXTRA_IS_DISPLAY_AREA_VISIBLE"; 45 46 private final CarDisplayAreaController mCarDisplayAreaController; 47 private final Context mContext; 48 final Handler mHandler = new Handler(Looper.myLooper()); 49 50 @Inject DisplayAreaComponent(Context context, CarDisplayAreaController carDisplayAreaController)51 public DisplayAreaComponent(Context context, 52 CarDisplayAreaController carDisplayAreaController) { 53 mContext = context; 54 mCarDisplayAreaController = carDisplayAreaController; 55 } 56 57 @Override start()58 public void start() { 59 logIfDebuggable("start:"); 60 if (CarDisplayAreaUtils.isCustomDisplayPolicyDefined(mContext)) { 61 // Register the DA's 62 mCarDisplayAreaController.register(); 63 64 IntentFilter filter = new IntentFilter(); 65 // add a receiver to listen to ACTION_BOOT_COMPLETED where we will perform tasks that 66 // require system to be ready. For example, search list of activities with a specific 67 // Intent. This cannot be done while the component is created as that is too early in 68 // the lifecycle of system starting and the results returned by package manager is 69 // not reliable. So we want to wait until system is ready before we query for list of 70 // activities. 71 filter.addAction(Intent.ACTION_BOOT_COMPLETED); 72 mContext.registerReceiverForAllUsers(new BroadcastReceiver() { 73 @Override 74 public void onReceive(Context context, Intent intent) { 75 if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) { 76 mCarDisplayAreaController.updateVoicePlateActivityMap(); 77 } 78 } 79 }, filter, /* broadcastPermission= */ null, /* scheduler= */ null); 80 81 IntentFilter packageChangeFilter = new IntentFilter(); 82 // add a receiver to listen to ACTION_PACKAGE_ADDED to perform any action when a new 83 // application is installed on the system. 84 packageChangeFilter.addAction(Intent.ACTION_PACKAGE_ADDED); 85 packageChangeFilter.addAction(Intent.ACTION_PACKAGE_REPLACED); 86 packageChangeFilter.addDataScheme("package"); 87 mContext.registerReceiverForAllUsers(new BroadcastReceiver() { 88 @Override 89 public void onReceive(Context context, Intent intent) { 90 mCarDisplayAreaController.updateVoicePlateActivityMap(); 91 } 92 }, packageChangeFilter, null, null); 93 } 94 } 95 96 /** 97 * enum to define the state of display area possible. 98 * CONTROL_BAR state is when only control bar is visible. 99 * FULL state is when display area hosting default apps cover the screen fully. 100 * DEFAULT state where maps are shown above DA for default apps. 101 */ 102 public enum FOREGROUND_DA_STATE { 103 CONTROL_BAR, DEFAULT, FULL, FULL_TO_DEFAULT 104 } 105 logIfDebuggable(String message)106 private static void logIfDebuggable(String message) { 107 if (Build.IS_DEBUGGABLE) { 108 Log.d(TAG, message); 109 } 110 } 111 } 112