Search in sources :

Example 16 with ServiceInfo

use of android.content.pm.ServiceInfo in project platform_frameworks_base by android.

the class TextServicesManagerService method buildSpellCheckerMapLocked.

private static void buildSpellCheckerMapLocked(Context context, ArrayList<SpellCheckerInfo> list, HashMap<String, SpellCheckerInfo> map, TextServicesSettings settings) {
    list.clear();
    map.clear();
    final PackageManager pm = context.getPackageManager();
    // Note: We do not specify PackageManager.MATCH_ENCRYPTION_* flags here because the default
    // behavior of PackageManager is exactly what we want.  It by default picks up appropriate
    // services depending on the unlock state for the specified user.
    final List<ResolveInfo> services = pm.queryIntentServicesAsUser(new Intent(SpellCheckerService.SERVICE_INTERFACE), PackageManager.GET_META_DATA, settings.getCurrentUserId());
    final int N = services.size();
    for (int i = 0; i < N; ++i) {
        final ResolveInfo ri = services.get(i);
        final ServiceInfo si = ri.serviceInfo;
        final ComponentName compName = new ComponentName(si.packageName, si.name);
        if (!android.Manifest.permission.BIND_TEXT_SERVICE.equals(si.permission)) {
            Slog.w(TAG, "Skipping text service " + compName + ": it does not require the permission " + android.Manifest.permission.BIND_TEXT_SERVICE);
            continue;
        }
        if (DBG)
            Slog.d(TAG, "Add: " + compName);
        try {
            final SpellCheckerInfo sci = new SpellCheckerInfo(context, ri);
            if (sci.getSubtypeCount() <= 0) {
                Slog.w(TAG, "Skipping text service " + compName + ": it does not contain subtypes.");
                continue;
            }
            list.add(sci);
            map.put(sci.getId(), sci);
        } catch (XmlPullParserException e) {
            Slog.w(TAG, "Unable to load the spell checker " + compName, e);
        } catch (IOException e) {
            Slog.w(TAG, "Unable to load the spell checker " + compName, e);
        }
    }
    if (DBG) {
        Slog.d(TAG, "buildSpellCheckerMapLocked: " + list.size() + "," + map.size());
    }
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) ServiceInfo(android.content.pm.ServiceInfo) PackageManager(android.content.pm.PackageManager) Intent(android.content.Intent) ComponentName(android.content.ComponentName) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) IOException(java.io.IOException) SpellCheckerInfo(android.view.textservice.SpellCheckerInfo)

Example 17 with ServiceInfo

use of android.content.pm.ServiceInfo in project platform_frameworks_base by android.

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 18 with ServiceInfo

use of android.content.pm.ServiceInfo in project platform_frameworks_base by android.

the class NetworkScorerAppManagerTest method mockRecommendationServiceAvailable.

private void mockRecommendationServiceAvailable(final String packageName, int packageUid) {
    final ResolveInfo serviceInfo = new ResolveInfo();
    serviceInfo.serviceInfo = new ServiceInfo();
    serviceInfo.serviceInfo.name = ".RecommendationService";
    serviceInfo.serviceInfo.packageName = packageName;
    serviceInfo.serviceInfo.applicationInfo = new ApplicationInfo();
    serviceInfo.serviceInfo.applicationInfo.uid = packageUid;
    final int flags = 0;
    when(mMockPm.resolveService(Mockito.argThat(new ArgumentMatcher<Intent>() {

        @Override
        public boolean matchesObject(Object object) {
            Intent intent = (Intent) object;
            return NetworkScoreManager.ACTION_RECOMMEND_NETWORKS.equals(intent.getAction()) && packageName.equals(intent.getPackage());
        }
    }), Mockito.eq(flags))).thenReturn(serviceInfo);
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) ServiceInfo(android.content.pm.ServiceInfo) ArgumentMatcher(org.mockito.compat.ArgumentMatcher) ApplicationInfo(android.content.pm.ApplicationInfo) Intent(android.content.Intent)

Example 19 with ServiceInfo

use of android.content.pm.ServiceInfo in project platform_frameworks_base by android.

the class RemoteDisplayProviderWatcher method scanPackages.

private void scanPackages() {
    if (!mRunning) {
        return;
    }
    // Add providers for all new services.
    // Reorder the list so that providers left at the end will be the ones to remove.
    int targetIndex = 0;
    Intent intent = new Intent(RemoteDisplayState.SERVICE_INTERFACE);
    for (ResolveInfo resolveInfo : mPackageManager.queryIntentServicesAsUser(intent, 0, mUserId)) {
        ServiceInfo serviceInfo = resolveInfo.serviceInfo;
        if (serviceInfo != null && verifyServiceTrusted(serviceInfo)) {
            int sourceIndex = findProvider(serviceInfo.packageName, serviceInfo.name);
            if (sourceIndex < 0) {
                RemoteDisplayProviderProxy provider = new RemoteDisplayProviderProxy(mContext, new ComponentName(serviceInfo.packageName, serviceInfo.name), mUserId);
                provider.start();
                mProviders.add(targetIndex++, provider);
                mCallback.addProvider(provider);
            } else if (sourceIndex >= targetIndex) {
                RemoteDisplayProviderProxy provider = mProviders.get(sourceIndex);
                // restart the provider if needed
                provider.start();
                provider.rebindIfDisconnected();
                Collections.swap(mProviders, sourceIndex, targetIndex++);
            }
        }
    }
    // Remove providers for missing services.
    if (targetIndex < mProviders.size()) {
        for (int i = mProviders.size() - 1; i >= targetIndex; i--) {
            RemoteDisplayProviderProxy provider = mProviders.get(i);
            mCallback.removeProvider(provider);
            mProviders.remove(provider);
            provider.stop();
        }
    }
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) ServiceInfo(android.content.pm.ServiceInfo) Intent(android.content.Intent) ComponentName(android.content.ComponentName)

Example 20 with ServiceInfo

use of android.content.pm.ServiceInfo in project platform_frameworks_base by android.

the class ZenModeHelper method getServiceInfo.

private ServiceInfo getServiceInfo(ComponentName owner) {
    Intent queryIntent = new Intent();
    queryIntent.setComponent(owner);
    List<ResolveInfo> installedServices = mPm.queryIntentServicesAsUser(queryIntent, PackageManager.GET_SERVICES | PackageManager.GET_META_DATA, UserHandle.getCallingUserId());
    if (installedServices != null) {
        for (int i = 0, count = installedServices.size(); i < count; i++) {
            ResolveInfo resolveInfo = installedServices.get(i);
            ServiceInfo info = resolveInfo.serviceInfo;
            if (mServiceConfig.bindPermission.equals(info.permission)) {
                return info;
            }
        }
    }
    return null;
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) ServiceInfo(android.content.pm.ServiceInfo) Intent(android.content.Intent)

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