blob: 1c6a0710d18f9de0c8ef1f87cca44dc81ad5f25f [file] [log] [blame]
Felipe Lemeb9238b32015-11-24 17:31:47 -08001/*
2 * Copyright (C) 2015 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
17package com.android.shell;
18
Felipe Lemed1e0f122015-12-18 16:12:41 -080019import static android.os.Process.THREAD_PRIORITY_BACKGROUND;
Felipe Lemeb9238b32015-11-24 17:31:47 -080020import static com.android.shell.BugreportPrefs.STATE_SHOW;
21import static com.android.shell.BugreportPrefs.getWarningState;
22
23import java.io.BufferedOutputStream;
Felipe Leme4967f732016-01-06 11:38:53 -080024import java.io.ByteArrayInputStream;
Felipe Lemeb9238b32015-11-24 17:31:47 -080025import java.io.File;
Felipe Leme69c02922015-11-24 17:48:05 -080026import java.io.FileDescriptor;
Felipe Lemeb9238b32015-11-24 17:31:47 -080027import java.io.FileInputStream;
28import java.io.FileOutputStream;
29import java.io.IOException;
30import java.io.InputStream;
Felipe Leme69c02922015-11-24 17:48:05 -080031import java.io.PrintWriter;
Felipe Leme4967f732016-01-06 11:38:53 -080032import java.nio.charset.StandardCharsets;
Felipe Leme69c02922015-11-24 17:48:05 -080033import java.text.NumberFormat;
Felipe Lemeb9238b32015-11-24 17:31:47 -080034import java.util.ArrayList;
Felipe Leme4967f732016-01-06 11:38:53 -080035import java.util.Enumeration;
Felipe Lemed1e0f122015-12-18 16:12:41 -080036import java.util.List;
Felipe Lemeb9238b32015-11-24 17:31:47 -080037import java.util.zip.ZipEntry;
Felipe Leme4967f732016-01-06 11:38:53 -080038import java.util.zip.ZipFile;
Felipe Lemeb9238b32015-11-24 17:31:47 -080039import java.util.zip.ZipOutputStream;
40
41import libcore.io.Streams;
42
Felipe Lemebc73ffc2015-12-11 15:07:14 -080043import com.android.internal.annotations.VisibleForTesting;
Felipe Leme6605bd82016-02-22 15:22:20 -080044import com.android.internal.logging.MetricsLogger;
45import com.android.internal.logging.MetricsProto.MetricsEvent;
Felipe Lemeb9238b32015-11-24 17:31:47 -080046import com.google.android.collect.Lists;
47
48import android.accounts.Account;
49import android.accounts.AccountManager;
Felipe Lemebc73ffc2015-12-11 15:07:14 -080050import android.annotation.SuppressLint;
51import android.app.AlertDialog;
Felipe Lemeb9238b32015-11-24 17:31:47 -080052import android.app.Notification;
Felipe Leme9cadb752015-11-30 09:35:59 -080053import android.app.Notification.Action;
Felipe Lemeb9238b32015-11-24 17:31:47 -080054import android.app.NotificationManager;
55import android.app.PendingIntent;
56import android.app.Service;
57import android.content.ClipData;
58import android.content.Context;
Felipe Lemebc73ffc2015-12-11 15:07:14 -080059import android.content.DialogInterface;
Felipe Lemeb9238b32015-11-24 17:31:47 -080060import android.content.Intent;
61import android.content.res.Configuration;
62import android.net.Uri;
63import android.os.AsyncTask;
Felipe Leme69c02922015-11-24 17:48:05 -080064import android.os.Handler;
65import android.os.HandlerThread;
Felipe Lemeb9238b32015-11-24 17:31:47 -080066import android.os.IBinder;
Felipe Leme69c02922015-11-24 17:48:05 -080067import android.os.Looper;
68import android.os.Message;
Felipe Lemec4f646772016-01-12 18:12:09 -080069import android.os.Parcel;
Felipe Leme69c02922015-11-24 17:48:05 -080070import android.os.Parcelable;
Felipe Lemeb9238b32015-11-24 17:31:47 -080071import android.os.SystemProperties;
Felipe Lemed1e0f122015-12-18 16:12:41 -080072import android.os.Vibrator;
Felipe Lemeb9238b32015-11-24 17:31:47 -080073import android.support.v4.content.FileProvider;
Felipe Lemebc73ffc2015-12-11 15:07:14 -080074import android.text.TextUtils;
Felipe Leme69c02922015-11-24 17:48:05 -080075import android.text.format.DateUtils;
Felipe Lemeb9238b32015-11-24 17:31:47 -080076import android.util.Log;
77import android.util.Patterns;
Felipe Leme69c02922015-11-24 17:48:05 -080078import android.util.SparseArray;
Felipe Lemebc73ffc2015-12-11 15:07:14 -080079import android.view.View;
80import android.view.WindowManager;
81import android.view.View.OnFocusChangeListener;
82import android.view.inputmethod.EditorInfo;
83import android.widget.Button;
84import android.widget.EditText;
Felipe Lemeb9238b32015-11-24 17:31:47 -080085import android.widget.Toast;
86
Felipe Leme69c02922015-11-24 17:48:05 -080087/**
Felipe Leme46d47912015-12-09 13:03:09 -080088 * Service used to keep progress of bugreport processes ({@code dumpstate}).
Felipe Leme69c02922015-11-24 17:48:05 -080089 * <p>
90 * The workflow is:
91 * <ol>
Felipe Lemefd8ea072016-02-09 10:13:47 -080092 * <li>When {@code dumpstate} starts, it sends a {@code BUGREPORT_STARTED} with a sequential id,
93 * its pid, and the estimated total effort.
Felipe Leme69c02922015-11-24 17:48:05 -080094 * <li>{@link BugreportReceiver} receives the intent and delegates it to this service.
95 * <li>Upon start, this service:
96 * <ol>
97 * <li>Issues a system notification so user can watch the progresss (which is 0% initially).
98 * <li>Polls the {@link SystemProperties} for updates on the {@code dumpstate} progress.
99 * <li>If the progress changed, it updates the system notification.
100 * </ol>
101 * <li>As {@code dumpstate} progresses, it updates the system property.
102 * <li>When {@code dumpstate} finishes, it sends a {@code BUGREPORT_FINISHED} intent.
103 * <li>{@link BugreportReceiver} receives the intent and delegates it to this service, which in
104 * turn:
105 * <ol>
Felipe Leme46d47912015-12-09 13:03:09 -0800106 * <li>Updates the system notification so user can share the bugreport.
Felipe Leme69c02922015-11-24 17:48:05 -0800107 * <li>Stops monitoring that {@code dumpstate} process.
108 * <li>Stops itself if it doesn't have any process left to monitor.
109 * </ol>
110 * </ol>
111 */
Felipe Lemeb9238b32015-11-24 17:31:47 -0800112public class BugreportProgressService extends Service {
Felipe Lemec4f646772016-01-12 18:12:09 -0800113 private static final String TAG = "BugreportProgressService";
Felipe Leme69c02922015-11-24 17:48:05 -0800114 private static final boolean DEBUG = false;
Felipe Lemeb9238b32015-11-24 17:31:47 -0800115
116 private static final String AUTHORITY = "com.android.shell";
117
Felipe Leme46d47912015-12-09 13:03:09 -0800118 // External intents sent by dumpstate.
Felipe Leme69c02922015-11-24 17:48:05 -0800119 static final String INTENT_BUGREPORT_STARTED = "android.intent.action.BUGREPORT_STARTED";
120 static final String INTENT_BUGREPORT_FINISHED = "android.intent.action.BUGREPORT_FINISHED";
Michal Karpinski226940e2015-12-15 18:14:26 +0000121 static final String INTENT_REMOTE_BUGREPORT_FINISHED =
122 "android.intent.action.REMOTE_BUGREPORT_FINISHED";
Felipe Leme46d47912015-12-09 13:03:09 -0800123
124 // Internal intents used on notification actions.
Felipe Leme9cadb752015-11-30 09:35:59 -0800125 static final String INTENT_BUGREPORT_CANCEL = "android.intent.action.BUGREPORT_CANCEL";
Felipe Leme46d47912015-12-09 13:03:09 -0800126 static final String INTENT_BUGREPORT_SHARE = "android.intent.action.BUGREPORT_SHARE";
Felipe Lemebc73ffc2015-12-11 15:07:14 -0800127 static final String INTENT_BUGREPORT_INFO_LAUNCH =
128 "android.intent.action.BUGREPORT_INFO_LAUNCH";
Felipe Lemed1e0f122015-12-18 16:12:41 -0800129 static final String INTENT_BUGREPORT_SCREENSHOT =
130 "android.intent.action.BUGREPORT_SCREENSHOT";
Felipe Leme69c02922015-11-24 17:48:05 -0800131
Felipe Lemeb9238b32015-11-24 17:31:47 -0800132 static final String EXTRA_BUGREPORT = "android.intent.extra.BUGREPORT";
133 static final String EXTRA_SCREENSHOT = "android.intent.extra.SCREENSHOT";
Felipe Lemefd8ea072016-02-09 10:13:47 -0800134 static final String EXTRA_ID = "android.intent.extra.ID";
Felipe Leme69c02922015-11-24 17:48:05 -0800135 static final String EXTRA_PID = "android.intent.extra.PID";
136 static final String EXTRA_MAX = "android.intent.extra.MAX";
137 static final String EXTRA_NAME = "android.intent.extra.NAME";
Felipe Lemebc73ffc2015-12-11 15:07:14 -0800138 static final String EXTRA_TITLE = "android.intent.extra.TITLE";
139 static final String EXTRA_DESCRIPTION = "android.intent.extra.DESCRIPTION";
Felipe Leme69c02922015-11-24 17:48:05 -0800140 static final String EXTRA_ORIGINAL_INTENT = "android.intent.extra.ORIGINAL_INTENT";
Felipe Lemec4f646772016-01-12 18:12:09 -0800141 static final String EXTRA_INFO = "android.intent.extra.INFO";
Felipe Leme69c02922015-11-24 17:48:05 -0800142
143 private static final int MSG_SERVICE_COMMAND = 1;
144 private static final int MSG_POLL = 2;
Felipe Lemed1e0f122015-12-18 16:12:41 -0800145 private static final int MSG_DELAYED_SCREENSHOT = 3;
146 private static final int MSG_SCREENSHOT_REQUEST = 4;
147 private static final int MSG_SCREENSHOT_RESPONSE = 5;
148
Felipe Leme8648a152016-02-25 16:22:38 -0800149 // Passed to Message.obtain() when msg.arg2 is not used.
150 private static final int UNUSED_ARG2 = -2;
151
Felipe Lemed1e0f122015-12-18 16:12:41 -0800152 /**
153 * Delay before a screenshot is taken.
154 * <p>
155 * Should be at least 3 seconds, otherwise its toast might show up in the screenshot.
156 */
157 static final int SCREENSHOT_DELAY_SECONDS = 3;
Felipe Leme69c02922015-11-24 17:48:05 -0800158
159 /** Polling frequency, in milliseconds. */
Felipe Lemebc73ffc2015-12-11 15:07:14 -0800160 static final long POLLING_FREQUENCY = 2 * DateUtils.SECOND_IN_MILLIS;
Felipe Leme69c02922015-11-24 17:48:05 -0800161
162 /** How long (in ms) a dumpstate process will be monitored if it didn't show progress. */
Felipe Leme1eee1992016-02-16 13:01:38 -0800163 private static final long INACTIVITY_TIMEOUT = 10 * DateUtils.MINUTE_IN_MILLIS;
Felipe Leme69c02922015-11-24 17:48:05 -0800164
Felipe Leme719aaae2015-11-30 15:41:11 -0800165 /** System properties used for monitoring progress. */
166 private static final String DUMPSTATE_PREFIX = "dumpstate.";
167 private static final String PROGRESS_SUFFIX = ".progress";
168 private static final String MAX_SUFFIX = ".max";
Felipe Lemebc73ffc2015-12-11 15:07:14 -0800169 private static final String NAME_SUFFIX = ".name";
Felipe Leme9cadb752015-11-30 09:35:59 -0800170
Felipe Lemebc73ffc2015-12-11 15:07:14 -0800171 /** System property (and value) used to stop dumpstate. */
Felipe Lemed1e0f122015-12-18 16:12:41 -0800172 // TODO: should call ActiveManager API instead
Felipe Leme719aaae2015-11-30 15:41:11 -0800173 private static final String CTL_STOP = "ctl.stop";
Felipe Leme4cc86332015-12-04 16:37:28 -0800174 private static final String BUGREPORT_SERVICE = "bugreportplus";
Felipe Leme69c02922015-11-24 17:48:05 -0800175
Felipe Lemed1e0f122015-12-18 16:12:41 -0800176 /**
177 * Directory on Shell's data storage where screenshots will be stored.
178 * <p>
179 * Must be a path supported by its FileProvider.
180 */
181 private static final String SCREENSHOT_DIR = "bugreports";
182
Felipe Lemefd8ea072016-02-09 10:13:47 -0800183 /** Managed dumpstate processes (keyed by id) */
Felipe Leme69c02922015-11-24 17:48:05 -0800184 private final SparseArray<BugreportInfo> mProcesses = new SparseArray<>();
185
Felipe Lemed1e0f122015-12-18 16:12:41 -0800186 private Context mContext;
187 private ServiceHandler mMainHandler;
188 private ScreenshotHandler mScreenshotHandler;
Felipe Leme69c02922015-11-24 17:48:05 -0800189
Felipe Lemebc73ffc2015-12-11 15:07:14 -0800190 private final BugreportInfoDialog mInfoDialog = new BugreportInfoDialog();
191
Felipe Lemed1e0f122015-12-18 16:12:41 -0800192 private File mScreenshotsDir;
193
194 /**
195 * Flag indicating whether a screenshot is being taken.
196 * <p>
197 * This is the only state that is shared between the 2 handlers and hence must have synchronized
198 * access.
199 */
200 private boolean mTakingScreenshot;
201
Felipe Leme69c02922015-11-24 17:48:05 -0800202 @Override
203 public void onCreate() {
Felipe Lemed1e0f122015-12-18 16:12:41 -0800204 mContext = getApplicationContext();
205 mMainHandler = new ServiceHandler("BugreportProgressServiceMainThread");
206 mScreenshotHandler = new ScreenshotHandler("BugreportProgressServiceScreenshotThread");
Felipe Leme69c02922015-11-24 17:48:05 -0800207
Felipe Leme4f663f62016-03-08 11:41:18 -0800208 mScreenshotsDir = new File(getFilesDir(), SCREENSHOT_DIR);
Felipe Lemed1e0f122015-12-18 16:12:41 -0800209 if (!mScreenshotsDir.exists()) {
210 Log.i(TAG, "Creating directory " + mScreenshotsDir + " to store temporary screenshots");
211 if (!mScreenshotsDir.mkdir()) {
212 Log.w(TAG, "Could not create directory " + mScreenshotsDir);
213 }
214 }
Felipe Leme69c02922015-11-24 17:48:05 -0800215 }
Felipe Lemeb9238b32015-11-24 17:31:47 -0800216
217 @Override
218 public int onStartCommand(Intent intent, int flags, int startId) {
219 if (intent != null) {
Felipe Leme69c02922015-11-24 17:48:05 -0800220 // Handle it in a separate thread.
Felipe Lemed1e0f122015-12-18 16:12:41 -0800221 final Message msg = mMainHandler.obtainMessage();
Felipe Leme69c02922015-11-24 17:48:05 -0800222 msg.what = MSG_SERVICE_COMMAND;
223 msg.obj = intent;
Felipe Lemed1e0f122015-12-18 16:12:41 -0800224 mMainHandler.sendMessage(msg);
Felipe Lemeb9238b32015-11-24 17:31:47 -0800225 }
Felipe Leme69c02922015-11-24 17:48:05 -0800226
227 // If service is killed it cannot be recreated because it would not know which
Felipe Lemefd8ea072016-02-09 10:13:47 -0800228 // dumpstate IDs it would have to watch.
Felipe Lemeb9238b32015-11-24 17:31:47 -0800229 return START_NOT_STICKY;
230 }
231
232 @Override
233 public IBinder onBind(Intent intent) {
234 return null;
235 }
236
Felipe Leme69c02922015-11-24 17:48:05 -0800237 @Override
238 public void onDestroy() {
Felipe Lemed1e0f122015-12-18 16:12:41 -0800239 mMainHandler.getLooper().quit();
240 mScreenshotHandler.getLooper().quit();
Felipe Leme69c02922015-11-24 17:48:05 -0800241 super.onDestroy();
242 }
Felipe Lemeb9238b32015-11-24 17:31:47 -0800243
Felipe Leme69c02922015-11-24 17:48:05 -0800244 @Override
245 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Felipe Lemed1e0f122015-12-18 16:12:41 -0800246 final int size = mProcesses.size();
247 if (size == 0) {
248 writer.printf("No monitored processes");
249 return;
250 }
251 writer.printf("Monitored dumpstate processes\n");
252 writer.printf("-----------------------------\n");
253 for (int i = 0; i < size; i++) {
254 writer.printf("%s\n", mProcesses.valueAt(i));
Felipe Lemeb9238b32015-11-24 17:31:47 -0800255 }
Felipe Leme69c02922015-11-24 17:48:05 -0800256 }
257
Felipe Lemed1e0f122015-12-18 16:12:41 -0800258 /**
259 * Main thread used to handle all requests but taking screenshots.
260 */
Felipe Leme69c02922015-11-24 17:48:05 -0800261 private final class ServiceHandler extends Handler {
Felipe Lemed1e0f122015-12-18 16:12:41 -0800262 public ServiceHandler(String name) {
263 super(newLooper(name));
Felipe Leme69c02922015-11-24 17:48:05 -0800264 }
265
266 @Override
267 public void handleMessage(Message msg) {
268 if (msg.what == MSG_POLL) {
Felipe Leme923afa92015-12-04 12:15:30 -0800269 poll();
Felipe Leme69c02922015-11-24 17:48:05 -0800270 return;
271 }
272
Felipe Lemed1e0f122015-12-18 16:12:41 -0800273 if (msg.what == MSG_DELAYED_SCREENSHOT) {
274 takeScreenshot(msg.arg1, msg.arg2);
275 return;
276 }
277
278 if (msg.what == MSG_SCREENSHOT_RESPONSE) {
279 handleScreenshotResponse(msg);
280 return;
281 }
282
Felipe Leme69c02922015-11-24 17:48:05 -0800283 if (msg.what != MSG_SERVICE_COMMAND) {
284 // Sanity check.
285 Log.e(TAG, "Invalid message type: " + msg.what);
286 return;
287 }
288
Felipe Leme46d47912015-12-09 13:03:09 -0800289 // At this point it's handling onStartCommand(), with the intent passed as an Extra.
Felipe Leme69c02922015-11-24 17:48:05 -0800290 if (!(msg.obj instanceof Intent)) {
291 // Sanity check.
Felipe Lemeaf6fd402016-01-29 18:01:49 -0800292 Log.wtf(TAG, "handleMessage(): invalid msg.obj type: " + msg.obj);
Felipe Leme69c02922015-11-24 17:48:05 -0800293 return;
294 }
295 final Parcelable parcel = ((Intent) msg.obj).getParcelableExtra(EXTRA_ORIGINAL_INTENT);
Felipe Leme46d47912015-12-09 13:03:09 -0800296 final Intent intent;
297 if (parcel instanceof Intent) {
298 // The real intent was passed to BugreportReceiver, which delegated to the service.
299 intent = (Intent) parcel;
300 } else {
301 intent = (Intent) msg.obj;
Felipe Leme69c02922015-11-24 17:48:05 -0800302 }
Felipe Leme69c02922015-11-24 17:48:05 -0800303 final String action = intent.getAction();
Felipe Leme46d47912015-12-09 13:03:09 -0800304 final int pid = intent.getIntExtra(EXTRA_PID, 0);
Felipe Leme85ae3cf2016-02-24 15:36:50 -0800305 final int id = intent.getIntExtra(EXTRA_ID, 0);
Felipe Leme46d47912015-12-09 13:03:09 -0800306 final int max = intent.getIntExtra(EXTRA_MAX, -1);
307 final String name = intent.getStringExtra(EXTRA_NAME);
Felipe Leme69c02922015-11-24 17:48:05 -0800308
Felipe Lemefd8ea072016-02-09 10:13:47 -0800309 if (DEBUG)
310 Log.v(TAG, "action: " + action + ", name: " + name + ", id: " + id + ", pid: "
311 + pid + ", max: " + max);
Felipe Leme69c02922015-11-24 17:48:05 -0800312 switch (action) {
313 case INTENT_BUGREPORT_STARTED:
Felipe Lemefd8ea072016-02-09 10:13:47 -0800314 if (!startProgress(name, id, pid, max)) {
Felipe Leme69c02922015-11-24 17:48:05 -0800315 stopSelfWhenDone();
316 return;
317 }
Felipe Leme46d47912015-12-09 13:03:09 -0800318 poll();
Felipe Leme69c02922015-11-24 17:48:05 -0800319 break;
320 case INTENT_BUGREPORT_FINISHED:
Felipe Lemefd8ea072016-02-09 10:13:47 -0800321 if (id == 0) {
Felipe Leme69c02922015-11-24 17:48:05 -0800322 // Shouldn't happen, unless BUGREPORT_FINISHED is received from a legacy,
323 // out-of-sync dumpstate process.
Felipe Lemefd8ea072016-02-09 10:13:47 -0800324 Log.w(TAG, "Missing " + EXTRA_ID + " on intent " + intent);
Felipe Leme69c02922015-11-24 17:48:05 -0800325 }
Felipe Lemefd8ea072016-02-09 10:13:47 -0800326 onBugreportFinished(id, intent);
Felipe Leme46d47912015-12-09 13:03:09 -0800327 break;
Felipe Lemebc73ffc2015-12-11 15:07:14 -0800328 case INTENT_BUGREPORT_INFO_LAUNCH:
Felipe Lemefd8ea072016-02-09 10:13:47 -0800329 launchBugreportInfoDialog(id);
Felipe Lemebc73ffc2015-12-11 15:07:14 -0800330 break;
Felipe Lemed1e0f122015-12-18 16:12:41 -0800331 case INTENT_BUGREPORT_SCREENSHOT:
Felipe Lemefd8ea072016-02-09 10:13:47 -0800332 takeScreenshot(id, true);
Felipe Lemed1e0f122015-12-18 16:12:41 -0800333 break;
Felipe Leme46d47912015-12-09 13:03:09 -0800334 case INTENT_BUGREPORT_SHARE:
Felipe Lemefd8ea072016-02-09 10:13:47 -0800335 shareBugreport(id, (BugreportInfo) intent.getParcelableExtra(EXTRA_INFO));
Felipe Leme69c02922015-11-24 17:48:05 -0800336 break;
Felipe Leme9cadb752015-11-30 09:35:59 -0800337 case INTENT_BUGREPORT_CANCEL:
Felipe Lemefd8ea072016-02-09 10:13:47 -0800338 cancel(id);
Felipe Leme9cadb752015-11-30 09:35:59 -0800339 break;
Felipe Leme69c02922015-11-24 17:48:05 -0800340 default:
341 Log.w(TAG, "Unsupported intent: " + action);
342 }
343 return;
344
345 }
346
Felipe Leme923afa92015-12-04 12:15:30 -0800347 private void poll() {
348 if (pollProgress()) {
Felipe Leme69c02922015-11-24 17:48:05 -0800349 // Keep polling...
350 sendEmptyMessageDelayed(MSG_POLL, POLLING_FREQUENCY);
Felipe Leme46d47912015-12-09 13:03:09 -0800351 } else {
352 Log.i(TAG, "Stopped polling");
Felipe Leme69c02922015-11-24 17:48:05 -0800353 }
354 }
Felipe Leme923afa92015-12-04 12:15:30 -0800355 }
Felipe Leme69c02922015-11-24 17:48:05 -0800356
Felipe Leme923afa92015-12-04 12:15:30 -0800357 /**
Felipe Lemed1e0f122015-12-18 16:12:41 -0800358 * Separate thread used only to take screenshots so it doesn't block the main thread.
359 */
360 private final class ScreenshotHandler extends Handler {
361 public ScreenshotHandler(String name) {
362 super(newLooper(name));
363 }
364
365 @Override
366 public void handleMessage(Message msg) {
367 if (msg.what != MSG_SCREENSHOT_REQUEST) {
368 Log.e(TAG, "Invalid message type: " + msg.what);
369 return;
370 }
371 handleScreenshotRequest(msg);
372 }
373 }
374
Felipe Lemefd8ea072016-02-09 10:13:47 -0800375 private BugreportInfo getInfo(int id) {
376 final BugreportInfo info = mProcesses.get(id);
Felipe Lemed1e0f122015-12-18 16:12:41 -0800377 if (info == null) {
Felipe Lemefd8ea072016-02-09 10:13:47 -0800378 Log.w(TAG, "Not monitoring process with ID " + id);
Felipe Lemed1e0f122015-12-18 16:12:41 -0800379 }
380 return info;
381 }
382
383 /**
Felipe Leme923afa92015-12-04 12:15:30 -0800384 * Creates the {@link BugreportInfo} for a process and issue a system notification to
385 * indicate its progress.
386 *
387 * @return whether it succeeded or not.
388 */
Felipe Lemefd8ea072016-02-09 10:13:47 -0800389 private boolean startProgress(String name, int id, int pid, int max) {
Felipe Leme923afa92015-12-04 12:15:30 -0800390 if (name == null) {
391 Log.w(TAG, "Missing " + EXTRA_NAME + " on start intent");
392 }
Felipe Lemefd8ea072016-02-09 10:13:47 -0800393 if (id == -1) {
394 Log.e(TAG, "Missing " + EXTRA_ID + " on start intent");
395 return false;
396 }
Felipe Leme923afa92015-12-04 12:15:30 -0800397 if (pid == -1) {
398 Log.e(TAG, "Missing " + EXTRA_PID + " on start intent");
399 return false;
400 }
401 if (max <= 0) {
402 Log.e(TAG, "Invalid value for extra " + EXTRA_MAX + ": " + max);
403 return false;
Felipe Leme69c02922015-11-24 17:48:05 -0800404 }
405
Felipe Lemefd8ea072016-02-09 10:13:47 -0800406 final BugreportInfo info = new BugreportInfo(mContext, id, pid, name, max);
407 if (mProcesses.indexOfKey(id) >= 0) {
408 Log.w(TAG, "ID " + id + " already watched");
Felipe Lemed1e0f122015-12-18 16:12:41 -0800409 } else {
Felipe Lemefd8ea072016-02-09 10:13:47 -0800410 mProcesses.put(info.id, info);
Felipe Leme69c02922015-11-24 17:48:05 -0800411 }
Felipe Lemed1e0f122015-12-18 16:12:41 -0800412 // Take initial screenshot.
Felipe Lemefd8ea072016-02-09 10:13:47 -0800413 takeScreenshot(id, false);
Felipe Leme923afa92015-12-04 12:15:30 -0800414 updateProgress(info);
415 return true;
416 }
417
418 /**
Felipe Leme46d47912015-12-09 13:03:09 -0800419 * Updates the system notification for a given bugreport.
Felipe Leme923afa92015-12-04 12:15:30 -0800420 */
421 private void updateProgress(BugreportInfo info) {
422 if (info.max <= 0 || info.progress < 0) {
423 Log.e(TAG, "Invalid progress values for " + info);
424 return;
425 }
426
Felipe Leme923afa92015-12-04 12:15:30 -0800427 final NumberFormat nf = NumberFormat.getPercentInstance();
428 nf.setMinimumFractionDigits(2);
429 nf.setMaximumFractionDigits(2);
430 final String percentText = nf.format((double) info.progress / info.max);
Felipe Lemed1e0f122015-12-18 16:12:41 -0800431 final Action cancelAction = new Action.Builder(null, mContext.getString(
432 com.android.internal.R.string.cancel), newCancelIntent(mContext, info)).build();
433 final Intent infoIntent = new Intent(mContext, BugreportProgressService.class);
Felipe Lemebc73ffc2015-12-11 15:07:14 -0800434 infoIntent.setAction(INTENT_BUGREPORT_INFO_LAUNCH);
Felipe Lemefd8ea072016-02-09 10:13:47 -0800435 infoIntent.putExtra(EXTRA_ID, info.id);
Felipe Lemedb313632016-02-25 17:06:58 -0800436 final PendingIntent infoPendingIntent =
437 PendingIntent.getService(mContext, info.id, infoIntent,
438 PendingIntent.FLAG_UPDATE_CURRENT);
Felipe Lemebc73ffc2015-12-11 15:07:14 -0800439 final Action infoAction = new Action.Builder(null,
Felipe Lemed1e0f122015-12-18 16:12:41 -0800440 mContext.getString(R.string.bugreport_info_action),
Felipe Lemedb313632016-02-25 17:06:58 -0800441 infoPendingIntent).build();
Felipe Lemed1e0f122015-12-18 16:12:41 -0800442 final Intent screenshotIntent = new Intent(mContext, BugreportProgressService.class);
443 screenshotIntent.setAction(INTENT_BUGREPORT_SCREENSHOT);
Felipe Lemefd8ea072016-02-09 10:13:47 -0800444 screenshotIntent.putExtra(EXTRA_ID, info.id);
Felipe Lemed1e0f122015-12-18 16:12:41 -0800445 PendingIntent screenshotPendingIntent = mTakingScreenshot ? null : PendingIntent
Felipe Lemefd8ea072016-02-09 10:13:47 -0800446 .getService(mContext, info.id, screenshotIntent,
Felipe Lemed1e0f122015-12-18 16:12:41 -0800447 PendingIntent.FLAG_UPDATE_CURRENT);
448 final Action screenshotAction = new Action.Builder(null,
449 mContext.getString(R.string.bugreport_screenshot_action),
450 screenshotPendingIntent).build();
Felipe Leme923afa92015-12-04 12:15:30 -0800451
Felipe Lemefd8ea072016-02-09 10:13:47 -0800452 final String title = mContext.getString(R.string.bugreport_in_progress_title, info.id);
Felipe Lemed1e0f122015-12-18 16:12:41 -0800453
Felipe Leme923afa92015-12-04 12:15:30 -0800454 final String name =
Felipe Lemed1e0f122015-12-18 16:12:41 -0800455 info.name != null ? info.name : mContext.getString(R.string.bugreport_unnamed);
Felipe Leme923afa92015-12-04 12:15:30 -0800456
Felipe Lemed1e0f122015-12-18 16:12:41 -0800457 final Notification notification = new Notification.Builder(mContext)
Felipe Leme923afa92015-12-04 12:15:30 -0800458 .setSmallIcon(com.android.internal.R.drawable.stat_sys_adb)
459 .setContentTitle(title)
460 .setTicker(title)
461 .setContentText(name)
462 .setContentInfo(percentText)
463 .setProgress(info.max, info.progress, false)
464 .setOngoing(true)
465 .setLocalOnly(true)
Felipe Lemed1e0f122015-12-18 16:12:41 -0800466 .setColor(mContext.getColor(
Felipe Leme923afa92015-12-04 12:15:30 -0800467 com.android.internal.R.color.system_notification_accent_color))
Felipe Lemedb313632016-02-25 17:06:58 -0800468 .setContentIntent(infoPendingIntent)
Felipe Lemebc73ffc2015-12-11 15:07:14 -0800469 .addAction(infoAction)
Felipe Lemed1e0f122015-12-18 16:12:41 -0800470 .addAction(screenshotAction)
Felipe Leme923afa92015-12-04 12:15:30 -0800471 .addAction(cancelAction)
472 .build();
473
Felipe Leme22881292016-01-06 09:57:23 -0800474 if (info.finished) {
475 Log.w(TAG, "Not sending progress notification because bugreport has finished already ("
476 + info + ")");
477 return;
478 }
Felipe Leme26288782016-02-25 12:10:43 -0800479 if (DEBUG) {
480 Log.d(TAG, "Sending 'Progress' notification for id " + info.id + "(pid " + info.pid
481 + "): " + percentText);
482 }
Felipe Lemefd8ea072016-02-09 10:13:47 -0800483 NotificationManager.from(mContext).notify(TAG, info.id, notification);
Felipe Leme923afa92015-12-04 12:15:30 -0800484 }
485
486 /**
Felipe Leme46d47912015-12-09 13:03:09 -0800487 * Creates a {@link PendingIntent} for a notification action used to cancel a bugreport.
Felipe Leme923afa92015-12-04 12:15:30 -0800488 */
Felipe Leme46d47912015-12-09 13:03:09 -0800489 private static PendingIntent newCancelIntent(Context context, BugreportInfo info) {
490 final Intent intent = new Intent(INTENT_BUGREPORT_CANCEL);
491 intent.setClass(context, BugreportProgressService.class);
Felipe Lemefd8ea072016-02-09 10:13:47 -0800492 intent.putExtra(EXTRA_ID, info.id);
493 return PendingIntent.getService(context, info.id, intent,
Felipe Lemebc73ffc2015-12-11 15:07:14 -0800494 PendingIntent.FLAG_UPDATE_CURRENT);
Felipe Leme46d47912015-12-09 13:03:09 -0800495 }
496
497 /**
498 * Finalizes the progress on a given bugreport and cancel its notification.
499 */
Felipe Lemefd8ea072016-02-09 10:13:47 -0800500 private void stopProgress(int id) {
501 if (mProcesses.indexOfKey(id) < 0) {
502 Log.w(TAG, "ID not watched: " + id);
Felipe Lemed1e0f122015-12-18 16:12:41 -0800503 } else {
Felipe Lemefd8ea072016-02-09 10:13:47 -0800504 Log.d(TAG, "Removing ID " + id);
505 mProcesses.remove(id);
Felipe Leme923afa92015-12-04 12:15:30 -0800506 }
Felipe Lemefd8ea072016-02-09 10:13:47 -0800507 Log.v(TAG, "stopProgress(" + id + "): cancel notification");
508 NotificationManager.from(mContext).cancel(TAG, id);
Felipe Leme0f2daaf2016-03-08 12:44:22 -0800509 stopSelfWhenDone();
Felipe Leme923afa92015-12-04 12:15:30 -0800510 }
511
512 /**
513 * Cancels a bugreport upon user's request.
514 */
Felipe Lemefd8ea072016-02-09 10:13:47 -0800515 private void cancel(int id) {
Felipe Leme6605bd82016-02-22 15:22:20 -0800516 MetricsLogger.action(this, MetricsEvent.ACTION_BUGREPORT_NOTIFICATION_ACTION_CANCEL);
Felipe Lemefd8ea072016-02-09 10:13:47 -0800517 Log.v(TAG, "cancel: ID=" + id);
518 final BugreportInfo info = getInfo(id);
Felipe Lemed1e0f122015-12-18 16:12:41 -0800519 if (info != null && !info.finished) {
Felipe Lemefd8ea072016-02-09 10:13:47 -0800520 Log.i(TAG, "Cancelling bugreport service (ID=" + id + ") on user's request");
Felipe Lemed1e0f122015-12-18 16:12:41 -0800521 setSystemProperty(CTL_STOP, BUGREPORT_SERVICE);
522 deleteScreenshots(info);
Felipe Lemebc73ffc2015-12-11 15:07:14 -0800523 }
Felipe Lemefd8ea072016-02-09 10:13:47 -0800524 stopProgress(id);
Felipe Leme923afa92015-12-04 12:15:30 -0800525 }
526
527 /**
528 * Poll {@link SystemProperties} to get the progress on each monitored process.
529 *
530 * @return whether it should keep polling.
531 */
532 private boolean pollProgress() {
Felipe Lemed1e0f122015-12-18 16:12:41 -0800533 final int total = mProcesses.size();
534 if (total == 0) {
535 Log.d(TAG, "No process to poll progress.");
Felipe Leme923afa92015-12-04 12:15:30 -0800536 }
Felipe Lemed1e0f122015-12-18 16:12:41 -0800537 int activeProcesses = 0;
538 for (int i = 0; i < total; i++) {
Felipe Lemed1e0f122015-12-18 16:12:41 -0800539 final BugreportInfo info = mProcesses.valueAt(i);
Felipe Lemeaf6fd402016-01-29 18:01:49 -0800540 if (info == null) {
Felipe Lemefd8ea072016-02-09 10:13:47 -0800541 Log.wtf(TAG, "pollProgress(): null info at index " + i + "(ID = "
Felipe Lemeaf6fd402016-01-29 18:01:49 -0800542 + mProcesses.keyAt(i) + ")");
543 continue;
544 }
545
546 final int pid = info.pid;
Felipe Lemefd8ea072016-02-09 10:13:47 -0800547 final int id = info.id;
Felipe Lemed1e0f122015-12-18 16:12:41 -0800548 if (info.finished) {
Felipe Leme85ae3cf2016-02-24 15:36:50 -0800549 if (DEBUG) Log.v(TAG, "Skipping finished process " + pid + " (id: " + id + ")");
Felipe Lemed1e0f122015-12-18 16:12:41 -0800550 continue;
551 }
552 activeProcesses++;
553 final String progressKey = DUMPSTATE_PREFIX + pid + PROGRESS_SUFFIX;
554 final int progress = SystemProperties.getInt(progressKey, 0);
555 if (progress == 0) {
556 Log.v(TAG, "System property " + progressKey + " is not set yet");
557 }
558 final int max = SystemProperties.getInt(DUMPSTATE_PREFIX + pid + MAX_SUFFIX, 0);
559 final boolean maxChanged = max > 0 && max != info.max;
560 final boolean progressChanged = progress > 0 && progress != info.progress;
561
562 if (progressChanged || maxChanged) {
563 if (progressChanged) {
Felipe Lemefd8ea072016-02-09 10:13:47 -0800564 if (DEBUG) Log.v(TAG, "Updating progress for PID " + pid + "(id: " + id
565 + ") from " + info.progress + " to " + progress);
Felipe Lemed1e0f122015-12-18 16:12:41 -0800566 info.progress = progress;
567 }
568 if (maxChanged) {
Felipe Lemefd8ea072016-02-09 10:13:47 -0800569 Log.i(TAG, "Updating max progress for PID " + pid + "(id: " + id
570 + ") from " + info.max + " to " + max);
Felipe Lemed1e0f122015-12-18 16:12:41 -0800571 info.max = max;
572 }
573 info.lastUpdate = System.currentTimeMillis();
574 updateProgress(info);
575 } else {
576 long inactiveTime = System.currentTimeMillis() - info.lastUpdate;
577 if (inactiveTime >= INACTIVITY_TIMEOUT) {
Felipe Lemefd8ea072016-02-09 10:13:47 -0800578 Log.w(TAG, "No progress update for PID " + pid + " since "
Felipe Lemed1e0f122015-12-18 16:12:41 -0800579 + info.getFormattedLastUpdate());
Felipe Lemefd8ea072016-02-09 10:13:47 -0800580 stopProgress(info.id);
Felipe Lemed1e0f122015-12-18 16:12:41 -0800581 }
582 }
583 }
584 if (DEBUG) Log.v(TAG, "pollProgress() total=" + total + ", actives=" + activeProcesses);
585 return activeProcesses > 0;
Felipe Leme923afa92015-12-04 12:15:30 -0800586 }
587
588 /**
Felipe Lemebc73ffc2015-12-11 15:07:14 -0800589 * Fetches a {@link BugreportInfo} for a given process and launches a dialog where the user can
590 * change its values.
591 */
Felipe Lemefd8ea072016-02-09 10:13:47 -0800592 private void launchBugreportInfoDialog(int id) {
Felipe Leme6605bd82016-02-22 15:22:20 -0800593 MetricsLogger.action(this, MetricsEvent.ACTION_BUGREPORT_NOTIFICATION_ACTION_DETAILS);
Felipe Lemebc73ffc2015-12-11 15:07:14 -0800594 // Copy values so it doesn't lock mProcesses while UI is being updated
595 final String name, title, description;
Felipe Lemefd8ea072016-02-09 10:13:47 -0800596 final BugreportInfo info = getInfo(id);
Felipe Lemed1e0f122015-12-18 16:12:41 -0800597 if (info == null) {
Felipe Leme1eee1992016-02-16 13:01:38 -0800598 // Most likely am killed Shell before user tapped the notification. Since system might
599 // be too busy anwyays, it's better to ignore the notification and switch back to the
600 // non-interactive mode (where the bugerport will be shared upon completion).
Felipe Lemebbd91e52016-02-26 16:48:22 -0800601 Log.w(TAG, "launchBugreportInfoDialog(): canceling notification because id " + id
602 + " was not found");
Felipe Leme1eee1992016-02-16 13:01:38 -0800603 // TODO: add test case to make sure notification is canceled.
604 NotificationManager.from(mContext).cancel(TAG, id);
Felipe Lemed1e0f122015-12-18 16:12:41 -0800605 return;
606 }
Felipe Lemed1e0f122015-12-18 16:12:41 -0800607
608 collapseNotificationBar();
Felipe Lemefd8ea072016-02-09 10:13:47 -0800609 mInfoDialog.initialize(mContext, info);
Felipe Lemed1e0f122015-12-18 16:12:41 -0800610 }
611
612 /**
613 * Starting point for taking a screenshot.
614 * <p>
615 * If {@code delayed} is set, it first display a toast message and waits
616 * {@link #SCREENSHOT_DELAY_SECONDS} seconds before taking it, otherwise it takes the screenshot
617 * right away.
618 * <p>
619 * Typical usage is delaying when taken from the notification action, and taking it right away
620 * upon receiving a {@link #INTENT_BUGREPORT_STARTED}.
621 */
Felipe Lemefd8ea072016-02-09 10:13:47 -0800622 private void takeScreenshot(int id, boolean delayed) {
Felipe Leme6605bd82016-02-22 15:22:20 -0800623 MetricsLogger.action(this, MetricsEvent.ACTION_BUGREPORT_NOTIFICATION_ACTION_SCREENSHOT);
Felipe Leme1eee1992016-02-16 13:01:38 -0800624 if (getInfo(id) == null) {
625 // Most likely am killed Shell before user tapped the notification. Since system might
626 // be too busy anwyays, it's better to ignore the notification and switch back to the
627 // non-interactive mode (where the bugerport will be shared upon completion).
Felipe Lemebbd91e52016-02-26 16:48:22 -0800628 Log.w(TAG, "takeScreenshot(): canceling notification because id " + id
629 + " was not found");
Felipe Leme1eee1992016-02-16 13:01:38 -0800630 // TODO: add test case to make sure notification is canceled.
631 NotificationManager.from(mContext).cancel(TAG, id);
632 return;
633 }
Felipe Lemed1e0f122015-12-18 16:12:41 -0800634 setTakingScreenshot(true);
635 if (delayed) {
636 collapseNotificationBar();
637 final String msg = mContext.getResources()
638 .getQuantityString(com.android.internal.R.plurals.bugreport_countdown,
639 SCREENSHOT_DELAY_SECONDS, SCREENSHOT_DELAY_SECONDS);
640 Log.i(TAG, msg);
641 // Show a toast just once, otherwise it might be captured in the screenshot.
642 Toast.makeText(mContext, msg, Toast.LENGTH_SHORT).show();
643
Felipe Lemefd8ea072016-02-09 10:13:47 -0800644 takeScreenshot(id, SCREENSHOT_DELAY_SECONDS);
Felipe Lemed1e0f122015-12-18 16:12:41 -0800645 } else {
Felipe Lemefd8ea072016-02-09 10:13:47 -0800646 takeScreenshot(id, 0);
Felipe Lemed1e0f122015-12-18 16:12:41 -0800647 }
648 }
649
650 /**
651 * Takes a screenshot after {@code delay} seconds.
652 */
Felipe Lemefd8ea072016-02-09 10:13:47 -0800653 private void takeScreenshot(int id, int delay) {
Felipe Lemed1e0f122015-12-18 16:12:41 -0800654 if (delay > 0) {
Felipe Lemefd8ea072016-02-09 10:13:47 -0800655 Log.d(TAG, "Taking screenshot for " + id + " in " + delay + " seconds");
Felipe Lemed1e0f122015-12-18 16:12:41 -0800656 final Message msg = mMainHandler.obtainMessage();
657 msg.what = MSG_DELAYED_SCREENSHOT;
Felipe Lemefd8ea072016-02-09 10:13:47 -0800658 msg.arg1 = id;
Felipe Lemed1e0f122015-12-18 16:12:41 -0800659 msg.arg2 = delay - 1;
660 mMainHandler.sendMessageDelayed(msg, DateUtils.SECOND_IN_MILLIS);
661 return;
Felipe Lemebc73ffc2015-12-11 15:07:14 -0800662 }
663
Felipe Lemed1e0f122015-12-18 16:12:41 -0800664 // It's time to take the screenshot: let the proper thread handle it
Felipe Lemefd8ea072016-02-09 10:13:47 -0800665 final BugreportInfo info = getInfo(id);
Felipe Lemed1e0f122015-12-18 16:12:41 -0800666 if (info == null) {
667 return;
668 }
669 final String screenshotPath =
670 new File(mScreenshotsDir, info.getPathNextScreenshot()).getAbsolutePath();
Felipe Lemebc73ffc2015-12-11 15:07:14 -0800671
Felipe Leme8648a152016-02-25 16:22:38 -0800672 Message.obtain(mScreenshotHandler, MSG_SCREENSHOT_REQUEST, id, UNUSED_ARG2, screenshotPath)
673 .sendToTarget();
Felipe Lemed1e0f122015-12-18 16:12:41 -0800674 }
675
676 /**
677 * Sets the internal {@code mTakingScreenshot} state and updates all notifications so their
678 * SCREENSHOT button is enabled or disabled accordingly.
679 */
680 private void setTakingScreenshot(boolean flag) {
681 synchronized (BugreportProgressService.this) {
682 mTakingScreenshot = flag;
683 for (int i = 0; i < mProcesses.size(); i++) {
Felipe Leme22881292016-01-06 09:57:23 -0800684 final BugreportInfo info = mProcesses.valueAt(i);
685 if (info.finished) {
686 Log.d(TAG, "Not updating progress because share notification was already sent");
687 continue;
688 }
689 updateProgress(info);
Felipe Lemed1e0f122015-12-18 16:12:41 -0800690 }
691 }
692 }
693
694 private void handleScreenshotRequest(Message requestMsg) {
695 String screenshotFile = (String) requestMsg.obj;
696 boolean taken = takeScreenshot(mContext, screenshotFile);
697 setTakingScreenshot(false);
698
Felipe Leme8648a152016-02-25 16:22:38 -0800699 Message.obtain(mMainHandler, MSG_SCREENSHOT_RESPONSE, requestMsg.arg1, taken ? 1 : 0,
700 screenshotFile).sendToTarget();
Felipe Lemed1e0f122015-12-18 16:12:41 -0800701 }
702
703 private void handleScreenshotResponse(Message resultMsg) {
704 final boolean taken = resultMsg.arg2 != 0;
705 final BugreportInfo info = getInfo(resultMsg.arg1);
706 if (info == null) {
707 return;
708 }
709 final File screenshotFile = new File((String) resultMsg.obj);
710
Felipe Leme5d9000a2016-02-25 13:10:14 -0800711 final String msg;
Felipe Lemed1e0f122015-12-18 16:12:41 -0800712 if (taken) {
713 info.addScreenshot(screenshotFile);
Felipe Lemec4f646772016-01-12 18:12:09 -0800714 if (info.finished) {
715 Log.d(TAG, "Screenshot finished after bugreport; updating share notification");
716 info.renameScreenshots(mScreenshotsDir);
717 sendBugreportNotification(mContext, info);
718 }
Felipe Leme5d9000a2016-02-25 13:10:14 -0800719 msg = mContext.getString(R.string.bugreport_screenshot_taken);
Felipe Lemed1e0f122015-12-18 16:12:41 -0800720 } else {
721 // TODO: try again using Framework APIs instead of relying on screencap.
Felipe Leme5d9000a2016-02-25 13:10:14 -0800722 msg = mContext.getString(R.string.bugreport_screenshot_failed);
723 Toast.makeText(mContext, msg, Toast.LENGTH_SHORT).show();
Felipe Lemed1e0f122015-12-18 16:12:41 -0800724 }
Felipe Lemed1e0f122015-12-18 16:12:41 -0800725 Log.d(TAG, msg);
Felipe Lemed1e0f122015-12-18 16:12:41 -0800726 }
727
728 /**
729 * Deletes all screenshots taken for a given bugreport.
730 */
731 private void deleteScreenshots(BugreportInfo info) {
732 for (File file : info.screenshotFiles) {
733 Log.i(TAG, "Deleting screenshot file " + file);
734 file.delete();
735 }
Felipe Lemebc73ffc2015-12-11 15:07:14 -0800736 }
737
738 /**
Felipe Leme923afa92015-12-04 12:15:30 -0800739 * Finishes the service when it's not monitoring any more processes.
740 */
741 private void stopSelfWhenDone() {
Felipe Lemed1e0f122015-12-18 16:12:41 -0800742 if (mProcesses.size() > 0) {
Felipe Lemefd8ea072016-02-09 10:13:47 -0800743 if (DEBUG) Log.d(TAG, "Staying alive, waiting for IDs " + mProcesses);
Felipe Lemed1e0f122015-12-18 16:12:41 -0800744 return;
Felipe Leme923afa92015-12-04 12:15:30 -0800745 }
Felipe Lemefd8ea072016-02-09 10:13:47 -0800746 Log.v(TAG, "No more processes to handle, shutting down");
Felipe Lemed1e0f122015-12-18 16:12:41 -0800747 stopSelf();
Felipe Leme923afa92015-12-04 12:15:30 -0800748 }
749
Felipe Lemebc73ffc2015-12-11 15:07:14 -0800750 /**
751 * Handles the BUGREPORT_FINISHED intent sent by {@code dumpstate}.
752 */
Felipe Lemefd8ea072016-02-09 10:13:47 -0800753 private void onBugreportFinished(int id, Intent intent) {
Felipe Lemeaf6fd402016-01-29 18:01:49 -0800754 final File bugreportFile = getFileExtra(intent, EXTRA_BUGREPORT);
755 if (bugreportFile == null) {
756 // Should never happen, dumpstate always set the file.
757 Log.wtf(TAG, "Missing " + EXTRA_BUGREPORT + " on intent " + intent);
758 return;
759 }
Felipe Lemefd8ea072016-02-09 10:13:47 -0800760 mInfoDialog.onBugreportFinished(id);
761 BugreportInfo info = getInfo(id);
Felipe Lemed1e0f122015-12-18 16:12:41 -0800762 if (info == null) {
763 // Happens when BUGREPORT_FINISHED was received without a BUGREPORT_STARTED first.
Felipe Lemefd8ea072016-02-09 10:13:47 -0800764 Log.v(TAG, "Creating info for untracked ID " + id);
765 info = new BugreportInfo(mContext, id);
766 mProcesses.put(id, info);
Felipe Leme46d47912015-12-09 13:03:09 -0800767 }
Felipe Lemed1e0f122015-12-18 16:12:41 -0800768 info.renameScreenshots(mScreenshotsDir);
Felipe Lemeaf6fd402016-01-29 18:01:49 -0800769 info.bugreportFile = bugreportFile;
770
Felipe Leme510e9222016-02-22 18:07:49 -0800771 final int max = intent.getIntExtra(EXTRA_MAX, -1);
772 if (max != -1) {
773 MetricsLogger.histogram(this, "dumpstate_duration", max);
774 info.max = max;
775 }
776
Felipe Lemed1e0f122015-12-18 16:12:41 -0800777 final File screenshot = getFileExtra(intent, EXTRA_SCREENSHOT);
778 if (screenshot != null) {
779 info.addScreenshot(screenshot);
780 }
781 info.finished = true;
Felipe Leme923afa92015-12-04 12:15:30 -0800782
Felipe Lemed1e0f122015-12-18 16:12:41 -0800783 final Configuration conf = mContext.getResources().getConfiguration();
Felipe Leme923afa92015-12-04 12:15:30 -0800784 if ((conf.uiMode & Configuration.UI_MODE_TYPE_MASK) != Configuration.UI_MODE_TYPE_WATCH) {
Felipe Lemed1e0f122015-12-18 16:12:41 -0800785 triggerLocalNotification(mContext, info);
Felipe Leme923afa92015-12-04 12:15:30 -0800786 }
Felipe Lemeb9238b32015-11-24 17:31:47 -0800787 }
788
789 /**
Felipe Leme69c02922015-11-24 17:48:05 -0800790 * Responsible for triggering a notification that allows the user to start a "share" intent with
Felipe Leme46d47912015-12-09 13:03:09 -0800791 * the bugreport. On watches we have other methods to allow the user to start this intent
Felipe Leme69c02922015-11-24 17:48:05 -0800792 * (usually by triggering it on another connected device); we don't need to display the
793 * notification in this case.
Felipe Lemeb9238b32015-11-24 17:31:47 -0800794 */
Felipe Lemed1e0f122015-12-18 16:12:41 -0800795 private void triggerLocalNotification(final Context context, final BugreportInfo info) {
Felipe Leme46d47912015-12-09 13:03:09 -0800796 if (!info.bugreportFile.exists() || !info.bugreportFile.canRead()) {
797 Log.e(TAG, "Could not read bugreport file " + info.bugreportFile);
Felipe Lemed1e0f122015-12-18 16:12:41 -0800798 Toast.makeText(context, R.string.bugreport_unreadable_text, Toast.LENGTH_LONG).show();
Felipe Lemefd8ea072016-02-09 10:13:47 -0800799 stopProgress(info.id);
Felipe Lemeb9238b32015-11-24 17:31:47 -0800800 return;
801 }
802
Felipe Leme46d47912015-12-09 13:03:09 -0800803 boolean isPlainText = info.bugreportFile.getName().toLowerCase().endsWith(".txt");
Felipe Lemeb9238b32015-11-24 17:31:47 -0800804 if (!isPlainText) {
805 // Already zipped, send it right away.
Felipe Leme46d47912015-12-09 13:03:09 -0800806 sendBugreportNotification(context, info);
Felipe Lemeb9238b32015-11-24 17:31:47 -0800807 } else {
808 // Asynchronously zip the file first, then send it.
Felipe Leme46d47912015-12-09 13:03:09 -0800809 sendZippedBugreportNotification(context, info);
Felipe Lemeb9238b32015-11-24 17:31:47 -0800810 }
811 }
812
813 private static Intent buildWarningIntent(Context context, Intent sendIntent) {
814 final Intent intent = new Intent(context, BugreportWarningActivity.class);
815 intent.putExtra(Intent.EXTRA_INTENT, sendIntent);
816 return intent;
817 }
818
819 /**
820 * Build {@link Intent} that can be used to share the given bugreport.
821 */
Felipe Lemebc73ffc2015-12-11 15:07:14 -0800822 private static Intent buildSendIntent(Context context, BugreportInfo info) {
823 // Files are kept on private storage, so turn into Uris that we can
824 // grant temporary permissions for.
825 final Uri bugreportUri = getUri(context, info.bugreportFile);
Felipe Lemebc73ffc2015-12-11 15:07:14 -0800826
Felipe Lemeb9238b32015-11-24 17:31:47 -0800827 final Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE);
828 final String mimeType = "application/vnd.android.bugreport";
829 intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
830 intent.addCategory(Intent.CATEGORY_DEFAULT);
831 intent.setType(mimeType);
832
Felipe Lemec8e2b602016-01-29 13:55:35 -0800833 final String subject = !TextUtils.isEmpty(info.title) ?
834 info.title : bugreportUri.getLastPathSegment();
Felipe Lemebc73ffc2015-12-11 15:07:14 -0800835 intent.putExtra(Intent.EXTRA_SUBJECT, subject);
Felipe Lemeb9238b32015-11-24 17:31:47 -0800836
837 // EXTRA_TEXT should be an ArrayList, but some clients are expecting a single String.
838 // So, to avoid an exception on Intent.migrateExtraStreamToClipData(), we need to manually
839 // create the ClipData object with the attachments URIs.
Felipe Lemed1e0f122015-12-18 16:12:41 -0800840 final StringBuilder messageBody = new StringBuilder("Build info: ")
Felipe Lemebc73ffc2015-12-11 15:07:14 -0800841 .append(SystemProperties.get("ro.build.description"))
842 .append("\nSerial number: ")
843 .append(SystemProperties.get("ro.serialno"));
844 if (!TextUtils.isEmpty(info.description)) {
845 messageBody.append("\nDescription: ").append(info.description);
846 }
847 intent.putExtra(Intent.EXTRA_TEXT, messageBody.toString());
Felipe Lemeb9238b32015-11-24 17:31:47 -0800848 final ClipData clipData = new ClipData(null, new String[] { mimeType },
849 new ClipData.Item(null, null, null, bugreportUri));
850 final ArrayList<Uri> attachments = Lists.newArrayList(bugreportUri);
Felipe Lemed1e0f122015-12-18 16:12:41 -0800851 for (File screenshot : info.screenshotFiles) {
852 final Uri screenshotUri = getUri(context, screenshot);
Felipe Lemeb9238b32015-11-24 17:31:47 -0800853 clipData.addItem(new ClipData.Item(null, null, null, screenshotUri));
854 attachments.add(screenshotUri);
855 }
856 intent.setClipData(clipData);
857 intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, attachments);
858
859 final Account sendToAccount = findSendToAccount(context);
860 if (sendToAccount != null) {
861 intent.putExtra(Intent.EXTRA_EMAIL, new String[] { sendToAccount.name });
862 }
863
864 return intent;
865 }
866
867 /**
Felipe Leme46d47912015-12-09 13:03:09 -0800868 * Shares the bugreport upon user's request by issuing a {@link Intent#ACTION_SEND_MULTIPLE}
869 * intent, but issuing a warning dialog the first time.
Felipe Lemeb9238b32015-11-24 17:31:47 -0800870 */
Felipe Lemefd8ea072016-02-09 10:13:47 -0800871 private void shareBugreport(int id, BugreportInfo sharedInfo) {
Felipe Leme6605bd82016-02-22 15:22:20 -0800872 MetricsLogger.action(this, MetricsEvent.ACTION_BUGREPORT_NOTIFICATION_ACTION_SHARE);
Felipe Lemefd8ea072016-02-09 10:13:47 -0800873 BugreportInfo info = getInfo(id);
Felipe Lemed1e0f122015-12-18 16:12:41 -0800874 if (info == null) {
Felipe Lemec4f646772016-01-12 18:12:09 -0800875 // Service was terminated but notification persisted
876 info = sharedInfo;
Felipe Lemefd8ea072016-02-09 10:13:47 -0800877 Log.d(TAG, "shareBugreport(): no info for ID " + id + " on managed processes ("
Felipe Lemec4f646772016-01-12 18:12:09 -0800878 + mProcesses + "), using info from intent instead (" + info + ")");
Felipe Leme4f663f62016-03-08 11:41:18 -0800879 } else {
880 Log.v(TAG, "shareBugReport(): id " + id + " info = " + info);
Felipe Leme46d47912015-12-09 13:03:09 -0800881 }
Felipe Leme4967f732016-01-06 11:38:53 -0800882
Felipe Leme18b58922016-01-29 12:24:25 -0800883 addDetailsToZipFile(mContext, info);
Felipe Leme4967f732016-01-06 11:38:53 -0800884
Felipe Lemed1e0f122015-12-18 16:12:41 -0800885 final Intent sendIntent = buildSendIntent(mContext, info);
Felipe Leme46d47912015-12-09 13:03:09 -0800886 final Intent notifIntent;
Felipe Lemeb9238b32015-11-24 17:31:47 -0800887
888 // Send through warning dialog by default
Felipe Lemed1e0f122015-12-18 16:12:41 -0800889 if (getWarningState(mContext, STATE_SHOW) == STATE_SHOW) {
890 notifIntent = buildWarningIntent(mContext, sendIntent);
Felipe Lemeb9238b32015-11-24 17:31:47 -0800891 } else {
892 notifIntent = sendIntent;
893 }
894 notifIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
895
Felipe Leme46d47912015-12-09 13:03:09 -0800896 // Send the share intent...
Felipe Lemed1e0f122015-12-18 16:12:41 -0800897 mContext.startActivity(notifIntent);
Felipe Leme46d47912015-12-09 13:03:09 -0800898
899 // ... and stop watching this process.
Felipe Lemefd8ea072016-02-09 10:13:47 -0800900 stopProgress(id);
Felipe Leme46d47912015-12-09 13:03:09 -0800901 }
902
903 /**
Felipe Leme2758d5d2016-01-19 10:30:56 -0800904 * Sends a notification indicating the bugreport has finished so use can share it.
Felipe Leme46d47912015-12-09 13:03:09 -0800905 */
906 private static void sendBugreportNotification(Context context, BugreportInfo info) {
Felipe Leme18b58922016-01-29 12:24:25 -0800907
908 // Since adding the details can take a while, do it before notifying user.
909 addDetailsToZipFile(context, info);
910
Felipe Leme46d47912015-12-09 13:03:09 -0800911 final Intent shareIntent = new Intent(INTENT_BUGREPORT_SHARE);
912 shareIntent.setClass(context, BugreportProgressService.class);
913 shareIntent.setAction(INTENT_BUGREPORT_SHARE);
Felipe Lemefd8ea072016-02-09 10:13:47 -0800914 shareIntent.putExtra(EXTRA_ID, info.id);
Felipe Lemec4f646772016-01-12 18:12:09 -0800915 shareIntent.putExtra(EXTRA_INFO, info);
Felipe Leme46d47912015-12-09 13:03:09 -0800916
Felipe Lemefd8ea072016-02-09 10:13:47 -0800917 final String title = context.getString(R.string.bugreport_finished_title, info.id);
Felipe Lemeb9238b32015-11-24 17:31:47 -0800918 final Notification.Builder builder = new Notification.Builder(context)
919 .setSmallIcon(com.android.internal.R.drawable.stat_sys_adb)
Felipe Leme69c02922015-11-24 17:48:05 -0800920 .setContentTitle(title)
921 .setTicker(title)
Felipe Lemeb9238b32015-11-24 17:31:47 -0800922 .setContentText(context.getString(R.string.bugreport_finished_text))
Felipe Lemefd8ea072016-02-09 10:13:47 -0800923 .setContentIntent(PendingIntent.getService(context, info.id, shareIntent,
Felipe Lemebc73ffc2015-12-11 15:07:14 -0800924 PendingIntent.FLAG_UPDATE_CURRENT))
Felipe Leme46d47912015-12-09 13:03:09 -0800925 .setDeleteIntent(newCancelIntent(context, info))
Felipe Lemeb9238b32015-11-24 17:31:47 -0800926 .setLocalOnly(true)
927 .setColor(context.getColor(
928 com.android.internal.R.color.system_notification_accent_color));
929
Felipe Lemebc73ffc2015-12-11 15:07:14 -0800930 if (!TextUtils.isEmpty(info.name)) {
931 builder.setContentInfo(info.name);
932 }
933
Felipe Lemefd8ea072016-02-09 10:13:47 -0800934 Log.v(TAG, "Sending 'Share' notification for ID " + info.id + ": " + title);
935 NotificationManager.from(context).notify(TAG, info.id, builder.build());
Felipe Lemeb9238b32015-11-24 17:31:47 -0800936 }
937
938 /**
Felipe Leme2758d5d2016-01-19 10:30:56 -0800939 * Sends a notification indicating the bugreport is being updated so the user can wait until it
940 * finishes - at this point there is nothing to be done other than waiting, hence it has no
941 * pending action.
942 */
Felipe Lemefd8ea072016-02-09 10:13:47 -0800943 private static void sendBugreportBeingUpdatedNotification(Context context, int id) {
Felipe Leme2758d5d2016-01-19 10:30:56 -0800944 final String title = context.getString(R.string.bugreport_updating_title);
945 final Notification.Builder builder = new Notification.Builder(context)
946 .setSmallIcon(com.android.internal.R.drawable.stat_sys_adb)
947 .setContentTitle(title)
948 .setTicker(title)
949 .setContentText(context.getString(R.string.bugreport_updating_wait))
950 .setLocalOnly(true)
951 .setColor(context.getColor(
952 com.android.internal.R.color.system_notification_accent_color));
Felipe Lemefd8ea072016-02-09 10:13:47 -0800953 Log.v(TAG, "Sending 'Updating zip' notification for ID " + id + ": " + title);
954 NotificationManager.from(context).notify(TAG, id, builder.build());
Felipe Leme2758d5d2016-01-19 10:30:56 -0800955 }
956
957 /**
Felipe Lemeb9238b32015-11-24 17:31:47 -0800958 * Sends a zipped bugreport notification.
959 */
960 private static void sendZippedBugreportNotification(final Context context,
Felipe Leme46d47912015-12-09 13:03:09 -0800961 final BugreportInfo info) {
Felipe Lemeb9238b32015-11-24 17:31:47 -0800962 new AsyncTask<Void, Void, Void>() {
963 @Override
964 protected Void doInBackground(Void... params) {
Felipe Leme4967f732016-01-06 11:38:53 -0800965 zipBugreport(info);
Felipe Leme46d47912015-12-09 13:03:09 -0800966 sendBugreportNotification(context, info);
Felipe Lemeb9238b32015-11-24 17:31:47 -0800967 return null;
968 }
969 }.execute();
970 }
971
972 /**
973 * Zips a bugreport file, returning the path to the new file (or to the
974 * original in case of failure).
975 */
Felipe Leme4967f732016-01-06 11:38:53 -0800976 private static void zipBugreport(BugreportInfo info) {
977 final String bugreportPath = info.bugreportFile.getAbsolutePath();
978 final String zippedPath = bugreportPath.replace(".txt", ".zip");
Felipe Lemeb9238b32015-11-24 17:31:47 -0800979 Log.v(TAG, "zipping " + bugreportPath + " as " + zippedPath);
Felipe Leme4967f732016-01-06 11:38:53 -0800980 final File bugreportZippedFile = new File(zippedPath);
981 try (InputStream is = new FileInputStream(info.bugreportFile);
Felipe Leme69c02922015-11-24 17:48:05 -0800982 ZipOutputStream zos = new ZipOutputStream(
983 new BufferedOutputStream(new FileOutputStream(bugreportZippedFile)))) {
Felipe Leme4967f732016-01-06 11:38:53 -0800984 addEntry(zos, info.bugreportFile.getName(), is);
985 // Delete old file
986 final boolean deleted = info.bugreportFile.delete();
Felipe Lemeb9238b32015-11-24 17:31:47 -0800987 if (deleted) {
988 Log.v(TAG, "deleted original bugreport (" + bugreportPath + ")");
989 } else {
990 Log.e(TAG, "could not delete original bugreport (" + bugreportPath + ")");
991 }
Felipe Leme4967f732016-01-06 11:38:53 -0800992 info.bugreportFile = bugreportZippedFile;
Felipe Lemeb9238b32015-11-24 17:31:47 -0800993 } catch (IOException e) {
Felipe Leme69c02922015-11-24 17:48:05 -0800994 Log.e(TAG, "exception zipping file " + zippedPath, e);
Felipe Lemeb9238b32015-11-24 17:31:47 -0800995 }
996 }
997
998 /**
Felipe Leme4967f732016-01-06 11:38:53 -0800999 * Adds the user-provided info into the bugreport zip file.
1000 * <p>
1001 * If user provided a title, it will be saved into a {@code title.txt} entry; similarly, the
1002 * description will be saved on {@code description.txt}.
1003 */
Felipe Leme18b58922016-01-29 12:24:25 -08001004 private static void addDetailsToZipFile(Context context, BugreportInfo info) {
Felipe Lemec4f646772016-01-12 18:12:09 -08001005 if (info.bugreportFile == null) {
1006 // One possible reason is a bug in the Parcelization code.
Felipe Lemeaf6fd402016-01-29 18:01:49 -08001007 Log.wtf(TAG, "addDetailsToZipFile(): no bugreportFile on " + info);
Felipe Lemec4f646772016-01-12 18:12:09 -08001008 return;
1009 }
Felipe Lemeb9d598c2016-01-19 10:31:39 -08001010 if (TextUtils.isEmpty(info.title) && TextUtils.isEmpty(info.description)) {
1011 Log.d(TAG, "Not touching zip file since neither title nor description are set");
1012 return;
1013 }
Felipe Leme18b58922016-01-29 12:24:25 -08001014 if (info.addedDetailsToZip || info.addingDetailsToZip) {
1015 Log.d(TAG, "Already added details to zip file for " + info);
1016 return;
1017 }
1018 info.addingDetailsToZip = true;
Felipe Leme2758d5d2016-01-19 10:30:56 -08001019
Felipe Leme4967f732016-01-06 11:38:53 -08001020 // It's not possible to add a new entry into an existing file, so we need to create a new
1021 // zip, copy all entries, then rename it.
Felipe Lemefd8ea072016-02-09 10:13:47 -08001022 sendBugreportBeingUpdatedNotification(context, info.id); // ...and that takes time
Felipe Leme4967f732016-01-06 11:38:53 -08001023 final File dir = info.bugreportFile.getParentFile();
1024 final File tmpZip = new File(dir, "tmp-" + info.bugreportFile.getName());
Felipe Leme2758d5d2016-01-19 10:30:56 -08001025 Log.d(TAG, "Writing temporary zip file (" + tmpZip + ") with title and/or description");
Felipe Leme4967f732016-01-06 11:38:53 -08001026 try (ZipFile oldZip = new ZipFile(info.bugreportFile);
1027 ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(tmpZip))) {
1028
1029 // First copy contents from original zip.
1030 Enumeration<? extends ZipEntry> entries = oldZip.entries();
1031 while (entries.hasMoreElements()) {
1032 final ZipEntry entry = entries.nextElement();
1033 final String entryName = entry.getName();
1034 if (!entry.isDirectory()) {
1035 addEntry(zos, entryName, entry.getTime(), oldZip.getInputStream(entry));
1036 } else {
1037 Log.w(TAG, "skipping directory entry: " + entryName);
1038 }
1039 }
1040
1041 // Then add the user-provided info.
1042 addEntry(zos, "title.txt", info.title);
1043 addEntry(zos, "description.txt", info.description);
1044 } catch (IOException e) {
Felipe Leme18b58922016-01-29 12:24:25 -08001045 info.addingDetailsToZip = false;
Felipe Leme4967f732016-01-06 11:38:53 -08001046 Log.e(TAG, "exception zipping file " + tmpZip, e);
1047 return;
1048 }
1049
1050 if (!tmpZip.renameTo(info.bugreportFile)) {
1051 Log.e(TAG, "Could not rename " + tmpZip + " to " + info.bugreportFile);
1052 }
Felipe Leme18b58922016-01-29 12:24:25 -08001053 info.addedDetailsToZip = true;
1054 info.addingDetailsToZip = false;
Felipe Leme4967f732016-01-06 11:38:53 -08001055 }
1056
1057 private static void addEntry(ZipOutputStream zos, String entry, String text)
1058 throws IOException {
1059 if (DEBUG) Log.v(TAG, "adding entry '" + entry + "': " + text);
1060 if (!TextUtils.isEmpty(text)) {
1061 addEntry(zos, entry, new ByteArrayInputStream(text.getBytes(StandardCharsets.UTF_8)));
1062 }
1063 }
1064
1065 private static void addEntry(ZipOutputStream zos, String entryName, InputStream is)
1066 throws IOException {
1067 addEntry(zos, entryName, System.currentTimeMillis(), is);
1068 }
1069
1070 private static void addEntry(ZipOutputStream zos, String entryName, long timestamp,
1071 InputStream is) throws IOException {
1072 final ZipEntry entry = new ZipEntry(entryName);
1073 entry.setTime(timestamp);
1074 zos.putNextEntry(entry);
1075 final int totalBytes = Streams.copy(is, zos);
1076 if (DEBUG) Log.v(TAG, "size of '" + entryName + "' entry: " + totalBytes + " bytes");
1077 zos.closeEntry();
1078 }
1079
1080 /**
Felipe Lemeb9238b32015-11-24 17:31:47 -08001081 * Find the best matching {@link Account} based on build properties.
1082 */
1083 private static Account findSendToAccount(Context context) {
1084 final AccountManager am = (AccountManager) context.getSystemService(
1085 Context.ACCOUNT_SERVICE);
1086
1087 String preferredDomain = SystemProperties.get("sendbug.preferred.domain");
1088 if (!preferredDomain.startsWith("@")) {
1089 preferredDomain = "@" + preferredDomain;
1090 }
1091
1092 final Account[] accounts = am.getAccounts();
1093 Account foundAccount = null;
1094 for (Account account : accounts) {
1095 if (Patterns.EMAIL_ADDRESS.matcher(account.name).matches()) {
1096 if (!preferredDomain.isEmpty()) {
1097 // if we have a preferred domain and it matches, return; otherwise keep
1098 // looking
1099 if (account.name.endsWith(preferredDomain)) {
1100 return account;
1101 } else {
1102 foundAccount = account;
1103 }
1104 // if we don't have a preferred domain, just return since it looks like
1105 // an email address
1106 } else {
1107 return account;
1108 }
1109 }
1110 }
1111 return foundAccount;
1112 }
1113
Michal Karpinski226940e2015-12-15 18:14:26 +00001114 static Uri getUri(Context context, File file) {
Felipe Lemeb9238b32015-11-24 17:31:47 -08001115 return file != null ? FileProvider.getUriForFile(context, AUTHORITY, file) : null;
1116 }
1117
1118 static File getFileExtra(Intent intent, String key) {
1119 final String path = intent.getStringExtra(key);
1120 if (path != null) {
1121 return new File(path);
1122 } else {
1123 return null;
1124 }
1125 }
Felipe Leme69c02922015-11-24 17:48:05 -08001126
Felipe Lemebc73ffc2015-12-11 15:07:14 -08001127 private static boolean setSystemProperty(String key, String value) {
1128 try {
Felipe Leme85ae3cf2016-02-24 15:36:50 -08001129 if (DEBUG) Log.v(TAG, "Setting system property " + key + " to " + value);
Felipe Lemebc73ffc2015-12-11 15:07:14 -08001130 SystemProperties.set(key, value);
1131 } catch (IllegalArgumentException e) {
1132 Log.e(TAG, "Could not set property " + key + " to " + value, e);
1133 return false;
1134 }
1135 return true;
1136 }
1137
1138 /**
1139 * Updates the system property used by {@code dumpstate} to rename the final bugreport files.
1140 */
1141 private boolean setBugreportNameProperty(int pid, String name) {
1142 Log.d(TAG, "Updating bugreport name to " + name);
1143 final String key = DUMPSTATE_PREFIX + pid + NAME_SUFFIX;
1144 return setSystemProperty(key, name);
1145 }
1146
1147 /**
1148 * Updates the user-provided details of a bugreport.
1149 */
Felipe Lemefd8ea072016-02-09 10:13:47 -08001150 private void updateBugreportInfo(int id, String name, String title, String description) {
1151 final BugreportInfo info = getInfo(id);
Felipe Lemed1e0f122015-12-18 16:12:41 -08001152 if (info == null) {
1153 return;
Felipe Lemebc73ffc2015-12-11 15:07:14 -08001154 }
Felipe Leme6605bd82016-02-22 15:22:20 -08001155 if (title != null && !title.equals(info.title)) {
1156 MetricsLogger.action(this, MetricsEvent.ACTION_BUGREPORT_DETAILS_TITLE_CHANGED);
1157 }
Felipe Lemed1e0f122015-12-18 16:12:41 -08001158 info.title = title;
Felipe Leme6605bd82016-02-22 15:22:20 -08001159 if (description != null && !description.equals(info.description)) {
1160 MetricsLogger.action(this, MetricsEvent.ACTION_BUGREPORT_DETAILS_DESCRIPTION_CHANGED);
1161 }
Felipe Lemed1e0f122015-12-18 16:12:41 -08001162 info.description = description;
Felipe Leme1eee1992016-02-16 13:01:38 -08001163 if (name != null && !name.equals(info.name)) {
Felipe Leme6605bd82016-02-22 15:22:20 -08001164 MetricsLogger.action(this, MetricsEvent.ACTION_BUGREPORT_DETAILS_NAME_CHANGED);
Felipe Lemed1e0f122015-12-18 16:12:41 -08001165 info.name = name;
1166 updateProgress(info);
1167 }
1168 }
1169
1170 private void collapseNotificationBar() {
1171 sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS));
1172 }
1173
1174 private static Looper newLooper(String name) {
1175 final HandlerThread thread = new HandlerThread(name, THREAD_PRIORITY_BACKGROUND);
1176 thread.start();
1177 return thread.getLooper();
1178 }
1179
1180 /**
1181 * Takes a screenshot and save it to the given location.
1182 */
1183 private static boolean takeScreenshot(Context context, String screenshotFile) {
1184 ((Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE))
1185 .vibrate(150);
1186 final ProcessBuilder screencap = new ProcessBuilder()
1187 .command("/system/bin/screencap", "-p", screenshotFile);
1188 Log.d(TAG, "Taking screenshot using " + screencap.command());
1189 try {
1190 final int exitValue = screencap.start().waitFor();
1191 if (exitValue == 0) {
1192 return true;
1193 }
1194 Log.e(TAG, "screencap (" + screencap.command() + ") failed: " + exitValue);
1195 } catch (IOException e) {
1196 Log.e(TAG, "screencap (" + screencap.command() + ") failed", e);
1197 } catch (InterruptedException e) {
1198 Log.w(TAG, "Thread interrupted while screencap still running");
1199 Thread.currentThread().interrupt();
1200 }
1201 return false;
Felipe Lemebc73ffc2015-12-11 15:07:14 -08001202 }
1203
1204 /**
1205 * Checks whether a character is valid on bugreport names.
1206 */
1207 @VisibleForTesting
1208 static boolean isValid(char c) {
1209 return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9')
1210 || c == '_' || c == '-';
1211 }
1212
1213 /**
1214 * Helper class encapsulating the UI elements and logic used to display a dialog where user
1215 * can change the details of a bugreport.
1216 */
1217 private final class BugreportInfoDialog {
1218 private EditText mInfoName;
1219 private EditText mInfoTitle;
1220 private EditText mInfoDescription;
1221 private AlertDialog mDialog;
1222 private Button mOkButton;
Felipe Lemefd8ea072016-02-09 10:13:47 -08001223 private int mId;
Felipe Lemebc73ffc2015-12-11 15:07:14 -08001224 private int mPid;
1225
1226 /**
1227 * Last "committed" value of the bugreport name.
1228 * <p>
1229 * Once initially set, it's only updated when user clicks the OK button.
1230 */
1231 private String mSavedName;
1232
1233 /**
1234 * Last value of the bugreport name as entered by the user.
1235 * <p>
1236 * Every time it's changed the equivalent system property is changed as well, but if the
1237 * user clicks CANCEL, the old value (stored on {@code mSavedName} is restored.
1238 * <p>
1239 * This logic handles the corner-case scenario where {@code dumpstate} finishes after the
1240 * user changed the name but didn't clicked OK yet (for example, because the user is typing
1241 * the description). The only drawback is that if the user changes the name while
1242 * {@code dumpstate} is running but clicks CANCEL after it finishes, then the final name
1243 * will be the one that has been canceled. But when {@code dumpstate} finishes the {code
1244 * name} UI is disabled and the old name restored anyways, so the user will be "alerted" of
1245 * such drawback.
1246 */
1247 private String mTempName;
1248
1249 /**
1250 * Sets its internal state and displays the dialog.
1251 */
Felipe Leme6605bd82016-02-22 15:22:20 -08001252 private void initialize(final Context context, BugreportInfo info) {
Felipe Leme26288782016-02-25 12:10:43 -08001253 final String dialogTitle =
1254 context.getString(R.string.bugreport_info_dialog_title, info.id);
Felipe Lemebc73ffc2015-12-11 15:07:14 -08001255 // First initializes singleton.
1256 if (mDialog == null) {
1257 @SuppressLint("InflateParams")
1258 // It's ok pass null ViewRoot on AlertDialogs.
1259 final View view = View.inflate(context, R.layout.dialog_bugreport_info, null);
1260
1261 mInfoName = (EditText) view.findViewById(R.id.name);
1262 mInfoTitle = (EditText) view.findViewById(R.id.title);
1263 mInfoDescription = (EditText) view.findViewById(R.id.description);
1264
1265 mInfoName.setOnFocusChangeListener(new OnFocusChangeListener() {
1266
1267 @Override
1268 public void onFocusChange(View v, boolean hasFocus) {
1269 if (hasFocus) {
1270 return;
1271 }
Felipe Lemebbd91e52016-02-26 16:48:22 -08001272 // Select-all is useful just initially, since the date-based filename is
1273 // full of hyphens.
1274 mInfoName.setSelectAllOnFocus(false);
Felipe Lemebc73ffc2015-12-11 15:07:14 -08001275 sanitizeName();
1276 }
1277 });
1278
1279 mDialog = new AlertDialog.Builder(context)
1280 .setView(view)
Felipe Leme26288782016-02-25 12:10:43 -08001281 .setTitle(dialogTitle)
Felipe Lemebc73ffc2015-12-11 15:07:14 -08001282 .setCancelable(false)
Felipe Lemebbd91e52016-02-26 16:48:22 -08001283 .setPositiveButton(context.getString(R.string.save),
Felipe Lemebc73ffc2015-12-11 15:07:14 -08001284 null)
1285 .setNegativeButton(context.getString(com.android.internal.R.string.cancel),
1286 new DialogInterface.OnClickListener()
1287 {
1288 @Override
1289 public void onClick(DialogInterface dialog, int id)
1290 {
Felipe Leme6605bd82016-02-22 15:22:20 -08001291 MetricsLogger.action(context,
1292 MetricsEvent.ACTION_BUGREPORT_DETAILS_CANCELED);
Felipe Lemebc73ffc2015-12-11 15:07:14 -08001293 if (!mTempName.equals(mSavedName)) {
1294 // Must restore dumpstate's name since it was changed
1295 // before user clicked OK.
1296 setBugreportNameProperty(mPid, mSavedName);
1297 }
1298 }
1299 })
1300 .create();
1301
1302 mDialog.getWindow().setAttributes(
1303 new WindowManager.LayoutParams(
1304 WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG));
1305
Felipe Leme26288782016-02-25 12:10:43 -08001306 } else {
1307 // Re-use view, but reset fields first.
1308 mDialog.setTitle(dialogTitle);
1309 mInfoName.setText(null);
1310 mInfoTitle.setText(null);
1311 mInfoDescription.setText(null);
Felipe Lemebc73ffc2015-12-11 15:07:14 -08001312 }
1313
1314 // Then set fields.
Felipe Lemefd8ea072016-02-09 10:13:47 -08001315 mSavedName = mTempName = info.name;
1316 mId = info.id;
1317 mPid = info.pid;
1318 if (!TextUtils.isEmpty(info.name)) {
1319 mInfoName.setText(info.name);
Felipe Lemebc73ffc2015-12-11 15:07:14 -08001320 }
Felipe Lemefd8ea072016-02-09 10:13:47 -08001321 if (!TextUtils.isEmpty(info.title)) {
1322 mInfoTitle.setText(info.title);
Felipe Lemebc73ffc2015-12-11 15:07:14 -08001323 }
Felipe Lemefd8ea072016-02-09 10:13:47 -08001324 if (!TextUtils.isEmpty(info.description)) {
1325 mInfoDescription.setText(info.description);
Felipe Lemebc73ffc2015-12-11 15:07:14 -08001326 }
1327
1328 // And finally display it.
1329 mDialog.show();
1330
1331 // TODO: in a traditional AlertDialog, when the positive button is clicked the
1332 // dialog is always closed, but we need to validate the name first, so we need to
1333 // get a reference to it, which is only available after it's displayed.
1334 // It would be cleaner to use a regular dialog instead, but let's keep this
1335 // workaround for now and change it later, when we add another button to take
1336 // extra screenshots.
1337 if (mOkButton == null) {
1338 mOkButton = mDialog.getButton(DialogInterface.BUTTON_POSITIVE);
1339 mOkButton.setOnClickListener(new View.OnClickListener() {
1340
1341 @Override
1342 public void onClick(View view) {
Felipe Leme6605bd82016-02-22 15:22:20 -08001343 MetricsLogger.action(context, MetricsEvent.ACTION_BUGREPORT_DETAILS_SAVED);
Felipe Lemebc73ffc2015-12-11 15:07:14 -08001344 sanitizeName();
1345 final String name = mInfoName.getText().toString();
1346 final String title = mInfoTitle.getText().toString();
1347 final String description = mInfoDescription.getText().toString();
1348
Felipe Lemefd8ea072016-02-09 10:13:47 -08001349 updateBugreportInfo(mId, name, title, description);
Felipe Lemebc73ffc2015-12-11 15:07:14 -08001350 mDialog.dismiss();
1351 }
1352 });
1353 }
1354 }
1355
1356 /**
1357 * Sanitizes the user-provided value for the {@code name} field, automatically replacing
1358 * invalid characters if necessary.
1359 */
Felipe Lemed1e0f122015-12-18 16:12:41 -08001360 private void sanitizeName() {
Felipe Lemebc73ffc2015-12-11 15:07:14 -08001361 String name = mInfoName.getText().toString();
1362 if (name.equals(mTempName)) {
1363 if (DEBUG) Log.v(TAG, "name didn't change, no need to sanitize: " + name);
1364 return;
1365 }
1366 final StringBuilder safeName = new StringBuilder(name.length());
1367 boolean changed = false;
1368 for (int i = 0; i < name.length(); i++) {
1369 final char c = name.charAt(i);
1370 if (isValid(c)) {
1371 safeName.append(c);
1372 } else {
1373 changed = true;
1374 safeName.append('_');
1375 }
1376 }
1377 if (changed) {
1378 Log.v(TAG, "changed invalid name '" + name + "' to '" + safeName + "'");
1379 name = safeName.toString();
1380 mInfoName.setText(name);
1381 }
1382 mTempName = name;
1383
1384 // Must update system property for the cases where dumpstate finishes
1385 // while the user is still entering other fields (like title or
1386 // description)
Felipe Leme85ae3cf2016-02-24 15:36:50 -08001387 setBugreportNameProperty(mPid, name);
Felipe Lemebc73ffc2015-12-11 15:07:14 -08001388 }
1389
1390 /**
1391 * Notifies the dialog that the bugreport has finished so it disables the {@code name}
1392 * field.
1393 * <p>Once the bugreport is finished dumpstate has already generated the final files, so
1394 * changing the name would have no effect.
1395 */
Felipe Lemefd8ea072016-02-09 10:13:47 -08001396 private void onBugreportFinished(int id) {
Felipe Lemebc73ffc2015-12-11 15:07:14 -08001397 if (mInfoName != null) {
1398 mInfoName.setEnabled(false);
1399 mInfoName.setText(mSavedName);
1400 }
1401 }
1402
1403 }
1404
Felipe Leme69c02922015-11-24 17:48:05 -08001405 /**
Felipe Leme46d47912015-12-09 13:03:09 -08001406 * Information about a bugreport process while its in progress.
Felipe Leme69c02922015-11-24 17:48:05 -08001407 */
Felipe Lemec4f646772016-01-12 18:12:09 -08001408 private static final class BugreportInfo implements Parcelable {
Felipe Leme719aaae2015-11-30 15:41:11 -08001409 private final Context context;
1410
Felipe Leme69c02922015-11-24 17:48:05 -08001411 /**
Felipe Lemefd8ea072016-02-09 10:13:47 -08001412 * Sequential, user-friendly id used to identify the bugreport.
1413 */
1414 final int id;
1415
1416 /**
Felipe Leme46d47912015-12-09 13:03:09 -08001417 * {@code pid} of the {@code dumpstate} process generating the bugreport.
Felipe Leme69c02922015-11-24 17:48:05 -08001418 */
1419 final int pid;
1420
1421 /**
Felipe Leme46d47912015-12-09 13:03:09 -08001422 * Name of the bugreport, will be used to rename the final files.
Felipe Leme69c02922015-11-24 17:48:05 -08001423 * <p>
Felipe Leme46d47912015-12-09 13:03:09 -08001424 * Initial value is the bugreport filename reported by {@code dumpstate}, but user can
Felipe Leme69c02922015-11-24 17:48:05 -08001425 * change it later to a more meaningful name.
1426 */
Felipe Leme719aaae2015-11-30 15:41:11 -08001427 String name;
Felipe Leme69c02922015-11-24 17:48:05 -08001428
1429 /**
Felipe Lemebc73ffc2015-12-11 15:07:14 -08001430 * User-provided, one-line summary of the bug; when set, will be used as the subject
1431 * of the {@link Intent#ACTION_SEND_MULTIPLE} intent.
1432 */
1433 String title;
1434
1435 /**
1436 * User-provided, detailed description of the bugreport; when set, will be added to the body
1437 * of the {@link Intent#ACTION_SEND_MULTIPLE} intent.
1438 */
1439 String description;
1440
1441 /**
Felipe Leme46d47912015-12-09 13:03:09 -08001442 * Maximum progress of the bugreport generation.
Felipe Leme69c02922015-11-24 17:48:05 -08001443 */
Felipe Leme719aaae2015-11-30 15:41:11 -08001444 int max;
Felipe Leme69c02922015-11-24 17:48:05 -08001445
1446 /**
Felipe Leme46d47912015-12-09 13:03:09 -08001447 * Current progress of the bugreport generation.
Felipe Leme69c02922015-11-24 17:48:05 -08001448 */
1449 int progress;
1450
1451 /**
1452 * Time of the last progress update.
1453 */
1454 long lastUpdate = System.currentTimeMillis();
1455
Felipe Leme46d47912015-12-09 13:03:09 -08001456 /**
Felipe Lemec4f646772016-01-12 18:12:09 -08001457 * Time of the last progress update when Parcel was created.
1458 */
1459 String formattedLastUpdate;
1460
1461 /**
Felipe Leme46d47912015-12-09 13:03:09 -08001462 * Path of the main bugreport file.
1463 */
1464 File bugreportFile;
1465
1466 /**
Felipe Lemed1e0f122015-12-18 16:12:41 -08001467 * Path of the screenshot files.
Felipe Leme46d47912015-12-09 13:03:09 -08001468 */
Felipe Lemed1e0f122015-12-18 16:12:41 -08001469 List<File> screenshotFiles = new ArrayList<>(1);
Felipe Leme46d47912015-12-09 13:03:09 -08001470
1471 /**
1472 * Whether dumpstate sent an intent informing it has finished.
1473 */
1474 boolean finished;
1475
1476 /**
Felipe Leme18b58922016-01-29 12:24:25 -08001477 * Whether the details entries have been added to the bugreport yet.
1478 */
1479 boolean addingDetailsToZip;
1480 boolean addedDetailsToZip;
1481
1482 /**
Felipe Lemed1e0f122015-12-18 16:12:41 -08001483 * Internal counter used to name screenshot files.
1484 */
1485 int screenshotCounter;
1486
1487 /**
Felipe Leme46d47912015-12-09 13:03:09 -08001488 * Constructor for tracked bugreports - typically called upon receiving BUGREPORT_STARTED.
1489 */
Felipe Lemefd8ea072016-02-09 10:13:47 -08001490 BugreportInfo(Context context, int id, int pid, String name, int max) {
Felipe Leme719aaae2015-11-30 15:41:11 -08001491 this.context = context;
Felipe Lemefd8ea072016-02-09 10:13:47 -08001492 this.id = id;
Felipe Leme69c02922015-11-24 17:48:05 -08001493 this.pid = pid;
1494 this.name = name;
1495 this.max = max;
1496 }
1497
Felipe Leme46d47912015-12-09 13:03:09 -08001498 /**
1499 * Constructor for untracked bugreports - typically called upon receiving BUGREPORT_FINISHED
1500 * without a previous call to BUGREPORT_STARTED.
1501 */
Felipe Lemefd8ea072016-02-09 10:13:47 -08001502 BugreportInfo(Context context, int id) {
1503 this(context, id, id, null, 0);
Felipe Leme46d47912015-12-09 13:03:09 -08001504 this.finished = true;
1505 }
1506
Felipe Lemed1e0f122015-12-18 16:12:41 -08001507 /**
1508 * Gets the name for next screenshot file.
1509 */
1510 String getPathNextScreenshot() {
1511 screenshotCounter ++;
1512 return "screenshot-" + pid + "-" + screenshotCounter + ".png";
1513 }
1514
1515 /**
1516 * Saves the location of a taken screenshot so it can be sent out at the end.
1517 */
1518 void addScreenshot(File screenshot) {
1519 screenshotFiles.add(screenshot);
1520 }
1521
1522 /**
1523 * Rename all screenshots files so that they contain the user-generated name instead of pid.
1524 */
1525 void renameScreenshots(File screenshotDir) {
1526 if (TextUtils.isEmpty(name)) {
1527 return;
1528 }
1529 final List<File> renamedFiles = new ArrayList<>(screenshotFiles.size());
1530 for (File oldFile : screenshotFiles) {
1531 final String oldName = oldFile.getName();
Felipe Leme85ae3cf2016-02-24 15:36:50 -08001532 final String newName = oldName.replaceFirst(Integer.toString(pid), name);
Felipe Lemed1e0f122015-12-18 16:12:41 -08001533 final File newFile;
1534 if (!newName.equals(oldName)) {
1535 final File renamedFile = new File(screenshotDir, newName);
Felipe Leme4f663f62016-03-08 11:41:18 -08001536 Log.d(TAG, "Renaming screenshot file " + oldFile + " to " + renamedFile);
Felipe Lemed1e0f122015-12-18 16:12:41 -08001537 newFile = oldFile.renameTo(renamedFile) ? renamedFile : oldFile;
1538 } else {
1539 Log.w(TAG, "Name didn't change: " + oldName); // Shouldn't happen.
1540 newFile = oldFile;
1541 }
1542 renamedFiles.add(newFile);
1543 }
1544 screenshotFiles = renamedFiles;
1545 }
1546
Felipe Leme69c02922015-11-24 17:48:05 -08001547 String getFormattedLastUpdate() {
Felipe Lemec4f646772016-01-12 18:12:09 -08001548 if (context == null) {
1549 // Restored from Parcel
1550 return formattedLastUpdate == null ?
1551 Long.toString(lastUpdate) : formattedLastUpdate;
1552 }
Felipe Leme719aaae2015-11-30 15:41:11 -08001553 return DateUtils.formatDateTime(context, lastUpdate,
1554 DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_TIME);
Felipe Leme69c02922015-11-24 17:48:05 -08001555 }
1556
1557 @Override
1558 public String toString() {
1559 final float percent = ((float) progress * 100 / max);
Felipe Lemefd8ea072016-02-09 10:13:47 -08001560 return "id: " + id + ", pid: " + pid + ", name: " + name + ", finished: " + finished
Felipe Lemebc73ffc2015-12-11 15:07:14 -08001561 + "\n\ttitle: " + title + "\n\tdescription: " + description
Felipe Lemed1e0f122015-12-18 16:12:41 -08001562 + "\n\tfile: " + bugreportFile + "\n\tscreenshots: " + screenshotFiles
Felipe Leme510e9222016-02-22 18:07:49 -08001563 + "\n\tprogress: " + progress + "/" + max + " (" + percent + ")"
Felipe Leme18b58922016-01-29 12:24:25 -08001564 + "\n\tlast_update: " + getFormattedLastUpdate()
1565 + "\naddingDetailsToZip: " + addingDetailsToZip
1566 + " addedDetailsToZip: " + addedDetailsToZip;
Felipe Leme69c02922015-11-24 17:48:05 -08001567 }
Felipe Lemec4f646772016-01-12 18:12:09 -08001568
1569 // Parcelable contract
1570 protected BugreportInfo(Parcel in) {
1571 context = null;
Felipe Lemefd8ea072016-02-09 10:13:47 -08001572 id = in.readInt();
Felipe Lemec4f646772016-01-12 18:12:09 -08001573 pid = in.readInt();
1574 name = in.readString();
1575 title = in.readString();
1576 description = in.readString();
1577 max = in.readInt();
1578 progress = in.readInt();
1579 lastUpdate = in.readLong();
1580 formattedLastUpdate = in.readString();
1581 bugreportFile = readFile(in);
1582
1583 int screenshotSize = in.readInt();
1584 for (int i = 1; i <= screenshotSize; i++) {
1585 screenshotFiles.add(readFile(in));
1586 }
1587
1588 finished = in.readInt() == 1;
1589 screenshotCounter = in.readInt();
1590 }
1591
1592 @Override
1593 public void writeToParcel(Parcel dest, int flags) {
Felipe Lemefd8ea072016-02-09 10:13:47 -08001594 dest.writeInt(id);
Felipe Lemec4f646772016-01-12 18:12:09 -08001595 dest.writeInt(pid);
1596 dest.writeString(name);
1597 dest.writeString(title);
1598 dest.writeString(description);
1599 dest.writeInt(max);
1600 dest.writeInt(progress);
1601 dest.writeLong(lastUpdate);
1602 dest.writeString(getFormattedLastUpdate());
1603 writeFile(dest, bugreportFile);
1604
1605 dest.writeInt(screenshotFiles.size());
1606 for (File screenshotFile : screenshotFiles) {
1607 writeFile(dest, screenshotFile);
1608 }
1609
1610 dest.writeInt(finished ? 1 : 0);
1611 dest.writeInt(screenshotCounter);
1612 }
1613
1614 @Override
1615 public int describeContents() {
1616 return 0;
1617 }
1618
1619 private void writeFile(Parcel dest, File file) {
1620 dest.writeString(file == null ? null : file.getPath());
1621 }
1622
1623 private File readFile(Parcel in) {
1624 final String path = in.readString();
1625 return path == null ? null : new File(path);
1626 }
1627
1628 public static final Parcelable.Creator<BugreportInfo> CREATOR =
1629 new Parcelable.Creator<BugreportInfo>() {
1630 public BugreportInfo createFromParcel(Parcel source) {
1631 return new BugreportInfo(source);
1632 }
1633
1634 public BugreportInfo[] newArray(int size) {
1635 return new BugreportInfo[size];
1636 }
1637 };
1638
Felipe Leme69c02922015-11-24 17:48:05 -08001639 }
Felipe Lemeb9238b32015-11-24 17:31:47 -08001640}