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 import android.annotation.NonNull; 18 import android.annotation.Nullable; 19 import android.annotation.RequiresPermission; 20 import android.annotation.UserIdInt; 21 import android.content.BroadcastReceiver; 22 import android.content.ComponentName; 23 import android.content.Context; 24 import android.content.Intent; 25 import android.content.IntentFilter; 26 import android.os.Handler; 27 import android.os.UserHandle; 28 29 public class ContextCompat { 30 public static final String SENSOR_PRIVACY_SERVICE = Context.SENSOR_PRIVACY_SERVICE; 31 ContextCompat(Context context)32 public ContextCompat(Context context) { 33 mContext = context; 34 } 35 36 private final Context mContext; 37 sendBroadcastAsUser(@equiresPermission Intent intent, UserHandle handle)38 public void sendBroadcastAsUser(@RequiresPermission Intent intent, UserHandle handle) { 39 mContext.sendBroadcastAsUser(intent, handle); 40 } 41 42 public static final String OEM_LOCK_SERVICE = "oem_lock"; 43 44 public @UserIdInt getUserId()45 int getUserId() { 46 return mContext.getUserId(); 47 } 48 startServiceAsUser(Intent service, UserHandle user)49 public ComponentName startServiceAsUser(Intent service, UserHandle user) { 50 return mContext.startServiceAsUser(service, user); 51 } 52 startActivityAsUser( @equiresPermission @onNull Intent intent, @NonNull UserHandle user)53 public void startActivityAsUser( 54 @RequiresPermission @NonNull Intent intent, @NonNull UserHandle user) { 55 mContext.startActivityAsUser(intent, user); 56 } 57 stopServiceAsUser(Intent service, UserHandle user)58 public boolean stopServiceAsUser(Intent service, UserHandle user) { 59 return mContext.stopServiceAsUser(service, user); 60 } 61 registerReceiverAsUser(BroadcastReceiver receiver, UserHandle user, IntentFilter filter, @Nullable String broadcastPermission, @Nullable Handler scheduler)62 public Intent registerReceiverAsUser(BroadcastReceiver receiver, UserHandle user, 63 IntentFilter filter, @Nullable String broadcastPermission, 64 @Nullable Handler scheduler) { 65 return mContext.registerReceiverAsUser( 66 receiver, user, filter, broadcastPermission, scheduler); 67 } 68 } 69