1 /*
2  * Copyright (C) 2019 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 android.annotation;
17 
18 import static java.lang.annotation.ElementType.CONSTRUCTOR;
19 import static java.lang.annotation.ElementType.METHOD;
20 import static java.lang.annotation.ElementType.PACKAGE;
21 import static java.lang.annotation.ElementType.TYPE;
22 import static java.lang.annotation.RetentionPolicy.SOURCE;
23 
24 import java.lang.annotation.Retention;
25 import java.lang.annotation.Target;
26 
27 /**
28  * Indicates an API that uses {@code context.getUser} or {@code context.getUserId}
29  * to operate across users (as the user associated with the context)
30  * <p>
31  * To create a {@link android.content.Context} associated with a different user,
32  *  use {@link android.content.Context#createContextAsUser} or
33  *  {@link android.content.Context#createPackageContextAsUser}
34  * <p>
35  * Example:
36  * <pre>{@code
37  * {@literal @}UserHandleAware
38  * public abstract PackageInfo getPackageInfo({@literal @}NonNull String packageName,
39  *      {@literal @}PackageInfoFlags int flags) throws NameNotFoundException;
40  * }</pre>
41  *
42  * @memberDoc This method uses {@linkplain android.content.Context#getUser}
43  *            or {@linkplain android.content.Context#getUserId} to execute across users.
44  * @hide
45  */
46 @Retention(SOURCE)
47 @Target({TYPE, METHOD, CONSTRUCTOR, PACKAGE})
48 public @interface UserHandleAware {
49 }
50