Merge "Destroy Save UI when it's hidden without a pending restoration." into oc-mr1-dev

am: 415c7aadd0

Change-Id: If1bad19eb25126c1b5d1e650ed245ad677ffacdc
This commit is contained in:
Felipe Leme
2017-09-09 07:16:22 +00:00
committed by android-build-merger
5 changed files with 41 additions and 28 deletions

View File

@@ -624,7 +624,7 @@ final class AutofillManagerServiceImpl {
void destroySessionsLocked() {
if (mSessions.size() == 0) {
mUi.destroyAll(AutofillManager.NO_SESSION, null, null);
mUi.destroyAll(null, null);
return;
}
while (mSessions.size() > 0) {

View File

@@ -969,9 +969,9 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
if (sDebug) Slog.d(TAG, "Good news, everyone! All checks passed, show save UI!");
mService.setSaveShown(id);
final IAutoFillManagerClient client = getClient();
mPendingSaveUi = new PendingUi(mActivityToken);
mPendingSaveUi = new PendingUi(mActivityToken, id, client);
getUiForShowing().showSaveUi(mService.getServiceLabel(), saveInfo,
valueFinder, mPackageName, this, mPendingSaveUi, id, client);
valueFinder, mPackageName, this, mPendingSaveUi);
if (client != null) {
try {
client.setSaveUiState(id, true);
@@ -1715,7 +1715,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
if (mDestroyed) {
return null;
}
mUi.destroyAll(id, getClient(), this);
mUi.destroyAll(mPendingSaveUi, this);
mUi.clearCallback(this);
mDestroyed = true;
mMetricsLogger.action(MetricsEvent.AUTOFILL_SESSION_FINISHED, mPackageName);
@@ -1731,7 +1731,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
mPendingSaveUi = null;
removeSelfLocked();
mUi.destroyAll(id, getClient(), this);
mUi.destroyAll(mPendingSaveUi, this);
}
/**

View File

@@ -35,7 +35,6 @@ import android.text.TextUtils;
import android.util.Slog;
import android.view.autofill.AutofillId;
import android.view.autofill.AutofillManager;
import android.view.autofill.IAutoFillManagerClient;
import android.view.autofill.IAutofillWindowPresenter;
import android.widget.Toast;
@@ -247,8 +246,7 @@ public final class AutoFillUI {
*/
public void showSaveUi(@NonNull CharSequence providerLabel, @NonNull SaveInfo info,
@NonNull ValueFinder valueFinder, @NonNull String packageName,
@NonNull AutoFillUiCallback callback, @NonNull PendingUi pendingUi,
int sessionId, @Nullable IAutoFillManagerClient client) {
@NonNull AutoFillUiCallback callback, @NonNull PendingUi pendingSaveUi) {
if (sVerbose) Slog.v(TAG, "showSaveUi() for " + packageName + ": " + info);
int numIds = 0;
numIds += info.getRequiredIds() == null ? 0 : info.getRequiredIds().length;
@@ -263,8 +261,8 @@ public final class AutoFillUI {
return;
}
hideAllUiThread(callback);
mSaveUi = new SaveUi(mContext, pendingUi, providerLabel, info, valueFinder,
mOverlayControl, client, new SaveUi.OnSaveListener() {
mSaveUi = new SaveUi(mContext, pendingSaveUi, providerLabel, info, valueFinder,
mOverlayControl, new SaveUi.OnSaveListener() {
@Override
public void onSave() {
log.setType(MetricsProto.MetricsEvent.TYPE_ACTION);
@@ -272,7 +270,7 @@ public final class AutoFillUI {
if (mCallback != null) {
mCallback.save();
}
destroySaveUiUiThread(sessionId, client);
destroySaveUiUiThread(pendingSaveUi);
}
@Override
@@ -290,7 +288,7 @@ public final class AutoFillUI {
if (mCallback != null) {
mCallback.cancelSave();
}
destroySaveUiUiThread(sessionId, client);
destroySaveUiUiThread(pendingSaveUi);
}
@Override
@@ -331,9 +329,9 @@ public final class AutoFillUI {
/**
* Destroy all UI affordances.
*/
public void destroyAll(int sessionId, @Nullable IAutoFillManagerClient client,
public void destroyAll(@Nullable PendingUi pendingSaveUi,
@Nullable AutoFillUiCallback callback) {
mHandler.post(() -> destroyAllUiThread(sessionId, client, callback));
mHandler.post(() -> destroyAllUiThread(pendingSaveUi, callback));
}
public void dump(PrintWriter pw) {
@@ -363,18 +361,20 @@ public final class AutoFillUI {
}
@android.annotation.UiThread
private void hideSaveUiUiThread(@Nullable AutoFillUiCallback callback) {
@Nullable
private PendingUi hideSaveUiUiThread(@Nullable AutoFillUiCallback callback) {
if (sVerbose) {
Slog.v(TAG, "hideSaveUiUiThread(): mSaveUi=" + mSaveUi + ", callback=" + callback
+ ", mCallback=" + mCallback);
}
if (mSaveUi != null && (callback == null || callback == mCallback)) {
mSaveUi.hide();
return mSaveUi.hide();
}
return null;
}
@android.annotation.UiThread
private void destroySaveUiUiThread(int sessionId, @Nullable IAutoFillManagerClient client) {
private void destroySaveUiUiThread(@Nullable PendingUi pendingSaveUi) {
if (mSaveUi == null) {
// Calling destroySaveUiUiThread() twice is normal - it usually happens when the
// first call is made after the SaveUI is hidden and the second when the session is
@@ -383,13 +383,13 @@ public final class AutoFillUI {
return;
}
if (sDebug) Slog.d(TAG, "destroySaveUiUiThread(): id=" + sessionId);
if (sDebug) Slog.d(TAG, "destroySaveUiUiThread(): " + pendingSaveUi);
mSaveUi.destroy();
mSaveUi = null;
if (client != null) {
if (pendingSaveUi != null) {
try {
if (sDebug) Slog.d(TAG, "destroySaveUiUiThread(): notifying client");
client.setSaveUiState(sessionId, false);
pendingSaveUi.client.setSaveUiState(pendingSaveUi.id, false);
} catch (RemoteException e) {
Slog.e(TAG, "Error notifying client to set save UI state to hidden: " + e);
}
@@ -397,15 +397,22 @@ public final class AutoFillUI {
}
@android.annotation.UiThread
private void destroyAllUiThread(int sessionId, @Nullable IAutoFillManagerClient client,
private void destroyAllUiThread(@Nullable PendingUi pendingSaveUi,
@Nullable AutoFillUiCallback callback) {
hideFillUiUiThread(callback);
destroySaveUiUiThread(sessionId, client);
destroySaveUiUiThread(pendingSaveUi);
}
@android.annotation.UiThread
private void hideAllUiThread(@Nullable AutoFillUiCallback callback) {
hideFillUiUiThread(callback);
hideSaveUiUiThread(callback);
final PendingUi pendingSaveUi = hideSaveUiUiThread(callback);
if (pendingSaveUi != null && pendingSaveUi.getState() == PendingUi.STATE_FINISHED) {
if (sDebug) {
Slog.d(TAG, "hideAllUiThread(): "
+ "destroying Save UI because pending restoration is finished");
}
destroySaveUiUiThread(pendingSaveUi);
}
}
}

View File

@@ -18,6 +18,7 @@ package com.android.server.autofill.ui;
import android.annotation.NonNull;
import android.os.IBinder;
import android.util.DebugUtils;
import android.view.autofill.IAutoFillManagerClient;
/**
* Helper class used to handle a pending Autofill affordance such as the Save UI.
@@ -34,15 +35,19 @@ public final class PendingUi {
private final IBinder mToken;
private int mState;
public final int id;
public final IAutoFillManagerClient client;
/**
* Default constructor.
*
* @param token token used to identify this pending UI.
*/
public PendingUi(@NonNull IBinder token) {
public PendingUi(@NonNull IBinder token, int id, @NonNull IAutoFillManagerClient client) {
mToken = token;
mState = STATE_CREATED;
this.id = id;
this.client = client;
}
/**
@@ -76,7 +81,7 @@ public final class PendingUi {
@Override
public String toString() {
return "PendingUi: [token=" + mToken + ", state="
return "PendingUi: [token=" + mToken + ", id=" + id + ", state="
+ DebugUtils.flagsToString(PendingUi.class, "STATE_", mState) + "]";
}
}

View File

@@ -123,7 +123,7 @@ final class SaveUi {
SaveUi(@NonNull Context context, @NonNull PendingUi pendingUi,
@NonNull CharSequence providerLabel, @NonNull SaveInfo info,
@NonNull ValueFinder valueFinder, @NonNull OverlayControl overlayControl,
@NonNull IAutoFillManagerClient client, @NonNull OnSaveListener listener) {
@NonNull OnSaveListener listener) {
mPendingUi= pendingUi;
mListener = new OneTimeListener(listener);
mOverlayControl = overlayControl;
@@ -206,7 +206,7 @@ final class SaveUi {
final IBinder token = mPendingUi.getToken();
intent.putExtra(AutofillManager.EXTRA_RESTORE_SESSION_TOKEN, token);
try {
client.startIntentSender(pendingIntent.getIntentSender(),
pendingUi.client.startIntentSender(pendingIntent.getIntentSender(),
intent);
mPendingUi.setState(PendingUi.STATE_PENDING);
if (sDebug) {
@@ -318,13 +318,14 @@ final class SaveUi {
mOverlayControl.hideOverlays();
}
void hide() {
PendingUi hide() {
if (sVerbose) Slog.v(TAG, "Hiding save dialog.");
try {
mDialog.hide();
} finally {
mOverlayControl.showOverlays();
}
return mPendingUi;
}
void destroy() {