Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5a66e72a authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Allow auto-fill services to disable themselves"

parents aba6330a 7ad11281
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -265,6 +265,7 @@ 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 \
+1 −0
Original line number Diff line number Diff line
@@ -36472,6 +36472,7 @@ 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();
+1 −0
Original line number Diff line number Diff line
@@ -39395,6 +39395,7 @@ 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();
+1 −0
Original line number Diff line number Diff line
@@ -36611,6 +36611,7 @@ 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();
+34 −10
Original line number Diff line number Diff line
@@ -15,9 +15,12 @@
 */
package android.service.autofill;

import android.accessibilityservice.IAccessibilityServiceConnection;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.os.Message;
import android.os.RemoteException;
import android.view.accessibility.AccessibilityInteractionClient;
import com.android.internal.os.HandlerCaller;
import android.annotation.SdkConstant;
import android.app.Activity;
@@ -78,6 +81,15 @@ public abstract class AutoFillService extends Service {
    private static final int MSG_ON_SAVE_REQUEST = 4;

    private final IAutoFillService mInterface = new IAutoFillService.Stub() {
        @Override
        public void onInit(IAutoFillServiceConnection connection) {
            if (connection != null) {
                mHandlerCaller.obtainMessageO(MSG_CONNECT, connection).sendToTarget();
            } else {
                mHandlerCaller.obtainMessage(MSG_DISCONNECT).sendToTarget();
            }
        }

        @Override
        public void onFillRequest(AssistStructure structure, Bundle extras,
                IFillCallback callback) {
@@ -98,21 +110,12 @@ public abstract class AutoFillService extends Service {
            mHandlerCaller.obtainMessageOOO(MSG_ON_SAVE_REQUEST, structure,
                    extras, callback).sendToTarget();
        }

        @Override
        public void onConnected() {
            mHandlerCaller.sendMessage(mHandlerCaller.obtainMessage(MSG_CONNECT));
        }

        @Override
        public void onDisconnected() {
            mHandlerCaller.sendMessage(mHandlerCaller.obtainMessage(MSG_DISCONNECT));
        }
    };

    private final HandlerCaller.Callback mHandlerCallback = (msg) -> {
        switch (msg.what) {
            case MSG_CONNECT: {
                mConnection = (IAutoFillServiceConnection) msg.obj;
                onConnected();
                break;
            } case MSG_ON_FILL_REQUEST: {
@@ -136,6 +139,7 @@ public abstract class AutoFillService extends Service {
                break;
            } case MSG_DISCONNECT: {
                onDisconnected();
                mConnection = null;
                break;
            } default: {
                Log.w(TAG, "MyCallbacks received invalid message type: " + msg);
@@ -145,6 +149,8 @@ public abstract class AutoFillService extends Service {

    private HandlerCaller mHandlerCaller;

    private IAutoFillServiceConnection mConnection;

    /**
     * {@inheritDoc}
     *
@@ -223,4 +229,22 @@ public abstract class AutoFillService extends Service {
    public void onDisconnected() {
        //TODO(b/33197203): is not called anymore, fix it!
    }

    /**
     * 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>
     */
    public final void disableSelf() {
        if (mConnection != null) {
            try {
                mConnection.disableSelf();
            } catch (RemoteException re) {
                throw re.rethrowFromSystemServer();
            }
        }
    }
}
Loading