Merge "Added more logging to diagnose a racy runtime restart." into oc-mr1-dev

This commit is contained in:
TreeHugger Robot
2017-09-09 04:01:35 +00:00
committed by Android (Google) Code Review
3 changed files with 47 additions and 27 deletions

View File

@@ -20,7 +20,6 @@ import android.annotation.IntDef;
import android.annotation.NonNull; import android.annotation.NonNull;
import android.annotation.Nullable; import android.annotation.Nullable;
import android.os.Bundle; import android.os.Bundle;
import android.os.CancellationSignal;
import android.os.Parcel; import android.os.Parcel;
import android.os.Parcelable; import android.os.Parcelable;
import android.view.View; import android.view.View;
@@ -38,7 +37,7 @@ import java.util.List;
* interesting for saving and what are the possible ways to fill the inputs on * interesting for saving and what are the possible ways to fill the inputs on
* the screen if applicable. * the screen if applicable.
* *
* @see AutofillService#onFillRequest(FillRequest, CancellationSignal, FillCallback) * @see AutofillService#onFillRequest(FillRequest, android.os.CancellationSignal, FillCallback)
*/ */
public final class FillRequest implements Parcelable { public final class FillRequest implements Parcelable {
@@ -122,9 +121,14 @@ public final class FillRequest implements Parcelable {
return mContexts; return mContexts;
} }
@Override
public String toString() {
return "FillRequest: [id=" + mId + ", flags=" + mFlags + ", ctxts= " + mContexts + "]";
}
/** /**
* Gets the extra client state returned from the last {@link * Gets the extra client state returned from the last {@link
* AutofillService#onFillRequest(FillRequest, CancellationSignal, FillCallback) * AutofillService#onFillRequest(FillRequest, android.os.CancellationSignal, FillCallback)
* fill request}, so the service can use it for state management. * fill request}, so the service can use it for state management.
* *
* <p>Once a {@link AutofillService#onSaveRequest(SaveRequest, SaveCallback) * <p>Once a {@link AutofillService#onSaveRequest(SaveRequest, SaveCallback)

View File

@@ -387,8 +387,10 @@ final class RemoteFillService implements DeathRecipient {
@Override @Override
public void executeMessage(Message message) { public void executeMessage(Message message) {
if (mDestroyed) { if (mDestroyed) {
Slog.w(LOG_TAG, "Not handling " + message + " as service for " if (sVerbose) {
+ mComponentName + " is already destroyed"); Slog.v(LOG_TAG, "Not handling " + message + " as service for "
+ mComponentName + " is already destroyed");
}
return; return;
} }
switch (message.what) { switch (message.what) {
@@ -574,6 +576,13 @@ final class RemoteFillService implements DeathRecipient {
@Override @Override
public void run() { public void run() {
synchronized (mLock) {
if (isCancelledLocked()) {
// TODO(b/653742740): we should probably return here, but for now we're justing
// logging to confirm this is the problem if it happens again.
Slog.e(LOG_TAG, "run() called after canceled: " + mRequest);
}
}
final RemoteFillService remoteService = getService(); final RemoteFillService remoteService = getService();
if (remoteService != null) { if (remoteService != null) {
try { try {

View File

@@ -268,7 +268,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
value = state.getCurrentValue(); value = state.getCurrentValue();
if (value == null) { if (value == null) {
if (sDebug) Slog.d(TAG, "getValue(): no current value for " + id); if (sDebug) Slog.d(TAG, "getValue(): no current value for " + id);
value = getValueFromContexts(id); value = getValueFromContextsLocked(id);
} }
} }
if (value != null) { if (value != null) {
@@ -276,7 +276,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
return value.getTextValue().toString(); return value.getTextValue().toString();
} }
if (value.isList()) { if (value.isList()) {
final CharSequence[] options = getAutofillOptionsFromContexts(id); final CharSequence[] options = getAutofillOptionsFromContextsLocked(id);
if (options != null) { if (options != null) {
final int index = value.getListValue(); final int index = value.getListValue();
final CharSequence option = options[index]; final CharSequence option = options[index];
@@ -339,21 +339,21 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
* Cancels the last request sent to the {@link #mRemoteFillService}. * Cancels the last request sent to the {@link #mRemoteFillService}.
*/ */
private void cancelCurrentRequestLocked() { private void cancelCurrentRequestLocked() {
int canceledRequest = mRemoteFillService.cancelCurrentRequest(); final int canceledRequest = mRemoteFillService.cancelCurrentRequest();
// Remove the FillContext as there will never be a response for the service // Remove the FillContext as there will never be a response for the service
if (canceledRequest != INVALID_REQUEST_ID && mContexts != null) { if (canceledRequest != INVALID_REQUEST_ID && mContexts != null) {
int numContexts = mContexts.size(); final int numContexts = mContexts.size();
// It is most likely the last context, hence search backwards // It is most likely the last context, hence search backwards
for (int i = numContexts - 1; i >= 0; i--) { for (int i = numContexts - 1; i >= 0; i--) {
if (mContexts.get(i).getRequestId() == canceledRequest) { if (mContexts.get(i).getRequestId() == canceledRequest) {
if (sDebug) Slog.d(TAG, "cancelCurrentRequest(): id = " + canceledRequest);
mContexts.remove(i); mContexts.remove(i);
break; break;
} }
} }
} }
} }
/** /**
@@ -579,17 +579,13 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
public void authenticate(int requestId, int datasetIndex, IntentSender intent, Bundle extras) { public void authenticate(int requestId, int datasetIndex, IntentSender intent, Bundle extras) {
final Intent fillInIntent; final Intent fillInIntent;
synchronized (mLock) { synchronized (mLock) {
synchronized (mLock) { if (mDestroyed) {
if (mDestroyed) { Slog.w(TAG, "Call to Session#authenticate() rejected - session: "
Slog.w(TAG, "Call to Session#authenticate() rejected - session: " + id + " destroyed");
+ id + " destroyed"); return;
return;
}
} }
fillInIntent = createAuthFillInIntent( fillInIntent = createAuthFillInIntentLocked(requestId, extras);
getFillContextByRequestIdLocked(requestId).getStructure(), extras);
} }
mService.setAuthenticationSelected(id); mService.setAuthenticationSelected(id);
final int authenticationId = AutofillManager.makeAuthenticationId(requestId, datasetIndex); final int authenticationId = AutofillManager.makeAuthenticationId(requestId, datasetIndex);
@@ -846,7 +842,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
AutofillValue value = viewState.getCurrentValue(); AutofillValue value = viewState.getCurrentValue();
if (value == null || value.isEmpty()) { if (value == null || value.isEmpty()) {
final AutofillValue initialValue = getValueFromContexts(id); final AutofillValue initialValue = getValueFromContextsLocked(id);
if (initialValue != null) { if (initialValue != null) {
if (sDebug) { if (sDebug) {
Slog.d(TAG, "Value of required field " + id + " didn't change; " Slog.d(TAG, "Value of required field " + id + " didn't change; "
@@ -900,7 +896,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
} }
} else { } else {
// Update current values cache based on initial value // Update current values cache based on initial value
final AutofillValue initialValue = getValueFromContexts(id); final AutofillValue initialValue = getValueFromContextsLocked(id);
if (sDebug) { if (sDebug) {
Slog.d(TAG, "no current value for " + id + "; initial value is " Slog.d(TAG, "no current value for " + id + "; initial value is "
+ initialValue); + initialValue);
@@ -1007,7 +1003,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
* Gets the latest non-empty value for the given id in the autofill contexts. * Gets the latest non-empty value for the given id in the autofill contexts.
*/ */
@Nullable @Nullable
private AutofillValue getValueFromContexts(AutofillId id) { private AutofillValue getValueFromContextsLocked(AutofillId id) {
final int numContexts = mContexts.size(); final int numContexts = mContexts.size();
for (int i = numContexts - 1; i >= 0; i--) { for (int i = numContexts - 1; i >= 0; i--) {
final FillContext context = mContexts.get(i); final FillContext context = mContexts.get(i);
@@ -1029,7 +1025,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
* Gets the latest autofill options for the given id in the autofill contexts. * Gets the latest autofill options for the given id in the autofill contexts.
*/ */
@Nullable @Nullable
private CharSequence[] getAutofillOptionsFromContexts(AutofillId id) { private CharSequence[] getAutofillOptionsFromContextsLocked(AutofillId id) {
final int numContexts = mContexts.size(); final int numContexts = mContexts.size();
for (int i = numContexts - 1; i >= 0; i--) { for (int i = numContexts - 1; i >= 0; i--) {
@@ -1054,6 +1050,11 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
if (sVerbose) Slog.v(TAG, "callSaveLocked(): mViewStates=" + mViewStates); if (sVerbose) Slog.v(TAG, "callSaveLocked(): mViewStates=" + mViewStates);
if (mContexts == null) {
Slog.w(TAG, "callSaveLocked(): no contexts");
return;
}
final int numContexts = mContexts.size(); final int numContexts = mContexts.size();
for (int contextNum = 0; contextNum < numContexts; contextNum++) { for (int contextNum = 0; contextNum < numContexts; contextNum++) {
@@ -1553,8 +1554,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
// ...or handle authentication. // ...or handle authentication.
mService.setDatasetAuthenticationSelected(dataset.getId(), id); mService.setDatasetAuthenticationSelected(dataset.getId(), id);
setViewStatesLocked(null, dataset, ViewState.STATE_WAITING_DATASET_AUTH, false); setViewStatesLocked(null, dataset, ViewState.STATE_WAITING_DATASET_AUTH, false);
final Intent fillInIntent = createAuthFillInIntent( final Intent fillInIntent = createAuthFillInIntentLocked(requestId, mClientState);
getFillContextByRequestIdLocked(requestId).getStructure(), mClientState);
final int authenticationId = AutofillManager.makeAuthenticationId(requestId, final int authenticationId = AutofillManager.makeAuthenticationId(requestId,
datasetIndex); datasetIndex);
@@ -1568,9 +1568,16 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
} }
} }
private Intent createAuthFillInIntent(AssistStructure structure, Bundle extras) { private Intent createAuthFillInIntentLocked(int requestId, Bundle extras) {
final Intent fillInIntent = new Intent(); final Intent fillInIntent = new Intent();
fillInIntent.putExtra(AutofillManager.EXTRA_ASSIST_STRUCTURE, structure);
final FillContext context = getFillContextByRequestIdLocked(requestId);
if (context == null) {
// TODO(b/653742740): this will crash system_server. We need to handle it, but we're
// keeping it crashing for now so we can diagnose when it happens again
Slog.wtf(TAG, "no FillContext for requestId" + requestId + "; mContexts= " + mContexts);
}
fillInIntent.putExtra(AutofillManager.EXTRA_ASSIST_STRUCTURE, context.getStructure());
fillInIntent.putExtra(AutofillManager.EXTRA_CLIENT_STATE, extras); fillInIntent.putExtra(AutofillManager.EXTRA_CLIENT_STATE, extras);
return fillInIntent; return fillInIntent;
} }