use of android.content.pm.ServiceInfo in project platform_frameworks_base by android.
the class InputMethodInfo method buildDummyResolveInfo.
private static ResolveInfo buildDummyResolveInfo(String packageName, String className, CharSequence label) {
ResolveInfo ri = new ResolveInfo();
ServiceInfo si = new ServiceInfo();
ApplicationInfo ai = new ApplicationInfo();
ai.packageName = packageName;
ai.enabled = true;
si.applicationInfo = ai;
si.enabled = true;
si.packageName = packageName;
si.name = className;
si.exported = true;
si.nonLocalizedLabel = label;
ri.serviceInfo = si;
return ri;
}
use of android.content.pm.ServiceInfo in project leakcanary by square.
the class LeakCanaryInternals method isInServiceProcess.
public static boolean isInServiceProcess(Context context, Class<? extends Service> serviceClass) {
PackageManager packageManager = context.getPackageManager();
PackageInfo packageInfo;
try {
packageInfo = packageManager.getPackageInfo(context.getPackageName(), GET_SERVICES);
} catch (Exception e) {
CanaryLog.d(e, "Could not get package info for %s", context.getPackageName());
return false;
}
String mainProcess = packageInfo.applicationInfo.processName;
ComponentName component = new ComponentName(context, serviceClass);
ServiceInfo serviceInfo;
try {
serviceInfo = packageManager.getServiceInfo(component, 0);
} catch (PackageManager.NameNotFoundException ignored) {
// Service is disabled.
return false;
}
if (serviceInfo.processName.equals(mainProcess)) {
CanaryLog.d("Did not expect service %s to run in main process %s", serviceClass, mainProcess);
// Technically we are in the service process, but we're not in the service dedicated process.
return false;
}
int myPid = android.os.Process.myPid();
ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
ActivityManager.RunningAppProcessInfo myProcess = null;
List<ActivityManager.RunningAppProcessInfo> runningProcesses = activityManager.getRunningAppProcesses();
if (runningProcesses != null) {
for (ActivityManager.RunningAppProcessInfo process : runningProcesses) {
if (process.pid == myPid) {
myProcess = process;
break;
}
}
}
if (myProcess == null) {
CanaryLog.d("Could not find running process for %d", myPid);
return false;
}
return myProcess.processName.equals(serviceInfo.processName);
}
use of android.content.pm.ServiceInfo in project VirtualApp by asLody.
the class StartService method call.
@Override
public Object call(Object who, Method method, Object... args) throws Throwable {
IInterface appThread = (IInterface) args[0];
Intent service = (Intent) args[1];
String resolvedType = (String) args[2];
if (service.getComponent() != null && getHostPkg().equals(service.getComponent().getPackageName())) {
// for server process
return method.invoke(who, args);
}
int userId = VUserHandle.myUserId();
if (service.getBooleanExtra("_VA_|_from_inner_", false)) {
service = service.getParcelableExtra("_VA_|_intent_");
userId = service.getIntExtra("_VA_|_user_id_", userId);
} else {
if (isServerProcess()) {
userId = service.getIntExtra("_VA_|_user_id_", VUserHandle.USER_NULL);
}
}
service.setDataAndType(service.getData(), resolvedType);
ServiceInfo serviceInfo = VirtualCore.get().resolveServiceInfo(service, VUserHandle.myUserId());
if (serviceInfo != null) {
return VActivityManager.get().startService(appThread, service, resolvedType, userId);
}
return method.invoke(who, args);
}
use of android.content.pm.ServiceInfo in project VirtualApp by asLody.
the class GetServiceInfo method call.
@Override
public Object call(Object who, Method method, Object... args) throws Throwable {
ComponentName componentName = (ComponentName) args[0];
int flags = (int) args[1];
if ((flags & GET_DISABLED_COMPONENTS) == 0) {
flags |= GET_DISABLED_COMPONENTS;
}
int userId = VUserHandle.myUserId();
ServiceInfo info = VPackageManager.get().getServiceInfo(componentName, flags, userId);
if (info != null) {
return info;
}
info = (ServiceInfo) method.invoke(who, args);
if (info != null) {
if (getHostPkg().equals(info.packageName) || ComponentUtils.isSystemApp(info.applicationInfo)) {
return info;
}
}
return null;
}
use of android.content.pm.ServiceInfo in project VirtualApp by asLody.
the class VirtualCore method resolveServiceInfo.
public ServiceInfo resolveServiceInfo(Intent intent, int userId) {
ServiceInfo serviceInfo = null;
ResolveInfo resolveInfo = VPackageManager.get().resolveService(intent, intent.getType(), 0, userId);
if (resolveInfo != null) {
serviceInfo = resolveInfo.serviceInfo;
}
return serviceInfo;
}
Aggregations