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 * Flag to indicate whether task resizing is veiled. 47 */ 48 private static final boolean IS_VEILED_RESIZE_ENABLED = SystemProperties.getBoolean( 49 "persist.wm.debug.desktop_veiled_resizing", true); 50 51 /** 52 * Flag to indicate is moving task to another display is enabled. 53 */ 54 public static final boolean IS_DISPLAY_CHANGE_ENABLED = SystemProperties.getBoolean( 55 "persist.wm.debug.desktop_change_display", false); 56 57 58 /** 59 * Flag to indicate that desktop stashing is enabled. 60 * When enabled, swiping home from desktop stashes the open apps. Next app that launches, 61 * will be added to the desktop. 62 */ 63 private static final boolean IS_STASHING_ENABLED = SystemProperties.getBoolean( 64 "persist.wm.debug.desktop_stashing", false); 65 66 /** 67 * Return {@code true} if desktop mode support is enabled 68 */ isProto1Enabled()69 public static boolean isProto1Enabled() { 70 return IS_SUPPORTED; 71 } 72 73 /** 74 * Return {@code true} is desktop windowing proto 2 is enabled 75 */ isProto2Enabled()76 public static boolean isProto2Enabled() { 77 return IS_PROTO2_ENABLED; 78 } 79 80 /** 81 * Return {@code true} if proto 1 or 2 is enabled. 82 * Can be used to guard logic that is common for both prototypes. 83 */ isAnyEnabled()84 public static boolean isAnyEnabled() { 85 return isProto1Enabled() || isProto2Enabled(); 86 } 87 88 /** 89 * Return {@code true} if veiled resizing is active. If false, fluid resizing is used. 90 */ isVeiledResizeEnabled()91 public static boolean isVeiledResizeEnabled() { 92 return IS_VEILED_RESIZE_ENABLED; 93 } 94 95 /** 96 * Return {@code true} if desktop task stashing is enabled when going home. 97 * Allows users to use home screen to add tasks to desktop. 98 */ isStashingEnabled()99 public static boolean isStashingEnabled() { 100 return IS_STASHING_ENABLED; 101 } 102 /** 103 * Check if desktop mode is active 104 * 105 * @return {@code true} if active 106 */ isActive(Context context)107 public static boolean isActive(Context context) { 108 if (!isAnyEnabled()) { 109 return false; 110 } 111 if (isProto2Enabled()) { 112 // Desktop mode is always active in prototype 2 113 return true; 114 } 115 try { 116 int result = Settings.System.getIntForUser(context.getContentResolver(), 117 Settings.System.DESKTOP_MODE, UserHandle.USER_CURRENT); 118 return result != 0; 119 } catch (Exception e) { 120 ProtoLog.e(WM_SHELL_DESKTOP_MODE, "Failed to read DESKTOP_MODE setting %s", e); 121 return false; 122 } 123 } 124 } 125