Search in sources :

Example 26 with ServiceInfo

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;
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) ServiceInfo(android.content.pm.ServiceInfo) ApplicationInfo(android.content.pm.ApplicationInfo)

Example 27 with ServiceInfo

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);
}
Also used : ServiceInfo(android.content.pm.ServiceInfo) PackageManager(android.content.pm.PackageManager) PackageInfo(android.content.pm.PackageInfo) ComponentName(android.content.ComponentName) ActivityManager(android.app.ActivityManager)

Example 28 with ServiceInfo

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);
}
Also used : ServiceInfo(android.content.pm.ServiceInfo) IInterface(android.os.IInterface) Intent(android.content.Intent)

Example 29 with ServiceInfo

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;
}
Also used : ServiceInfo(android.content.pm.ServiceInfo) ComponentName(android.content.ComponentName)

Example 30 with ServiceInfo

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;
}
Also used : ServiceInfo(android.content.pm.ServiceInfo) ResolveInfo(android.content.pm.ResolveInfo)

Aggregations

ServiceInfo (android.content.pm.ServiceInfo)236 ResolveInfo (android.content.pm.ResolveInfo)120 Intent (android.content.Intent)99 ComponentName (android.content.ComponentName)95 PackageManager (android.content.pm.PackageManager)60 RemoteException (android.os.RemoteException)48 PendingIntent (android.app.PendingIntent)37 ApplicationInfo (android.content.pm.ApplicationInfo)35 AccessibilityServiceInfo (android.accessibilityservice.AccessibilityServiceInfo)32 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)29 IOException (java.io.IOException)28 ArrayList (java.util.ArrayList)27 InputMethodInfo (android.view.inputmethod.InputMethodInfo)21 PackageInfo (android.content.pm.PackageInfo)16 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)14 Service (android.app.Service)13 Point (android.graphics.Point)11 SpellCheckerInfo (android.view.textservice.SpellCheckerInfo)11 ArraySet (android.util.ArraySet)10 ActivityInfo (android.content.pm.ActivityInfo)9