Merge "Initial APIs for Intelligence Service."

This commit is contained in:
Felipe Leme
2018-11-05 21:48:54 +00:00
committed by Android (Google) Code Review
11 changed files with 723 additions and 1 deletions

View File

@@ -2,6 +2,7 @@ package android.app.assist;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SystemApi;
import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
@@ -713,7 +714,11 @@ public class AssistStructure implements Parcelable {
ViewNode[] mChildren;
ViewNode() {
// TODO(b/111276913): temporarily made public / @hide until we decide what will be used by
// ScreenObservation.
/** @hide */
@SystemApi
public ViewNode() {
}
ViewNode(ParcelTransferReader reader, int nestingLevel) {

View File

@@ -935,6 +935,21 @@ public class UserManager {
*/
public static final String DISALLOW_AUTOFILL = "no_autofill";
/**
* Specifies if the contents of a user's screen is not allowed to be captured for artificial
* intelligence purposes.
*
* <p>Device owner and profile owner can set this restriction. When it is set by device owner,
* only the target user will be affected.
*
* <p>The default value is <code>false</code>.
*
* @see DevicePolicyManager#addUserRestriction(ComponentName, String)
* @see DevicePolicyManager#clearUserRestriction(ComponentName, String)
* @see #getUserRestrictions()
*/
public static final String DISALLOW_INTELLIGENCE_CAPTURE = "no_intelligence_capture";
/**
* Specifies if user switching is blocked on the current user.
*

View File

@@ -0,0 +1,71 @@
/*
* 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.annotation.NonNull;
import android.annotation.SystemApi;
import android.app.Service;
import android.content.Intent;
import android.view.intelligence.ContentCaptureEvent;
import java.util.List;
/**
* A service used to captures the content of the screen.
*
* <p>The data collected by this service can be analyzed and combined with other sources to provide
* contextual data in other areas of the system such as Autofill.
*
* @hide
*/
@SystemApi
public abstract class IntelligenceService extends Service {
/**
* The {@link Intent} that must be declared as handled by the service.
* To be supported, the service must also require the
* {@link android.Manifest.permission#BIND_INTELLIGENCE_SERVICE} permission so
* that other applications can not abuse it.
*/
public static final String SERVICE_INTERFACE =
"android.service.intelligence.IntelligenceService";
/**
* Creates a new interaction session.
*
* @param context interaction context
* @param sessionId the session's Id
*/
public void onCreateInteractionSession(@NonNull InteractionContext context,
@NonNull InteractionSessionId sessionId) {}
/**
* Notifies the service of {@link ContentCaptureEvent events} associated with a content capture
* session.
*
* @param sessionId the session's Id
* @param events the events
*/
public abstract void onContentCaptureEvent(@NonNull InteractionSessionId sessionId,
@NonNull List<ContentCaptureEvent> events);
/**
* Destroys the content capture session identified by the specified {@code sessionId}.
*
* @param sessionId the id of the session to destroy
*/
public void onDestroyInteractionSession(@NonNull InteractionSessionId sessionId) {}
}

View File

@@ -0,0 +1,120 @@
/*
* 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.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.SystemApi;
import android.app.TaskInfo;
import android.content.ComponentName;
import android.os.Parcel;
import android.os.Parcelable;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
// TODO(b/111276913): add javadocs / implement Parcelable / implement equals/hashcode/toString
/** @hide */
@SystemApi
public final class InteractionContext implements Parcelable {
/**
* Flag used to indicate that the app explicitly disabled contents capture for the activity
* (using
* {@link android.view.intelligence.IntelligenceManager#disableContentCapture()}),
* in which case the service will just receive activity-level events.
*/
public static final int FLAG_DISABLED_BY_APP = 0x1;
/**
* Flag used to indicate that the activity's window is tagged with
* {@link android.view.Display#FLAG_SECURE}, in which case the service will just receive
* activity-level events.
*/
public static final int FLAG_DISABLED_BY_FLAG_SECURE = 0x2;
/** @hide */
@IntDef(flag = true, prefix = { "FLAG_" }, value = {
FLAG_DISABLED_BY_APP,
FLAG_DISABLED_BY_FLAG_SECURE
})
@Retention(RetentionPolicy.SOURCE)
@interface ContextCreationFlags{}
/** @hide */
InteractionContext() {
}
/**
* Gets the id of the {@link TaskInfo task} associated with this context.
*/
public int getTaskId() {
//TODO(b/111276913): implement
return 108;
}
/**
* Gets the activity associated with this context.
*/
public @NonNull ComponentName getActivityComponent() {
//TODO(b/111276913): implement
return null;
}
/**
* Gets the ID of the display associated with this context, as defined by
* {G android.hardware.display.DisplayManager#getDisplay(int) DisplayManager.getDisplay()}.
*/
public int getDisplayId() {
//TODO(b/111276913): implement
return 42;
}
/**
* Gets the flags associated with this context.
*
* @return any combination of {@link #FLAG_DISABLED_BY_FLAG_SECURE} and
* {@link #FLAG_DISABLED_BY_APP}.
*/
public @ContextCreationFlags int getFlags() {
//TODO(b/111276913): implement
return 42;
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel parcel, int flags) {
}
public static final Parcelable.Creator<InteractionContext> CREATOR =
new Parcelable.Creator<InteractionContext>() {
@Override
public InteractionContext createFromParcel(Parcel parcel) {
// TODO(b/111276913): implement
return null;
}
@Override
public InteractionContext[] newArray(int size) {
return new InteractionContext[size];
}
};
}

View File

@@ -0,0 +1,55 @@
/*
* 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.annotation.SystemApi;
import android.os.Parcel;
import android.os.Parcelable;
// TODO(b/111276913): add javadocs / implement equals/hashcode/string
/** @hide */
@SystemApi
public final class InteractionSessionId implements Parcelable {
/** @hide */
public InteractionSessionId() {
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel parcel, int flags) {
}
public static final Parcelable.Creator<InteractionSessionId> CREATOR =
new Parcelable.Creator<InteractionSessionId>() {
@Override
public InteractionSessionId createFromParcel(Parcel parcel) {
// TODO(b/111276913): implement
return null;
}
@Override
public InteractionSessionId[] newArray(int size) {
return new InteractionSessionId[size];
}
};
}

View File

@@ -0,0 +1,176 @@
/*
* 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;
import android.annotation.IntDef;
import android.annotation.Nullable;
import android.annotation.SystemApi;
import android.os.Parcel;
import android.os.Parcelable;
import android.view.autofill.AutofillId;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
// TODO(b/111276913): add javadocs / implement Parcelable / implement
/** @hide */
@SystemApi
public final class ContentCaptureEvent implements Parcelable {
/**
* Called when the activity is started.
*/
public static final int TYPE_ACTIVITY_STARTED = 1;
/**
* Called when the activity is resumed.
*/
public static final int TYPE_ACTIVITY_RESUMED = 2;
/**
* Called when the activity is paused.
*/
public static final int TYPE_ACTIVITY_PAUSED = 3;
/**
* Called when the activity is stopped.
*/
public static final int TYPE_ACTIVITY_STOPPED = 4;
/**
* Called when a node has been added to the screen and is visible to the user.
*
* <p>The metadata of the node is available through {@link #getViewNode()}.
*/
public static final int TYPE_VIEW_ADDED = 5;
/**
* Called when a node has been removed from the screen and is not visible to the user anymore.
*
* <p>The id of the node is available through {@link #getId()}.
*/
public static final int TYPE_VIEW_REMOVED = 6;
/**
* Called when the text of a node has been changed.
*
* <p>The id of the node is available through {@link #getId()}, and the new text is
* available through {@link #getText()}.
*/
public static final int TYPE_VIEW_TEXT_CHANGED = 7;
// TODO(b/111276913): add event to indicate when FLAG_SECURE was changed?
/** @hide */
@IntDef(prefix = { "TYPE_" }, value = {
TYPE_ACTIVITY_STARTED,
TYPE_ACTIVITY_PAUSED,
TYPE_ACTIVITY_RESUMED,
TYPE_ACTIVITY_STOPPED,
TYPE_VIEW_ADDED,
TYPE_VIEW_REMOVED,
TYPE_VIEW_TEXT_CHANGED
})
@Retention(RetentionPolicy.SOURCE)
@interface EventType{}
/** @hide */
ContentCaptureEvent() {
}
/**
* Gets the type of the event.
*
* @return one of {@link #TYPE_ACTIVITY_STARTED}, {@link #TYPE_ACTIVITY_RESUMED},
* {@link #TYPE_ACTIVITY_PAUSED}, {@link #TYPE_ACTIVITY_STOPPED},
* {@link #TYPE_VIEW_ADDED}, {@link #TYPE_VIEW_REMOVED}, or {@link #TYPE_VIEW_TEXT_CHANGED}.
*/
public @EventType int getType() {
return 42;
}
/**
* Gets when the event was generated, in ms.
*/
public long getEventTime() {
return 48151623;
}
/**
* Gets optional flags associated with the event.
*
* @return either {@code 0} or
* {@link android.view.intelligence.IntelligenceManager#FLAG_USER_INPUT}.
*/
public int getFlags() {
return 0;
}
/**
* Gets the whole metadata of the node associated with the event.
*
* <p>Only set on {@link #TYPE_VIEW_ADDED} events.
*/
@Nullable
public ViewNode getViewNode() {
return null;
}
/**
* Gets the {@link AutofillId} of the node associated with the event.
*
* <p>Only set on {@link #TYPE_VIEW_REMOVED} and {@link #TYPE_VIEW_TEXT_CHANGED} events.
*/
@Nullable
public AutofillId getId() {
return null;
}
/**
* Gets the current text of the node associated with the event.
*
* <p>Only set on {@link #TYPE_VIEW_TEXT_CHANGED} events.
*/
@Nullable
public CharSequence getText() {
return null;
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel parcel, int flags) {
}
public static final Parcelable.Creator<ContentCaptureEvent> CREATOR =
new Parcelable.Creator<ContentCaptureEvent>() {
@Override
public ContentCaptureEvent createFromParcel(Parcel parcel) {
// TODO(b/111276913): implement
return null;
}
@Override
public ContentCaptureEvent[] newArray(int size) {
return new ContentCaptureEvent[size];
}
};
}

View File

@@ -0,0 +1,143 @@
/*
* 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;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SystemApi;
import android.content.ComponentName;
import android.content.Context;
import com.android.internal.util.Preconditions;
import java.util.Set;
/**
* TODO(b/111276913): add javadocs / implement / add SystemService / PackageFeature
*/
public final class IntelligenceManager {
/**
* Used to indicate that a text change was caused by user input (for example, through IME).
*/
//TODO(b/111276913): link to notifyTextChanged() method once available
public static final int FLAG_USER_INPUT = 0x1;
private final Context mContext;
/** @hide */
public IntelligenceManager(@NonNull Context context) {
mContext = Preconditions.checkNotNull(context, "context cannot be null");
}
/**
* Returns the component name of the {@link android.service.intelligence.IntelligenceService}
* that is enabled for the current user.
*/
@Nullable
public ComponentName getIntelligenceServiceComponentName() {
//TODO(b/111276913): implement
return null;
}
/**
* Checks whether contents capture is enabled for this activity.
*/
public boolean isContentCaptureEnabled() {
//TODO(b/111276913): implement
return false;
}
/**
* Called by apps to disable content capture.
*
* <p><b>Note: </b> this call is not persisted accross reboots, so apps should typically call
* it on {@link android.app.Activity#onCreate(android.os.Bundle, android.os.PersistableBundle)}.
*/
public void disableContentCapture() {
}
/**
* Called by the the service {@link android.service.intelligence.IntelligenceService}
* to define whether content capture should be enabled for activities with such
* {@link android.content.ComponentName}.
*
* <p>Useful to blacklist a particular activity.
*
* @throws UnsupportedOperationException if not called by the UID that owns the
* {@link android.service.intelligence.IntelligenceService} associated with the
* current user.
*
* @hide
*/
@SystemApi
public void setActivityContentCaptureEnabled(@NonNull ComponentName activity,
boolean enabled) {
//TODO(b/111276913): implement
}
/**
* Called by the the service {@link android.service.intelligence.IntelligenceService}
* to define whether content capture should be enabled for activities of the app with such
* {@code packageName}.
*
* <p>Useful to blacklist any activity from a particular app.
*
* @throws UnsupportedOperationException if not called by the UID that owns the
* {@link android.service.intelligence.IntelligenceService} associated with the
* current user.
*
* @hide
*/
@SystemApi
public void setPackageContentCaptureEnabled(@NonNull String packageName, boolean enabled) {
//TODO(b/111276913): implement
}
/**
* Gets the activities where content capture was disabled by
* {@link #setActivityContentCaptureEnabled(ComponentName, boolean)}.
*
* @throws UnsupportedOperationException if not called by the UID that owns the
* {@link android.service.intelligence.IntelligenceService} associated with the
* current user.
*
* @hide
*/
@SystemApi
@NonNull
public Set<ComponentName> getContentCaptureDisabledActivities() {
//TODO(b/111276913): implement
return null;
}
/**
* Gets the apps where content capture was disabled by
* {@link #setPackageContentCaptureEnabled(String, boolean)}.
*
* @throws UnsupportedOperationException if not called by the UID that owns the
* {@link android.service.intelligence.IntelligenceService} associated with the
* current user.
*
* @hide
*/
@SystemApi
@NonNull
public Set<String> getContentCaptureDisabledPackages() {
//TODO(b/111276913): implement
return null;
}
}

View File

@@ -0,0 +1,44 @@
/*
* 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;
import android.annotation.Nullable;
import android.annotation.SystemApi;
import android.app.assist.AssistStructure;
import android.view.autofill.AutofillId;
//TODO(b/111276913): add javadocs / implement Parcelable / implement
//TODO(b/111276913): for now it's extending ViewNode directly as it needs most of its properties,
// but it might be better to create a common, abstract android.view.ViewNode class that both extend
// instead
/** @hide */
@SystemApi
public final class ViewNode extends AssistStructure.ViewNode {
/** @hide */
public ViewNode() {
}
/**
* Returns the {@link AutofillId} of this view's parent, if the parent is also part of the
* screen observation tree.
*/
@Nullable
public AutofillId getParentAutofillId() {
//TODO(b/111276913): implement
return null;
}
}