Search in sources :

Example 31 with ServiceInfo

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

the class EnableAccessibilityController method enableAccessibility.

private void enableAccessibility() {
    List<AccessibilityServiceInfo> services = getInstalledSpeakingAccessibilityServices(mContext);
    if (services.isEmpty()) {
        return;
    }
    boolean keyguardLocked = false;
    try {
        keyguardLocked = mWindowManager.isKeyguardLocked();
    } catch (RemoteException re) {
    /* ignore */
    }
    final boolean hasMoreThanOneUser = mUserManager.getUsers().size() > 1;
    AccessibilityServiceInfo service = services.get(0);
    boolean enableTouchExploration = (service.flags & AccessibilityServiceInfo.FLAG_REQUEST_TOUCH_EXPLORATION_MODE) != 0;
    // Try to find a service supporting explore by touch.
    if (!enableTouchExploration) {
        final int serviceCount = services.size();
        for (int i = 1; i < serviceCount; i++) {
            AccessibilityServiceInfo candidate = services.get(i);
            if ((candidate.flags & AccessibilityServiceInfo.FLAG_REQUEST_TOUCH_EXPLORATION_MODE) != 0) {
                enableTouchExploration = true;
                service = candidate;
                break;
            }
        }
    }
    ServiceInfo serviceInfo = service.getResolveInfo().serviceInfo;
    ComponentName componentName = new ComponentName(serviceInfo.packageName, serviceInfo.name);
    if (!keyguardLocked || !hasMoreThanOneUser) {
        final int userId = ActivityManager.getCurrentUser();
        String enabledServiceString = componentName.flattenToString();
        ContentResolver resolver = mContext.getContentResolver();
        // Enable one speaking accessibility service.
        Settings.Secure.putStringForUser(resolver, Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES, enabledServiceString, userId);
        // Allow the services we just enabled to toggle touch exploration.
        Settings.Secure.putStringForUser(resolver, Settings.Secure.TOUCH_EXPLORATION_GRANTED_ACCESSIBILITY_SERVICES, enabledServiceString, userId);
        // Enable touch exploration.
        if (enableTouchExploration) {
            Settings.Secure.putIntForUser(resolver, Settings.Secure.TOUCH_EXPLORATION_ENABLED, 1, userId);
        }
        // Enable accessibility script injection (AndroidVox) for web content.
        Settings.Secure.putIntForUser(resolver, Settings.Secure.ACCESSIBILITY_SCRIPT_INJECTION, 1, userId);
        // Turn on accessibility mode last.
        Settings.Secure.putIntForUser(resolver, Settings.Secure.ACCESSIBILITY_ENABLED, 1, userId);
    } else if (keyguardLocked) {
        try {
            mAccessibilityManager.temporaryEnableAccessibilityStateUntilKeyguardRemoved(componentName, enableTouchExploration);
        } catch (RemoteException re) {
        /* ignore */
        }
    }
}
Also used : AccessibilityServiceInfo(android.accessibilityservice.AccessibilityServiceInfo) ServiceInfo(android.content.pm.ServiceInfo) AccessibilityServiceInfo(android.accessibilityservice.AccessibilityServiceInfo) ComponentName(android.content.ComponentName) RemoteException(android.os.RemoteException) ContentResolver(android.content.ContentResolver)

Example 32 with ServiceInfo

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

the class InputMethodManagerService method buildInputMethodListLocked.

void buildInputMethodListLocked(ArrayList<InputMethodInfo> list, HashMap<String, InputMethodInfo> map, boolean resetDefaultEnabledIme) {
    if (DEBUG) {
        Slog.d(TAG, "--- re-buildInputMethodList reset = " + resetDefaultEnabledIme + " \n ------ \n" + getStackTrace());
    }
    list.clear();
    map.clear();
    // Use for queryIntentServicesAsUser
    final PackageManager pm = mContext.getPackageManager();
    String disabledSysImes = mSettings.getDisabledSystemInputMethods();
    if (disabledSysImes == null)
        disabledSysImes = "";
    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);
            list.add(p);
            final String id = p.getId();
            map.put(id, p);
            if (DEBUG) {
                Slog.d(TAG, "Found an input method " + p);
            }
        } catch (XmlPullParserException e) {
            Slog.w(TAG, "Unable to load input method " + compName, e);
        } catch (IOException e) {
            Slog.w(TAG, "Unable to load input method " + compName, e);
        }
    }
    if (resetDefaultEnabledIme) {
        final ArrayList<InputMethodInfo> defaultEnabledIme = InputMethodUtils.getDefaultEnabledImes(mContext, mSystemReady, list);
        for (int i = 0; i < defaultEnabledIme.size(); ++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 (!map.containsKey(defaultImiId)) {
            Slog.w(TAG, "Default IME is uninstalled. Choose new default IME.");
            if (chooseNewDefaultIMELocked()) {
                updateFromSettingsLocked(true);
            }
        } else {
            // Double check that the default IME is certainly enabled.
            setInputMethodEnabledLocked(defaultImiId, true);
        }
    }
}
Also used : PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) IOException(java.io.IOException) InputMethodInfo(android.view.inputmethod.InputMethodInfo) 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) ComponentName(android.content.ComponentName) XmlPullParserException(org.xmlpull.v1.XmlPullParserException)

Example 33 with ServiceInfo

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

the class RecognitionManagerService method findAvailRecognizer.

ComponentName findAvailRecognizer(String prefPackage, int userHandle) {
    List<ResolveInfo> available = mContext.getPackageManager().queryIntentServicesAsUser(new Intent(RecognitionService.SERVICE_INTERFACE), 0, userHandle);
    int numAvailable = available.size();
    if (numAvailable == 0) {
        Slog.w(TAG, "no available voice recognition services found for user " + userHandle);
        return null;
    } else {
        if (prefPackage != null) {
            for (int i = 0; i < numAvailable; i++) {
                ServiceInfo serviceInfo = available.get(i).serviceInfo;
                if (prefPackage.equals(serviceInfo.packageName)) {
                    return new ComponentName(serviceInfo.packageName, serviceInfo.name);
                }
            }
        }
        if (numAvailable > 1) {
            Slog.w(TAG, "more than one voice recognition service found, picking first");
        }
        ServiceInfo serviceInfo = available.get(0).serviceInfo;
        return new ComponentName(serviceInfo.packageName, serviceInfo.name);
    }
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) ServiceInfo(android.content.pm.ServiceInfo) Intent(android.content.Intent) ComponentName(android.content.ComponentName)

Example 34 with ServiceInfo

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

the class NotificationManagerService method disableNonexistentListeners.

/**
     * Remove notification access for any services that no longer exist.
     */
void disableNonexistentListeners() {
    int currentUser = ActivityManager.getCurrentUser();
    String flatIn = Settings.Secure.getStringForUser(mContext.getContentResolver(), Settings.Secure.ENABLED_NOTIFICATION_LISTENERS, currentUser);
    if (!TextUtils.isEmpty(flatIn)) {
        if (DBG)
            Slog.v(TAG, "flat before: " + flatIn);
        PackageManager pm = mContext.getPackageManager();
        List<ResolveInfo> installedServices = pm.queryIntentServicesAsUser(new Intent(NotificationListenerService.SERVICE_INTERFACE), PackageManager.GET_SERVICES | PackageManager.GET_META_DATA, currentUser);
        Set<ComponentName> installed = new HashSet<ComponentName>();
        for (int i = 0, count = installedServices.size(); i < count; i++) {
            ResolveInfo resolveInfo = installedServices.get(i);
            ServiceInfo info = resolveInfo.serviceInfo;
            if (!android.Manifest.permission.BIND_NOTIFICATION_LISTENER_SERVICE.equals(info.permission)) {
                Slog.w(TAG, "Skipping notification listener service " + info.packageName + "/" + info.name + ": it does not require the permission " + android.Manifest.permission.BIND_NOTIFICATION_LISTENER_SERVICE);
                continue;
            }
            installed.add(new ComponentName(info.packageName, info.name));
        }
        String flatOut = "";
        if (!installed.isEmpty()) {
            String[] enabled = flatIn.split(ENABLED_NOTIFICATION_LISTENERS_SEPARATOR);
            ArrayList<String> remaining = new ArrayList<String>(enabled.length);
            for (int i = 0; i < enabled.length; i++) {
                ComponentName enabledComponent = ComponentName.unflattenFromString(enabled[i]);
                if (installed.contains(enabledComponent)) {
                    remaining.add(enabled[i]);
                }
            }
            flatOut = TextUtils.join(ENABLED_NOTIFICATION_LISTENERS_SEPARATOR, remaining);
        }
        if (DBG)
            Slog.v(TAG, "flat after: " + flatOut);
        if (!flatIn.equals(flatOut)) {
            Settings.Secure.putStringForUser(mContext.getContentResolver(), Settings.Secure.ENABLED_NOTIFICATION_LISTENERS, flatOut, currentUser);
        }
    }
}
Also used : ArrayList(java.util.ArrayList) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) ResolveInfo(android.content.pm.ResolveInfo) ServiceInfo(android.content.pm.ServiceInfo) PackageManager(android.content.pm.PackageManager) ComponentName(android.content.ComponentName) HashSet(java.util.HashSet)

Example 35 with ServiceInfo

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

the class ActiveServices method retrieveServiceLocked.

private ServiceLookupResult retrieveServiceLocked(Intent service, String resolvedType, int callingPid, int callingUid, int userId, boolean createIfNeeded) {
    ServiceRecord r = null;
    if (DEBUG_SERVICE)
        Slog.v(TAG, "retrieveServiceLocked: " + service + " type=" + resolvedType + " callingUid=" + callingUid);
    userId = mAm.handleIncomingUser(callingPid, callingUid, userId, false, true, "service", null);
    if (service.getComponent() != null) {
        r = mServiceMap.getServiceByName(service.getComponent(), userId);
    }
    if (r == null) {
        Intent.FilterComparison filter = new Intent.FilterComparison(service);
        r = mServiceMap.getServiceByIntent(filter, userId);
    }
    if (r == null) {
        try {
            ResolveInfo rInfo = AppGlobals.getPackageManager().resolveService(service, resolvedType, ActivityManagerService.STOCK_PM_FLAGS, userId);
            ServiceInfo sInfo = rInfo != null ? rInfo.serviceInfo : null;
            if (sInfo == null) {
                Slog.w(TAG, "Unable to start service " + service + " U=" + userId + ": not found");
                return null;
            }
            ComponentName name = new ComponentName(sInfo.applicationInfo.packageName, sInfo.name);
            if (userId > 0) {
                if (mAm.isSingleton(sInfo.processName, sInfo.applicationInfo, sInfo.name, sInfo.flags)) {
                    userId = 0;
                }
                sInfo = new ServiceInfo(sInfo);
                sInfo.applicationInfo = mAm.getAppInfoForUser(sInfo.applicationInfo, userId);
            }
            r = mServiceMap.getServiceByName(name, userId);
            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, res);
                res.setService(r);
                mServiceMap.putServiceByName(name, UserHandle.getUserId(r.appInfo.uid), r);
                mServiceMap.putServiceByIntent(filter, UserHandle.getUserId(r.appInfo.uid), r);
                // Make sure this component isn't in the pending list.
                int N = mPendingServices.size();
                for (int i = 0; i < N; i++) {
                    ServiceRecord pr = mPendingServices.get(i);
                    if (pr.serviceInfo.applicationInfo.uid == sInfo.applicationInfo.uid && pr.name.equals(name)) {
                        mPendingServices.remove(i);
                        i--;
                        N--;
                    }
                }
            }
        } 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);
        }
        return new ServiceLookupResult(r, null);
    }
    return null;
}
Also used : Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) 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