Loading core/java/android/app/Activity.java +33 −8 Original line number Diff line number Diff line Loading @@ -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.ContentCaptureEvent; import android.view.intelligence.IntelligenceManager; import android.widget.AdapterView; import android.widget.Toast; Loading Loading @@ -1023,6 +1024,31 @@ public class Activity extends ContextThemeWrapper return mIntelligenceManager; } private void notifyIntelligenceManagerIfNeeded(@ContentCaptureEvent.EventType int event) { final IntelligenceManager im = getIntelligenceManager(); if (im == null || !im.isContentCaptureEnabled()) { return; } switch (event) { case ContentCaptureEvent.TYPE_ACTIVITY_CREATED: //TODO(b/111276913): decide whether the InteractionSessionId should be // saved / restored in the activity bundle. im.onActivityCreated(mToken, getComponentName()); break; case ContentCaptureEvent.TYPE_ACTIVITY_DESTROYED: im.onActivityDestroyed(); break; case ContentCaptureEvent.TYPE_ACTIVITY_STARTED: case ContentCaptureEvent.TYPE_ACTIVITY_RESUMED: case ContentCaptureEvent.TYPE_ACTIVITY_PAUSED: case ContentCaptureEvent.TYPE_ACTIVITY_STOPPED: im.onActivityLifecycleEvent(event); break; default: Log.w(TAG, "notifyIntelligenceManagerIfNeeded(): invalid type " + event); } } @Override protected void attachBaseContext(Context newBase) { super.attachBaseContext(newBase); Loading Loading @@ -1099,11 +1125,7 @@ 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()); } notifyIntelligenceManagerIfNeeded(ContentCaptureEvent.TYPE_ACTIVITY_CREATED); } /** Loading Loading @@ -1337,6 +1359,7 @@ public class Activity extends ContextThemeWrapper if (mAutoFillResetNeeded) { getAutofillManager().onVisibleForAutofill(); } notifyIntelligenceManagerIfNeeded(ContentCaptureEvent.TYPE_ACTIVITY_STARTED); } /** Loading Loading @@ -1419,6 +1442,7 @@ public class Activity extends ContextThemeWrapper } } } notifyIntelligenceManagerIfNeeded(ContentCaptureEvent.TYPE_ACTIVITY_RESUMED); mCalled = true; } Loading Loading @@ -1812,6 +1836,7 @@ public class Activity extends ContextThemeWrapper mAutoFillIgnoreFirstResumePause = false; } } notifyIntelligenceManagerIfNeeded(ContentCaptureEvent.TYPE_ACTIVITY_PAUSED); mCalled = true; } Loading Loading @@ -2000,6 +2025,7 @@ public class Activity extends ContextThemeWrapper getAutofillManager().onPendingSaveUi(AutofillManager.PENDING_UI_OPERATION_CANCEL, mIntent.getIBinderExtra(AutofillManager.EXTRA_RESTORE_SESSION_TOKEN)); } notifyIntelligenceManagerIfNeeded(ContentCaptureEvent.TYPE_ACTIVITY_STOPPED); } } Loading Loading @@ -2071,9 +2097,8 @@ public class Activity extends ContextThemeWrapper getApplication().dispatchActivityDestroyed(this); if (getIntelligenceManager() != null) { mIntelligenceManager.onActivityDestroyed(); } notifyIntelligenceManagerIfNeeded(ContentCaptureEvent.TYPE_ACTIVITY_DESTROYED); } /** Loading core/java/android/service/intelligence/IIntelligenceService.aidl +8 −0 Original line number Diff line number Diff line Loading @@ -19,6 +19,11 @@ package android.service.intelligence; import android.service.intelligence.InteractionSessionId; import android.service.intelligence.InteractionContext; import android.view.intelligence.ContentCaptureEvent; import java.util.List; /** * Interface from the system to an intelligence service. * Loading @@ -28,4 +33,7 @@ oneway interface IIntelligenceService { // Called when session is created (context not null) or destroyed (context null) void onSessionLifecycle(in InteractionContext context, in InteractionSessionId sessionId); void onContentCaptureEvents(in InteractionSessionId sessionId, in List<ContentCaptureEvent> events); } core/java/android/service/intelligence/IntelligenceService.java +9 −0 Original line number Diff line number Diff line Loading @@ -70,6 +70,14 @@ public abstract class IntelligenceService extends Service { IntelligenceService.this, sessionId)); } } @Override public void onContentCaptureEvents(InteractionSessionId sessionId, List<ContentCaptureEvent> events) { mHandler.sendMessage( obtainMessage(IntelligenceService::onContentCaptureEvent, IntelligenceService.this, sessionId, events)); } }; @CallSuper Loading Loading @@ -105,6 +113,7 @@ public abstract class IntelligenceService extends Service { * @param sessionId the session's Id * @param events the events */ // TODO(b/111276913): rename to onContentCaptureEvents public abstract void onContentCaptureEvent(@NonNull InteractionSessionId sessionId, @NonNull List<ContentCaptureEvent> events); Loading core/java/android/view/intelligence/ContentCaptureEvent.aidl 0 → 100644 +19 −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.view.intelligence; parcelable ContentCaptureEvent; core/java/android/view/intelligence/ContentCaptureEvent.java +58 −8 Original line number Diff line number Diff line Loading @@ -30,6 +30,11 @@ import java.lang.annotation.RetentionPolicy; @SystemApi public final class ContentCaptureEvent implements Parcelable { /** @hide */ public static final int TYPE_ACTIVITY_DESTROYED = -2; /** @hide */ public static final int TYPE_ACTIVITY_CREATED = -1; /** * Called when the activity is started. */ Loading Loading @@ -85,10 +90,18 @@ public final class ContentCaptureEvent implements Parcelable { TYPE_VIEW_TEXT_CHANGED }) @Retention(RetentionPolicy.SOURCE) @interface EventType{} public @interface EventType{} private final int mType; private final long mEventTime; private final int mFlags; /** @hide */ ContentCaptureEvent() { public ContentCaptureEvent(int type, long eventTime, int flags) { mType = type; mEventTime = eventTime; mFlags = flags; } /** Loading @@ -99,14 +112,14 @@ public final class ContentCaptureEvent implements Parcelable { * {@link #TYPE_VIEW_ADDED}, {@link #TYPE_VIEW_REMOVED}, or {@link #TYPE_VIEW_TEXT_CHANGED}. */ public @EventType int getType() { return 42; return mType; } /** * Gets when the event was generated, in ms. */ public long getEventTime() { return 48151623; return mEventTime; } /** Loading @@ -116,7 +129,7 @@ public final class ContentCaptureEvent implements Parcelable { * {@link android.view.intelligence.IntelligenceManager#FLAG_USER_INPUT}. */ public int getFlags() { return 0; return mFlags; } /** Loading Loading @@ -149,6 +162,16 @@ public final class ContentCaptureEvent implements Parcelable { return null; } @Override public String toString() { final StringBuilder string = new StringBuilder("ContentCaptureEvent[type=") .append(getTypeAsString(mType)).append(", time=").append(mEventTime); if (mFlags > 0) { string.append(", flags=").append(mFlags); } return string.append(']').toString(); } @Override public int describeContents() { return 0; Loading @@ -156,7 +179,9 @@ public final class ContentCaptureEvent implements Parcelable { @Override public void writeToParcel(Parcel parcel, int flags) { // TODO(b/111276913): implement parcel.writeInt(mType); parcel.writeLong(mEventTime); parcel.writeInt(mFlags); } public static final Parcelable.Creator<ContentCaptureEvent> CREATOR = Loading @@ -164,8 +189,10 @@ public final class ContentCaptureEvent implements Parcelable { @Override public ContentCaptureEvent createFromParcel(Parcel parcel) { // TODO(b/111276913): implement return null; final int type = parcel.readInt(); final long eventTime = parcel.readLong(); final int flags = parcel.readInt(); return new ContentCaptureEvent(type, eventTime, flags); } @Override Loading @@ -173,4 +200,27 @@ public final class ContentCaptureEvent implements Parcelable { return new ContentCaptureEvent[size]; } }; /** @hide */ public static String getTypeAsString(@EventType int type) { switch (type) { case TYPE_ACTIVITY_STARTED: return "ACTIVITY_STARTED"; case TYPE_ACTIVITY_RESUMED: return "ACTIVITY_RESUMED"; case TYPE_ACTIVITY_PAUSED: return "ACTIVITY_PAUSED"; case TYPE_ACTIVITY_STOPPED: return "ACTIVITY_STOPPED"; case TYPE_VIEW_ADDED: return "VIEW_ADDED"; case TYPE_VIEW_REMOVED: return "VIEW_REMOVED"; case TYPE_VIEW_TEXT_CHANGED: return "VIEW_TEXT_CHANGED"; default: return "UKNOWN_TYPE: " + type; } } } Loading
core/java/android/app/Activity.java +33 −8 Original line number Diff line number Diff line Loading @@ -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.ContentCaptureEvent; import android.view.intelligence.IntelligenceManager; import android.widget.AdapterView; import android.widget.Toast; Loading Loading @@ -1023,6 +1024,31 @@ public class Activity extends ContextThemeWrapper return mIntelligenceManager; } private void notifyIntelligenceManagerIfNeeded(@ContentCaptureEvent.EventType int event) { final IntelligenceManager im = getIntelligenceManager(); if (im == null || !im.isContentCaptureEnabled()) { return; } switch (event) { case ContentCaptureEvent.TYPE_ACTIVITY_CREATED: //TODO(b/111276913): decide whether the InteractionSessionId should be // saved / restored in the activity bundle. im.onActivityCreated(mToken, getComponentName()); break; case ContentCaptureEvent.TYPE_ACTIVITY_DESTROYED: im.onActivityDestroyed(); break; case ContentCaptureEvent.TYPE_ACTIVITY_STARTED: case ContentCaptureEvent.TYPE_ACTIVITY_RESUMED: case ContentCaptureEvent.TYPE_ACTIVITY_PAUSED: case ContentCaptureEvent.TYPE_ACTIVITY_STOPPED: im.onActivityLifecycleEvent(event); break; default: Log.w(TAG, "notifyIntelligenceManagerIfNeeded(): invalid type " + event); } } @Override protected void attachBaseContext(Context newBase) { super.attachBaseContext(newBase); Loading Loading @@ -1099,11 +1125,7 @@ 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()); } notifyIntelligenceManagerIfNeeded(ContentCaptureEvent.TYPE_ACTIVITY_CREATED); } /** Loading Loading @@ -1337,6 +1359,7 @@ public class Activity extends ContextThemeWrapper if (mAutoFillResetNeeded) { getAutofillManager().onVisibleForAutofill(); } notifyIntelligenceManagerIfNeeded(ContentCaptureEvent.TYPE_ACTIVITY_STARTED); } /** Loading Loading @@ -1419,6 +1442,7 @@ public class Activity extends ContextThemeWrapper } } } notifyIntelligenceManagerIfNeeded(ContentCaptureEvent.TYPE_ACTIVITY_RESUMED); mCalled = true; } Loading Loading @@ -1812,6 +1836,7 @@ public class Activity extends ContextThemeWrapper mAutoFillIgnoreFirstResumePause = false; } } notifyIntelligenceManagerIfNeeded(ContentCaptureEvent.TYPE_ACTIVITY_PAUSED); mCalled = true; } Loading Loading @@ -2000,6 +2025,7 @@ public class Activity extends ContextThemeWrapper getAutofillManager().onPendingSaveUi(AutofillManager.PENDING_UI_OPERATION_CANCEL, mIntent.getIBinderExtra(AutofillManager.EXTRA_RESTORE_SESSION_TOKEN)); } notifyIntelligenceManagerIfNeeded(ContentCaptureEvent.TYPE_ACTIVITY_STOPPED); } } Loading Loading @@ -2071,9 +2097,8 @@ public class Activity extends ContextThemeWrapper getApplication().dispatchActivityDestroyed(this); if (getIntelligenceManager() != null) { mIntelligenceManager.onActivityDestroyed(); } notifyIntelligenceManagerIfNeeded(ContentCaptureEvent.TYPE_ACTIVITY_DESTROYED); } /** Loading
core/java/android/service/intelligence/IIntelligenceService.aidl +8 −0 Original line number Diff line number Diff line Loading @@ -19,6 +19,11 @@ package android.service.intelligence; import android.service.intelligence.InteractionSessionId; import android.service.intelligence.InteractionContext; import android.view.intelligence.ContentCaptureEvent; import java.util.List; /** * Interface from the system to an intelligence service. * Loading @@ -28,4 +33,7 @@ oneway interface IIntelligenceService { // Called when session is created (context not null) or destroyed (context null) void onSessionLifecycle(in InteractionContext context, in InteractionSessionId sessionId); void onContentCaptureEvents(in InteractionSessionId sessionId, in List<ContentCaptureEvent> events); }
core/java/android/service/intelligence/IntelligenceService.java +9 −0 Original line number Diff line number Diff line Loading @@ -70,6 +70,14 @@ public abstract class IntelligenceService extends Service { IntelligenceService.this, sessionId)); } } @Override public void onContentCaptureEvents(InteractionSessionId sessionId, List<ContentCaptureEvent> events) { mHandler.sendMessage( obtainMessage(IntelligenceService::onContentCaptureEvent, IntelligenceService.this, sessionId, events)); } }; @CallSuper Loading Loading @@ -105,6 +113,7 @@ public abstract class IntelligenceService extends Service { * @param sessionId the session's Id * @param events the events */ // TODO(b/111276913): rename to onContentCaptureEvents public abstract void onContentCaptureEvent(@NonNull InteractionSessionId sessionId, @NonNull List<ContentCaptureEvent> events); Loading
core/java/android/view/intelligence/ContentCaptureEvent.aidl 0 → 100644 +19 −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.view.intelligence; parcelable ContentCaptureEvent;
core/java/android/view/intelligence/ContentCaptureEvent.java +58 −8 Original line number Diff line number Diff line Loading @@ -30,6 +30,11 @@ import java.lang.annotation.RetentionPolicy; @SystemApi public final class ContentCaptureEvent implements Parcelable { /** @hide */ public static final int TYPE_ACTIVITY_DESTROYED = -2; /** @hide */ public static final int TYPE_ACTIVITY_CREATED = -1; /** * Called when the activity is started. */ Loading Loading @@ -85,10 +90,18 @@ public final class ContentCaptureEvent implements Parcelable { TYPE_VIEW_TEXT_CHANGED }) @Retention(RetentionPolicy.SOURCE) @interface EventType{} public @interface EventType{} private final int mType; private final long mEventTime; private final int mFlags; /** @hide */ ContentCaptureEvent() { public ContentCaptureEvent(int type, long eventTime, int flags) { mType = type; mEventTime = eventTime; mFlags = flags; } /** Loading @@ -99,14 +112,14 @@ public final class ContentCaptureEvent implements Parcelable { * {@link #TYPE_VIEW_ADDED}, {@link #TYPE_VIEW_REMOVED}, or {@link #TYPE_VIEW_TEXT_CHANGED}. */ public @EventType int getType() { return 42; return mType; } /** * Gets when the event was generated, in ms. */ public long getEventTime() { return 48151623; return mEventTime; } /** Loading @@ -116,7 +129,7 @@ public final class ContentCaptureEvent implements Parcelable { * {@link android.view.intelligence.IntelligenceManager#FLAG_USER_INPUT}. */ public int getFlags() { return 0; return mFlags; } /** Loading Loading @@ -149,6 +162,16 @@ public final class ContentCaptureEvent implements Parcelable { return null; } @Override public String toString() { final StringBuilder string = new StringBuilder("ContentCaptureEvent[type=") .append(getTypeAsString(mType)).append(", time=").append(mEventTime); if (mFlags > 0) { string.append(", flags=").append(mFlags); } return string.append(']').toString(); } @Override public int describeContents() { return 0; Loading @@ -156,7 +179,9 @@ public final class ContentCaptureEvent implements Parcelable { @Override public void writeToParcel(Parcel parcel, int flags) { // TODO(b/111276913): implement parcel.writeInt(mType); parcel.writeLong(mEventTime); parcel.writeInt(mFlags); } public static final Parcelable.Creator<ContentCaptureEvent> CREATOR = Loading @@ -164,8 +189,10 @@ public final class ContentCaptureEvent implements Parcelable { @Override public ContentCaptureEvent createFromParcel(Parcel parcel) { // TODO(b/111276913): implement return null; final int type = parcel.readInt(); final long eventTime = parcel.readLong(); final int flags = parcel.readInt(); return new ContentCaptureEvent(type, eventTime, flags); } @Override Loading @@ -173,4 +200,27 @@ public final class ContentCaptureEvent implements Parcelable { return new ContentCaptureEvent[size]; } }; /** @hide */ public static String getTypeAsString(@EventType int type) { switch (type) { case TYPE_ACTIVITY_STARTED: return "ACTIVITY_STARTED"; case TYPE_ACTIVITY_RESUMED: return "ACTIVITY_RESUMED"; case TYPE_ACTIVITY_PAUSED: return "ACTIVITY_PAUSED"; case TYPE_ACTIVITY_STOPPED: return "ACTIVITY_STOPPED"; case TYPE_VIEW_ADDED: return "VIEW_ADDED"; case TYPE_VIEW_REMOVED: return "VIEW_REMOVED"; case TYPE_VIEW_TEXT_CHANGED: return "VIEW_TEXT_CHANGED"; default: return "UKNOWN_TYPE: " + type; } } }