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

Commit e5c140a5 authored by Adam He's avatar Adam He
Browse files

Add api to propagating translation capability updates.

This change adda the apia in the TranslationService that allows to
update the TranslationCapability to the registered clients. This
change doesn't contain the register part in the TranslationManager,
the change will be done on the next change.

Bug: 176208267
Test: atest CtsTranslationTestCases
Test: manual verification
CTS-Coverage-Bug: 182990474

Change-Id: Iec7b3dc30f99985415162394d0e64d8e825ea5d9
parent 9753f5c3
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -52771,6 +52771,7 @@ package android.view.translation {
    field @NonNull public static final android.os.Parcelable.Creator<android.view.translation.TranslationCapability> CREATOR;
    field public static final int STATE_AVAILABLE_TO_DOWNLOAD = 1; // 0x1
    field public static final int STATE_DOWNLOADING = 2; // 0x2
    field public static final int STATE_NOT_AVAILABLE = 4; // 0x4
    field public static final int STATE_ON_DEVICE = 3; // 0x3
  }
+1 −0
Original line number Diff line number Diff line
@@ -10405,6 +10405,7 @@ package android.service.translation {
    method public abstract void onFinishTranslationSession(int);
    method public abstract void onTranslationCapabilitiesRequest(int, int, @NonNull java.util.function.Consumer<java.util.Set<android.view.translation.TranslationCapability>>);
    method public abstract void onTranslationRequest(@NonNull android.view.translation.TranslationRequest, int, @Nullable android.os.CancellationSignal, @NonNull android.service.translation.TranslationService.OnTranslationResultCallback);
    method public final void updateTranslationCapability(@NonNull android.view.translation.TranslationCapability);
    field public static final String SERVICE_INTERFACE = "android.service.translation.TranslationService";
    field public static final String SERVICE_META_DATA = "android.translation_service";
  }
+2 −1
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package android.service.translation;

import android.os.IBinder;
import android.os.ResultReceiver;
import android.view.translation.TranslationContext;
import com.android.internal.os.IResultReceiver;
@@ -30,7 +31,7 @@ import com.android.internal.os.IResultReceiver;
 * @hide
 */
oneway interface ITranslationService {
    void onConnected();
    void onConnected(in IBinder callback);
    void onDisconnected();
    void onCreateTranslationSession(in TranslationContext translationContext, int sessionId,
         in IResultReceiver receiver);
+33 −3
Original line number Diff line number Diff line
@@ -41,6 +41,7 @@ import android.os.ResultReceiver;
import android.util.ArraySet;
import android.util.Log;
import android.view.translation.ITranslationDirectManager;
import android.view.translation.ITranslationServiceCallback;
import android.view.translation.TranslationCapability;
import android.view.translation.TranslationContext;
import android.view.translation.TranslationManager;
@@ -50,6 +51,7 @@ import android.view.translation.TranslationSpec;

import com.android.internal.os.IResultReceiver;

import java.util.Objects;
import java.util.Set;
import java.util.function.Consumer;

@@ -84,15 +86,17 @@ public abstract class TranslationService extends Service {
    public static final String SERVICE_META_DATA = "android.translation_service";

    private Handler mHandler;
    private ITranslationServiceCallback mCallback;


    /**
     * Binder to receive calls from system server.
     */
    private final ITranslationService mInterface = new ITranslationService.Stub() {
        @Override
        public void onConnected() {
            mHandler.sendMessage(obtainMessage(TranslationService::onConnected,
                    TranslationService.this));
        public void onConnected(IBinder callback) {
            mHandler.sendMessage(obtainMessage(TranslationService::handleOnConnected,
                    TranslationService.this, callback));
        }

        @Override
@@ -273,6 +277,32 @@ public abstract class TranslationService extends Service {
            @TranslationSpec.DataFormat int targetFormat,
            @NonNull Consumer<Set<TranslationCapability>> callback);

    /**
     * Called by the service to notify an update in existing {@link TranslationCapability}s.
     *
     * @param capability the updated {@link TranslationCapability} with its new states and flags.
     */
    public final void updateTranslationCapability(@NonNull TranslationCapability capability) {
        Objects.requireNonNull(capability, "translation capability should not be null");

        final ITranslationServiceCallback callback = mCallback;
        if (callback == null) {
            Log.w(TAG, "updateTranslationCapability(): no server callback");
            return;
        }

        try {
            callback.updateTranslationCapability(capability);
        } catch (RemoteException e) {
            e.rethrowFromSystemServer();
        }
    }

    private void handleOnConnected(@NonNull IBinder callback) {
        mCallback = ITranslationServiceCallback.Stub.asInterface(callback);
        onConnected();
    }

    // TODO(b/176464808): Need to handle client dying case

    private void handleOnCreateTranslationSession(@NonNull TranslationContext translationContext,
+28 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2021 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.view.translation;

import android.view.translation.TranslationCapability;

/**
 * Interface from the Translation service to the system.
 *
 * @hide
 */
oneway interface ITranslationServiceCallback {
    void updateTranslationCapability(in TranslationCapability capability);
}
Loading