Search in sources :

Example 66 with ServiceInfo

use of android.content.pm.ServiceInfo in project DroidPlugin by DroidPluginTeam.

the class ServcesManager method stopServiceToken.

public boolean stopServiceToken(ComponentName cn, IBinder token, int startId) throws Exception {
    Service service = mTokenServices.get(token);
    if (service != null) {
        Integer lastId = mServiceTaskIds.get(token);
        if (lastId == null) {
            return false;
        }
        if (startId != lastId) {
            return false;
        }
        Intent intent = new Intent();
        intent.setComponent(cn);
        ServiceInfo info = PluginManager.getInstance().resolveServiceInfo(intent, 0);
        if (info != null) {
            handleOnUnbindOne(intent);
            handleOnDestroyOne(info);
            return true;
        }
    }
    return false;
}
Also used : ServiceInfo(android.content.pm.ServiceInfo) Service(android.app.Service) Intent(android.content.Intent)

Example 67 with ServiceInfo

use of android.content.pm.ServiceInfo in project DroidPlugin by DroidPluginTeam.

the class IntentMatcher method queryIntentServiceForPackage.

private static void queryIntentServiceForPackage(Context context, PluginPackageParser packageParser, Intent intent, int flags, List<ResolveInfo> outList) throws Exception {
    List<ServiceInfo> serviceInfos = packageParser.getServices();
    if (serviceInfos != null && serviceInfos.size() >= 0) {
        for (ServiceInfo serviceInfo : serviceInfos) {
            ComponentName className = new ComponentName(serviceInfo.packageName, serviceInfo.name);
            List<IntentFilter> intentFilters = packageParser.getServiceIntentFilter(className);
            if (intentFilters != null && intentFilters.size() > 0) {
                for (IntentFilter intentFilter : intentFilters) {
                    int match = intentFilter.match(context.getContentResolver(), intent, true, "");
                    if (match >= 0) {
                        ServiceInfo flagServiceInfo = packageParser.getServiceInfo(new ComponentName(serviceInfo.packageName, serviceInfo.name), flags);
                        if ((flags & PackageManager.MATCH_DEFAULT_ONLY) != 0) {
                            if (intentFilter.hasCategory(Intent.CATEGORY_DEFAULT)) {
                                ResolveInfo resolveInfo = newResolveInfo(flagServiceInfo, intentFilter);
                                resolveInfo.match = match;
                                resolveInfo.isDefault = true;
                                outList.add(resolveInfo);
                            } else {
                            //只是匹配默认。这里也算匹配不上。
                            }
                        } else {
                            ResolveInfo resolveInfo = newResolveInfo(flagServiceInfo, intentFilter);
                            resolveInfo.match = match;
                            resolveInfo.isDefault = false;
                            outList.add(resolveInfo);
                        }
                    }
                }
                if (outList.size() <= 0) {
                //没有在插件包中找到IntentFilter匹配的Service
                }
            } else {
            //该插件包中没有具有IntentFilter的Service
            }
        }
    } else {
    //该插件apk包中没有Service
    }
}
Also used : ServiceInfo(android.content.pm.ServiceInfo) ResolveInfo(android.content.pm.ResolveInfo) IntentFilter(android.content.IntentFilter) ComponentName(android.content.ComponentName)

Example 68 with ServiceInfo

use of android.content.pm.ServiceInfo in project android_frameworks_base by DirtyUnicorns.

the class MidiService method addPackageDeviceServers.

private void addPackageDeviceServers(String packageName) {
    PackageInfo info;
    try {
        info = mPackageManager.getPackageInfo(packageName, PackageManager.GET_SERVICES | PackageManager.GET_META_DATA);
    } catch (PackageManager.NameNotFoundException e) {
        Log.e(TAG, "handlePackageUpdate could not find package " + packageName, e);
        return;
    }
    ServiceInfo[] services = info.services;
    if (services == null)
        return;
    for (int i = 0; i < services.length; i++) {
        addPackageDeviceServer(services[i]);
    }
}
Also used : ServiceInfo(android.content.pm.ServiceInfo) PackageManager(android.content.pm.PackageManager) PackageInfo(android.content.pm.PackageInfo)

Example 69 with ServiceInfo

use of android.content.pm.ServiceInfo in project android_frameworks_base by DirtyUnicorns.

the class MetaDataTest method testServiceWithData.

@SmallTest
public void testServiceWithData() throws Exception {
    ComponentName cn = new ComponentName(mContext, LocalService.class);
    ServiceInfo si = mContext.getPackageManager().getServiceInfo(cn, PackageManager.GET_META_DATA);
    checkMetaData(cn, si);
    si = mContext.getPackageManager().getServiceInfo(cn, 0);
    assertNull("Meta data returned when not requested", si.metaData);
}
Also used : ServiceInfo(android.content.pm.ServiceInfo) ComponentName(android.content.ComponentName) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 70 with ServiceInfo

use of android.content.pm.ServiceInfo in project android_frameworks_base by DirtyUnicorns.

the class MidiService method onUnlockUser.

private void onUnlockUser() {
    mPackageMonitor.register(mContext, null, true);
    Intent intent = new Intent(MidiDeviceService.SERVICE_INTERFACE);
    List<ResolveInfo> resolveInfos = mPackageManager.queryIntentServices(intent, PackageManager.GET_META_DATA);
    if (resolveInfos != null) {
        int count = resolveInfos.size();
        for (int i = 0; i < count; i++) {
            ServiceInfo serviceInfo = resolveInfos.get(i).serviceInfo;
            if (serviceInfo != null) {
                addPackageDeviceServer(serviceInfo);
            }
        }
    }
    PackageInfo info;
    try {
        info = mPackageManager.getPackageInfo(MidiManager.BLUETOOTH_MIDI_SERVICE_PACKAGE, 0);
    } catch (PackageManager.NameNotFoundException e) {
        info = null;
    }
    if (info != null && info.applicationInfo != null) {
        mBluetoothServiceUid = info.applicationInfo.uid;
    } else {
        mBluetoothServiceUid = -1;
    }
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) ServiceInfo(android.content.pm.ServiceInfo) PackageManager(android.content.pm.PackageManager) PackageInfo(android.content.pm.PackageInfo) Intent(android.content.Intent)

Aggregations

ServiceInfo (android.content.pm.ServiceInfo)238 ResolveInfo (android.content.pm.ResolveInfo)120 Intent (android.content.Intent)99 ComponentName (android.content.ComponentName)96 PackageManager (android.content.pm.PackageManager)62 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)18 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)16 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