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.wm.shell.desktopmode; 18 19 import static com.android.wm.shell.protolog.ShellProtoLogGroup.WM_SHELL_DESKTOP_MODE; 20 21 import android.content.Context; 22 import android.os.SystemProperties; 23 import android.os.UserHandle; 24 import android.provider.Settings; 25 26 import com.android.internal.protolog.common.ProtoLog; 27 28 /** 29 * Constants for desktop mode feature 30 */ 31 public class DesktopModeStatus { 32 33 /** 34 * Flag to indicate whether desktop mode is available on the device 35 */ 36 private static final boolean IS_SUPPORTED = SystemProperties.getBoolean( 37 "persist.wm.debug.desktop_mode", false); 38 39 /** 40 * Flag to indicate whether desktop mode proto 2 is available on the device 41 */ 42 private static final boolean IS_PROTO2_ENABLED = SystemProperties.getBoolean( 43 "persist.wm.debug.desktop_mode_2", false); 44 45 /** 46 * Return {@code true} if desktop mode support is enabled 47 */ isProto1Enabled()48 public static boolean isProto1Enabled() { 49 return IS_SUPPORTED; 50 } 51 52 /** 53 * Return {@code true} is desktop windowing proto 2 is enabled 54 */ isProto2Enabled()55 public static boolean isProto2Enabled() { 56 return IS_PROTO2_ENABLED; 57 } 58 59 /** 60 * Return {@code true} if proto 1 or 2 is enabled. 61 * Can be used to guard logic that is common for both prototypes. 62 */ isAnyEnabled()63 public static boolean isAnyEnabled() { 64 return isProto1Enabled() || isProto2Enabled(); 65 } 66 67 /** 68 * Check if desktop mode is active 69 * 70 * @return {@code true} if active 71 */ isActive(Context context)72 public static boolean isActive(Context context) { 73 if (!isAnyEnabled()) { 74 return false; 75 } 76 if (isProto2Enabled()) { 77 // Desktop mode is always active in prototype 2 78 return true; 79 } 80 try { 81 int result = Settings.System.getIntForUser(context.getContentResolver(), 82 Settings.System.DESKTOP_MODE, UserHandle.USER_CURRENT); 83 return result != 0; 84 } catch (Exception e) { 85 ProtoLog.e(WM_SHELL_DESKTOP_MODE, "Failed to read DESKTOP_MODE setting %s", e); 86 return false; 87 } 88 } 89 } 90