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.packageinstaller.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.Bundle; 25 import android.os.UserHandle; 26 27 import androidx.annotation.NonNull; 28 import androidx.annotation.Nullable; 29 30 import com.android.packageinstaller.role.utils.UserUtils; 31 32 import java.util.List; 33 34 /** 35 * Specifies a required {@code Service} for an application to qualify for a {@link Role}. 36 */ 37 public class RequiredService extends RequiredComponent { 38 RequiredService(@onNull IntentFilterData intentFilterData, @Nullable String permission, @NonNull List<RequiredMetaData> metaData)39 public RequiredService(@NonNull IntentFilterData intentFilterData, 40 @Nullable String permission, @NonNull List<RequiredMetaData> metaData) { 41 super(intentFilterData, permission, metaData); 42 } 43 44 @NonNull 45 @Override queryIntentComponentsAsUser(@onNull Intent intent, int flags, @NonNull UserHandle user, @NonNull Context context)46 protected List<ResolveInfo> queryIntentComponentsAsUser(@NonNull Intent intent, int flags, 47 @NonNull UserHandle user, @NonNull Context context) { 48 Context userContext = UserUtils.getUserContext(context, user); 49 PackageManager userPackageManager = userContext.getPackageManager(); 50 return userPackageManager.queryIntentServices(intent, flags); 51 } 52 53 @NonNull 54 @Override getComponentComponentName(@onNull ResolveInfo resolveInfo)55 protected ComponentName getComponentComponentName(@NonNull ResolveInfo resolveInfo) { 56 return new ComponentName(resolveInfo.serviceInfo.packageName, resolveInfo.serviceInfo.name); 57 } 58 59 @Nullable 60 @Override getComponentPermission(@onNull ResolveInfo resolveInfo)61 protected String getComponentPermission(@NonNull ResolveInfo resolveInfo) { 62 return resolveInfo.serviceInfo.permission; 63 } 64 65 @Nullable 66 @Override getComponentMetaData(@onNull ResolveInfo resolveInfo)67 protected Bundle getComponentMetaData(@NonNull ResolveInfo resolveInfo) { 68 return resolveInfo.serviceInfo.metaData; 69 } 70 } 71