1 /*
2  * Copyright (C) 2019 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 android.os;
18 
19 import android.annotation.IntDef;
20 import android.annotation.SystemApi;
21 
22 import java.lang.annotation.Retention;
23 import java.lang.annotation.RetentionPolicy;
24 import java.util.concurrent.Executor;
25 
26 /**
27  * Parameters that specify what kind of bugreport should be taken.
28  *
29  * @hide
30  */
31 @SystemApi
32 public final class BugreportParams {
33     private final int mMode;
34     private final int mFlags;
35 
36     /**
37      * Constructs a BugreportParams object to specify what kind of bugreport should be taken.
38      *
39      * @param mode of the bugreport to request
40      */
BugreportParams(@ugreportMode int mode)41     public BugreportParams(@BugreportMode int mode) {
42         mMode = mode;
43         mFlags = 0;
44     }
45 
46     /**
47      * Constructs a BugreportParams object to specify what kind of bugreport should be taken.
48      *
49      * @param mode of the bugreport to request
50      * @param flags to customize the bugreport request
51      */
BugreportParams(@ugreportMode int mode, @BugreportFlag int flags)52     public BugreportParams(@BugreportMode int mode, @BugreportFlag int flags) {
53         mMode = mode;
54         mFlags = flags;
55     }
56 
57     /**
58      * Returns the mode of the bugreport to request.
59      */
60     @BugreportMode
getMode()61     public int getMode() {
62         return mMode;
63     }
64 
65     /**
66      * Returns the flags to customize the bugreport request.
67      */
68     @BugreportFlag
getFlags()69     public int getFlags() {
70         return mFlags;
71     }
72 
73     /**
74      * Defines acceptable types of bugreports.
75      * @hide
76      */
77     @Retention(RetentionPolicy.SOURCE)
78     @IntDef(prefix = { "BUGREPORT_MODE_" }, value = {
79             BUGREPORT_MODE_FULL,
80             BUGREPORT_MODE_INTERACTIVE,
81             BUGREPORT_MODE_REMOTE,
82             BUGREPORT_MODE_WEAR,
83             BUGREPORT_MODE_TELEPHONY,
84             BUGREPORT_MODE_WIFI
85     })
86     public @interface BugreportMode {}
87 
88     /**
89      * Options for a bugreport without user interference (and hence causing less
90      * interference to the system), but includes all sections.
91      */
92     public static final int BUGREPORT_MODE_FULL = IDumpstate.BUGREPORT_MODE_FULL;
93 
94     /**
95      * Options that allow user to monitor progress and enter additional data; might not
96      * include all sections.
97      */
98     public static final int BUGREPORT_MODE_INTERACTIVE = IDumpstate.BUGREPORT_MODE_INTERACTIVE;
99 
100     /**
101      * Options for a bugreport requested remotely by administrator of the Device Owner app,
102      * not the device's user.
103      */
104     public static final int BUGREPORT_MODE_REMOTE = IDumpstate.BUGREPORT_MODE_REMOTE;
105 
106     /**
107      * Options for a bugreport on a wearable device.
108      */
109     public static final int BUGREPORT_MODE_WEAR = IDumpstate.BUGREPORT_MODE_WEAR;
110 
111     /**
112      * Options for a lightweight version of bugreport that only includes a few, urgent
113      * sections used to report telephony bugs.
114      */
115     public static final int BUGREPORT_MODE_TELEPHONY = IDumpstate.BUGREPORT_MODE_TELEPHONY;
116 
117     /**
118      * Options for a lightweight bugreport that only includes a few sections related to
119      * Wifi.
120      */
121     public static final int BUGREPORT_MODE_WIFI = IDumpstate.BUGREPORT_MODE_WIFI;
122 
123     /**
124      * Defines acceptable flags for customizing bugreport requests.
125      * @hide
126      */
127     @Retention(RetentionPolicy.SOURCE)
128     @IntDef(flag = true, prefix = { "BUGREPORT_FLAG_" }, value = {
129             BUGREPORT_FLAG_USE_PREDUMPED_UI_DATA,
130             BUGREPORT_FLAG_DEFER_CONSENT
131     })
132     public @interface BugreportFlag {}
133 
134     /**
135      * Flag for reusing pre-dumped UI data. The pre-dump and bugreport request calls must be
136      * performed by the same UID, otherwise the flag is ignored.
137      */
138     public static final int BUGREPORT_FLAG_USE_PREDUMPED_UI_DATA =
139             IDumpstate.BUGREPORT_FLAG_USE_PREDUMPED_UI_DATA;
140 
141     /**
142      * Flag for deferring user consent.
143      *
144      * <p>This flag should be used in cases where it may not be possible for the user to respond
145      * to a consent dialog immediately, such as when the user is driving. The generated bugreport
146      * may be retrieved at a later time using {@link BugreportManager#retrieveBugreport(
147      * String, ParcelFileDescriptor, Executor, BugreportManager.BugreportCallback)}.
148      */
149     public static final int BUGREPORT_FLAG_DEFER_CONSENT = IDumpstate.BUGREPORT_FLAG_DEFER_CONSENT;
150 }
151