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

Commit edd12149 authored by Narayan Kamath's avatar Narayan Kamath Committed by Android (Google) Code Review
Browse files

Merge "Don't enforce defaults any more in the TextToSpeech API."

parents 9266847e c3edf2a0
Loading
Loading
Loading
Loading
+5 −6
Original line number Diff line number Diff line
@@ -498,8 +498,7 @@ public class TextToSpeech {
    private int initTts() {
        String defaultEngine = getDefaultEngine();
        String engine = defaultEngine;
        if (!areDefaultsEnforced() && !TextUtils.isEmpty(mRequestedEngine)
                && mEnginesHelper.isEngineEnabled(mRequestedEngine)) {
        if (mEnginesHelper.isEngineInstalled(mRequestedEngine)) {
            engine = mRequestedEngine;
        }

@@ -1080,12 +1079,12 @@ public class TextToSpeech {
    }

    /**
     * Checks whether the user's settings should override settings requested by the calling
     * application.
     * Checks whether the user's settings should override settings requested
     * by the calling application. As of the Ice cream sandwich release,
     * user settings never forcibly override the app's settings.
     */
    public boolean areDefaultsEnforced() {
        return Settings.Secure.getInt(mContext.getContentResolver(),
                Settings.Secure.TTS_USE_DEFAULTS, Engine.USE_DEFAULTS) == 1;
        return false;
    }

    /**
+3 −26
Original line number Diff line number Diff line
@@ -191,11 +191,6 @@ public abstract class TextToSpeechService extends Service {
    protected abstract void onSynthesizeText(SynthesisRequest request,
            SynthesisCallback callback);

    private boolean areDefaultsEnforced() {
        return getSecureSettingInt(Settings.Secure.TTS_USE_DEFAULTS,
                TextToSpeech.Engine.USE_DEFAULTS) == 1;
    }

    private int getDefaultSpeechRate() {
        return getSecureSettingInt(Settings.Secure.TTS_DEFAULT_RATE, Engine.DEFAULT_RATE);
    }
@@ -504,13 +499,9 @@ public abstract class TextToSpeechService extends Service {
        }

        private void setRequestParams(SynthesisRequest request) {
            if (areDefaultsEnforced()) {
                request.setLanguage(getDefaultLanguage(), getDefaultCountry(), getDefaultVariant());
                request.setSpeechRate(getDefaultSpeechRate());
            } else {
            request.setLanguage(getLanguage(), getCountry(), getVariant());
            request.setSpeechRate(getSpeechRate());
            }

            request.setPitch(getPitch());
        }

@@ -749,13 +740,6 @@ public abstract class TextToSpeechService extends Service {
                return TextToSpeech.ERROR;
            }

            if (areDefaultsEnforced()) {
                if (isDefault(lang, country, variant)) {
                    return mDefaultAvailability;
                } else {
                    return TextToSpeech.LANG_NOT_SUPPORTED;
                }
            }
            return onIsLanguageAvailable(lang, country, variant);
        }

@@ -768,13 +752,6 @@ public abstract class TextToSpeechService extends Service {
                return TextToSpeech.ERROR;
            }

            if (areDefaultsEnforced()) {
                if (isDefault(lang, country, variant)) {
                    return mDefaultAvailability;
                } else {
                    return TextToSpeech.LANG_NOT_SUPPORTED;
                }
            }
            return onLoadLanguage(lang, country, variant);
        }

+6 −45
Original line number Diff line number Diff line
@@ -117,30 +117,10 @@ public class TtsEngines {
        return engines;
    }

    /**
     * Checks whether a given engine is enabled or not. Note that all system
     * engines are enabled by default.
     */
    // TODO: Used only by the settings app. Remove once
    // the settings UI change has been finalized.
    public boolean isEngineEnabled(String engine) {
        // System engines are enabled by default always.
        EngineInfo info = getEngineInfo(engine);
        if (info == null) {
            // The engine is not installed, and therefore cannot
            // be enabled.
            return false;
        }

        if (info.system) {
            // All system engines are enabled by default.
            return true;
        }

        for (String enabled : getUserEnabledEngines()) {
            if (engine.equals(enabled)) {
                return true;
            }
        }
        return false;
        return isEngineInstalled(engine);
    }

    private boolean isSystemEngine(ServiceInfo info) {
@@ -149,22 +129,14 @@ public class TtsEngines {
    }

    /**
     * @return true if a given engine is installed on the system. Useful to deal
     *         with cases where an engine has been uninstalled by the user or removed
     *         for any other reason.
     * @return true if a given engine is installed on the system.
     */
    private boolean isEngineInstalled(String engine) {
    public boolean isEngineInstalled(String engine) {
        if (engine == null) {
            return false;
        }

        for (EngineInfo info : getEngines()) {
            if (engine.equals(info.name)) {
                return true;
            }
        }

        return false;
        return getEngineInfo(engine) != null;
    }

    private EngineInfo getEngineInfo(ResolveInfo resolve, PackageManager pm) {
@@ -185,17 +157,6 @@ public class TtsEngines {
        return null;
    }

    // Note that in addition to this list, all engines that are a part
    // of the system are enabled by default.
    private String[] getUserEnabledEngines() {
        String str = Settings.Secure.getString(mContext.getContentResolver(),
                Settings.Secure.TTS_ENABLED_PLUGINS);
        if (TextUtils.isEmpty(str)) {
            return new String[0];
        }
        return str.split(" ");
    }

    private static class EngineInfoComparator implements Comparator<EngineInfo> {
        private EngineInfoComparator() { }