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
|
@NonNull
|
||||||
private final Handler mWorkerHandler;
|
private final Handler mWorkerHandler;
|
||||||
private int mCurrentState;
|
private int mCurrentState;
|
||||||
|
@NonNull
|
||||||
|
private ArraySet<AutofillId> mLastRequestAutofillIds;
|
||||||
|
|
||||||
public UiTranslationController(Activity activity, Context context) {
|
public UiTranslationController(Activity activity, Context context) {
|
||||||
mActivity = activity;
|
mActivity = activity;
|
||||||
@@ -120,6 +122,9 @@ public class UiTranslationController {
|
|||||||
+ (DEBUG ? (", views: " + views + ", spec: " + uiTranslationSpec) : ""));
|
+ (DEBUG ? (", views: " + views + ", spec: " + uiTranslationSpec) : ""));
|
||||||
synchronized (mLock) {
|
synchronized (mLock) {
|
||||||
mCurrentState = state;
|
mCurrentState = state;
|
||||||
|
if (views != null) {
|
||||||
|
setLastRequestAutofillIdsLocked(views);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case STATE_UI_TRANSLATION_STARTED:
|
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.
|
* Called to dump the translation information for Activity.
|
||||||
*/
|
*/
|
||||||
public void dump(String outerPrefix, PrintWriter pw) {
|
public void dump(String outerPrefix, PrintWriter pw) {
|
||||||
pw.print(outerPrefix); pw.println("UiTranslationController:");
|
pw.print(outerPrefix); pw.println("UiTranslationController:");
|
||||||
final String pfx = outerPrefix + " ";
|
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();
|
final int translatorSize = mTranslators.size();
|
||||||
pw.print(outerPrefix); pw.print("number translator: "); pw.println(translatorSize);
|
pw.print(outerPrefix); pw.print("number translator: "); pw.println(translatorSize);
|
||||||
for (int i = 0; i < translatorSize; i++) {
|
for (int i = 0; i < translatorSize; i++) {
|
||||||
@@ -244,13 +261,18 @@ public class UiTranslationController {
|
|||||||
pw.print(outerPrefix); pw.print("autofillId: "); pw.print(autofillId);
|
pw.print(outerPrefix); pw.print("autofillId: "); pw.print(autofillId);
|
||||||
// TODO: print TranslationTransformation
|
// TODO: print TranslationTransformation
|
||||||
boolean isContainsView = false;
|
boolean isContainsView = false;
|
||||||
|
boolean isRequestedView = false;
|
||||||
synchronized (mLock) {
|
synchronized (mLock) {
|
||||||
|
if (mLastRequestAutofillIds.contains(autofillId)) {
|
||||||
|
isRequestedView = true;
|
||||||
|
}
|
||||||
final WeakReference<View> viewRef = mViews.get(autofillId);
|
final WeakReference<View> viewRef = mViews.get(autofillId);
|
||||||
if (viewRef != null && viewRef.get() != null) {
|
if (viewRef != null && viewRef.get() != null) {
|
||||||
isContainsView = true;
|
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) {
|
synchronized (mLock) {
|
||||||
dumpLocked("", pw);
|
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.annotations.GuardedBy;
|
||||||
import com.android.internal.os.IResultReceiver;
|
import com.android.internal.os.IResultReceiver;
|
||||||
|
import com.android.internal.os.TransferPipe;
|
||||||
import com.android.server.LocalServices;
|
import com.android.server.LocalServices;
|
||||||
import com.android.server.infra.AbstractPerUserSystemService;
|
import com.android.server.infra.AbstractPerUserSystemService;
|
||||||
import com.android.server.inputmethod.InputMethodManagerInternal;
|
import com.android.server.inputmethod.InputMethodManagerInternal;
|
||||||
import com.android.server.wm.ActivityTaskManagerInternal;
|
import com.android.server.wm.ActivityTaskManagerInternal;
|
||||||
import com.android.server.wm.ActivityTaskManagerInternal.ActivityTokens;
|
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;
|
import java.util.List;
|
||||||
|
|
||||||
final class TranslationManagerServiceImpl extends
|
final class TranslationManagerServiceImpl extends
|
||||||
@@ -69,6 +74,9 @@ final class TranslationManagerServiceImpl extends
|
|||||||
@GuardedBy("mLock")
|
@GuardedBy("mLock")
|
||||||
private TranslationServiceInfo mTranslationServiceInfo;
|
private TranslationServiceInfo mTranslationServiceInfo;
|
||||||
|
|
||||||
|
@GuardedBy("mLock")
|
||||||
|
private WeakReference<ActivityTokens> mLastActivityTokens;
|
||||||
|
|
||||||
private ActivityTaskManagerInternal mActivityTaskManagerInternal;
|
private ActivityTaskManagerInternal mActivityTaskManagerInternal;
|
||||||
|
|
||||||
private final TranslationServiceRemoteCallback mRemoteServiceCallback =
|
private final TranslationServiceRemoteCallback mRemoteServiceCallback =
|
||||||
@@ -178,12 +186,35 @@ final class TranslationManagerServiceImpl extends
|
|||||||
taskTopActivityTokens.getApplicationThread().updateUiTranslationState(
|
taskTopActivityTokens.getApplicationThread().updateUiTranslationState(
|
||||||
taskTopActivityTokens.getActivityToken(), state, sourceSpec, targetSpec,
|
taskTopActivityTokens.getActivityToken(), state, sourceSpec, targetSpec,
|
||||||
viewIds, uiTranslationSpec);
|
viewIds, uiTranslationSpec);
|
||||||
|
mLastActivityTokens = new WeakReference<>(taskTopActivityTokens);
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
Slog.w(TAG, "Update UiTranslationState fail: " + e);
|
Slog.w(TAG, "Update UiTranslationState fail: " + e);
|
||||||
}
|
}
|
||||||
invokeCallbacks(state, sourceSpec, targetSpec);
|
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(
|
private void invokeCallbacks(
|
||||||
int state, TranslationSpec sourceSpec, TranslationSpec targetSpec) {
|
int state, TranslationSpec sourceSpec, TranslationSpec targetSpec) {
|
||||||
Bundle res = new Bundle();
|
Bundle res = new Bundle();
|
||||||
|
|||||||
Reference in New Issue
Block a user