Debian Codegraph @

libs/WindowManager/Shell/src/com/android/wm/shell/compatui/CompatUIConfiguration.java

raw symbols SCIP
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.compatui;
18
19 import android.content.Context;
20 import android.provider.DeviceConfig;
21
22 import androidx.annotation.NonNull;
23
24 import com.android.wm.shell.R;
25 import com.android.wm.shell.common.ShellExecutor;
26 import com.android.wm.shell.common.annotations.ShellMainThread;
27 import com.android.wm.shell.dagger.WMSingleton;
28
29 import javax.inject.Inject;
30
31 /**
32 * Configuration flags for the CompatUX implementation
33 */
34 @WMSingleton
35 public class CompatUIConfiguration implements DeviceConfig.OnPropertiesChangedListener {
36
37 static final String KEY_ENABLE_LETTERBOX_RESTART_DIALOG = "enable_letterbox_restart_dialog";
38
39 static final String KEY_ENABLE_LETTERBOX_REACHABILITY_EDUCATION =
40 "enable_letterbox_reachability_education";
41
42 // Whether the extended restart dialog is enabled
43 private boolean mIsRestartDialogEnabled;
44
45 // Whether the additional education about reachability is enabled
46 private boolean mIsReachabilityEducationEnabled;
47
48 // Whether the extended restart dialog is enabled
49 private boolean mIsRestartDialogOverrideEnabled;
50
51 // Whether the additional education about reachability is enabled
52 private boolean mIsReachabilityEducationOverrideEnabled;
53
54 // Whether the extended restart dialog is allowed from backend
55 private boolean mIsLetterboxRestartDialogAllowed;
56
57 // Whether the additional education about reachability is allowed from backend
58 private boolean mIsLetterboxReachabilityEducationAllowed;
59
60 @Inject
61 public CompatUIConfiguration(Context context, @ShellMainThread ShellExecutor mainExecutor) {
62 mIsRestartDialogEnabled = context.getResources().getBoolean(
63 R.bool.config_letterboxIsRestartDialogEnabled);
64 mIsReachabilityEducationEnabled = context.getResources().getBoolean(
65 R.bool.config_letterboxIsReachabilityEducationEnabled);
66 mIsLetterboxRestartDialogAllowed = DeviceConfig.getBoolean(
67 DeviceConfig.NAMESPACE_WINDOW_MANAGER, KEY_ENABLE_LETTERBOX_RESTART_DIALOG, false);
68 mIsLetterboxReachabilityEducationAllowed = DeviceConfig.getBoolean(
69 DeviceConfig.NAMESPACE_WINDOW_MANAGER, KEY_ENABLE_LETTERBOX_REACHABILITY_EDUCATION,
70 false);
71 DeviceConfig.addOnPropertiesChangedListener(DeviceConfig.NAMESPACE_APP_COMPAT, mainExecutor,
72 this);
73 }
74
75 /**
76 * @return {@value true} if the restart dialog is enabled.
77 */
78 boolean isRestartDialogEnabled() {
79 return mIsRestartDialogOverrideEnabled || (mIsRestartDialogEnabled
80 && mIsLetterboxRestartDialogAllowed);
81 }
82
83 /**
84 * Enables/Disables the restart education dialog
85 */
86 void setIsRestartDialogOverrideEnabled(boolean enabled) {
87 mIsRestartDialogOverrideEnabled = enabled;
88 }
89
90 /**
91 * @return {@value true} if the reachability education is enabled.
92 */
93 boolean isReachabilityEducationEnabled() {
94 return mIsReachabilityEducationOverrideEnabled || (mIsReachabilityEducationEnabled
95 && mIsLetterboxReachabilityEducationAllowed);
96 }
97
98 /**
99 * Enables/Disables the reachability education
100 */
101 void setIsReachabilityEducationOverrideEnabled(boolean enabled) {
102 mIsReachabilityEducationOverrideEnabled = enabled;
103 }
104
105 @Override
106 public void onPropertiesChanged(@NonNull DeviceConfig.Properties properties) {
107 // TODO(b/263349751): Update flag and default value to true
108 if (properties.getKeyset().contains(KEY_ENABLE_LETTERBOX_RESTART_DIALOG)) {
109 mIsLetterboxRestartDialogAllowed = DeviceConfig.getBoolean(
110 DeviceConfig.NAMESPACE_WINDOW_MANAGER, KEY_ENABLE_LETTERBOX_RESTART_DIALOG,
111 false);
112 }
113 if (properties.getKeyset().contains(KEY_ENABLE_LETTERBOX_REACHABILITY_EDUCATION)) {
114 mIsLetterboxReachabilityEducationAllowed = DeviceConfig.getBoolean(
115 DeviceConfig.NAMESPACE_WINDOW_MANAGER,
116 KEY_ENABLE_LETTERBOX_REACHABILITY_EDUCATION, false);
117 }
118 }
119 }