summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author TreeHugger Robot <treehugger-gerrit@google.com> 2019-03-15 01:49:11 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2019-03-15 01:49:11 +0000
commit92512d5f18ef9a8e59debd2fcb493f94c226784d (patch)
tree385a96ae9e76902b014b01005eb3014ac66e2470
parent18c3f0c4a88203ffb9573150586262d00f4ba910 (diff)
parent387c7cb14a79829a120097b58ddc1cf0f1ba874e (diff)
Merge "Adds nullability annotation and java docs to App Prediction APIs"
-rw-r--r--api/system-current.txt34
-rw-r--r--api/test-current.txt28
-rw-r--r--core/java/android/app/prediction/AppPredictionContext.java16
-rw-r--r--core/java/android/app/prediction/AppPredictionManager.java1
-rw-r--r--core/java/android/app/prediction/AppPredictor.java11
-rw-r--r--core/java/android/app/prediction/AppTarget.java12
-rw-r--r--core/java/android/app/prediction/AppTargetEvent.java9
-rw-r--r--core/java/android/content/pm/ShortcutManager.java8
-rw-r--r--core/java/android/service/appprediction/AppPredictionService.java3
9 files changed, 72 insertions, 50 deletions
diff --git a/api/system-current.txt b/api/system-current.txt
index 3a9d3dae1971..ed68bad1ff55 100644
--- a/api/system-current.txt
+++ b/api/system-current.txt
@@ -1030,22 +1030,22 @@ package android.app.prediction {
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 {
@@ -1075,7 +1075,7 @@ package android.app.prediction {
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);
@@ -1084,8 +1084,8 @@ package android.app.prediction {
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
@@ -1096,8 +1096,8 @@ package android.app.prediction {
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 {
@@ -1754,9 +1754,9 @@ package android.content.pm {
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;
}
@@ -6305,7 +6305,7 @@ package android.service.appprediction {
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>);
diff --git a/api/test-current.txt b/api/test-current.txt
index af93d17a3a28..096631e558c2 100644
--- a/api/test-current.txt
+++ b/api/test-current.txt
@@ -427,22 +427,22 @@ package android.app.prediction {
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 {
@@ -472,7 +472,7 @@ package android.app.prediction {
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);
@@ -481,8 +481,8 @@ package android.app.prediction {
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
@@ -493,8 +493,8 @@ package android.app.prediction {
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 {
@@ -2225,7 +2225,7 @@ package android.service.appprediction {
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>);
diff --git a/core/java/android/app/prediction/AppPredictionContext.java b/core/java/android/app/prediction/AppPredictionContext.java
index 2da46719cd79..b6f37f6e30c5 100644
--- a/core/java/android/app/prediction/AppPredictionContext.java
+++ b/core/java/android/app/prediction/AppPredictionContext.java
@@ -15,6 +15,7 @@
*/
package android.app.prediction;
+import android.annotation.IntRange;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SystemApi;
@@ -49,18 +50,19 @@ public final class AppPredictionContext implements Parcelable {
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;
}
@@ -91,7 +93,7 @@ public final class AppPredictionContext implements Parcelable {
}
@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);
@@ -144,7 +146,8 @@ public final class AppPredictionContext implements Parcelable {
/**
* 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;
}
@@ -152,7 +155,8 @@ public final class AppPredictionContext implements Parcelable {
/**
* Sets the UI surface.
*/
- public Builder setUiSurface(@Nullable String uiSurface) {
+ @NonNull
+ public Builder setUiSurface(@NonNull String uiSurface) {
mUiSurface = uiSurface;
return this;
}
@@ -160,6 +164,7 @@ public final class AppPredictionContext implements Parcelable {
/**
* Sets the extras.
*/
+ @NonNull
public Builder setExtras(@Nullable Bundle extras) {
mExtras = extras;
return this;
@@ -168,6 +173,7 @@ public final class AppPredictionContext implements Parcelable {
/**
* Builds a new context instance.
*/
+ @NonNull
public AppPredictionContext build() {
return new AppPredictionContext(mUiSurface, mPredictedTargetCount, mPackageName,
mExtras);
diff --git a/core/java/android/app/prediction/AppPredictionManager.java b/core/java/android/app/prediction/AppPredictionManager.java
index 99f78f1957b9..45825cf93ae3 100644
--- a/core/java/android/app/prediction/AppPredictionManager.java
+++ b/core/java/android/app/prediction/AppPredictionManager.java
@@ -42,6 +42,7 @@ public final class AppPredictionManager {
/**
* Creates a new app prediction session.
*/
+ @NonNull
public AppPredictor createAppPredictionSession(
@NonNull AppPredictionContext predictionContext) {
return new AppPredictor(mContext, predictionContext);
diff --git a/core/java/android/app/prediction/AppPredictor.java b/core/java/android/app/prediction/AppPredictor.java
index 12d6ce3c5b90..284327dac524 100644
--- a/core/java/android/app/prediction/AppPredictor.java
+++ b/core/java/android/app/prediction/AppPredictor.java
@@ -94,7 +94,7 @@ public final class AppPredictor {
mPredictionManager.createPredictionSession(predictionContext, mSessionId);
} catch (RemoteException e) {
Log.e(TAG, "Failed to create predictor", e);
- return;
+ e.rethrowAsRuntimeException();
}
mCloseGuard.open("close");
@@ -112,6 +112,7 @@ public final class AppPredictor {
mPredictionManager.notifyAppTargetEvent(mSessionId, event);
} catch (RemoteException e) {
Log.e(TAG, "Failed to notify app target event", e);
+ e.rethrowAsRuntimeException();
}
}
@@ -129,6 +130,7 @@ public final class AppPredictor {
new ParceledListSlice<>(targetIds));
} catch (RemoteException e) {
Log.e(TAG, "Failed to notify location shown event", e);
+ e.rethrowAsRuntimeException();
}
}
@@ -155,6 +157,7 @@ public final class AppPredictor {
mRegisteredCallbacks.put(callback, callbackWrapper);
} catch (RemoteException e) {
Log.e(TAG, "Failed to register for prediction updates", e);
+ e.rethrowAsRuntimeException();
}
}
@@ -176,6 +179,7 @@ public final class AppPredictor {
mPredictionManager.unregisterPredictionUpdates(mSessionId, callbackWrapper);
} catch (RemoteException e) {
Log.e(TAG, "Failed to unregister for prediction updates", e);
+ e.rethrowAsRuntimeException();
}
}
@@ -194,6 +198,7 @@ public final class AppPredictor {
mPredictionManager.requestPredictionUpdate(mSessionId);
} catch (RemoteException e) {
Log.e(TAG, "Failed to request prediction update", e);
+ e.rethrowAsRuntimeException();
}
}
@@ -213,14 +218,13 @@ public final class AppPredictor {
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)) {
@@ -231,6 +235,7 @@ public final class AppPredictor {
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.");
diff --git a/core/java/android/app/prediction/AppTarget.java b/core/java/android/app/prediction/AppTarget.java
index 752c92bbca2a..6f09d344c13f 100644
--- a/core/java/android/app/prediction/AppTarget.java
+++ b/core/java/android/app/prediction/AppTarget.java
@@ -15,6 +15,7 @@
*/
package android.app.prediction;
+import android.annotation.IntRange;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SystemApi;
@@ -134,14 +135,19 @@ public final class AppTarget implements Parcelable {
* 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;
}
diff --git a/core/java/android/app/prediction/AppTargetEvent.java b/core/java/android/app/prediction/AppTargetEvent.java
index 01452dffa366..f6964f3f4236 100644
--- a/core/java/android/app/prediction/AppTargetEvent.java
+++ b/core/java/android/app/prediction/AppTargetEvent.java
@@ -84,7 +84,7 @@ public final class AppTargetEvent implements Parcelable {
/**
* Returns the launch location.
*/
- @NonNull
+ @Nullable
public String getLaunchLocation() {
return mLocation;
}
@@ -92,8 +92,7 @@ public final class AppTargetEvent implements Parcelable {
/**
* Returns the action type.
*/
- @NonNull
- public int getAction() {
+ public @ActionType int getAction() {
return mAction;
}
@@ -152,7 +151,8 @@ public final class AppTargetEvent implements Parcelable {
/**
* Sets the launch location.
*/
- public Builder setLaunchLocation(String location) {
+ @NonNull
+ public Builder setLaunchLocation(@Nullable String location) {
mLocation = location;
return this;
}
@@ -160,6 +160,7 @@ public final class AppTargetEvent implements Parcelable {
/**
* Builds a new event instance.
*/
+ @NonNull
public AppTargetEvent build() {
return new AppTargetEvent(mTarget, mLocation, mAction);
}
diff --git a/core/java/android/content/pm/ShortcutManager.java b/core/java/android/content/pm/ShortcutManager.java
index 22872437bd24..df6711761702 100644
--- a/core/java/android/content/pm/ShortcutManager.java
+++ b/core/java/android/content/pm/ShortcutManager.java
@@ -600,15 +600,17 @@ public class ShortcutManager {
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;
}
@@ -619,12 +621,12 @@ public class ShortcutManager {
}
@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);
diff --git a/core/java/android/service/appprediction/AppPredictionService.java b/core/java/android/service/appprediction/AppPredictionService.java
index d0128514d3e7..ff13e0361ab8 100644
--- a/core/java/android/service/appprediction/AppPredictionService.java
+++ b/core/java/android/service/appprediction/AppPredictionService.java
@@ -141,7 +141,8 @@ public abstract class AppPredictionService extends Service {
}
@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();
}