• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 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.car.os;
18 
19 import android.annotation.IntDef;
20 import android.annotation.IntRange;
21 import android.annotation.NonNull;
22 import android.annotation.SystemApi;
23 import android.car.annotation.ApiRequirements;
24 import android.os.Parcelable;
25 
26 import com.android.car.internal.util.AnnotationValidations;
27 import com.android.car.internal.util.DataClass;
28 
29 import java.lang.annotation.Retention;
30 import java.lang.annotation.RetentionPolicy;
31 
32 /**
33  * Defines the thread scheduling policy and priority.
34  *
35  * <p>This API supports real-time scheduling polices:
36  * ({@code SCHED_FIFO}, {@code SCHED_RR}) with a {@code sched_priority} value in the range within
37  * [{@link PRIORITY_MIN}, {@link PRIORITY_MAX}]. This API also supports the default round-robin
38  * time-sharing scheduling algorithm: {@code SCHED_DEFAULT}.
39  *
40  * @hide
41  */
42 @SystemApi
43 @DataClass(genConstructor = false, genHiddenConstDefs = true)
44 public final class ThreadPolicyWithPriority implements Parcelable {
45 
46     /**
47      * Min supported thread priority.
48      */
49     @Priority
50     @ApiRequirements(minCarVersion = ApiRequirements.CarVersion.TIRAMISU_1,
51              minPlatformVersion = ApiRequirements.PlatformVersion.TIRAMISU_1)
52     public static final int PRIORITY_MIN = 1;
53 
54     /**
55      * Max supported thread priority.
56      */
57     @Priority
58     @ApiRequirements(minCarVersion = ApiRequirements.CarVersion.TIRAMISU_1,
59              minPlatformVersion = ApiRequirements.PlatformVersion.TIRAMISU_1)
60     public static final int PRIORITY_MAX = 99;
61 
62     /** @hide */
63     @IntDef({SCHED_DEFAULT, SCHED_FIFO, SCHED_RR})
64     @Retention(RetentionPolicy.SOURCE)
65     @ApiRequirements(minCarVersion = ApiRequirements.CarVersion.TIRAMISU_1,
66              minPlatformVersion = ApiRequirements.PlatformVersion.TIRAMISU_1)
67     public @interface SchedPolicy {}
68 
69     /**
70      * Default round-robin time-sharing scheduling policy.
71      *
72      * <p> Same as {@code SCHED_OTHER} defined in {@code /include/uapi/linux/sched.h}.
73      */
74     @Sched
75     @ApiRequirements(minCarVersion = ApiRequirements.CarVersion.TIRAMISU_1,
76              minPlatformVersion = ApiRequirements.PlatformVersion.TIRAMISU_1)
77     public static final int SCHED_DEFAULT = 0;
78 
79     /**
80      * First-in-first-out scheduling policy. See definition for Linux {@code sched(7)}.
81      *
82      * <p>Same as {@code SCHED_FIFO} defined in {@code /include/uapi/linux/sched.h}.
83      */
84     @Sched
85     @ApiRequirements(minCarVersion = ApiRequirements.CarVersion.TIRAMISU_1,
86              minPlatformVersion = ApiRequirements.PlatformVersion.TIRAMISU_1)
87     public static final int SCHED_FIFO = 1;
88 
89     /**
90      * Round robin scheduling policy. See definition for Linux {@code sched(7)}.
91      *
92      * <p>Same as {@code SCHED_RR} defined in {@code /include/uapi/linux/sched.h}.
93      */
94     @Sched
95     @ApiRequirements(minCarVersion = ApiRequirements.CarVersion.TIRAMISU_1,
96              minPlatformVersion = ApiRequirements.PlatformVersion.TIRAMISU_1)
97     public static final int SCHED_RR = 2;
98 
99     @SchedPolicy
100     private final int mPolicy;
101 
102     @IntRange(from = 0, to = 99)
103     private final int mPriority;
104 
105     /**
106      * Creates a new thread policy with priority.
107      *
108      * @param policy The scheduling policy, must be one of {@link SchedPolicy}.
109      * @param priority The priority, must be within [{@link PRIORITY_MIN}, {@link PRIORITY_MAX}].
110      */
ThreadPolicyWithPriority( @chedPolicy int policy, @IntRange(from = 0, to = 99) int priority)111     public ThreadPolicyWithPriority(
112             @SchedPolicy int policy, @IntRange(from = 0, to = 99) int priority) {
113         if (policy != SCHED_FIFO && policy != SCHED_RR && policy != SCHED_DEFAULT) {
114             throw new IllegalArgumentException("invalid policy");
115         }
116         // priority is ignored for SCHED_DEFAULT
117         if (policy == SCHED_DEFAULT) {
118             priority = 0;
119         } else if (priority < PRIORITY_MIN || priority > PRIORITY_MAX) {
120             throw new IllegalArgumentException("invalid priority");
121         }
122         mPolicy = policy;
123         mPriority = priority;
124     }
125 
126 
127 
128     // Code below generated by codegen v1.0.23.
129     //
130     // DO NOT MODIFY!
131     // CHECKSTYLE:OFF Generated code
132     //
133     // The generated code is patched with adding "apiRequirements" annotation to all public
134     // methods/interfaces.
135     //
136     // To regenerate run:
137     // $ codegen $ANDROID_BUILD_TOP/packages/services/Car/car-lib/src/android/car/os/ThreadPolicyWithPriority.java
138     // Added AddedInOrBefore or ApiRequirement Annotation manually
139     //
140     // To exclude the generated code from IntelliJ auto-formatting enable (one-time):
141     //   Settings > Editor > Code Style > Formatter Control
142     //@formatter:off
143 
144 
145     /** @hide */
146     @IntDef(prefix = "PRIORITY_", value = {
147         PRIORITY_MIN,
148         PRIORITY_MAX
149     })
150     @Retention(RetentionPolicy.SOURCE)
151     @DataClass.Generated.Member
152     @ApiRequirements(minCarVersion = ApiRequirements.CarVersion.TIRAMISU_1,
153              minPlatformVersion = ApiRequirements.PlatformVersion.TIRAMISU_1)
154     public @interface Priority {}
155 
156     /** @hide */
157     @DataClass.Generated.Member
158     @ApiRequirements(minCarVersion = ApiRequirements.CarVersion.TIRAMISU_1,
159              minPlatformVersion = ApiRequirements.PlatformVersion.TIRAMISU_1)
priorityToString(@riority int value)160     public static String priorityToString(@Priority int value) {
161         switch (value) {
162             case PRIORITY_MIN:
163                     return "PRIORITY_MIN";
164             case PRIORITY_MAX:
165                     return "PRIORITY_MAX";
166             default: return Integer.toHexString(value);
167         }
168     }
169 
170     /** @hide */
171     @IntDef(prefix = "SCHED_", value = {
172         SCHED_DEFAULT,
173         SCHED_FIFO,
174         SCHED_RR
175     })
176     @Retention(RetentionPolicy.SOURCE)
177     @DataClass.Generated.Member
178     @ApiRequirements(minCarVersion = ApiRequirements.CarVersion.TIRAMISU_1,
179              minPlatformVersion = ApiRequirements.PlatformVersion.TIRAMISU_1)
180     public @interface Sched {}
181 
182     /** @hide */
183     @DataClass.Generated.Member
184     @ApiRequirements(minCarVersion = ApiRequirements.CarVersion.TIRAMISU_1,
185              minPlatformVersion = ApiRequirements.PlatformVersion.TIRAMISU_1)
schedToString(@ched int value)186     public static String schedToString(@Sched int value) {
187         switch (value) {
188             case SCHED_DEFAULT:
189                     return "SCHED_DEFAULT";
190             case SCHED_FIFO:
191                     return "SCHED_FIFO";
192             case SCHED_RR:
193                     return "SCHED_RR";
194             default: return Integer.toHexString(value);
195         }
196     }
197 
198     @DataClass.Generated.Member
199     @ApiRequirements(minCarVersion = ApiRequirements.CarVersion.TIRAMISU_1,
200              minPlatformVersion = ApiRequirements.PlatformVersion.TIRAMISU_1)
getPolicy()201     public @SchedPolicy int getPolicy() {
202         return mPolicy;
203     }
204 
205     @DataClass.Generated.Member
206     @ApiRequirements(minCarVersion = ApiRequirements.CarVersion.TIRAMISU_1,
207              minPlatformVersion = ApiRequirements.PlatformVersion.TIRAMISU_1)
getPriority()208     public @IntRange(from = 0, to = 99) int getPriority() {
209         return mPriority;
210     }
211 
212     @Override
213     @DataClass.Generated.Member
214     @ApiRequirements(minCarVersion = ApiRequirements.CarVersion.TIRAMISU_1,
215              minPlatformVersion = ApiRequirements.PlatformVersion.TIRAMISU_1)
writeToParcel(@onNull android.os.Parcel dest, int flags)216     public void writeToParcel(@NonNull android.os.Parcel dest, int flags) {
217         // You can override field parcelling by defining methods like:
218         // void parcelFieldName(Parcel dest, int flags) { ... }
219 
220         dest.writeInt(mPolicy);
221         dest.writeInt(mPriority);
222     }
223 
224     @Override
225     @DataClass.Generated.Member
226     @ApiRequirements(minCarVersion = ApiRequirements.CarVersion.TIRAMISU_1,
227              minPlatformVersion = ApiRequirements.PlatformVersion.TIRAMISU_1)
describeContents()228     public int describeContents() { return 0; }
229 
230     /** @hide */
231     @SuppressWarnings({"unchecked", "RedundantCast"})
232     @DataClass.Generated.Member
ThreadPolicyWithPriority(@onNull android.os.Parcel in)233     /* package-private */ ThreadPolicyWithPriority(@NonNull android.os.Parcel in) {
234         // You can override field unparcelling by defining methods like:
235         // static FieldType unparcelFieldName(Parcel in) { ... }
236 
237         int policy = in.readInt();
238         int priority = in.readInt();
239 
240         this.mPolicy = policy;
241         AnnotationValidations.validate(
242                 SchedPolicy.class, null, mPolicy);
243         this.mPriority = priority;
244         AnnotationValidations.validate(
245                 IntRange.class, null, mPriority,
246                 "from", 0,
247                 "to", 99);
248 
249         // onConstructed(); // You can define this method to get a callback
250     }
251 
252     @DataClass.Generated.Member
253     @ApiRequirements(minCarVersion = ApiRequirements.CarVersion.TIRAMISU_1,
254              minPlatformVersion = ApiRequirements.PlatformVersion.TIRAMISU_1)
255     public static final @NonNull Parcelable.Creator<ThreadPolicyWithPriority> CREATOR
256             = new Parcelable.Creator<ThreadPolicyWithPriority>() {
257         @Override
258         public ThreadPolicyWithPriority[] newArray(int size) {
259             return new ThreadPolicyWithPriority[size];
260         }
261 
262         @Override
263         public ThreadPolicyWithPriority createFromParcel(@NonNull android.os.Parcel in) {
264             return new ThreadPolicyWithPriority(in);
265         }
266     };
267 
268     @DataClass.Generated(
269             time = 1657845707744L,
270             codegenVersion = "1.0.23",
271             sourceFile = "packages/services/Car/car-lib/src/android/car/os/ThreadPolicyWithPriority.java",
272             inputSignatures = "public static final @android.car.os.ThreadPolicyWithPriority.Priority @android.car.annotation.AddedIn int PRIORITY_MIN\npublic static final @android.car.os.ThreadPolicyWithPriority.Priority @android.car.annotation.AddedIn int PRIORITY_MAX\npublic static final @android.car.os.ThreadPolicyWithPriority.Sched @android.car.annotation.AddedIn int SCHED_DEFAULT\npublic static final @android.car.os.ThreadPolicyWithPriority.Sched @android.car.annotation.AddedIn int SCHED_FIFO\npublic static final @android.car.os.ThreadPolicyWithPriority.Sched @android.car.annotation.AddedIn int SCHED_RR\nprivate final @android.car.os.ThreadPolicyWithPriority.SchedPolicy int mPolicy\nprivate final @android.annotation.IntRange int mPriority\nclass ThreadPolicyWithPriority extends java.lang.Object implements [android.os.Parcelable]\n@com.android.car.internal.util.DataClass(genConstructor=false, genHiddenConstDefs=true)")
273     @Deprecated
__metadata()274     private void __metadata() {}
275 
276 
277     //@formatter:on
278     // End of generated code
279 
280 }
281