1/*
2 * Copyright 2020 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17syntax = "proto3";
18
19package androidx.work.inspection;
20
21option java_package = "androidx.work.inspection";
22option java_outer_classname = "WorkManagerInspectorProtocol";
23
24// --- Commands ---
25
26// Generic Command object grouping all Inspector Command types. Expected in
27// Inspector's onReceiveCommand.
28message Command {
29  // Wrapped specialised Command.
30  oneof OneOf {
31    TrackWorkManagerCommand track_work_manager = 1;
32    CancelWorkCommand cancel_work = 2;
33  }
34}
35
36// Request for the Inspector to listen to the WorkManager
37// for work related updates.
38message TrackWorkManagerCommand {}
39
40// Request for the Inspector to cancel a work request.
41message CancelWorkCommand {
42    string id = 1;
43}
44
45// --- Responses ---
46
47// Generic Response object grouping all Inspector Response types to Command
48// objects.
49message Response {
50    oneof OneOf {
51        TrackWorkManagerResponse track_work_manager = 1;
52        CancelWorkResponse cancel_response = 2;
53        ErrorResponse error = 400;
54    }
55}
56
57// Object expected as a response to TrackWorkManagerCommand.
58message TrackWorkManagerResponse {}
59
60// Object expected as a response to CancelWorkCommand.
61message CancelWorkResponse{}
62
63// General Error message.
64message ErrorResponse {
65  string content = 1;
66}
67
68// --- Events ---
69
70// Generic Event object grouping all Inspector Event types. Expected in
71// Connection's sendEvent method.
72message Event {
73  // Wrapped specialised Event.
74  oneof OneOf {
75    WorkAddedEvent work_added = 1;
76    WorkRemovedEvent work_removed = 2;
77    WorkUpdatedEvent work_updated = 3;
78  }
79}
80
81// Notification of a work established (new) / discovered
82// (existing).
83message WorkAddedEvent {
84    WorkInfo work = 1;
85}
86
87// Notification of a work removed
88message WorkRemovedEvent {
89    string id = 1;
90}
91
92// Notification of a work updated
93message WorkUpdatedEvent {
94    string id = 1;
95    oneof OneOf {
96        WorkInfo.State state = 2;
97        int32 run_attempt_count = 3;
98        Data data = 4;
99        int64 schedule_requested_at = 5;
100    }
101}
102
103// Information about a particular Work
104message WorkInfo {
105    enum State {
106        UNSPECIFIED = 0;
107        ENQUEUED = 1;
108        RUNNING = 2;
109        SUCCEEDED = 3;
110        FAILED = 4;
111        BLOCKED = 5;
112        CANCELLED = 6;
113    }
114    string id = 1;
115    State state = 2;
116    string worker_class_name = 3;
117    Data data = 4;
118    repeated string tags = 5;
119    int32 run_attempt_count = 6;
120    bool is_periodic = 7;
121    Constraints constraints = 8;
122    CallStack call_stack = 9;
123    int64 schedule_requested_at = 10;
124    repeated string prerequisites = 11;
125    repeated string dependents = 12;
126    repeated string names = 13;
127}
128
129// A list of key/value pairs which are used as inputs and outputs for Workers
130message Data {
131    repeated DataEntry entries = 1;
132}
133
134// Key/value pairs for Data
135message DataEntry {
136    string key = 1;
137    string value = 2;
138}
139
140// A specification of the requirements that need to be met before a WorkRequest can run.
141message Constraints {
142    enum NetworkType {
143        UNSPECIFIED = 0;
144        NOT_REQUIRED = 1;
145        CONNECTED = 2;
146        UNMETERED = 3;
147        NOT_ROAMING = 4;
148        METERED = 5;
149    }
150    NetworkType required_network_type = 1;
151    bool requires_charging = 2;
152    bool requires_device_idle = 3;
153    bool requires_battery_not_low = 4;
154    bool requires_storage_not_low = 5;
155}
156
157// Stack trace information.
158message CallStack {
159  message Frame {
160    string class_name = 1;
161    string method_name = 2;
162    string file_name = 3;
163    int32 line_number = 4;
164  }
165  repeated Frame frames = 1;
166}
167