1/* 2 * Copyright (C) 2011 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 17package com.android.providers.contacts; 18 19import android.content.Intent; 20import android.content.pm.ActivityInfo; 21import android.content.pm.ResolveInfo; 22 23import java.util.ArrayList; 24import java.util.List; 25 26public class MockPackageManager extends android.test.mock.MockPackageManager { 27 private final String[] mPackages; 28 public MockPackageManager(String... packages) { 29 mPackages = packages; 30 } 31 32 @Override 33 public List<ResolveInfo> queryBroadcastReceivers(Intent intent, int flags) { 34 List<ResolveInfo> resolveInfos = new ArrayList<ResolveInfo>(); 35 for (String pkg : mPackages) { 36 resolveInfos.add(createResolveInfo(pkg)); 37 } 38 return resolveInfos; 39 } 40 41 private ResolveInfo createResolveInfo(String packageName) { 42 ActivityInfo activityInfo = new ActivityInfo(); 43 activityInfo.packageName = packageName; 44 activityInfo.name = "FooClass"; 45 ResolveInfo resolveInfo = new ResolveInfo(); 46 resolveInfo.activityInfo = activityInfo; 47 return resolveInfo; 48 } 49 50 @Override 51 public String[] getPackagesForUid(int uid) { 52 return new String[] {mPackages[0]}; 53 } 54 55 @Override 56 public int checkPermission(String permName, String pkgName) { 57 return PERMISSION_GRANTED; 58 } 59} 60