• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 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 com.android.permissioncontroller.role.model;
18 
19 import android.content.ComponentName;
20 import android.content.Context;
21 import android.content.Intent;
22 import android.content.pm.PackageManager;
23 import android.content.pm.ResolveInfo;
24 import android.os.UserHandle;
25 
26 import androidx.annotation.NonNull;
27 import androidx.annotation.Nullable;
28 
29 import com.android.permissioncontroller.role.utils.UserUtils;
30 
31 import java.util.List;
32 
33 /**
34  * Specifies a required {@code BroadcastReceiver} for an application to qualify for a {@link Role}.
35  */
36 public class RequiredBroadcastReceiver extends RequiredComponent {
37 
RequiredBroadcastReceiver(@onNull IntentFilterData intentFilterData, @Nullable String permission, int queryFlags)38     public RequiredBroadcastReceiver(@NonNull IntentFilterData intentFilterData,
39             @Nullable String permission, int queryFlags) {
40         super(intentFilterData, permission, queryFlags);
41     }
42 
43     @NonNull
44     @Override
queryIntentComponentsAsUser(@onNull Intent intent, int flags, @NonNull UserHandle user, @NonNull Context context)45     protected List<ResolveInfo> queryIntentComponentsAsUser(@NonNull Intent intent, int flags,
46             @NonNull UserHandle user, @NonNull Context context) {
47         Context userContext = UserUtils.getUserContext(context, user);
48         PackageManager userPackageManager = userContext.getPackageManager();
49         return userPackageManager.queryBroadcastReceivers(intent, flags);
50     }
51 
52     @NonNull
53     @Override
getComponentComponentName(@onNull ResolveInfo resolveInfo)54     protected ComponentName getComponentComponentName(@NonNull ResolveInfo resolveInfo) {
55         return new ComponentName(resolveInfo.activityInfo.packageName,
56                 resolveInfo.activityInfo.name);
57     }
58 
59     @Nullable
60     @Override
getComponentPermission(@onNull ResolveInfo resolveInfo)61     protected String getComponentPermission(@NonNull ResolveInfo resolveInfo) {
62         return resolveInfo.activityInfo.permission;
63     }
64 }
65