1 /*
2  * Copyright (C) 2021 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 package com.android.car.bugreport;
17 
18 /** Defines {@link MetaBugReport} statuses. */
19 public enum Status {
20     // Bugreport is being written
21     STATUS_WRITE_PENDING(0),
22 
23     // Writing bugreport failed. This is a final state.
24     STATUS_WRITE_FAILED(1),
25 
26     // Bugreport is waiting to be uploaded, or is currently uploading.
27     STATUS_UPLOAD_PENDING(2),
28 
29     // Bugreport uploaded successfully. This is a final state.
30     STATUS_UPLOAD_SUCCESS(3),
31 
32     // Bugreport failed to upload. This is a final state.
33     STATUS_UPLOAD_FAILED(4),
34 
35     // Bugreport is cancelled by user. This is a final state.
36     STATUS_USER_CANCELLED(5),
37 
38     // Bugreport is pending user choice on whether to upload or copy.
39     STATUS_PENDING_USER_ACTION(6),
40 
41     // Bugreport was moved successfully.
42     STATUS_MOVE_SUCCESSFUL(7),
43 
44     // Bugreport move has failed. This is a final state.
45     STATUS_MOVE_FAILED(8),
46 
47     // Bugreport is moving to USB drive.
48     STATUS_MOVE_IN_PROGRESS(9),
49 
50     // Bugreport is expired. Associated file is deleted from the disk.
51     // This is the final state.
52     STATUS_EXPIRED(10),
53 
54     // Bugreport needs audio message.
55     STATUS_AUDIO_PENDING(11),
56 
57     // Bugreport was uploaded before. New upload failed.
58     // It may happen when bugreport was uploaded but because
59     // of network or other issues bugreport status wasn't changed from
60     // STATUS_UPLOAD_PENDING to STATUS_UPLOAD_SUCCESS.
61     //
62     // The bugreport zip files are stored in the device for some time in case the previous
63     // upload failed. The files are cleaned-up in ExpireOldBugReportsJob.
64     // This is the final state.
65     STATUS_UPLOADED_BEFORE(12);
66 
67     private final int mValue;
68 
Status(int value)69     Status(int value) {
70         mValue = value;
71     }
72 
73     /** Returns integer value of the status. */
getValue()74     public int getValue() {
75         return mValue;
76     }
77 
78     /** Generates human-readable string from a status value. */
toString(int value)79     public static String toString(int value) {
80         switch (value) {
81             case 0:
82                 return "Write pending";
83             case 1:
84                 return "Write failed";
85             case 2:
86                 return "Uploading, or waiting for network";
87             case 3:
88                 return "Upload successful";
89             case 4:
90                 return "Upload failed";
91             case 5:
92                 return "User cancelled";
93             case 6:
94                 return "Pending user action";
95             case 7:
96                 return "Move successful";
97             case 8:
98                 return "Move failed";
99             case 9:
100                 return "Move in progress";
101             case 10:
102                 return "Expired";
103             case 11:
104                 return "Audio message pending";
105             default:
106                 break;
107         }
108         return "unknown";
109     }
110 }
111