Merge "Remove AutofillManagerClient after AutofillManager is finalized"

am: dd5384a4fe

Change-Id: If0b092c5e18005fb4b8c1fd8405f4d666c98de5a
This commit is contained in:
Koji Fukui
2017-11-15 02:35:18 +00:00
committed by android-build-merger
5 changed files with 52 additions and 1 deletions

View File

@@ -19,6 +19,7 @@ package android.os;
import android.util.ArrayMap;
import android.util.Slog;
import java.io.PrintWriter;
import java.util.function.Consumer;
/**
@@ -399,6 +400,13 @@ public class RemoteCallbackList<E extends IInterface> {
}
}
/** @hide */
public void dump(PrintWriter pw, String prefix) {
pw.print(prefix); pw.print("callbacks: "); pw.println(mCallbacks.size());
pw.print(prefix); pw.print("killed: "); pw.println(mKilled);
pw.print(prefix); pw.print("broadcasts count: "); pw.println(mBroadcastCount);
}
private void logExcessiveCallbacks() {
final long size = mCallbacks.size();
final long TOO_MANY = 3000;

View File

@@ -53,6 +53,9 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
// TODO: use java.lang.ref.Cleaner once Android supports Java 9
import sun.misc.Cleaner;
/**
* The {@link AutofillManager} provides ways for apps and custom views to integrate with the
* Autofill Framework lifecycle.
@@ -285,6 +288,9 @@ public final class AutofillManager {
@GuardedBy("mLock")
private IAutoFillManagerClient mServiceClient;
@GuardedBy("mLock")
private Cleaner mServiceClientCleaner;
@GuardedBy("mLock")
private AutofillCallback mCallback;
@@ -1080,10 +1086,19 @@ public final class AutofillManager {
if (mServiceClient == null) {
mServiceClient = new AutofillManagerClient(this);
try {
final int flags = mService.addClient(mServiceClient, mContext.getUserId());
final int userId = mContext.getUserId();
final int flags = mService.addClient(mServiceClient, userId);
mEnabled = (flags & FLAG_ADD_CLIENT_ENABLED) != 0;
sDebug = (flags & FLAG_ADD_CLIENT_DEBUG) != 0;
sVerbose = (flags & FLAG_ADD_CLIENT_VERBOSE) != 0;
final IAutoFillManager service = mService;
final IAutoFillManagerClient serviceClient = mServiceClient;
mServiceClientCleaner = Cleaner.create(this, () -> {
try {
service.removeClient(serviceClient, userId);
} catch (RemoteException e) {
}
});
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
@@ -1190,6 +1205,10 @@ public final class AutofillManager {
if (resetClient) {
// Reset connection to system
mServiceClient = null;
if (mServiceClientCleaner != null) {
mServiceClientCleaner.clean();
mServiceClientCleaner = null;
}
}
}
}

View File

@@ -32,6 +32,7 @@ import android.view.autofill.IAutoFillManagerClient;
interface IAutoFillManager {
// Returns flags: FLAG_ADD_CLIENT_ENABLED | FLAG_ADD_CLIENT_DEBUG | FLAG_ADD_CLIENT_VERBOSE
int addClient(in IAutoFillManagerClient client, int userId);
void removeClient(in IAutoFillManagerClient client, int userId);
int startSession(IBinder activityToken, in IBinder appCallback, in AutofillId autoFillId,
in Rect bounds, in AutofillValue value, int userId, boolean hasCallback, int flags,
String packageName);

View File

@@ -512,6 +512,16 @@ public final class AutofillManagerService extends SystemService {
}
}
@Override
public void removeClient(IAutoFillManagerClient client, int userId) {
synchronized (mLock) {
final AutofillManagerServiceImpl service = peekServiceForUserLocked(userId);
if (service != null) {
service.removeClientLocked(client);
}
}
}
@Override
public void setAuthenticationResult(Bundle data, int sessionId, int authenticationId,
int userId) {

View File

@@ -254,6 +254,12 @@ final class AutofillManagerServiceImpl {
return isEnabled();
}
void removeClientLocked(IAutoFillManagerClient client) {
if (mClients != null) {
mClients.unregister(client);
}
}
void setAuthenticationResultLocked(Bundle data, int sessionId, int authenticationId, int uid) {
if (!isEnabled()) {
return;
@@ -505,6 +511,10 @@ final class AutofillManagerServiceImpl {
}
sendStateToClients(true);
if (mClients != null) {
mClients.kill();
mClients = null;
}
}
@NonNull
@@ -638,6 +648,9 @@ final class AutofillManagerServiceImpl {
}
}
pw.print(prefix); pw.println("Clients");
mClients.dump(pw, prefix2);
if (mEventHistory == null || mEventHistory.getEvents() == null
|| mEventHistory.getEvents().size() == 0) {
pw.print(prefix); pw.println("No event on last fill response");