Search in sources :

Example 1 with VoiceInteractionServiceInfo

use of android.service.voice.VoiceInteractionServiceInfo in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class VoiceInputHelper method buildUi.

public void buildUi() {
    // Get the currently selected interactor from the secure setting.
    String currentSetting = Settings.Secure.getString(mContext.getContentResolver(), Settings.Secure.VOICE_INTERACTION_SERVICE);
    if (currentSetting != null && !currentSetting.isEmpty()) {
        mCurrentVoiceInteraction = ComponentName.unflattenFromString(currentSetting);
    } else {
        mCurrentVoiceInteraction = null;
    }
    ArraySet<ComponentName> interactorRecognizers = new ArraySet<>();
    // Iterate through all the available interactors and load up their info to show
    // in the preference.
    int size = mAvailableVoiceInteractions.size();
    for (int i = 0; i < size; i++) {
        ResolveInfo resolveInfo = mAvailableVoiceInteractions.get(i);
        VoiceInteractionServiceInfo info = new VoiceInteractionServiceInfo(mContext.getPackageManager(), resolveInfo.serviceInfo);
        if (info.getParseError() != null) {
            Log.w("VoiceInteractionService", "Error in VoiceInteractionService " + resolveInfo.serviceInfo.packageName + "/" + resolveInfo.serviceInfo.name + ": " + info.getParseError());
            continue;
        }
        mAvailableInteractionInfos.add(new InteractionInfo(mContext.getPackageManager(), info));
        interactorRecognizers.add(new ComponentName(resolveInfo.serviceInfo.packageName, info.getRecognitionService()));
    }
    Collections.sort(mAvailableInteractionInfos);
    // Get the currently selected recognizer from the secure setting.
    currentSetting = Settings.Secure.getString(mContext.getContentResolver(), Settings.Secure.VOICE_RECOGNITION_SERVICE);
    if (currentSetting != null && !currentSetting.isEmpty()) {
        mCurrentRecognizer = ComponentName.unflattenFromString(currentSetting);
    } else {
        mCurrentRecognizer = null;
    }
    // Iterate through all the available recognizers and load up their info to show
    // in the preference.
    size = mAvailableRecognition.size();
    for (int i = 0; i < size; i++) {
        ResolveInfo resolveInfo = mAvailableRecognition.get(i);
        ComponentName comp = new ComponentName(resolveInfo.serviceInfo.packageName, resolveInfo.serviceInfo.name);
        if (interactorRecognizers.contains(comp)) {
        //continue;
        }
        ServiceInfo si = resolveInfo.serviceInfo;
        XmlResourceParser parser = null;
        String settingsActivity = null;
        try {
            parser = si.loadXmlMetaData(mContext.getPackageManager(), RecognitionService.SERVICE_META_DATA);
            if (parser == null) {
                throw new XmlPullParserException("No " + RecognitionService.SERVICE_META_DATA + " meta-data for " + si.packageName);
            }
            Resources res = mContext.getPackageManager().getResourcesForApplication(si.applicationInfo);
            AttributeSet attrs = Xml.asAttributeSet(parser);
            int type;
            while ((type = parser.next()) != XmlPullParser.END_DOCUMENT && type != XmlPullParser.START_TAG) {
            }
            String nodeName = parser.getName();
            if (!"recognition-service".equals(nodeName)) {
                throw new XmlPullParserException("Meta-data does not start with recognition-service tag");
            }
            TypedArray array = res.obtainAttributes(attrs, com.android.internal.R.styleable.RecognitionService);
            settingsActivity = array.getString(com.android.internal.R.styleable.RecognitionService_settingsActivity);
            array.recycle();
        } catch (XmlPullParserException e) {
            Log.e(TAG, "error parsing recognition service meta-data", e);
        } catch (IOException e) {
            Log.e(TAG, "error parsing recognition service meta-data", e);
        } catch (PackageManager.NameNotFoundException e) {
            Log.e(TAG, "error parsing recognition service meta-data", e);
        } finally {
            if (parser != null)
                parser.close();
        }
        mAvailableRecognizerInfos.add(new RecognizerInfo(mContext.getPackageManager(), resolveInfo.serviceInfo, settingsActivity));
    }
    Collections.sort(mAvailableRecognizerInfos);
}
Also used : ArraySet(android.util.ArraySet) XmlResourceParser(android.content.res.XmlResourceParser) IOException(java.io.IOException) ResolveInfo(android.content.pm.ResolveInfo) VoiceInteractionServiceInfo(android.service.voice.VoiceInteractionServiceInfo) ServiceInfo(android.content.pm.ServiceInfo) PackageManager(android.content.pm.PackageManager) AttributeSet(android.util.AttributeSet) VoiceInteractionServiceInfo(android.service.voice.VoiceInteractionServiceInfo) TypedArray(android.content.res.TypedArray) ComponentName(android.content.ComponentName) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) Resources(android.content.res.Resources)

Example 2 with VoiceInteractionServiceInfo

use of android.service.voice.VoiceInteractionServiceInfo in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class DefaultAssistPreference method addAssistServices.

private void addAssistServices() {
    PackageManager pm = getContext().getPackageManager();
    List<ResolveInfo> services = pm.queryIntentServices(new Intent(VoiceInteractionService.SERVICE_INTERFACE), PackageManager.GET_META_DATA);
    for (int i = 0; i < services.size(); ++i) {
        ResolveInfo resolveInfo = services.get(i);
        VoiceInteractionServiceInfo voiceInteractionServiceInfo = new VoiceInteractionServiceInfo(pm, resolveInfo.serviceInfo);
        if (!voiceInteractionServiceInfo.getSupportsAssist()) {
            continue;
        }
        mAvailableAssistants.add(new Info(new ComponentName(resolveInfo.serviceInfo.packageName, resolveInfo.serviceInfo.name), voiceInteractionServiceInfo));
    }
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) PackageManager(android.content.pm.PackageManager) VoiceInteractionServiceInfo(android.service.voice.VoiceInteractionServiceInfo) Intent(android.content.Intent) ComponentName(android.content.ComponentName) ResolveInfo(android.content.pm.ResolveInfo) VoiceInteractionServiceInfo(android.service.voice.VoiceInteractionServiceInfo)

Aggregations

ComponentName (android.content.ComponentName)2 PackageManager (android.content.pm.PackageManager)2 ResolveInfo (android.content.pm.ResolveInfo)2 VoiceInteractionServiceInfo (android.service.voice.VoiceInteractionServiceInfo)2 Intent (android.content.Intent)1 ServiceInfo (android.content.pm.ServiceInfo)1 Resources (android.content.res.Resources)1 TypedArray (android.content.res.TypedArray)1 XmlResourceParser (android.content.res.XmlResourceParser)1 ArraySet (android.util.ArraySet)1 AttributeSet (android.util.AttributeSet)1 IOException (java.io.IOException)1 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)1