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 
17 package android.car.builtin.content;
18 
19 import android.annotation.NonNull;
20 import android.annotation.Nullable;
21 import android.annotation.RequiresPermission;
22 import android.annotation.SystemApi;
23 import android.content.Context;
24 import android.content.Intent;
25 import android.os.Bundle;
26 import android.os.UserHandle;
27 
28 import java.util.Objects;
29 
30 /**
31  * Helper for {@link Context}.
32  *
33  * @hide
34  */
35 @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
36 public final class ContextHelper {
ContextHelper()37     private ContextHelper() {
38         throw new UnsupportedOperationException();
39     }
40 
41     /** Returns display id relevant for the context */
getDisplayId(@onNull Context context)42     public static int getDisplayId(@NonNull Context context) {
43         return context.getDisplayId();
44     }
45 
46     /** Returns associated display id relevant for the context */
getAssociatedDisplayId(@onNull Context context)47     public static int getAssociatedDisplayId(@NonNull Context context) {
48         return context.getAssociatedDisplayId();
49     }
50 
51     /**
52      * Same as {@code context.startActivityAsUser(intent, options, user)}.
53      */
54     @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
startActivityAsUser(@onNull Context context, @NonNull Intent intent, @Nullable Bundle options, @NonNull UserHandle user)55     public static void startActivityAsUser(@NonNull Context context, @NonNull Intent intent,
56             @Nullable Bundle options, @NonNull UserHandle user) {
57         Objects.requireNonNull(context, "context");
58         Objects.requireNonNull(intent, "intent");
59         Objects.requireNonNull(user, "user");
60 
61         context.startActivityAsUser(intent, options, user);
62     }
63 
64 }
65