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