method public int describeContents();
method @Nullable public android.os.Bundle getExtras();
method @NonNull public String getPackageName();
- method public int getPredictedTargetCount();
- method public String getUiSurface();
- method public void writeToParcel(android.os.Parcel, int);
+ method @IntRange(from=0) public int getPredictedTargetCount();
+ method @NonNull public String getUiSurface();
+ method public void writeToParcel(@NonNull android.os.Parcel, int);
field @NonNull public static final android.os.Parcelable.Creator<android.app.prediction.AppPredictionContext> CREATOR;
}
public static final class AppPredictionContext.Builder {
ctor public AppPredictionContext.Builder(@NonNull android.content.Context);
- method public android.app.prediction.AppPredictionContext build();
- method public android.app.prediction.AppPredictionContext.Builder setExtras(@Nullable android.os.Bundle);
- method public android.app.prediction.AppPredictionContext.Builder setPredictedTargetCount(int);
- method public android.app.prediction.AppPredictionContext.Builder setUiSurface(@Nullable String);
+ method @NonNull public android.app.prediction.AppPredictionContext build();
+ method @NonNull public android.app.prediction.AppPredictionContext.Builder setExtras(@Nullable android.os.Bundle);
+ method @NonNull public android.app.prediction.AppPredictionContext.Builder setPredictedTargetCount(@IntRange(from=0) int);
+ method @NonNull public android.app.prediction.AppPredictionContext.Builder setUiSurface(@NonNull String);
}
public final class AppPredictionManager {
- method public android.app.prediction.AppPredictor createAppPredictionSession(@NonNull android.app.prediction.AppPredictionContext);
+ method @NonNull public android.app.prediction.AppPredictor createAppPredictionSession(@NonNull android.app.prediction.AppPredictionContext);
}
public final class AppPredictionSessionId implements android.os.Parcelable {
method @Nullable public String getClassName();
method @NonNull public android.app.prediction.AppTargetId getId();
method @NonNull public String getPackageName();
- method public int getRank();
+ method @IntRange(from=0) public int getRank();
method @Nullable public android.content.pm.ShortcutInfo getShortcutInfo();
method @NonNull public android.os.UserHandle getUser();
method public void writeToParcel(android.os.Parcel, int);
public final class AppTargetEvent implements android.os.Parcelable {
method public int describeContents();
- method @NonNull public int getAction();
- method @NonNull public String getLaunchLocation();
+ method public int getAction();
+ method @Nullable public String getLaunchLocation();
method @Nullable public android.app.prediction.AppTarget getTarget();
method public void writeToParcel(android.os.Parcel, int);
field public static final int ACTION_DISMISS = 2; // 0x2
public static final class AppTargetEvent.Builder {
ctor public AppTargetEvent.Builder(@Nullable android.app.prediction.AppTarget, int);
- method public android.app.prediction.AppTargetEvent build();
- method public android.app.prediction.AppTargetEvent.Builder setLaunchLocation(String);
+ method @NonNull public android.app.prediction.AppTargetEvent build();
+ method @NonNull public android.app.prediction.AppTargetEvent.Builder setLaunchLocation(@Nullable String);
}
public final class AppTargetId implements android.os.Parcelable {
public static final class ShortcutManager.ShareShortcutInfo implements android.os.Parcelable {
method public int describeContents();
- method public android.content.pm.ShortcutInfo getShortcutInfo();
- method public android.content.ComponentName getTargetComponent();
- method public void writeToParcel(android.os.Parcel, int);
+ method @NonNull public android.content.pm.ShortcutInfo getShortcutInfo();
+ method @NonNull public android.content.ComponentName getTargetComponent();
+ method public void writeToParcel(@NonNull android.os.Parcel, int);
field @NonNull public static final android.os.Parcelable.Creator<android.content.pm.ShortcutManager.ShareShortcutInfo> CREATOR;
}
public abstract class AppPredictionService extends android.app.Service {
ctor public AppPredictionService();
method @MainThread public abstract void onAppTargetEvent(@NonNull android.app.prediction.AppPredictionSessionId, @NonNull android.app.prediction.AppTargetEvent);
- method public final android.os.IBinder onBind(android.content.Intent);
+ method @NonNull public final android.os.IBinder onBind(@NonNull android.content.Intent);
method public void onCreatePredictionSession(@NonNull android.app.prediction.AppPredictionContext, @NonNull android.app.prediction.AppPredictionSessionId);
method @MainThread public void onDestroyPredictionSession(@NonNull android.app.prediction.AppPredictionSessionId);
method @MainThread public abstract void onLocationShown(@NonNull android.app.prediction.AppPredictionSessionId, @NonNull String, @NonNull java.util.List<android.app.prediction.AppTargetId>);
method public int describeContents();
method @Nullable public android.os.Bundle getExtras();
method @NonNull public String getPackageName();
- method public int getPredictedTargetCount();
- method public String getUiSurface();
- method public void writeToParcel(android.os.Parcel, int);
+ method @IntRange(from=0) public int getPredictedTargetCount();
+ method @NonNull public String getUiSurface();
+ method public void writeToParcel(@NonNull android.os.Parcel, int);
field @NonNull public static final android.os.Parcelable.Creator<android.app.prediction.AppPredictionContext> CREATOR;
}
public static final class AppPredictionContext.Builder {
ctor public AppPredictionContext.Builder(@NonNull android.content.Context);
- method public android.app.prediction.AppPredictionContext build();
- method public android.app.prediction.AppPredictionContext.Builder setExtras(@Nullable android.os.Bundle);
- method public android.app.prediction.AppPredictionContext.Builder setPredictedTargetCount(int);
- method public android.app.prediction.AppPredictionContext.Builder setUiSurface(@Nullable String);
+ method @NonNull public android.app.prediction.AppPredictionContext build();
+ method @NonNull public android.app.prediction.AppPredictionContext.Builder setExtras(@Nullable android.os.Bundle);
+ method @NonNull public android.app.prediction.AppPredictionContext.Builder setPredictedTargetCount(@IntRange(from=0) int);
+ method @NonNull public android.app.prediction.AppPredictionContext.Builder setUiSurface(@NonNull String);
}
public final class AppPredictionManager {
- method public android.app.prediction.AppPredictor createAppPredictionSession(@NonNull android.app.prediction.AppPredictionContext);
+ method @NonNull public android.app.prediction.AppPredictor createAppPredictionSession(@NonNull android.app.prediction.AppPredictionContext);
}
public final class AppPredictionSessionId implements android.os.Parcelable {
method @Nullable public String getClassName();
method @NonNull public android.app.prediction.AppTargetId getId();
method @NonNull public String getPackageName();
- method public int getRank();
+ method @IntRange(from=0) public int getRank();
method @Nullable public android.content.pm.ShortcutInfo getShortcutInfo();
method @NonNull public android.os.UserHandle getUser();
method public void writeToParcel(android.os.Parcel, int);
public final class AppTargetEvent implements android.os.Parcelable {
method public int describeContents();
- method @NonNull public int getAction();
- method @NonNull public String getLaunchLocation();
+ method public int getAction();
+ method @Nullable public String getLaunchLocation();
method @Nullable public android.app.prediction.AppTarget getTarget();
method public void writeToParcel(android.os.Parcel, int);
field public static final int ACTION_DISMISS = 2; // 0x2
public static final class AppTargetEvent.Builder {
ctor public AppTargetEvent.Builder(@Nullable android.app.prediction.AppTarget, int);
- method public android.app.prediction.AppTargetEvent build();
- method public android.app.prediction.AppTargetEvent.Builder setLaunchLocation(String);
+ method @NonNull public android.app.prediction.AppTargetEvent build();
+ method @NonNull public android.app.prediction.AppTargetEvent.Builder setLaunchLocation(@Nullable String);
}
public final class AppTargetId implements android.os.Parcelable {
public abstract class AppPredictionService extends android.app.Service {
ctor public AppPredictionService();
method @MainThread public abstract void onAppTargetEvent(@NonNull android.app.prediction.AppPredictionSessionId, @NonNull android.app.prediction.AppTargetEvent);
- method public final android.os.IBinder onBind(android.content.Intent);
+ method @NonNull public final android.os.IBinder onBind(@NonNull android.content.Intent);
method public void onCreatePredictionSession(@NonNull android.app.prediction.AppPredictionContext, @NonNull android.app.prediction.AppPredictionSessionId);
method @MainThread public void onDestroyPredictionSession(@NonNull android.app.prediction.AppPredictionSessionId);
method @MainThread public abstract void onLocationShown(@NonNull android.app.prediction.AppPredictionSessionId, @NonNull String, @NonNull java.util.List<android.app.prediction.AppTargetId>);
*/
package android.app.prediction;
+import android.annotation.IntRange;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SystemApi;
mExtras = extras;
}
- private AppPredictionContext(Parcel parcel) {
+ private AppPredictionContext(@NonNull Parcel parcel) {
mUiSurface = parcel.readString();
mPredictedTargetCount = parcel.readInt();
mPackageName = parcel.readString();
mExtras = parcel.readBundle();
}
+ @NonNull
public String getUiSurface() {
return mUiSurface;
}
- public int getPredictedTargetCount() {
+ public @IntRange(from = 0) int getPredictedTargetCount() {
return mPredictedTargetCount;
}
}
@Override
- public void writeToParcel(Parcel dest, int flags) {
+ public void writeToParcel(@NonNull Parcel dest, int flags) {
dest.writeString(mUiSurface);
dest.writeInt(mPredictedTargetCount);
dest.writeString(mPackageName);
/**
* Sets the number of prediction targets as a hint.
*/
- public Builder setPredictedTargetCount(int predictedTargetCount) {
+ @NonNull
+ public Builder setPredictedTargetCount(@IntRange(from = 0) int predictedTargetCount) {
mPredictedTargetCount = predictedTargetCount;
return this;
}
/**
* Sets the UI surface.
*/
- public Builder setUiSurface(@Nullable String uiSurface) {
+ @NonNull
+ public Builder setUiSurface(@NonNull String uiSurface) {
mUiSurface = uiSurface;
return this;
}
/**
* Sets the extras.
*/
+ @NonNull
public Builder setExtras(@Nullable Bundle extras) {
mExtras = extras;
return this;
/**
* Builds a new context instance.
*/
+ @NonNull
public AppPredictionContext build() {
return new AppPredictionContext(mUiSurface, mPredictedTargetCount, mPackageName,
mExtras);
/**
* Creates a new app prediction session.
*/
+ @NonNull
public AppPredictor createAppPredictionSession(
@NonNull AppPredictionContext predictionContext) {
return new AppPredictor(mContext, predictionContext);
mPredictionManager.createPredictionSession(predictionContext, mSessionId);
} catch (RemoteException e) {
Log.e(TAG, "Failed to create predictor", e);
- return;
+ e.rethrowAsRuntimeException();
}
mCloseGuard.open("close");
mPredictionManager.notifyAppTargetEvent(mSessionId, event);
} catch (RemoteException e) {
Log.e(TAG, "Failed to notify app target event", e);
+ e.rethrowAsRuntimeException();
}
}
new ParceledListSlice<>(targetIds));
} catch (RemoteException e) {
Log.e(TAG, "Failed to notify location shown event", e);
+ e.rethrowAsRuntimeException();
}
}
mRegisteredCallbacks.put(callback, callbackWrapper);
} catch (RemoteException e) {
Log.e(TAG, "Failed to register for prediction updates", e);
+ e.rethrowAsRuntimeException();
}
}
mPredictionManager.unregisterPredictionUpdates(mSessionId, callbackWrapper);
} catch (RemoteException e) {
Log.e(TAG, "Failed to unregister for prediction updates", e);
+ e.rethrowAsRuntimeException();
}
}
mPredictionManager.requestPredictionUpdate(mSessionId);
} catch (RemoteException e) {
Log.e(TAG, "Failed to request prediction update", e);
+ e.rethrowAsRuntimeException();
}
}
new CallbackWrapper(callbackExecutor, callback));
} catch (RemoteException e) {
Log.e(TAG, "Failed to sort targets", e);
+ e.rethrowAsRuntimeException();
}
}
/**
* Destroys the client and unregisters the callback. Any method on this class after this call
* with throw {@link IllegalStateException}.
- *
- * TODO(b/111701043): Add state check in other methods.
*/
public void destroy() {
if (!mIsClosed.getAndSet(true)) {
mPredictionManager.onDestroyPredictionSession(mSessionId);
} catch (RemoteException e) {
Log.e(TAG, "Failed to notify app target event", e);
+ e.rethrowAsRuntimeException();
}
} else {
throw new IllegalStateException("This client has already been destroyed.");
*/
package android.app.prediction;
+import android.annotation.IntRange;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SystemApi;
* Sets the rank of the for the target.
* @hide
*/
- public void setRank(int rank) {
+ public void setRank(@IntRange(from = 0) int rank) {
+ if (rank < 0) {
+ throw new IllegalArgumentException("rank cannot be a negative value");
+ }
mRank = rank;
}
/**
- * Returns the rank for the target.
+ * Returns the rank for the target. Rank of an AppTarget is a non-negative integer that
+ * represents the importance of this target compared to other candidate targets. A smaller value
+ * means higher importance in the list.
*/
- public int getRank() {
+ public @IntRange(from = 0) int getRank() {
return mRank;
}
/**
* Returns the launch location.
*/
- @NonNull
+ @Nullable
public String getLaunchLocation() {
return mLocation;
}
/**
* Returns the action type.
*/
- @NonNull
- public int getAction() {
+ public @ActionType int getAction() {
return mAction;
}
/**
* Sets the launch location.
*/
- public Builder setLaunchLocation(String location) {
+ @NonNull
+ public Builder setLaunchLocation(@Nullable String location) {
mLocation = location;
return this;
}
/**
* Builds a new event instance.
*/
+ @NonNull
public AppTargetEvent build() {
return new AppTargetEvent(mTarget, mLocation, mAction);
}
mTargetComponent = targetComponent;
}
- private ShareShortcutInfo(Parcel in) {
+ private ShareShortcutInfo(@NonNull Parcel in) {
mShortcutInfo = in.readParcelable(ShortcutInfo.class.getClassLoader());
mTargetComponent = in.readParcelable(ComponentName.class.getClassLoader());
}
+ @NonNull
public ShortcutInfo getShortcutInfo() {
return mShortcutInfo;
}
+ @NonNull
public ComponentName getTargetComponent() {
return mTargetComponent;
}
}
@Override
- public void writeToParcel(Parcel dest, int flags) {
+ public void writeToParcel(@NonNull Parcel dest, int flags) {
dest.writeParcelable(mShortcutInfo, flags);
dest.writeParcelable(mTargetComponent, flags);
}
- public static final @android.annotation.NonNull Parcelable.Creator<ShareShortcutInfo> CREATOR =
+ public static final @NonNull Parcelable.Creator<ShareShortcutInfo> CREATOR =
new Parcelable.Creator<ShareShortcutInfo>() {
public ShareShortcutInfo createFromParcel(Parcel in) {
return new ShareShortcutInfo(in);
}
@Override
- public final IBinder onBind(Intent intent) {
+ @NonNull
+ public final IBinder onBind(@NonNull Intent intent) {
// TODO(b/111701043): Verify that the action is valid
return mInterface.asBinder();
}