Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b4653373 authored by Przemyslaw Szczepaniak's avatar Przemyslaw Szczepaniak Committed by Android (Google) Code Review
Browse files

Set default language in new TTS clients.

A recent change altered semantics of getLanguage call to return client
language instead of service language. This solved problems
with interferences between two clients using different lanaguages.

This change created a bug - new TTS client instance have no language set.
Since reading user preferences requires additional permissions I've
added new tts service method - getClientDefaultLanguage that will return
user preferences.

I've also added new client method, getDefaultLanguage, that allow easy
access to this data.

Bug: 7666482
Change-Id: Ieb7d2ba3a99d20c513add97f054874720a1cd82e
parent d90a56fa
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -20556,6 +20556,7 @@ package android.speech.tts {
    method public int addSpeech(java.lang.String, java.lang.String);
    method public int addSpeech(java.lang.String, java.lang.String);
    method public boolean areDefaultsEnforced();
    method public boolean areDefaultsEnforced();
    method public java.lang.String getDefaultEngine();
    method public java.lang.String getDefaultEngine();
    method public java.util.Locale getDefaultLanguage();
    method public java.util.List<android.speech.tts.TextToSpeech.EngineInfo> getEngines();
    method public java.util.List<android.speech.tts.TextToSpeech.EngineInfo> getEngines();
    method public java.util.Set<java.lang.String> getFeatures(java.util.Locale);
    method public java.util.Set<java.lang.String> getFeatures(java.util.Locale);
    method public java.util.Locale getLanguage();
    method public java.util.Locale getLanguage();
+13 −1
Original line number Original line Diff line number Diff line
@@ -98,6 +98,18 @@ interface ITextToSpeechService {
     */
     */
    String[] getLanguage();
    String[] getLanguage();
    
    
    /**
     * Returns a default TTS language, country and variant as set by the user.
     *
     * Can be called from multiple threads.
     *
     * @return A 3-element array, containing language (ISO 3-letter code),
     *         country (ISO 3-letter code) and variant used by the engine.
     *         The country and variant may be {@code ""}. If country is empty, then variant must
     *         be empty too.
     */
    String[] getClientDefaultLanguage();
    
    /**
    /**
     * Checks whether the engine supports a given language.
     * Checks whether the engine supports a given language.
     *
     *
+25 −1
Original line number Original line Diff line number Diff line
@@ -1023,6 +1023,24 @@ public class TextToSpeech {
        return mCurrentEngine;
        return mCurrentEngine;
    }
    }


    /**
     * Returns a Locale instance describing the language currently being used as the default
     * Text-to-speech language.
     *
     * @return language, country (if any) and variant (if any) used by the client stored in a
     *     Locale instance, or {@code null} on error.
     */
    public Locale getDefaultLanguage() {
        return runAction(new Action<Locale>() {
            @Override
            public Locale run(ITextToSpeechService service) throws RemoteException {
                String[] defaultLanguage = service.getClientDefaultLanguage();

                return new Locale(defaultLanguage[0], defaultLanguage[1], defaultLanguage[2]);
            }
        }, null, "getDefaultLanguage");
    }

    /**
    /**
     * Sets the text-to-speech language.
     * Sets the text-to-speech language.
     * The TTS engine will try to use the closest match to the specified
     * The TTS engine will try to use the closest match to the specified
@@ -1338,7 +1356,13 @@ public class TextToSpeech {


                    try {
                    try {
                        mConnectedService.setCallback(getCallerIdentity(), mCallback);
                        mConnectedService.setCallback(getCallerIdentity(), mCallback);
                        Log.i(TAG, "Setuped connection to " + mName);
                        String[] defaultLanguage = mConnectedService.getClientDefaultLanguage();

                        mParams.putString(Engine.KEY_PARAM_LANGUAGE, defaultLanguage[0]);
                        mParams.putString(Engine.KEY_PARAM_COUNTRY, defaultLanguage[1]);
                        mParams.putString(Engine.KEY_PARAM_VARIANT, defaultLanguage[2]);

                        Log.i(TAG, "Set up connection to " + mName);
                        return SUCCESS;
                        return SUCCESS;
                    } catch (RemoteException re) {
                    } catch (RemoteException re) {
                        Log.e(TAG, "Error connecting to service, setCallback() failed");
                        Log.e(TAG, "Error connecting to service, setCallback() failed");
+5 −0
Original line number Original line Diff line number Diff line
@@ -850,6 +850,11 @@ public abstract class TextToSpeechService extends Service {
            return onGetLanguage();
            return onGetLanguage();
        }
        }


        @Override
        public String[] getClientDefaultLanguage() {
            return getSettingsLocale();
        }

        /*
        /*
         * If defaults are enforced, then no language is "available" except
         * If defaults are enforced, then no language is "available" except
         * perhaps the default language selected by the user.
         * perhaps the default language selected by the user.