Merge "Move API for disabling an autofill service to the manager" into oc-dev

This commit is contained in:
TreeHugger Robot
2017-04-11 06:10:07 +00:00
committed by Android (Google) Code Review
13 changed files with 91 additions and 111 deletions

View File

@ -273,7 +273,6 @@ LOCAL_SRC_FILES += \
core/java/android/security/IKeystoreService.aidl \
core/java/android/security/keymaster/IKeyAttestationApplicationIdProvider.aidl \
core/java/android/service/autofill/IAutoFillService.aidl \
core/java/android/service/autofill/IAutoFillServiceConnection.aidl \
core/java/android/service/autofill/IFillCallback.aidl \
core/java/android/service/autofill/ISaveCallback.aidl \
core/java/android/service/carrier/ICarrierService.aidl \

View File

@ -36986,7 +36986,6 @@ package android.service.autofill {
public abstract class AutofillService extends android.app.Service {
ctor public AutofillService();
method public final void disableSelf();
method public final android.os.IBinder onBind(android.content.Intent);
method public void onConnected();
method public void onDisconnected();
@ -47732,6 +47731,7 @@ package android.view.autofill {
public final class AutofillManager {
method public void cancel();
method public void commit();
method public void disableOwnedAutofillServices();
method public boolean isEnabled();
method public void notifyValueChanged(android.view.View);
method public void notifyValueChanged(android.view.View, int, android.view.autofill.AutofillValue);

View File

@ -40082,7 +40082,6 @@ package android.service.autofill {
public abstract class AutofillService extends android.app.Service {
ctor public AutofillService();
method public final void disableSelf();
method public final android.os.IBinder onBind(android.content.Intent);
method public void onConnected();
method public void onDisconnected();
@ -51284,6 +51283,7 @@ package android.view.autofill {
public final class AutofillManager {
method public void cancel();
method public void commit();
method public void disableOwnedAutofillServices();
method public boolean isEnabled();
method public void notifyValueChanged(android.view.View);
method public void notifyValueChanged(android.view.View, int, android.view.autofill.AutofillValue);

View File

@ -37144,7 +37144,6 @@ package android.service.autofill {
public abstract class AutofillService extends android.app.Service {
ctor public AutofillService();
method public final void disableSelf();
method public final android.os.IBinder onBind(android.content.Intent);
method public void onConnected();
method public void onDisconnected();
@ -48114,6 +48113,7 @@ package android.view.autofill {
public final class AutofillManager {
method public void cancel();
method public void commit();
method public void disableOwnedAutofillServices();
method public boolean isEnabled();
method public void notifyValueChanged(android.view.View);
method public void notifyValueChanged(android.view.View, int, android.view.autofill.AutofillValue);

View File

@ -94,9 +94,9 @@ public abstract class AutofillService extends Service {
private final IAutoFillService mInterface = new IAutoFillService.Stub() {
@Override
public void onInit(IAutoFillServiceConnection connection) {
if (connection != null) {
mHandlerCaller.obtainMessageO(MSG_CONNECT, connection).sendToTarget();
public void onConnectedStateChanged(boolean connected) {
if (connected) {
mHandlerCaller.obtainMessage(MSG_CONNECT).sendToTarget();
} else {
mHandlerCaller.obtainMessage(MSG_DISCONNECT).sendToTarget();
}
@ -127,7 +127,6 @@ public abstract class AutofillService extends Service {
private final HandlerCaller.Callback mHandlerCallback = (msg) -> {
switch (msg.what) {
case MSG_CONNECT: {
mConnection = (IAutoFillServiceConnection) msg.obj;
onConnected();
break;
} case MSG_ON_FILL_REQUEST: {
@ -152,7 +151,6 @@ public abstract class AutofillService extends Service {
break;
} case MSG_DISCONNECT: {
onDisconnected();
mConnection = null;
break;
} default: {
Log.w(TAG, "MyCallbacks received invalid message type: " + msg);
@ -162,8 +160,6 @@ public abstract class AutofillService extends Service {
private HandlerCaller mHandlerCaller;
private IAutoFillServiceConnection mConnection;
/**
* {@inheritDoc}
*
@ -246,21 +242,9 @@ public abstract class AutofillService extends Service {
public void onDisconnected() {
}
/**
* Disables the service. After calling this method, the service will
* be disabled and settings will show that it is turned off.
*
* <p>You should call this method only after a call to {@link #onConnected()}
* and before the corresponding call to {@link #onDisconnected()}. In other words
* you can disable your service only while the system is connected to it.</p>
*/
/** @hide */
public final void disableSelf() {
if (mConnection != null) {
try {
mConnection.disableSelf();
} catch (RemoteException re) {
throw re.rethrowFromSystemServer();
}
}
// TODO(b/33197203): Remove when GCore has migrated off this API
getSystemService(AutofillManager.class).disableOwnedAutofillServices();
}
}

View File

@ -18,7 +18,6 @@ package android.service.autofill;
import android.app.assist.AssistStructure;
import android.os.Bundle;
import android.service.autofill.IAutoFillServiceConnection;
import android.service.autofill.IFillCallback;
import android.service.autofill.ISaveCallback;
import com.android.internal.os.IResultReceiver;
@ -29,7 +28,7 @@ import com.android.internal.os.IResultReceiver;
* @hide
*/
oneway interface IAutoFillService {
void onInit(in IAutoFillServiceConnection connection);
void onConnectedStateChanged(boolean connected);
void onFillRequest(in AssistStructure structure, in Bundle extras,
in IFillCallback callback, int flags);
void onSaveRequest(in AssistStructure structure, in Bundle extras,

View File

@ -1,26 +0,0 @@
/*
* Copyright (C) 2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.service.autofill;
/**
* Interface from an auto fill service to the system.
*
* @hide
*/
interface IAutoFillServiceConnection {
void disableSelf();
}

View File

@ -537,6 +537,18 @@ public final class AutofillManager {
}
}
/**
* If the app calling this API has enabled autofill services they
* will be disabled.
*/
public void disableOwnedAutofillServices() {
try {
mService.disableOwnedAutofillServices(mContext.getUserId());
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
private AutofillClient getClientLocked() {
if (mContext instanceof AutofillClient) {
return (AutofillClient) mContext;

View File

@ -35,10 +35,11 @@ interface IAutoFillManager {
boolean hasCallback, int flags, String packageName);
boolean restoreSession(int sessionId, in IBinder activityToken, in IBinder appCallback);
void setWindow(int sessionId, in IBinder windowToken);
oneway void updateSession(int sessionId, in AutofillId id, in Rect bounds,
void updateSession(int sessionId, in AutofillId id, in Rect bounds,
in AutofillValue value, int flags, int userId);
void finishSession(int sessionId, int userId);
void cancelSession(int sessionId, int userId);
void setAuthenticationResult(in Bundle data, int sessionId, int userId);
oneway void setHasCallback(int sessionId, int userId, boolean hasIt);
void setHasCallback(int sessionId, int userId, boolean hasIt);
void disableOwnedAutofillServices(int userId);
}

View File

@ -24,6 +24,8 @@ import static com.android.server.autofill.Helper.VERBOSE;
import static com.android.server.autofill.Helper.bundleToString;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.app.ActivityManager;
import android.app.ActivityManagerInternal;
import android.content.BroadcastReceiver;
import android.content.ContentResolver;
@ -35,6 +37,7 @@ import android.content.pm.UserInfo;
import android.database.ContentObserver;
import android.graphics.Rect;
import android.net.Uri;
import android.os.Binder;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
@ -194,15 +197,29 @@ public final class AutofillManagerService extends SystemService {
*/
@NonNull
AutofillManagerServiceImpl getServiceForUserLocked(int userId) {
AutofillManagerServiceImpl service = mServicesCache.get(userId);
final int resolvedUserId = ActivityManager.handleIncomingUser(Binder.getCallingPid(),
Binder.getCallingUid(), userId, false, false, null, null);
AutofillManagerServiceImpl service = mServicesCache.get(resolvedUserId);
if (service == null) {
service = new AutofillManagerServiceImpl(mContext, mLock,
mRequestsHistory, userId, mUi, mDisabledUsers.get(userId));
service = new AutofillManagerServiceImpl(mContext, mLock, mRequestsHistory,
resolvedUserId, mUi, mDisabledUsers.get(resolvedUserId));
mServicesCache.put(userId, service);
}
return service;
}
/**
* Peeks the service instance for a user.
*
* @return service instance or null if not already present
*/
@Nullable
AutofillManagerServiceImpl peekServiceForUserLocked(int userId) {
final int resolvedUserId = ActivityManager.handleIncomingUser(Binder.getCallingPid(),
Binder.getCallingUid(), userId, false, false, null, null);
return mServicesCache.get(resolvedUserId);
}
// Called by Shell command.
void requestSaveForUser(int userId) {
Slog.i(TAG, "requestSaveForUser(): " + userId);
@ -210,7 +227,7 @@ public final class AutofillManagerService extends SystemService {
final IBinder activityToken = getTopActivityForUser();
if (activityToken != null) {
synchronized (mLock) {
final AutofillManagerServiceImpl service = mServicesCache.get(userId);
final AutofillManagerServiceImpl service = peekServiceForUserLocked(userId);
if (service == null) {
Log.w(TAG, "handleSaveForUser(): no cached service for userId " + userId);
return;
@ -228,7 +245,10 @@ public final class AutofillManagerService extends SystemService {
synchronized (mLock) {
if (userId != UserHandle.USER_ALL) {
mServicesCache.get(userId).destroySessionsLocked();
AutofillManagerServiceImpl service = peekServiceForUserLocked(userId);
if (service != null) {
service.destroySessionsLocked();
}
} else {
final int size = mServicesCache.size();
for (int i = 0; i < size; i++) {
@ -253,7 +273,10 @@ public final class AutofillManagerService extends SystemService {
synchronized (mLock) {
if (userId != UserHandle.USER_ALL) {
mServicesCache.get(userId).listSessionsLocked(sessions);
AutofillManagerServiceImpl service = peekServiceForUserLocked(userId);
if (service != null) {
service.listSessionsLocked(sessions);
}
} else {
final int size = mServicesCache.size();
for (int i = 0; i < size; i++) {
@ -287,7 +310,7 @@ public final class AutofillManagerService extends SystemService {
* Removes a cached service for a given user.
*/
private void removeCachedServiceLocked(int userId) {
final AutofillManagerServiceImpl service = mServicesCache.get(userId);
final AutofillManagerServiceImpl service = peekServiceForUserLocked(userId);
if (service != null) {
mServicesCache.delete(userId);
service.destroyLocked();
@ -305,7 +328,7 @@ public final class AutofillManagerService extends SystemService {
* Updates a cached service for a given user.
*/
private void updateCachedServiceLocked(int userId, boolean disabled) {
AutofillManagerServiceImpl service = mServicesCache.get(userId);
AutofillManagerServiceImpl service = peekServiceForUserLocked(userId);
if (service != null) {
service.updateLocked(disabled);
}
@ -409,8 +432,7 @@ public final class AutofillManagerService extends SystemService {
public void updateSession(int sessionId, AutofillId id, Rect bounds,
AutofillValue value, int flags, int userId) {
synchronized (mLock) {
final AutofillManagerServiceImpl service = mServicesCache.get(
UserHandle.getCallingUserId());
final AutofillManagerServiceImpl service = peekServiceForUserLocked(userId);
if (service != null) {
service.updateSessionLocked(sessionId, getCallingUid(), id, bounds, value,
flags);
@ -421,8 +443,7 @@ public final class AutofillManagerService extends SystemService {
@Override
public void finishSession(int sessionId, int userId) {
synchronized (mLock) {
final AutofillManagerServiceImpl service = mServicesCache.get(
UserHandle.getCallingUserId());
final AutofillManagerServiceImpl service = peekServiceForUserLocked(userId);
if (service != null) {
service.finishSessionLocked(sessionId, getCallingUid());
}
@ -432,14 +453,23 @@ public final class AutofillManagerService extends SystemService {
@Override
public void cancelSession(int sessionId, int userId) {
synchronized (mLock) {
final AutofillManagerServiceImpl service = mServicesCache.get(
UserHandle.getCallingUserId());
final AutofillManagerServiceImpl service = peekServiceForUserLocked(userId);
if (service != null) {
service.cancelSessionLocked(sessionId, getCallingUid());
}
}
}
@Override
public void disableOwnedAutofillServices(int userId) {
synchronized (mLock) {
final AutofillManagerServiceImpl service = peekServiceForUserLocked(userId);
if (service != null) {
service.disableOwnedAutofillServicesLocked(Binder.getCallingUid());
}
}
}
@Override
public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
if (!DumpUtils.checkDumpPermission(mContext, TAG, pw)) return;

View File

@ -43,6 +43,7 @@ import android.os.IBinder;
import android.os.Looper;
import android.os.RemoteCallbackList;
import android.os.RemoteException;
import android.os.UserHandle;
import android.os.UserManager;
import android.provider.Settings;
import android.service.autofill.AutofillService;
@ -348,6 +349,25 @@ final class AutofillManagerServiceImpl {
session.removeSelfLocked();
}
void disableOwnedAutofillServicesLocked(int uid) {
if (mInfo == null || mInfo.getServiceInfo().applicationInfo.uid
!= UserHandle.getAppId(uid)) {
return;
}
final long identity = Binder.clearCallingIdentity();
try {
final String autoFillService = getComponentNameFromSettings();
if (mInfo.getServiceInfo().getComponentName().equals(
ComponentName.unflattenFromString(autoFillService))) {
Settings.Secure.putStringForUser(mContext.getContentResolver(),
Settings.Secure.AUTOFILL_SERVICE, null, mUserId);
destroySessionsLocked();
}
} finally {
Binder.restoreCallingIdentity(identity);
}
}
private Session createSessionByTokenLocked(@NonNull IBinder activityToken, int uid,
@Nullable IBinder windowToken, @NonNull IBinder appCallbackToken, boolean hasCallback,
int flags, @NonNull String packageName) {
@ -474,20 +494,6 @@ final class AutofillManagerServiceImpl {
mSessions.clear();
}
void disableSelf() {
final long identity = Binder.clearCallingIdentity();
try {
final String autoFillService = getComponentNameFromSettings();
if (mInfo.getServiceInfo().getComponentName().equals(
ComponentName.unflattenFromString(autoFillService))) {
Settings.Secure.putStringForUser(mContext.getContentResolver(),
Settings.Secure.AUTOFILL_SERVICE, null, mUserId);
}
} finally {
Binder.restoreCallingIdentity(identity);
}
}
CharSequence getServiceLabel() {
return mInfo.getServiceInfo().loadLabel(mContext.getPackageManager());
}

View File

@ -35,7 +35,6 @@ import android.os.UserHandle;
import android.service.autofill.AutofillService;
import android.service.autofill.FillResponse;
import android.service.autofill.IAutoFillService;
import android.service.autofill.IAutoFillServiceConnection;
import android.service.autofill.IFillCallback;
import android.service.autofill.ISaveCallback;
import android.text.format.DateUtils;
@ -96,7 +95,6 @@ final class RemoteFillService implements DeathRecipient {
void onSaveRequestFailure(@Nullable CharSequence message,
@NonNull String servicePackageName);
void onServiceDied(RemoteFillService service);
void onDisableSelf();
}
public RemoteFillService(Context context, ComponentName componentName,
@ -203,10 +201,6 @@ final class RemoteFillService implements DeathRecipient {
}
}
private void handleDisableSelf() {
mCallbacks.onDisableSelf();
}
private boolean isBound() {
return mAutoFillService != null;
}
@ -246,7 +240,7 @@ final class RemoteFillService implements DeathRecipient {
mBinding = false;
if (isBound()) {
try {
mAutoFillService.onInit(null);
mAutoFillService.onConnectedStateChanged(false);
} catch (Exception e) {
Slog.w(LOG_TAG, "Exception calling onDisconnected(): " + e);
}
@ -322,12 +316,7 @@ final class RemoteFillService implements DeathRecipient {
return;
}
try {
mAutoFillService.onInit(new IAutoFillServiceConnection.Stub() {
@Override
public void disableSelf() {
mHandler.obtainMessage(MyHandler.MSG_ON_DISABLE_SELF).sendToTarget();
}
});
mAutoFillService.onConnectedStateChanged(true);
} catch (RemoteException e) {
Slog.w(LOG_TAG, "Exception calling onConnected(): " + e);
}
@ -353,7 +342,6 @@ final class RemoteFillService implements DeathRecipient {
public static final int MSG_BINDER_DIED = 2;
public static final int MSG_UNBIND = 3;
public static final int MSG_ON_PENDING_REQUEST = 4;
public static final int MSG_ON_DISABLE_SELF = 5;
public MyHandler(Context context) {
// Cannot use lambda - doesn't compile
@ -381,10 +369,6 @@ final class RemoteFillService implements DeathRecipient {
case MSG_ON_PENDING_REQUEST: {
handlePendingRequest((PendingRequest) message.obj);
} break;
case MSG_ON_DISABLE_SELF: {
handleDisableSelf();
} break;
}
}
}, false);

View File

@ -309,15 +309,6 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
mHandlerCaller.getHandler().post(() -> startAuthentication(intent, fillInIntent));
}
// FillServiceCallbacks
@Override
public void onDisableSelf() {
mService.disableSelf();
synchronized (mLock) {
removeSelfLocked();
}
}
// FillServiceCallbacks
@Override
public void onServiceDied(RemoteFillService service) {