1 /*
2  * Copyright (C) 2023 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.health.connect.datatypes;
18 
19 import android.annotation.IntDef;
20 
21 import java.lang.annotation.Retention;
22 import java.lang.annotation.RetentionPolicy;
23 import java.util.Set;
24 
25 /**
26  * Identifier for exercise types, as returned by {@link ExerciseSessionRecord#getExerciseType()}.
27  */
28 public final class ExerciseSessionType {
29 
30     /** Use this type if the type of the exercise session is not known. */
31     public static final int EXERCISE_SESSION_TYPE_UNKNOWN = 0;
32 
33     /** Use this type for the badminton playing session. */
34     public static final int EXERCISE_SESSION_TYPE_BADMINTON = 1;
35 
36     /** Use this type for the baseball playing session. */
37     public static final int EXERCISE_SESSION_TYPE_BASEBALL = 2;
38 
39     /** Use this type for the basketball playing session. */
40     public static final int EXERCISE_SESSION_TYPE_BASKETBALL = 3;
41 
42     /** Use this type for riding a bicycle session. */
43     public static final int EXERCISE_SESSION_TYPE_BIKING = 4;
44 
45     /** Use this type for riding a stationary bicycle session. */
46     public static final int EXERCISE_SESSION_TYPE_BIKING_STATIONARY = 5;
47 
48     /** Use this type for the boot camp session. */
49     public static final int EXERCISE_SESSION_TYPE_BOOT_CAMP = 6;
50 
51     /** Use this type for boxing session. */
52     public static final int EXERCISE_SESSION_TYPE_BOXING = 7;
53 
54     /** Use this type for calisthenics session. */
55     public static final int EXERCISE_SESSION_TYPE_CALISTHENICS = 8;
56 
57     /** Use this type for the cricket playing session. */
58     public static final int EXERCISE_SESSION_TYPE_CRICKET = 9;
59 
60     /** Use this type for the dancing session. */
61     public static final int EXERCISE_SESSION_TYPE_DANCING = 10;
62 
63     /** Use this type for the exercise class session. */
64     public static final int EXERCISE_SESSION_TYPE_EXERCISE_CLASS = 11;
65 
66     /** Use this type for the fencing session. */
67     public static final int EXERCISE_SESSION_TYPE_FENCING = 12;
68 
69     /** Use this type for the American football playing session. */
70     public static final int EXERCISE_SESSION_TYPE_FOOTBALL_AMERICAN = 13;
71 
72     /** Use this type for the Australian football playing session. */
73     public static final int EXERCISE_SESSION_TYPE_FOOTBALL_AUSTRALIAN = 14;
74 
75     /** Use this type for the frisbee disc playing session. */
76     public static final int EXERCISE_SESSION_TYPE_FRISBEE_DISC = 15;
77 
78     /** Use this type for the golf playing session. */
79     public static final int EXERCISE_SESSION_TYPE_GOLF = 16;
80 
81     /** Use this type for the guided breathing session. */
82     public static final int EXERCISE_SESSION_TYPE_GUIDED_BREATHING = 17;
83 
84     /** Use this type for the gymnastics session. */
85     public static final int EXERCISE_SESSION_TYPE_GYMNASTICS = 18;
86 
87     /** Use this type for the handball playing session. */
88     public static final int EXERCISE_SESSION_TYPE_HANDBALL = 19;
89 
90     /** Use this type for the high intensity interval training session. */
91     public static final int EXERCISE_SESSION_TYPE_HIGH_INTENSITY_INTERVAL_TRAINING = 20;
92 
93     /** Use this type for the hiking session. */
94     public static final int EXERCISE_SESSION_TYPE_HIKING = 21;
95 
96     /** Use this type for the ice hockey playing session. */
97     public static final int EXERCISE_SESSION_TYPE_ICE_HOCKEY = 22;
98 
99     /** Use this type for the ice skating session. */
100     public static final int EXERCISE_SESSION_TYPE_ICE_SKATING = 23;
101 
102     /** Use this type for the martial arts training session. */
103     public static final int EXERCISE_SESSION_TYPE_MARTIAL_ARTS = 24;
104 
105     /** Use this type for the paddling session. */
106     public static final int EXERCISE_SESSION_TYPE_PADDLING = 25;
107 
108     /** Use this type for the paragliding session. */
109     public static final int EXERCISE_SESSION_TYPE_PARAGLIDING = 26;
110 
111     /** Use this type for the pilates session. */
112     public static final int EXERCISE_SESSION_TYPE_PILATES = 27;
113 
114     /** Use this type for the racquetball playing session. */
115     public static final int EXERCISE_SESSION_TYPE_RACQUETBALL = 28;
116 
117     /** Use this type for the rock climbing session. */
118     public static final int EXERCISE_SESSION_TYPE_ROCK_CLIMBING = 29;
119 
120     /** Use this type for the roller hockey playing session. */
121     public static final int EXERCISE_SESSION_TYPE_ROLLER_HOCKEY = 30;
122 
123     /** Use this type for the rowing session. */
124     public static final int EXERCISE_SESSION_TYPE_ROWING = 31;
125 
126     /** Use this type for the rugby playing session. */
127     public static final int EXERCISE_SESSION_TYPE_RUGBY = 32;
128 
129     /** Use this type for the running session. */
130     public static final int EXERCISE_SESSION_TYPE_RUNNING = 33;
131 
132     /** Use this type for the treadmill running session. */
133     public static final int EXERCISE_SESSION_TYPE_RUNNING_TREADMILL = 34;
134 
135     /** Use this type for the sailing session. */
136     public static final int EXERCISE_SESSION_TYPE_SAILING = 35;
137 
138     /** Use this type for the scuba diving session. */
139     public static final int EXERCISE_SESSION_TYPE_SCUBA_DIVING = 36;
140 
141     /** Use this type for the skating session. */
142     public static final int EXERCISE_SESSION_TYPE_SKATING = 37;
143 
144     /** Use this type for the skiing session. */
145     public static final int EXERCISE_SESSION_TYPE_SKIING = 38;
146 
147     /** Use this type for the snowboarding session. */
148     public static final int EXERCISE_SESSION_TYPE_SNOWBOARDING = 39;
149 
150     /** Use this type for the snowshoeing session. */
151     public static final int EXERCISE_SESSION_TYPE_SNOWSHOEING = 40;
152 
153     /** Use this type for the soccer playing session. */
154     public static final int EXERCISE_SESSION_TYPE_SOCCER = 41;
155 
156     /** Use this type for the softball playing session. */
157     public static final int EXERCISE_SESSION_TYPE_SOFTBALL = 42;
158 
159     /** Use this type for the squash playing session. */
160     public static final int EXERCISE_SESSION_TYPE_SQUASH = 43;
161 
162     /** Use this type for the stair climbing session. */
163     public static final int EXERCISE_SESSION_TYPE_STAIR_CLIMBING = 44;
164 
165     /** Use this type for the strength training session. */
166     public static final int EXERCISE_SESSION_TYPE_STRENGTH_TRAINING = 45;
167 
168     /** Use this type for the stretching session. */
169     public static final int EXERCISE_SESSION_TYPE_STRETCHING = 46;
170 
171     /** Use this type for the surfing session. */
172     public static final int EXERCISE_SESSION_TYPE_SURFING = 47;
173 
174     /** Use this type for the swimming in the open water session. */
175     public static final int EXERCISE_SESSION_TYPE_SWIMMING_OPEN_WATER = 48;
176 
177     /** Use this type for the swimming in the pool session. */
178     public static final int EXERCISE_SESSION_TYPE_SWIMMING_POOL = 49;
179 
180     /** Use this type for the table tennis playing session. */
181     public static final int EXERCISE_SESSION_TYPE_TABLE_TENNIS = 50;
182 
183     /** Use this type for the tennis playing session. */
184     public static final int EXERCISE_SESSION_TYPE_TENNIS = 51;
185 
186     /** Use this type for the volleyball playing session. */
187     public static final int EXERCISE_SESSION_TYPE_VOLLEYBALL = 52;
188 
189     /** Use this type for the walking session. */
190     public static final int EXERCISE_SESSION_TYPE_WALKING = 53;
191 
192     /** Use this type for the water polo playing session. */
193     public static final int EXERCISE_SESSION_TYPE_WATER_POLO = 54;
194 
195     /** Use this type for the weightlifting session. */
196     public static final int EXERCISE_SESSION_TYPE_WEIGHTLIFTING = 55;
197 
198     /** Use this type for the wheelchair session. */
199     public static final int EXERCISE_SESSION_TYPE_WHEELCHAIR = 56;
200 
201     /** Use this type for the yoga session. */
202     public static final int EXERCISE_SESSION_TYPE_YOGA = 57;
203 
204     /** Use this type for the other workout session. */
205     public static final int EXERCISE_SESSION_TYPE_OTHER_WORKOUT = 58;
206 
207     /** Use this type for the stair climbing machine session. */
208     public static final int EXERCISE_SESSION_TYPE_STAIR_CLIMBING_MACHINE = 59;
209 
210     /** Use this type for elliptical workout. */
211     public static final int EXERCISE_SESSION_TYPE_ELLIPTICAL = 60;
212 
213     /** Use this type for rowing machine. */
214     public static final int EXERCISE_SESSION_TYPE_ROWING_MACHINE = 61;
215 
ExerciseSessionType()216     private ExerciseSessionType() {}
217 
218     /** @hide */
219     @IntDef({
220         EXERCISE_SESSION_TYPE_UNKNOWN,
221         EXERCISE_SESSION_TYPE_BADMINTON,
222         EXERCISE_SESSION_TYPE_BASEBALL,
223         EXERCISE_SESSION_TYPE_BASKETBALL,
224         EXERCISE_SESSION_TYPE_BIKING,
225         EXERCISE_SESSION_TYPE_BIKING_STATIONARY,
226         EXERCISE_SESSION_TYPE_BOOT_CAMP,
227         EXERCISE_SESSION_TYPE_BOXING,
228         EXERCISE_SESSION_TYPE_CALISTHENICS,
229         EXERCISE_SESSION_TYPE_CRICKET,
230         EXERCISE_SESSION_TYPE_DANCING,
231         EXERCISE_SESSION_TYPE_ELLIPTICAL,
232         EXERCISE_SESSION_TYPE_EXERCISE_CLASS,
233         EXERCISE_SESSION_TYPE_FENCING,
234         EXERCISE_SESSION_TYPE_FOOTBALL_AMERICAN,
235         EXERCISE_SESSION_TYPE_FOOTBALL_AUSTRALIAN,
236         EXERCISE_SESSION_TYPE_FRISBEE_DISC,
237         EXERCISE_SESSION_TYPE_GOLF,
238         EXERCISE_SESSION_TYPE_GUIDED_BREATHING,
239         EXERCISE_SESSION_TYPE_GYMNASTICS,
240         EXERCISE_SESSION_TYPE_HANDBALL,
241         EXERCISE_SESSION_TYPE_HIGH_INTENSITY_INTERVAL_TRAINING,
242         EXERCISE_SESSION_TYPE_HIKING,
243         EXERCISE_SESSION_TYPE_ICE_HOCKEY,
244         EXERCISE_SESSION_TYPE_ICE_SKATING,
245         EXERCISE_SESSION_TYPE_MARTIAL_ARTS,
246         EXERCISE_SESSION_TYPE_PADDLING,
247         EXERCISE_SESSION_TYPE_PARAGLIDING,
248         EXERCISE_SESSION_TYPE_PILATES,
249         EXERCISE_SESSION_TYPE_RACQUETBALL,
250         EXERCISE_SESSION_TYPE_ROCK_CLIMBING,
251         EXERCISE_SESSION_TYPE_ROLLER_HOCKEY,
252         EXERCISE_SESSION_TYPE_ROWING,
253         EXERCISE_SESSION_TYPE_ROWING_MACHINE,
254         EXERCISE_SESSION_TYPE_RUGBY,
255         EXERCISE_SESSION_TYPE_RUNNING,
256         EXERCISE_SESSION_TYPE_RUNNING_TREADMILL,
257         EXERCISE_SESSION_TYPE_SAILING,
258         EXERCISE_SESSION_TYPE_SCUBA_DIVING,
259         EXERCISE_SESSION_TYPE_SKATING,
260         EXERCISE_SESSION_TYPE_SKIING,
261         EXERCISE_SESSION_TYPE_SNOWBOARDING,
262         EXERCISE_SESSION_TYPE_SNOWSHOEING,
263         EXERCISE_SESSION_TYPE_SOCCER,
264         EXERCISE_SESSION_TYPE_SOFTBALL,
265         EXERCISE_SESSION_TYPE_SQUASH,
266         EXERCISE_SESSION_TYPE_STAIR_CLIMBING,
267         EXERCISE_SESSION_TYPE_STAIR_CLIMBING_MACHINE,
268         EXERCISE_SESSION_TYPE_STRENGTH_TRAINING,
269         EXERCISE_SESSION_TYPE_STRETCHING,
270         EXERCISE_SESSION_TYPE_SURFING,
271         EXERCISE_SESSION_TYPE_SWIMMING_OPEN_WATER,
272         EXERCISE_SESSION_TYPE_SWIMMING_POOL,
273         EXERCISE_SESSION_TYPE_TABLE_TENNIS,
274         EXERCISE_SESSION_TYPE_TENNIS,
275         EXERCISE_SESSION_TYPE_VOLLEYBALL,
276         EXERCISE_SESSION_TYPE_WALKING,
277         EXERCISE_SESSION_TYPE_WATER_POLO,
278         EXERCISE_SESSION_TYPE_WEIGHTLIFTING,
279         EXERCISE_SESSION_TYPE_WHEELCHAIR,
280         EXERCISE_SESSION_TYPE_OTHER_WORKOUT,
281         EXERCISE_SESSION_TYPE_YOGA,
282     })
283     @Retention(RetentionPolicy.SOURCE)
284     public @interface ExerciseSessionTypes {}
285 
286     // Update this set when add new type or deprecate existing type.
287     private static final Set<Integer> VALID_TYPES =
288             Set.of(
289                     EXERCISE_SESSION_TYPE_UNKNOWN,
290                     EXERCISE_SESSION_TYPE_BADMINTON,
291                     EXERCISE_SESSION_TYPE_BASEBALL,
292                     EXERCISE_SESSION_TYPE_BASKETBALL,
293                     EXERCISE_SESSION_TYPE_BIKING,
294                     EXERCISE_SESSION_TYPE_BIKING_STATIONARY,
295                     EXERCISE_SESSION_TYPE_BOOT_CAMP,
296                     EXERCISE_SESSION_TYPE_BOXING,
297                     EXERCISE_SESSION_TYPE_CALISTHENICS,
298                     EXERCISE_SESSION_TYPE_CRICKET,
299                     EXERCISE_SESSION_TYPE_DANCING,
300                     EXERCISE_SESSION_TYPE_ELLIPTICAL,
301                     EXERCISE_SESSION_TYPE_EXERCISE_CLASS,
302                     EXERCISE_SESSION_TYPE_FENCING,
303                     EXERCISE_SESSION_TYPE_FOOTBALL_AMERICAN,
304                     EXERCISE_SESSION_TYPE_FOOTBALL_AUSTRALIAN,
305                     EXERCISE_SESSION_TYPE_FRISBEE_DISC,
306                     EXERCISE_SESSION_TYPE_GOLF,
307                     EXERCISE_SESSION_TYPE_GUIDED_BREATHING,
308                     EXERCISE_SESSION_TYPE_GYMNASTICS,
309                     EXERCISE_SESSION_TYPE_HANDBALL,
310                     EXERCISE_SESSION_TYPE_HIGH_INTENSITY_INTERVAL_TRAINING,
311                     EXERCISE_SESSION_TYPE_HIKING,
312                     EXERCISE_SESSION_TYPE_ICE_HOCKEY,
313                     EXERCISE_SESSION_TYPE_ICE_SKATING,
314                     EXERCISE_SESSION_TYPE_MARTIAL_ARTS,
315                     EXERCISE_SESSION_TYPE_PADDLING,
316                     EXERCISE_SESSION_TYPE_PARAGLIDING,
317                     EXERCISE_SESSION_TYPE_PILATES,
318                     EXERCISE_SESSION_TYPE_RACQUETBALL,
319                     EXERCISE_SESSION_TYPE_ROCK_CLIMBING,
320                     EXERCISE_SESSION_TYPE_ROLLER_HOCKEY,
321                     EXERCISE_SESSION_TYPE_ROWING,
322                     EXERCISE_SESSION_TYPE_ROWING_MACHINE,
323                     EXERCISE_SESSION_TYPE_RUGBY,
324                     EXERCISE_SESSION_TYPE_RUNNING,
325                     EXERCISE_SESSION_TYPE_RUNNING_TREADMILL,
326                     EXERCISE_SESSION_TYPE_SAILING,
327                     EXERCISE_SESSION_TYPE_SCUBA_DIVING,
328                     EXERCISE_SESSION_TYPE_SKATING,
329                     EXERCISE_SESSION_TYPE_SKIING,
330                     EXERCISE_SESSION_TYPE_SNOWBOARDING,
331                     EXERCISE_SESSION_TYPE_SNOWSHOEING,
332                     EXERCISE_SESSION_TYPE_SOCCER,
333                     EXERCISE_SESSION_TYPE_SOFTBALL,
334                     EXERCISE_SESSION_TYPE_SQUASH,
335                     EXERCISE_SESSION_TYPE_STAIR_CLIMBING,
336                     EXERCISE_SESSION_TYPE_STAIR_CLIMBING_MACHINE,
337                     EXERCISE_SESSION_TYPE_STRENGTH_TRAINING,
338                     EXERCISE_SESSION_TYPE_STRETCHING,
339                     EXERCISE_SESSION_TYPE_SURFING,
340                     EXERCISE_SESSION_TYPE_SWIMMING_OPEN_WATER,
341                     EXERCISE_SESSION_TYPE_SWIMMING_POOL,
342                     EXERCISE_SESSION_TYPE_TABLE_TENNIS,
343                     EXERCISE_SESSION_TYPE_TENNIS,
344                     EXERCISE_SESSION_TYPE_VOLLEYBALL,
345                     EXERCISE_SESSION_TYPE_WALKING,
346                     EXERCISE_SESSION_TYPE_WATER_POLO,
347                     EXERCISE_SESSION_TYPE_WEIGHTLIFTING,
348                     EXERCISE_SESSION_TYPE_WHEELCHAIR,
349                     EXERCISE_SESSION_TYPE_OTHER_WORKOUT,
350                     EXERCISE_SESSION_TYPE_YOGA);
351 
352     /**
353      * Returns whether given session type is known by current module version, throws exception if
354      * the type is negative.
355      *
356      * @hide
357      */
isKnownSessionType(int sessionType)358     public static boolean isKnownSessionType(int sessionType) {
359         if (sessionType < 0) {
360             throw new IllegalArgumentException("Exercise session type must be non negative.");
361         }
362 
363         return VALID_TYPES.contains(sessionType);
364     }
365 }
366