1 /*
2  * Copyright (C) 2015 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.compatibility.common.preconditions;
18 
19 import static android.content.pm.PackageManager.FEATURE_AUTOMOTIVE;
20 
21 import android.app.Activity;
22 import android.content.Context;
23 import android.content.pm.PackageManager;
24 
25 /**
26  * SystemUiHelper is used to check SystemUI related status such as whether or not a
27  * traditional status bar is supported on this device platform.
28  */
29 public class SystemUiHelper {
30     /**
31      * This helper returns true if the device's system UI does not have a traditional android
32      * system status bar.  E.g. Android Automotive, WearOS, etc.
33      */
hasNoTraditionalStatusBar(Context context)34     public static boolean hasNoTraditionalStatusBar(Context context) {
35         PackageManager packageManager = context.getPackageManager();
36         boolean isTelevision = packageManager != null
37                 && (packageManager.hasSystemFeature(PackageManager.FEATURE_LEANBACK)
38                 || packageManager.hasSystemFeature(PackageManager.FEATURE_TELEVISION));
39 
40         boolean isWatch = context.getPackageManager().hasSystemFeature(
41                 PackageManager.FEATURE_WATCH);
42 
43         return isTelevision || isWatch || Boolean.getBoolean(
44                 "persist.sysui.nostatusbar");
45 
46     }
47 
48     /**
49      * Checks whether the device has non-overlapping multitasking feature enabled.
50      *
51      * When this is true, we expect the Task to not occlude other Task below it,
52      * which means both Tasks can be resumed and visible.
53      */
isNonOverlappingMultiWindowMode(Activity activity)54     public static boolean isNonOverlappingMultiWindowMode(Activity activity) {
55         if (!activity.isInMultiWindowMode()) {
56             return false;
57         }
58         Context context = activity.getApplicationContext();
59         if (context.getPackageManager().hasSystemFeature(/* PackageManager
60         .FEATURE_CAR_SPLITSCREEN_MULTITASKING */
61                 "android.software.car.splitscreen_multitasking")
62                 && context.getPackageManager().hasSystemFeature(FEATURE_AUTOMOTIVE)) {
63             // Automotive SplitScreen Multitasking devices overlap the windows.
64             return false;
65         }
66         return true;
67     }
68 }
69