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

Commit e348dc34 authored by Felipe Leme's avatar Felipe Leme
Browse files

Initial implementation of the IntelligenceService pipeline.

It's still full of TODOs, but at leats it now provides an end-to-end
workflow from the activity creation / destruction to the service implementation.

Test: mmm -j packages/experimental/FillService && \
      adb install -r ${OUT}/data/app/FillService/FillService.apk && \
      adb shell settings put secure intel_service foo.bar.fill/.AiaiService
Bug: 111276913

Change-Id: Id5daf7b8b51e97c74d9b6ec00f953ddb02b48e46
parent e0c2f7e1
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -287,6 +287,8 @@ java_defaults {
        "core/java/android/service/euicc/ISwitchToSubscriptionCallback.aidl",
        "core/java/android/service/euicc/IUpdateSubscriptionNicknameCallback.aidl",
        "core/java/android/service/gatekeeper/IGateKeeperService.aidl",
        "core/java/android/service/intelligence/IIntelligenceService.aidl",

        "core/java/android/service/notification/INotificationListener.aidl",
        "core/java/android/service/notification/IStatusBarNotificationHolder.aidl",
        "core/java/android/service/notification/IConditionListener.aidl",
@@ -343,6 +345,7 @@ java_defaults {
        "core/java/android/view/autofill/IAutoFillManager.aidl",
        "core/java/android/view/autofill/IAutoFillManagerClient.aidl",
        "core/java/android/view/autofill/IAutofillWindowPresenter.aidl",
        "core/java/android/view/intelligence/IIntelligenceManager.aidl",
        "core/java/android/view/IApplicationToken.aidl",
        "core/java/android/view/IAppTransitionAnimationSpecsFuture.aidl",
        "core/java/android/view/IDockedStackListener.aidl",
+48 −4
Original line number Diff line number Diff line
@@ -120,6 +120,7 @@ import android.view.autofill.AutofillManager;
import android.view.autofill.AutofillManager.AutofillClient;
import android.view.autofill.AutofillPopupWindow;
import android.view.autofill.IAutofillWindowPresenter;
import android.view.intelligence.IntelligenceManager;
import android.widget.AdapterView;
import android.widget.Toast;
import android.widget.Toolbar;
@@ -821,6 +822,10 @@ public class Activity extends ContextThemeWrapper
    /** The autofill manager. Always access via {@link #getAutofillManager()}. */
    @Nullable private AutofillManager mAutofillManager;

    /** The screen observation manager. Always access via {@link #getIntelligenceManager()}. */
    @Nullable private IntelligenceManager mIntelligenceManager;


    static final class NonConfigurationInstances {
        Object activity;
        HashMap<String, Object> children;
@@ -994,7 +999,7 @@ public class Activity extends ContextThemeWrapper
    }

    /**
     * (Create and) return the autofill manager
     * (Creates, sets and) returns the autofill manager
     *
     * @return The autofill manager
     */
@@ -1006,6 +1011,18 @@ public class Activity extends ContextThemeWrapper
        return mAutofillManager;
    }

    /**
     * (Creates, sets, and ) returns the intelligence manager
     *
     * @return The intelligence manager
     */
    @NonNull private IntelligenceManager getIntelligenceManager() {
        if (mIntelligenceManager == null) {
            mIntelligenceManager = getSystemService(IntelligenceManager.class);
        }
        return mIntelligenceManager;
    }

    @Override
    protected void attachBaseContext(Context newBase) {
        super.attachBaseContext(newBase);
@@ -1081,6 +1098,12 @@ public class Activity extends ContextThemeWrapper
        }
        mRestoredFromBundle = savedInstanceState != null;
        mCalled = true;

        if (getIntelligenceManager() != null) {
            //TODO(b/111276913): decide whether the screen_obs session id should be saved / restored
            // in the activity bundle.
            mIntelligenceManager.onActivityCreated(mToken, getComponentName());
        }
    }

    /**
@@ -2047,6 +2070,10 @@ public class Activity extends ContextThemeWrapper
        }

        getApplication().dispatchActivityDestroyed(this);

        if (getIntelligenceManager() != null) {
            mIntelligenceManager.onActivityDestroyed();
        }
    }

    /**
@@ -6403,9 +6430,16 @@ public class Activity extends ContextThemeWrapper

    void dumpInner(@NonNull String prefix, @Nullable FileDescriptor fd,
            @NonNull PrintWriter writer, @Nullable String[] args) {
        if (args != null && args.length > 0 && args[0].equals("--autofill")) {
        if (args != null && args.length > 0) {
            // Handle special cases
            switch (args[0]) {
                case "--autofill":
                    dumpAutofillManager(prefix, writer);
                    return;
                case "--intelligence":
                    dumpIntelligenceManager(prefix, writer);
                    return;
            }
        }
        writer.print(prefix); writer.print("Local Activity ");
                writer.print(Integer.toHexString(System.identityHashCode(this)));
@@ -6435,6 +6469,7 @@ public class Activity extends ContextThemeWrapper
        mHandler.getLooper().dump(new PrintWriterPrinter(writer), prefix);

        dumpAutofillManager(prefix, writer);
        dumpIntelligenceManager(prefix, writer);

        ResourcesManager.getInstance().dump(prefix, writer);
    }
@@ -6450,6 +6485,15 @@ public class Activity extends ContextThemeWrapper
        }
    }

    void dumpIntelligenceManager(String prefix, PrintWriter writer) {
        final IntelligenceManager im = getIntelligenceManager();
        if (im != null) {
            im.dump(prefix, writer);
        } else {
            writer.print(prefix); writer.println("No IntelligenceManager");
        }
    }

    /**
     * Bit indicating that this activity is "immersive" and should not be
     * interrupted by notifications if possible.
+14 −1
Original line number Diff line number Diff line
@@ -66,8 +66,8 @@ import android.hardware.fingerprint.IFingerprintService;
import android.hardware.hdmi.HdmiControlManager;
import android.hardware.hdmi.IHdmiControlService;
import android.hardware.input.InputManager;
import android.hardware.iris.IrisManager;
import android.hardware.iris.IIrisService;
import android.hardware.iris.IrisManager;
import android.hardware.location.ContextHubManager;
import android.hardware.radio.RadioManager;
import android.hardware.usb.IUsbManager;
@@ -163,6 +163,8 @@ import android.view.accessibility.CaptioningManager;
import android.view.autofill.AutofillManager;
import android.view.autofill.IAutoFillManager;
import android.view.inputmethod.InputMethodManager;
import android.view.intelligence.IIntelligenceManager;
import android.view.intelligence.IntelligenceManager;
import android.view.textclassifier.TextClassificationManager;
import android.view.textservice.TextServicesManager;

@@ -1032,6 +1034,17 @@ final class SystemServiceRegistry {
                return new AutofillManager(ctx.getOuterContext(), service);
            }});

        registerService(Context.INTELLIGENCE_MANAGER_SERVICE, IntelligenceManager.class,
                new CachedServiceFetcher<IntelligenceManager>() {
            @Override
            public IntelligenceManager createService(ContextImpl ctx)
                    throws ServiceNotFoundException {
                // Get the services without throwing as this is an optional feature
                IBinder b = ServiceManager.getService(Context.INTELLIGENCE_MANAGER_SERVICE);
                IIntelligenceManager service = IIntelligenceManager.Stub.asInterface(b);
                return new IntelligenceManager(ctx.getOuterContext(), service);
            }});

        registerService(Context.VR_SERVICE, VrManager.class, new CachedServiceFetcher<VrManager>() {
            @Override
            public VrManager createService(ContextImpl ctx) throws ServiceNotFoundException {
+8 −0
Original line number Diff line number Diff line
@@ -3864,6 +3864,14 @@ public abstract class Context {
     */
    public static final String AUTOFILL_MANAGER_SERVICE = "autofill";

    /**
     * Official published name of the intelligence service.
     *
     * @hide
     * @see #getSystemService(String)
     */
    public static final String INTELLIGENCE_MANAGER_SERVICE = "intelligence";

    /**
     * Use with {@link #getSystemService(String)} to access the
     * {@link com.android.server.voiceinteraction.SoundTriggerService}.
+31 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2018 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.intelligence;

import android.service.intelligence.InteractionSessionId;
import android.service.intelligence.InteractionContext;

/**
 * Interface from the system to an intelligence service.
 *
 * @hide
 */
oneway interface IIntelligenceService {

    // Called when session is created (context not null) or destroyed (context null)
    void onSessionLifecycle(in InteractionContext context, in InteractionSessionId sessionId);
}
Loading