1 /*
2  * Copyright (C) 2020 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.bubbles;
18 
19 import android.content.Context;
20 import android.provider.Settings;
21 
22 import java.util.List;
23 
24 /**
25  * Common class for the various debug {@link android.util.Log} output configuration in the Bubbles
26  * package.
27  */
28 public class BubbleDebugConfig {
29 
30     // All output logs in the Bubbles package use the {@link #TAG_BUBBLES} string for tagging their
31     // log output. This makes it easy to identify the origin of the log message when sifting
32     // through a large amount of log output from multiple sources. However, it also makes trying
33     // to figure-out the origin of a log message while debugging the Bubbles a little painful. By
34     // setting this constant to true, log messages from the Bubbles package will be tagged with
35     // their class names instead fot the generic tag.
36     public static final boolean TAG_WITH_CLASS_NAME = false;
37 
38     // Default log tag for the Bubbles package.
39     public static final String TAG_BUBBLES = "Bubbles";
40 
41     static final boolean DEBUG_BUBBLE_CONTROLLER = false;
42     static final boolean DEBUG_BUBBLE_DATA = false;
43     static final boolean DEBUG_BUBBLE_STACK_VIEW = false;
44     static final boolean DEBUG_BUBBLE_EXPANDED_VIEW = false;
45     static final boolean DEBUG_EXPERIMENTS = true;
46     static final boolean DEBUG_OVERFLOW = false;
47     static final boolean DEBUG_USER_EDUCATION = false;
48     static final boolean DEBUG_POSITIONER = false;
49     public static final boolean DEBUG_COLLAPSE_ANIMATOR = false;
50     public static boolean DEBUG_EXPANDED_VIEW_DRAGGING = false;
51 
52     private static final boolean FORCE_SHOW_USER_EDUCATION = false;
53     private static final String FORCE_SHOW_USER_EDUCATION_SETTING =
54             "force_show_bubbles_user_education";
55     /**
56      * When set to true, bubbles user education flow never shows up.
57      */
58     private static final String FORCE_HIDE_USER_EDUCATION_SETTING =
59             "force_hide_bubbles_user_education";
60 
61     /**
62      * @return whether we should force show user education for bubbles. Used for debugging & demos.
63      */
forceShowUserEducation(Context context)64     static boolean forceShowUserEducation(Context context) {
65         boolean forceShow = Settings.Secure.getInt(context.getContentResolver(),
66                 FORCE_SHOW_USER_EDUCATION_SETTING, 0) != 0;
67         return FORCE_SHOW_USER_EDUCATION || forceShow;
68     }
69 
70     /**
71      * @return whether we should never show user education for bubbles. Used in tests.
72      */
neverShowUserEducation(Context context)73     static boolean neverShowUserEducation(Context context) {
74         return Settings.Secure.getInt(context.getContentResolver(),
75                 FORCE_HIDE_USER_EDUCATION_SETTING, 0) != 0;
76     }
77 
formatBubblesString(List<Bubble> bubbles, BubbleViewProvider selected)78     static String formatBubblesString(List<Bubble> bubbles, BubbleViewProvider selected) {
79         StringBuilder sb = new StringBuilder();
80         for (Bubble bubble : bubbles) {
81             if (bubble == null) {
82                 sb.append("   <null> !!!!!\n");
83             } else {
84                 boolean isSelected = (selected != null
85                         && selected.getKey() != BubbleOverflow.KEY
86                         && bubble == selected);
87                 String arrow = isSelected ? "=>" : "  ";
88                 sb.append(String.format("%s Bubble{act=%12d, showInShade=%d, key=%s}\n",
89                         arrow,
90                         bubble.getLastActivity(),
91                         (bubble.showInShade() ? 1 : 0),
92                         bubble.getKey()));
93             }
94         }
95         return sb.toString();
96     }
97 }
98