Merge "Dump the last Activity information when dumpsys translation" into sc-dev
This commit is contained in:
@@ -90,6 +90,8 @@ public class UiTranslationController {
|
||||
@NonNull
|
||||
private final Handler mWorkerHandler;
|
||||
private int mCurrentState;
|
||||
@NonNull
|
||||
private ArraySet<AutofillId> mLastRequestAutofillIds;
|
||||
|
||||
public UiTranslationController(Activity activity, Context context) {
|
||||
mActivity = activity;
|
||||
@@ -120,6 +122,9 @@ public class UiTranslationController {
|
||||
+ (DEBUG ? (", views: " + views + ", spec: " + uiTranslationSpec) : ""));
|
||||
synchronized (mLock) {
|
||||
mCurrentState = state;
|
||||
if (views != null) {
|
||||
setLastRequestAutofillIdsLocked(views);
|
||||
}
|
||||
}
|
||||
switch (state) {
|
||||
case STATE_UI_TRANSLATION_STARTED:
|
||||
@@ -175,13 +180,25 @@ public class UiTranslationController {
|
||||
}
|
||||
}
|
||||
|
||||
private void setLastRequestAutofillIdsLocked(List<AutofillId> views) {
|
||||
if (mLastRequestAutofillIds == null) {
|
||||
mLastRequestAutofillIds = new ArraySet<>();
|
||||
}
|
||||
if (mLastRequestAutofillIds.size() > 0) {
|
||||
mLastRequestAutofillIds.clear();
|
||||
}
|
||||
mLastRequestAutofillIds.addAll(views);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called to dump the translation information for Activity.
|
||||
*/
|
||||
public void dump(String outerPrefix, PrintWriter pw) {
|
||||
pw.print(outerPrefix); pw.println("UiTranslationController:");
|
||||
final String pfx = outerPrefix + " ";
|
||||
pw.print(pfx); pw.print("activity: "); pw.println(mActivity);
|
||||
pw.print(pfx); pw.print("activity: "); pw.print(mActivity);
|
||||
pw.print(pfx); pw.print("resumed: "); pw.println(mActivity.isResumed());
|
||||
pw.print(pfx); pw.print("current state: "); pw.println(mCurrentState);
|
||||
final int translatorSize = mTranslators.size();
|
||||
pw.print(outerPrefix); pw.print("number translator: "); pw.println(translatorSize);
|
||||
for (int i = 0; i < translatorSize; i++) {
|
||||
@@ -244,13 +261,18 @@ public class UiTranslationController {
|
||||
pw.print(outerPrefix); pw.print("autofillId: "); pw.print(autofillId);
|
||||
// TODO: print TranslationTransformation
|
||||
boolean isContainsView = false;
|
||||
boolean isRequestedView = false;
|
||||
synchronized (mLock) {
|
||||
if (mLastRequestAutofillIds.contains(autofillId)) {
|
||||
isRequestedView = true;
|
||||
}
|
||||
final WeakReference<View> viewRef = mViews.get(autofillId);
|
||||
if (viewRef != null && viewRef.get() != null) {
|
||||
isContainsView = true;
|
||||
}
|
||||
}
|
||||
pw.print(outerPrefix); pw.print("isContainsView: "); pw.println(isContainsView);
|
||||
pw.print(outerPrefix); pw.print("isContainsView: "); pw.print(isContainsView);
|
||||
pw.print(outerPrefix); pw.print("isRequestedView: "); pw.println(isRequestedView);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -294,6 +294,11 @@ public final class TranslationManagerService
|
||||
|
||||
synchronized (mLock) {
|
||||
dumpLocked("", pw);
|
||||
final int userId = UserHandle.getCallingUserId();
|
||||
final TranslationManagerServiceImpl service = getServiceForUserLocked(userId);
|
||||
if (service != null) {
|
||||
service.dumpLocked(" ", fd, pw);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -45,12 +45,17 @@ import android.view.translation.UiTranslationSpec;
|
||||
|
||||
import com.android.internal.annotations.GuardedBy;
|
||||
import com.android.internal.os.IResultReceiver;
|
||||
import com.android.internal.os.TransferPipe;
|
||||
import com.android.server.LocalServices;
|
||||
import com.android.server.infra.AbstractPerUserSystemService;
|
||||
import com.android.server.inputmethod.InputMethodManagerInternal;
|
||||
import com.android.server.wm.ActivityTaskManagerInternal;
|
||||
import com.android.server.wm.ActivityTaskManagerInternal.ActivityTokens;
|
||||
|
||||
import java.io.FileDescriptor;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.List;
|
||||
|
||||
final class TranslationManagerServiceImpl extends
|
||||
@@ -69,6 +74,9 @@ final class TranslationManagerServiceImpl extends
|
||||
@GuardedBy("mLock")
|
||||
private TranslationServiceInfo mTranslationServiceInfo;
|
||||
|
||||
@GuardedBy("mLock")
|
||||
private WeakReference<ActivityTokens> mLastActivityTokens;
|
||||
|
||||
private ActivityTaskManagerInternal mActivityTaskManagerInternal;
|
||||
|
||||
private final TranslationServiceRemoteCallback mRemoteServiceCallback =
|
||||
@@ -178,12 +186,35 @@ final class TranslationManagerServiceImpl extends
|
||||
taskTopActivityTokens.getApplicationThread().updateUiTranslationState(
|
||||
taskTopActivityTokens.getActivityToken(), state, sourceSpec, targetSpec,
|
||||
viewIds, uiTranslationSpec);
|
||||
mLastActivityTokens = new WeakReference<>(taskTopActivityTokens);
|
||||
} catch (RemoteException e) {
|
||||
Slog.w(TAG, "Update UiTranslationState fail: " + e);
|
||||
}
|
||||
invokeCallbacks(state, sourceSpec, targetSpec);
|
||||
}
|
||||
|
||||
@GuardedBy("mLock")
|
||||
public void dumpLocked(String prefix, FileDescriptor fd, PrintWriter pw) {
|
||||
if (mLastActivityTokens != null) {
|
||||
ActivityTokens activityTokens = mLastActivityTokens.get();
|
||||
if (activityTokens == null) {
|
||||
return;
|
||||
}
|
||||
try (TransferPipe tp = new TransferPipe()) {
|
||||
activityTokens.getApplicationThread().dumpActivity(tp.getWriteFd(),
|
||||
activityTokens.getActivityToken(), prefix,
|
||||
new String[]{"--translation"});
|
||||
tp.go(fd);
|
||||
} catch (IOException e) {
|
||||
pw.println(prefix + "Failure while dumping the activity: " + e);
|
||||
} catch (RemoteException e) {
|
||||
pw.println(prefix + "Got a RemoteException while dumping the activity");
|
||||
}
|
||||
} else {
|
||||
pw.print(prefix); pw.println("No requested UiTranslation Activity.");
|
||||
}
|
||||
}
|
||||
|
||||
private void invokeCallbacks(
|
||||
int state, TranslationSpec sourceSpec, TranslationSpec targetSpec) {
|
||||
Bundle res = new Bundle();
|
||||
|
||||
Reference in New Issue
Block a user