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

Commit 596708b9 authored by James O'Leary's avatar James O'Leary
Browse files

Only selected VoiceInteractionService can call methods

- Extract current code for checking caller into a private method
- Replace occurrences of that code with a call to the private method
- Add method call to setTranscription/clearTranscription/setVoiceState

Test: Verified Milford can't call setTranscription/clearTranscription
when it is no longer the active service.
Bug: b/123412646

Change-Id: I2c428c6c65b62f6a83264286df4f44fb5d1c249e
parent fdc39187
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -348,7 +348,7 @@ public class VoiceInteractionService extends Service {
     */
    public final void setVoiceState(int state) {
        try {
            mSystemService.setVoiceState(state);
            mSystemService.setVoiceState(mInterface, state);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
@@ -359,7 +359,7 @@ public class VoiceInteractionService extends Service {
     */
    public final void setTranscription(@NonNull String transcription) {
        try {
            mSystemService.setTranscription(transcription);
            mSystemService.setTranscription(mInterface, transcription);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
@@ -372,7 +372,7 @@ public class VoiceInteractionService extends Service {
     */
    public final void clearTranscription(boolean immediate) {
        try {
            mSystemService.clearTranscription(immediate);
            mSystemService.clearTranscription(mInterface, immediate);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
+3 −3
Original line number Diff line number Diff line
@@ -155,15 +155,15 @@ interface IVoiceInteractionManagerService {
    /**
     * Sets the transcribed voice to the given string.
     */
    void setTranscription(String transcription);
    void setTranscription(IVoiceInteractionService service, String transcription);

    /**
     * Indicates that the transcription session is finished.
     */
    void clearTranscription(boolean immediate);
    void clearTranscription(IVoiceInteractionService service, boolean immediate);

    /**
     * Sets the voice state indication based upon the given value.
     */
    void setVoiceState(int state);
    void setVoiceState(IVoiceInteractionService service, int state);
}
+23 −28
Original line number Diff line number Diff line
@@ -613,11 +613,8 @@ public class VoiceInteractionManagerService extends SystemService {
        @Override
        public void showSession(IVoiceInteractionService service, Bundle args, int flags) {
            synchronized (this) {
                if (mImpl == null || mImpl.mService == null
                        || service.asBinder() != mImpl.mService.asBinder()) {
                    throw new SecurityException(
                            "Caller is not the current voice interaction service");
                }
                enforceIsCurrentVoiceInteractionService(service);

                final long caller = Binder.clearCallingIdentity();
                try {
                    mImpl.showSessionLocked(args, flags, null, null);
@@ -896,11 +893,7 @@ public class VoiceInteractionManagerService extends SystemService {
        public boolean isEnrolledForKeyphrase(IVoiceInteractionService service, int keyphraseId,
                String bcp47Locale) {
            synchronized (this) {
                if (mImpl == null || mImpl.mService == null
                        || service.asBinder() != mImpl.mService.asBinder()) {
                    throw new SecurityException(
                            "Caller is not the current voice interaction service");
                }
                enforceIsCurrentVoiceInteractionService(service);
            }

            if (bcp47Locale == null) {
@@ -922,11 +915,7 @@ public class VoiceInteractionManagerService extends SystemService {
        public ModuleProperties getDspModuleProperties(IVoiceInteractionService service) {
            // Allow the call if this is the current voice interaction service.
            synchronized (this) {
                if (mImpl == null || mImpl.mService == null
                        || service == null || service.asBinder() != mImpl.mService.asBinder()) {
                    throw new SecurityException(
                            "Caller is not the current voice interaction service");
                }
                enforceIsCurrentVoiceInteractionService(service);

                final long caller = Binder.clearCallingIdentity();
                try {
@@ -943,11 +932,7 @@ public class VoiceInteractionManagerService extends SystemService {
                RecognitionConfig recognitionConfig) {
            // Allow the call if this is the current voice interaction service.
            synchronized (this) {
                if (mImpl == null || mImpl.mService == null
                        || service == null || service.asBinder() != mImpl.mService.asBinder()) {
                    throw new SecurityException(
                            "Caller is not the current voice interaction service");
                }
                enforceIsCurrentVoiceInteractionService(service);

                if (callback == null || recognitionConfig == null || bcp47Locale == null) {
                    throw new IllegalArgumentException("Illegal argument(s) in startRecognition");
@@ -983,11 +968,7 @@ public class VoiceInteractionManagerService extends SystemService {
                IRecognitionStatusCallback callback) {
            // Allow the call if this is the current voice interaction service.
            synchronized (this) {
                if (mImpl == null || mImpl.mService == null
                        || service == null || service.asBinder() != mImpl.mService.asBinder()) {
                    throw new SecurityException(
                            "Caller is not the current voice interaction service");
                }
                enforceIsCurrentVoiceInteractionService(service);
            }

            final long caller = Binder.clearCallingIdentity();
@@ -1212,8 +1193,10 @@ public class VoiceInteractionManagerService extends SystemService {
        }

        @Override
        public void setTranscription(String transcription) {
        public void setTranscription(IVoiceInteractionService service, String transcription) {
            synchronized (this) {
                enforceIsCurrentVoiceInteractionService(service);

                final int size = mVoiceInteractionSessionListeners.beginBroadcast();
                for (int i = 0; i < size; ++i) {
                    final IVoiceInteractionSessionListener listener =
@@ -1229,8 +1212,10 @@ public class VoiceInteractionManagerService extends SystemService {
        }

        @Override
        public void clearTranscription(boolean immediate) {
        public void clearTranscription(IVoiceInteractionService service, boolean immediate) {
            synchronized (this) {
                enforceIsCurrentVoiceInteractionService(service);

                final int size = mVoiceInteractionSessionListeners.beginBroadcast();
                for (int i = 0; i < size; ++i) {
                    final IVoiceInteractionSessionListener listener =
@@ -1246,8 +1231,10 @@ public class VoiceInteractionManagerService extends SystemService {
        }

        @Override
        public void setVoiceState(int state) {
        public void setVoiceState(IVoiceInteractionService service, int state) {
            synchronized (this) {
                enforceIsCurrentVoiceInteractionService(service);

                final int size = mVoiceInteractionSessionListeners.beginBroadcast();
                for (int i = 0; i < size; ++i) {
                    final IVoiceInteractionSessionListener listener =
@@ -1269,6 +1256,14 @@ public class VoiceInteractionManagerService extends SystemService {
            }
        }

        private void enforceIsCurrentVoiceInteractionService(IVoiceInteractionService service) {
            if (mImpl == null || mImpl.mService == null
                    || service.asBinder() != mImpl.mService.asBinder()) {
                throw new
                    SecurityException("Caller is not the current voice interaction service");
            }
        }

        private void setImplLocked(VoiceInteractionManagerServiceImpl impl) {
            mImpl = impl;
            mAtmInternal.notifyActiveVoiceInteractionServiceChanged(