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

Commit 65327834 authored by Przemyslaw Szczepaniak's avatar Przemyslaw Szczepaniak
Browse files

Allow TTS service to identify caller.

Added new field (+setter and getter) to SynthesisRequest with
Uid of a calling process. TTS service will be able to discover
packages names associated with caller using
PackageManager.getPackagesForUid.

This will allow to block buggy or poorly designed programs from
an unintentional DDoS attacks against TTS service.

Bug: 8625440
Change-Id: I5ac0ea191f952495c00301f17efdf28205353ae4
parent 5b27decb
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -21551,6 +21551,7 @@ package android.speech.tts {
  public final class SynthesisRequest {
    ctor public SynthesisRequest(java.lang.String, android.os.Bundle);
    method public int getCallerUid();
    method public java.lang.String getCountry();
    method public java.lang.String getLanguage();
    method public android.os.Bundle getParams();
+15 −0
Original line number Diff line number Diff line
@@ -41,6 +41,7 @@ public final class SynthesisRequest {
    private String mVariant;
    private int mSpeechRate;
    private int mPitch;
    private int mCallerUid;

    public SynthesisRequest(String text, Bundle params) {
        mText = text;
@@ -97,6 +98,13 @@ public final class SynthesisRequest {
        return mParams;
    }

    /**
     * Gets the request caller Uid.
     */
    public int getCallerUid() {
        return mCallerUid;
    }

    /**
     * Sets the locale for the request.
     */
@@ -119,4 +127,11 @@ public final class SynthesisRequest {
    void setPitch(int pitch) {
        mPitch = pitch;
    }

    /**
     * Sets Caller Uid
     */
    void setCallerUid(int uid) {
        mCallerUid = uid;
    }
}
+3 −1
Original line number Diff line number Diff line
@@ -557,11 +557,13 @@ public abstract class TextToSpeechService extends Service {
        // guarded by 'this'.
        private AbstractSynthesisCallback mSynthesisCallback;
        private final EventLogger mEventLogger;
        private final int mCallerUid;

        public SynthesisSpeechItem(Object callerIdentity, int callerUid, int callerPid,
                Bundle params, String text) {
            super(callerIdentity, callerUid, callerPid, params);
            mText = text;
            mCallerUid = callerUid;
            mSynthesisRequest = new SynthesisRequest(mText, mParams);
            mDefaultLocale = getSettingsLocale();
            setRequestParams(mSynthesisRequest);
@@ -611,7 +613,7 @@ public abstract class TextToSpeechService extends Service {
        private void setRequestParams(SynthesisRequest request) {
            request.setLanguage(getLanguage(), getCountry(), getVariant());
            request.setSpeechRate(getSpeechRate());

            request.setCallerUid(mCallerUid);
            request.setPitch(getPitch());
        }