Loading core/java/android/app/Activity.java +16 −0 Original line number Diff line number Diff line Loading @@ -134,6 +134,8 @@ import android.view.autofill.IAutofillWindowPresenter; import android.view.contentcapture.ContentCaptureContext; import android.view.contentcapture.ContentCaptureManager; import android.view.contentcapture.ContentCaptureManager.ContentCaptureClient; import android.view.translation.TranslationSpec; import android.view.translation.UiTranslationController; import android.widget.AdapterView; import android.widget.Toast; import android.widget.Toolbar; Loading Loading @@ -957,6 +959,8 @@ public class Activity extends ContextThemeWrapper private boolean mIsInMultiWindowMode; private boolean mIsInPictureInPictureMode; private UiTranslationController mUiTranslationController; private final WindowControllerCallback mWindowControllerCallback = new WindowControllerCallback() { /** Loading Loading @@ -8635,6 +8639,18 @@ public class Activity extends ContextThemeWrapper ActivityClient.getInstance().unregisterRemoteAnimations(mToken); } /** * Notify {@link UiTranslationController} the ui translation state is changed. * @hide */ public void updateUiTranslationState(int state, TranslationSpec sourceSpec, TranslationSpec destSpec, List<AutofillId> viewIds) { if (mUiTranslationController == null) { mUiTranslationController = new UiTranslationController(this, getApplicationContext()); } mUiTranslationController.updateUiTranslationState(state, sourceSpec, destSpec, viewIds); } class HostCallbacks extends FragmentHostCallback<Activity> { public HostCallbacks() { super(Activity.this /*activity*/); Loading core/java/android/app/ActivityThread.java +32 −0 Original line number Diff line number Diff line Loading @@ -175,6 +175,8 @@ import android.view.ViewRootImpl; import android.view.Window; import android.view.WindowManager; import android.view.WindowManagerGlobal; import android.view.autofill.AutofillId; import android.view.translation.TranslationSpec; import android.webkit.WebView; import com.android.internal.annotations.GuardedBy; Loading Loading @@ -1808,6 +1810,18 @@ public final class ActivityThread extends ClientTransactionHandler { data.appInfo = targetInfo; sendMessage(H.INSTRUMENT_WITHOUT_RESTART, data); } @Override public void updateUiTranslationState(IBinder activityToken, int state, TranslationSpec sourceSpec, TranslationSpec destSpec, List<AutofillId> viewIds) { SomeArgs args = SomeArgs.obtain(); args.arg1 = activityToken; args.arg2 = state; args.arg3 = sourceSpec; args.arg4 = destSpec; args.arg5 = viewIds; sendMessage(H.UPDATE_UI_TRANSLATION_STATE, args); } } private @NonNull SafeCancellationTransport createSafeCancellationTransport( Loading Loading @@ -1912,6 +1926,7 @@ public final class ActivityThread extends ClientTransactionHandler { public static final int RELAUNCH_ACTIVITY = 160; public static final int PURGE_RESOURCES = 161; public static final int ATTACH_STARTUP_AGENTS = 162; public static final int UPDATE_UI_TRANSLATION_STATE = 163; public static final int INSTRUMENT_WITHOUT_RESTART = 170; public static final int FINISH_INSTRUMENTATION_WITHOUT_RESTART = 171; Loading Loading @@ -1958,6 +1973,7 @@ public final class ActivityThread extends ClientTransactionHandler { case RELAUNCH_ACTIVITY: return "RELAUNCH_ACTIVITY"; case PURGE_RESOURCES: return "PURGE_RESOURCES"; case ATTACH_STARTUP_AGENTS: return "ATTACH_STARTUP_AGENTS"; case UPDATE_UI_TRANSLATION_STATE: return "UPDATE_UI_TRANSLATION_STATE"; case INSTRUMENT_WITHOUT_RESTART: return "INSTRUMENT_WITHOUT_RESTART"; case FINISH_INSTRUMENTATION_WITHOUT_RESTART: return "FINISH_INSTRUMENTATION_WITHOUT_RESTART"; Loading Loading @@ -2142,6 +2158,12 @@ public final class ActivityThread extends ClientTransactionHandler { case ATTACH_STARTUP_AGENTS: handleAttachStartupAgents((String) msg.obj); break; case UPDATE_UI_TRANSLATION_STATE: final SomeArgs args = (SomeArgs) msg.obj; updateUiTranslationState((IBinder) args.arg1, (int) args.arg2, (TranslationSpec) args.arg3, (TranslationSpec) args.arg4, (List<AutofillId>) args.arg5); break; case INSTRUMENT_WITHOUT_RESTART: handleInstrumentWithoutRestart((AppBindData) msg.obj); break; Loading Loading @@ -4020,6 +4042,16 @@ public final class ActivityThread extends ClientTransactionHandler { } } private void updateUiTranslationState(IBinder activityToken, int state, TranslationSpec sourceSpec, TranslationSpec destSpec, List<AutofillId> viewIds) { final ActivityClientRecord r = mActivities.get(activityToken); if (r == null) { Log.w(TAG, "updateUiTranslationState(): no activity for " + activityToken); return; } r.activity.updateUiTranslationState(state, sourceSpec, destSpec, viewIds); } private static final ThreadLocal<Intent> sCurrentBroadcastIntent = new ThreadLocal<Intent>(); /** Loading core/java/android/app/IApplicationThread.aidl +4 −0 Original line number Diff line number Diff line Loading @@ -44,6 +44,8 @@ import android.os.ParcelFileDescriptor; import android.os.PersistableBundle; import android.os.RemoteCallback; import android.os.SharedMemory; import android.view.autofill.AutofillId; import android.view.translation.TranslationSpec; import com.android.internal.app.IVoiceInteractor; import com.android.internal.content.ReferrerIntent; Loading Loading @@ -157,4 +159,6 @@ oneway interface IApplicationThread { IInstrumentationWatcher instrumentationWatcher, IUiAutomationConnection instrumentationUiConnection, in ApplicationInfo targetInfo); void updateUiTranslationState(IBinder activityToken, int state, in TranslationSpec sourceSpec, in TranslationSpec destSpec, in List<AutofillId> viewIds); } core/java/android/view/translation/UiTranslationController.java 0 → 100644 +50 −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.app.Activity; import android.content.Context; import android.view.autofill.AutofillId; import java.util.List; /** * A controller to manage the ui translation requests. * * @hide */ public class UiTranslationController { private static final String TAG = "UiTranslationController"; private final Activity mActivity; private final Context mContext; public UiTranslationController(Activity activity, Context context) { mActivity = activity; mContext = context; } /** * Update the Ui translation state. */ public void updateUiTranslationState(int state, TranslationSpec sourceSpec, TranslationSpec destSpec, List<AutofillId> views) { // Implement it. Deal with the each states } } core/tests/coretests/src/android/app/servertransaction/TransactionParcelTests.java +9 −0 Original line number Diff line number Diff line Loading @@ -59,6 +59,8 @@ import android.platform.test.annotations.Presubmit; import android.view.DisplayAdjustments.FixedRotationAdjustments; import android.view.DisplayCutout; import android.view.Surface; import android.view.autofill.AutofillId; import android.view.translation.TranslationSpec; import androidx.test.filters.SmallTest; import androidx.test.runner.AndroidJUnit4; Loading @@ -70,6 +72,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import java.util.ArrayList; import java.util.List; import java.util.Map; /** Loading Loading @@ -686,5 +689,11 @@ public class TransactionParcelTests { Bundle instrumentationArgs, IInstrumentationWatcher instrumentationWatcher, IUiAutomationConnection instrumentationUiConnection, ApplicationInfo targetInfo) { } @Override public void updateUiTranslationState(IBinder activityToken, int state, TranslationSpec sourceSpec, TranslationSpec destSpec, List<AutofillId> viewIds) { } } } Loading
core/java/android/app/Activity.java +16 −0 Original line number Diff line number Diff line Loading @@ -134,6 +134,8 @@ import android.view.autofill.IAutofillWindowPresenter; import android.view.contentcapture.ContentCaptureContext; import android.view.contentcapture.ContentCaptureManager; import android.view.contentcapture.ContentCaptureManager.ContentCaptureClient; import android.view.translation.TranslationSpec; import android.view.translation.UiTranslationController; import android.widget.AdapterView; import android.widget.Toast; import android.widget.Toolbar; Loading Loading @@ -957,6 +959,8 @@ public class Activity extends ContextThemeWrapper private boolean mIsInMultiWindowMode; private boolean mIsInPictureInPictureMode; private UiTranslationController mUiTranslationController; private final WindowControllerCallback mWindowControllerCallback = new WindowControllerCallback() { /** Loading Loading @@ -8635,6 +8639,18 @@ public class Activity extends ContextThemeWrapper ActivityClient.getInstance().unregisterRemoteAnimations(mToken); } /** * Notify {@link UiTranslationController} the ui translation state is changed. * @hide */ public void updateUiTranslationState(int state, TranslationSpec sourceSpec, TranslationSpec destSpec, List<AutofillId> viewIds) { if (mUiTranslationController == null) { mUiTranslationController = new UiTranslationController(this, getApplicationContext()); } mUiTranslationController.updateUiTranslationState(state, sourceSpec, destSpec, viewIds); } class HostCallbacks extends FragmentHostCallback<Activity> { public HostCallbacks() { super(Activity.this /*activity*/); Loading
core/java/android/app/ActivityThread.java +32 −0 Original line number Diff line number Diff line Loading @@ -175,6 +175,8 @@ import android.view.ViewRootImpl; import android.view.Window; import android.view.WindowManager; import android.view.WindowManagerGlobal; import android.view.autofill.AutofillId; import android.view.translation.TranslationSpec; import android.webkit.WebView; import com.android.internal.annotations.GuardedBy; Loading Loading @@ -1808,6 +1810,18 @@ public final class ActivityThread extends ClientTransactionHandler { data.appInfo = targetInfo; sendMessage(H.INSTRUMENT_WITHOUT_RESTART, data); } @Override public void updateUiTranslationState(IBinder activityToken, int state, TranslationSpec sourceSpec, TranslationSpec destSpec, List<AutofillId> viewIds) { SomeArgs args = SomeArgs.obtain(); args.arg1 = activityToken; args.arg2 = state; args.arg3 = sourceSpec; args.arg4 = destSpec; args.arg5 = viewIds; sendMessage(H.UPDATE_UI_TRANSLATION_STATE, args); } } private @NonNull SafeCancellationTransport createSafeCancellationTransport( Loading Loading @@ -1912,6 +1926,7 @@ public final class ActivityThread extends ClientTransactionHandler { public static final int RELAUNCH_ACTIVITY = 160; public static final int PURGE_RESOURCES = 161; public static final int ATTACH_STARTUP_AGENTS = 162; public static final int UPDATE_UI_TRANSLATION_STATE = 163; public static final int INSTRUMENT_WITHOUT_RESTART = 170; public static final int FINISH_INSTRUMENTATION_WITHOUT_RESTART = 171; Loading Loading @@ -1958,6 +1973,7 @@ public final class ActivityThread extends ClientTransactionHandler { case RELAUNCH_ACTIVITY: return "RELAUNCH_ACTIVITY"; case PURGE_RESOURCES: return "PURGE_RESOURCES"; case ATTACH_STARTUP_AGENTS: return "ATTACH_STARTUP_AGENTS"; case UPDATE_UI_TRANSLATION_STATE: return "UPDATE_UI_TRANSLATION_STATE"; case INSTRUMENT_WITHOUT_RESTART: return "INSTRUMENT_WITHOUT_RESTART"; case FINISH_INSTRUMENTATION_WITHOUT_RESTART: return "FINISH_INSTRUMENTATION_WITHOUT_RESTART"; Loading Loading @@ -2142,6 +2158,12 @@ public final class ActivityThread extends ClientTransactionHandler { case ATTACH_STARTUP_AGENTS: handleAttachStartupAgents((String) msg.obj); break; case UPDATE_UI_TRANSLATION_STATE: final SomeArgs args = (SomeArgs) msg.obj; updateUiTranslationState((IBinder) args.arg1, (int) args.arg2, (TranslationSpec) args.arg3, (TranslationSpec) args.arg4, (List<AutofillId>) args.arg5); break; case INSTRUMENT_WITHOUT_RESTART: handleInstrumentWithoutRestart((AppBindData) msg.obj); break; Loading Loading @@ -4020,6 +4042,16 @@ public final class ActivityThread extends ClientTransactionHandler { } } private void updateUiTranslationState(IBinder activityToken, int state, TranslationSpec sourceSpec, TranslationSpec destSpec, List<AutofillId> viewIds) { final ActivityClientRecord r = mActivities.get(activityToken); if (r == null) { Log.w(TAG, "updateUiTranslationState(): no activity for " + activityToken); return; } r.activity.updateUiTranslationState(state, sourceSpec, destSpec, viewIds); } private static final ThreadLocal<Intent> sCurrentBroadcastIntent = new ThreadLocal<Intent>(); /** Loading
core/java/android/app/IApplicationThread.aidl +4 −0 Original line number Diff line number Diff line Loading @@ -44,6 +44,8 @@ import android.os.ParcelFileDescriptor; import android.os.PersistableBundle; import android.os.RemoteCallback; import android.os.SharedMemory; import android.view.autofill.AutofillId; import android.view.translation.TranslationSpec; import com.android.internal.app.IVoiceInteractor; import com.android.internal.content.ReferrerIntent; Loading Loading @@ -157,4 +159,6 @@ oneway interface IApplicationThread { IInstrumentationWatcher instrumentationWatcher, IUiAutomationConnection instrumentationUiConnection, in ApplicationInfo targetInfo); void updateUiTranslationState(IBinder activityToken, int state, in TranslationSpec sourceSpec, in TranslationSpec destSpec, in List<AutofillId> viewIds); }
core/java/android/view/translation/UiTranslationController.java 0 → 100644 +50 −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.app.Activity; import android.content.Context; import android.view.autofill.AutofillId; import java.util.List; /** * A controller to manage the ui translation requests. * * @hide */ public class UiTranslationController { private static final String TAG = "UiTranslationController"; private final Activity mActivity; private final Context mContext; public UiTranslationController(Activity activity, Context context) { mActivity = activity; mContext = context; } /** * Update the Ui translation state. */ public void updateUiTranslationState(int state, TranslationSpec sourceSpec, TranslationSpec destSpec, List<AutofillId> views) { // Implement it. Deal with the each states } }
core/tests/coretests/src/android/app/servertransaction/TransactionParcelTests.java +9 −0 Original line number Diff line number Diff line Loading @@ -59,6 +59,8 @@ import android.platform.test.annotations.Presubmit; import android.view.DisplayAdjustments.FixedRotationAdjustments; import android.view.DisplayCutout; import android.view.Surface; import android.view.autofill.AutofillId; import android.view.translation.TranslationSpec; import androidx.test.filters.SmallTest; import androidx.test.runner.AndroidJUnit4; Loading @@ -70,6 +72,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import java.util.ArrayList; import java.util.List; import java.util.Map; /** Loading Loading @@ -686,5 +689,11 @@ public class TransactionParcelTests { Bundle instrumentationArgs, IInstrumentationWatcher instrumentationWatcher, IUiAutomationConnection instrumentationUiConnection, ApplicationInfo targetInfo) { } @Override public void updateUiTranslationState(IBinder activityToken, int state, TranslationSpec sourceSpec, TranslationSpec destSpec, List<AutofillId> viewIds) { } } }