Search in sources :

Example 86 with ServiceInfo

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

the class InputMethodManagerService method buildInputMethodListLocked.

void buildInputMethodListLocked(boolean resetDefaultEnabledIme) {
    if (DEBUG) {
        Slog.d(TAG, "--- re-buildInputMethodList reset = " + resetDefaultEnabledIme + " \n ------ caller=" + Debug.getCallers(10));
    }
    mMethodList.clear();
    mMethodMap.clear();
    // Use for queryIntentServicesAsUser
    final PackageManager pm = mContext.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(InputMethod.SERVICE_INTERFACE), PackageManager.GET_META_DATA | PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS, mSettings.getCurrentUserId());
    final HashMap<String, List<InputMethodSubtype>> additionalSubtypes = mFileManager.getAllAdditionalInputMethodSubtypes();
    for (int i = 0; i < services.size(); ++i) {
        ResolveInfo ri = services.get(i);
        ServiceInfo si = ri.serviceInfo;
        ComponentName compName = new ComponentName(si.packageName, si.name);
        if (!android.Manifest.permission.BIND_INPUT_METHOD.equals(si.permission)) {
            Slog.w(TAG, "Skipping input method " + compName + ": it does not require the permission " + android.Manifest.permission.BIND_INPUT_METHOD);
            continue;
        }
        if (DEBUG)
            Slog.d(TAG, "Checking " + compName);
        try {
            InputMethodInfo p = new InputMethodInfo(mContext, ri, additionalSubtypes);
            mMethodList.add(p);
            final String id = p.getId();
            mMethodMap.put(id, p);
            if (DEBUG) {
                Slog.d(TAG, "Found an input method " + p);
            }
        } catch (Exception e) {
            Slog.wtf(TAG, "Unable to load input method " + compName, e);
        }
    }
    // TODO: The following code should find better place to live.
    if (!resetDefaultEnabledIme) {
        boolean enabledImeFound = false;
        final List<InputMethodInfo> enabledImes = mSettings.getEnabledInputMethodListLocked();
        final int N = enabledImes.size();
        for (int i = 0; i < N; ++i) {
            final InputMethodInfo imi = enabledImes.get(i);
            if (mMethodList.contains(imi)) {
                enabledImeFound = true;
                break;
            }
        }
        if (!enabledImeFound) {
            Slog.i(TAG, "All the enabled IMEs are gone. Reset default enabled IMEs.");
            resetDefaultEnabledIme = true;
            resetSelectedInputMethodAndSubtypeLocked("");
        }
    }
    if (resetDefaultEnabledIme) {
        final ArrayList<InputMethodInfo> defaultEnabledIme = InputMethodUtils.getDefaultEnabledImes(mContext, mSystemReady, mMethodList);
        final int N = defaultEnabledIme.size();
        for (int i = 0; i < N; ++i) {
            final InputMethodInfo imi = defaultEnabledIme.get(i);
            if (DEBUG) {
                Slog.d(TAG, "--- enable ime = " + imi);
            }
            setInputMethodEnabledLocked(imi.getId(), true);
        }
    }
    final String defaultImiId = mSettings.getSelectedInputMethod();
    if (!TextUtils.isEmpty(defaultImiId)) {
        if (!mMethodMap.containsKey(defaultImiId)) {
            Slog.w(TAG, "Default IME is uninstalled. Choose new default IME.");
            if (chooseNewDefaultIMELocked()) {
                updateInputMethodsFromSettingsLocked(true);
            }
        } else {
            // Double check that the default IME is certainly enabled.
            setInputMethodEnabledLocked(defaultImiId, true);
        }
    }
    // Here is not the perfect place to reset the switching controller. Ideally
    // mSwitchingController and mSettings should be able to share the same state.
    // TODO: Make sure that mSwitchingController and mSettings are sharing the
    // the same enabled IMEs list.
    mSwitchingController.resetCircularListLocked(mContext);
}
Also used : PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) InputMethodInfo(android.view.inputmethod.InputMethodInfo) InvalidParameterException(java.security.InvalidParameterException) RemoteException(android.os.RemoteException) IOException(java.io.IOException) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) ResolveInfo(android.content.pm.ResolveInfo) ServiceInfo(android.content.pm.ServiceInfo) PackageManager(android.content.pm.PackageManager) IPackageManager(android.content.pm.IPackageManager) ArrayList(java.util.ArrayList) List(java.util.List) LocaleList(android.os.LocaleList) ComponentName(android.content.ComponentName)

Example 87 with ServiceInfo

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

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)

Example 88 with ServiceInfo

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

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

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

the class AccessibilityServiceInfo method loadDescription.

/**
     * The localized description of the accessibility service.
     * <p>
     *    <strong>Statically set from
     *    {@link AccessibilityService#SERVICE_META_DATA meta-data}.</strong>
     * </p>
     * @return The localized description.
     */
public String loadDescription(PackageManager packageManager) {
    if (mDescriptionResId == 0) {
        return mNonLocalizedDescription;
    }
    ServiceInfo serviceInfo = mResolveInfo.serviceInfo;
    CharSequence description = packageManager.getText(serviceInfo.packageName, mDescriptionResId, serviceInfo.applicationInfo);
    if (description != null) {
        return description.toString().trim();
    }
    return null;
}
Also used : ServiceInfo(android.content.pm.ServiceInfo)

Example 90 with ServiceInfo

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

the class ActiveServices method retrieveServiceLocked.

private ServiceLookupResult retrieveServiceLocked(Intent service, String resolvedType, String callingPackage, int callingPid, int callingUid, int userId, boolean createIfNeeded, boolean callingFromFg, boolean isBindExternal) {
    ServiceRecord r = null;
    if (DEBUG_SERVICE)
        Slog.v(TAG_SERVICE, "retrieveServiceLocked: " + service + " type=" + resolvedType + " callingUid=" + callingUid);
    userId = mAm.mUserController.handleIncomingUser(callingPid, callingUid, userId, false, ActivityManagerService.ALLOW_NON_FULL_IN_PROFILE, "service", null);
    ServiceMap smap = getServiceMap(userId);
    final ComponentName comp = service.getComponent();
    if (comp != null) {
        r = smap.mServicesByName.get(comp);
    }
    if (r == null && !isBindExternal) {
        Intent.FilterComparison filter = new Intent.FilterComparison(service);
        r = smap.mServicesByIntent.get(filter);
    }
    if (r != null && (r.serviceInfo.flags & ServiceInfo.FLAG_EXTERNAL_SERVICE) != 0 && !callingPackage.equals(r.packageName)) {
        // If an external service is running within its own package, other packages
        // should not bind to that instance.
        r = null;
    }
    if (r == null) {
        try {
            // TODO: come back and remove this assumption to triage all services
            ResolveInfo rInfo = AppGlobals.getPackageManager().resolveService(service, resolvedType, ActivityManagerService.STOCK_PM_FLAGS | PackageManager.MATCH_DEBUG_TRIAGED_MISSING, userId);
            ServiceInfo sInfo = rInfo != null ? rInfo.serviceInfo : null;
            if (sInfo == null) {
                Slog.w(TAG_SERVICE, "Unable to start service " + service + " U=" + userId + ": not found");
                return null;
            }
            ComponentName name = new ComponentName(sInfo.applicationInfo.packageName, sInfo.name);
            if ((sInfo.flags & ServiceInfo.FLAG_EXTERNAL_SERVICE) != 0) {
                if (isBindExternal) {
                    if (!sInfo.exported) {
                        throw new SecurityException("BIND_EXTERNAL_SERVICE failed, " + name + " is not exported");
                    }
                    if ((sInfo.flags & ServiceInfo.FLAG_ISOLATED_PROCESS) == 0) {
                        throw new SecurityException("BIND_EXTERNAL_SERVICE failed, " + name + " is not an isolatedProcess");
                    }
                    // Run the service under the calling package's application.
                    ApplicationInfo aInfo = AppGlobals.getPackageManager().getApplicationInfo(callingPackage, ActivityManagerService.STOCK_PM_FLAGS, userId);
                    if (aInfo == null) {
                        throw new SecurityException("BIND_EXTERNAL_SERVICE failed, " + "could not resolve client package " + callingPackage);
                    }
                    sInfo = new ServiceInfo(sInfo);
                    sInfo.applicationInfo = new ApplicationInfo(sInfo.applicationInfo);
                    sInfo.applicationInfo.packageName = aInfo.packageName;
                    sInfo.applicationInfo.uid = aInfo.uid;
                    name = new ComponentName(aInfo.packageName, name.getClassName());
                    service.setComponent(name);
                } else {
                    throw new SecurityException("BIND_EXTERNAL_SERVICE required for " + name);
                }
            } else if (isBindExternal) {
                throw new SecurityException("BIND_EXTERNAL_SERVICE failed, " + name + " is not an externalService");
            }
            if (userId > 0) {
                if (mAm.isSingleton(sInfo.processName, sInfo.applicationInfo, sInfo.name, sInfo.flags) && mAm.isValidSingletonCall(callingUid, sInfo.applicationInfo.uid)) {
                    userId = 0;
                    smap = getServiceMap(0);
                }
                sInfo = new ServiceInfo(sInfo);
                sInfo.applicationInfo = mAm.getAppInfoForUser(sInfo.applicationInfo, userId);
            }
            r = smap.mServicesByName.get(name);
            if (r == null && createIfNeeded) {
                Intent.FilterComparison filter = new Intent.FilterComparison(service.cloneFilter());
                ServiceRestarter res = new ServiceRestarter();
                BatteryStatsImpl.Uid.Pkg.Serv ss = null;
                BatteryStatsImpl stats = mAm.mBatteryStatsService.getActiveStatistics();
                synchronized (stats) {
                    ss = stats.getServiceStatsLocked(sInfo.applicationInfo.uid, sInfo.packageName, sInfo.name);
                }
                r = new ServiceRecord(mAm, ss, name, filter, sInfo, callingFromFg, res);
                res.setService(r);
                smap.mServicesByName.put(name, r);
                smap.mServicesByIntent.put(filter, r);
                // Make sure this component isn't in the pending list.
                for (int i = mPendingServices.size() - 1; i >= 0; i--) {
                    ServiceRecord pr = mPendingServices.get(i);
                    if (pr.serviceInfo.applicationInfo.uid == sInfo.applicationInfo.uid && pr.name.equals(name)) {
                        mPendingServices.remove(i);
                    }
                }
            }
        } catch (RemoteException ex) {
        // pm is in same process, this will never happen.
        }
    }
    if (r != null) {
        if (mAm.checkComponentPermission(r.permission, callingPid, callingUid, r.appInfo.uid, r.exported) != PackageManager.PERMISSION_GRANTED) {
            if (!r.exported) {
                Slog.w(TAG, "Permission Denial: Accessing service " + r.name + " from pid=" + callingPid + ", uid=" + callingUid + " that is not exported from uid " + r.appInfo.uid);
                return new ServiceLookupResult(null, "not exported from uid " + r.appInfo.uid);
            }
            Slog.w(TAG, "Permission Denial: Accessing service " + r.name + " from pid=" + callingPid + ", uid=" + callingUid + " requires " + r.permission);
            return new ServiceLookupResult(null, r.permission);
        } else if (r.permission != null && callingPackage != null) {
            final int opCode = AppOpsManager.permissionToOpCode(r.permission);
            if (opCode != AppOpsManager.OP_NONE && mAm.mAppOpsService.noteOperation(opCode, callingUid, callingPackage) != AppOpsManager.MODE_ALLOWED) {
                Slog.w(TAG, "Appop Denial: Accessing service " + r.name + " from pid=" + callingPid + ", uid=" + callingUid + " requires appop " + AppOpsManager.opToName(opCode));
                return null;
            }
        }
        if (!mAm.mIntentFirewall.checkService(r.name, service, callingUid, callingPid, resolvedType, r.appInfo)) {
            return null;
        }
        return new ServiceLookupResult(r, null);
    }
    return null;
}
Also used : ApplicationInfo(android.content.pm.ApplicationInfo) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) BatteryStatsImpl(com.android.internal.os.BatteryStatsImpl) ResolveInfo(android.content.pm.ResolveInfo) ServiceInfo(android.content.pm.ServiceInfo) ComponentName(android.content.ComponentName) RemoteException(android.os.RemoteException)

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