1/* 2 * Copyright (C) 2008 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.internal.app; 18 19import android.content.ComponentName; 20import android.content.Intent; 21import android.content.pm.ActivityInfo; 22import android.content.pm.ApplicationInfo; 23import android.content.pm.ResolveInfo; 24import android.os.UserHandle; 25 26import java.util.HashMap; 27import java.util.Map; 28import java.util.concurrent.atomic.AtomicInteger; 29 30/** 31 * Utility class used by resolver tests to create mock data 32 */ 33class ResolverDataProvider { 34 35 static private int USER_SOMEONE_ELSE = 10; 36 37 static ResolverActivity.ResolvedComponentInfo createResolvedComponentInfo(int i) { 38 return new ResolverActivity.ResolvedComponentInfo(createComponentName(i), 39 createResolverIntent(i), createResolveInfo(i, UserHandle.USER_CURRENT)); 40 } 41 42 static ResolverActivity.ResolvedComponentInfo createResolvedComponentInfoWithOtherId(int i) { 43 return new ResolverActivity.ResolvedComponentInfo(createComponentName(i), 44 createResolverIntent(i), createResolveInfo(i, USER_SOMEONE_ELSE)); 45 } 46 47 static ComponentName createComponentName(int i) { 48 final String name = "component" + i; 49 return new ComponentName("foo.bar." + name, name); 50 } 51 52 static ResolveInfo createResolveInfo(int i, int userId) { 53 final ResolveInfo resolveInfo = new ResolveInfo(); 54 resolveInfo.activityInfo = createActivityInfo(i); 55 resolveInfo.targetUserId = userId; 56 return resolveInfo; 57 } 58 59 static ActivityInfo createActivityInfo(int i) { 60 ActivityInfo ai = new ActivityInfo(); 61 ai.name = "activity_name" + i; 62 ai.packageName = "foo_bar" + i; 63 ai.enabled = true; 64 ai.exported = true; 65 ai.permission = null; 66 ai.applicationInfo = createApplicationInfo(); 67 return ai; 68 } 69 70 static ApplicationInfo createApplicationInfo() { 71 ApplicationInfo ai = new ApplicationInfo(); 72 ai.name = "app_name"; 73 ai.packageName = "foo.bar"; 74 ai.enabled = true; 75 return ai; 76 } 77 78 static Intent createResolverIntent(int i) { 79 return new Intent("intentAction" + i); 80 } 81}