| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.service.ambientcontext; |
| 18 |
|
| 19 |
import android.annotation.NonNull; |
| 20 |
import android.annotation.SystemApi; |
| 21 |
import android.app.ambientcontext.AmbientContextManager; |
| 22 |
import android.app.ambientcontext.AmbientContextManager.StatusCode; |
| 23 |
import android.os.Parcelable; |
| 24 |
|
| 25 |
import com.android.internal.util.AnnotationValidations; |
| 26 |
|
| 27 |
import java.util.Objects; |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
@SystemApi |
| 35 |
public final class AmbientContextDetectionServiceStatus implements Parcelable { |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
public static final String STATUS_RESPONSE_BUNDLE_KEY = |
| 42 |
"android.app.ambientcontext.AmbientContextServiceStatusBundleKey"; |
| 43 |
|
| 44 |
@StatusCode private final int mStatusCode; |
| 45 |
@NonNull private final String mPackageName; |
| 46 |
|
| 47 |
AmbientContextDetectionServiceStatus( |
| 48 |
@StatusCode int statusCode, |
| 49 |
@NonNull String packageName) { |
| 50 |
this.mStatusCode = statusCode; |
| 51 |
AnnotationValidations.validate(StatusCode.class, null, mStatusCode); |
| 52 |
this.mPackageName = packageName; |
| 53 |
} |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
public @StatusCode int getStatusCode() { |
| 59 |
return mStatusCode; |
| 60 |
} |
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
public @NonNull String getPackageName() { |
| 66 |
return mPackageName; |
| 67 |
} |
| 68 |
|
| 69 |
@Override |
| 70 |
public String toString() { |
| 71 |
return "AmbientContextDetectionServiceStatus { " + "statusCode = " + mStatusCode + ", " |
| 72 |
+ "packageName = " + mPackageName + " }"; |
| 73 |
} |
| 74 |
|
| 75 |
@Override |
| 76 |
public void writeToParcel(@NonNull android.os.Parcel dest, int flags) { |
| 77 |
byte flg = 0; |
| 78 |
dest.writeByte(flg); |
| 79 |
dest.writeInt(mStatusCode); |
| 80 |
dest.writeString(mPackageName); |
| 81 |
} |
| 82 |
|
| 83 |
@Override |
| 84 |
public int describeContents() { |
| 85 |
return 0; |
| 86 |
} |
| 87 |
|
| 88 |
|
| 89 |
@SuppressWarnings({"unchecked", "RedundantCast"}) |
| 90 |
AmbientContextDetectionServiceStatus(@NonNull android.os.Parcel in) { |
| 91 |
byte flg = in.readByte(); |
| 92 |
int statusCode = in.readInt(); |
| 93 |
String packageName = in.readString(); |
| 94 |
|
| 95 |
this.mStatusCode = statusCode; |
| 96 |
AnnotationValidations.validate( |
| 97 |
StatusCode.class, null, mStatusCode); |
| 98 |
this.mPackageName = packageName; |
| 99 |
AnnotationValidations.validate( |
| 100 |
NonNull.class, null, mPackageName); |
| 101 |
} |
| 102 |
|
| 103 |
public static final @NonNull Creator<AmbientContextDetectionServiceStatus> CREATOR = |
| 104 |
new Creator<AmbientContextDetectionServiceStatus>() { |
| 105 |
@Override |
| 106 |
public AmbientContextDetectionServiceStatus[] newArray(int size) { |
| 107 |
return new AmbientContextDetectionServiceStatus[size]; |
| 108 |
} |
| 109 |
|
| 110 |
@Override |
| 111 |
public AmbientContextDetectionServiceStatus createFromParcel( |
| 112 |
@NonNull android.os.Parcel in) { |
| 113 |
return new AmbientContextDetectionServiceStatus(in); |
| 114 |
} |
| 115 |
}; |
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
@SuppressWarnings("WeakerAccess") |
| 121 |
public static final class Builder { |
| 122 |
private @StatusCode int mStatusCode; |
| 123 |
private @NonNull String mPackageName; |
| 124 |
private long mBuilderFieldsSet = 0L; |
| 125 |
|
| 126 |
public Builder(@NonNull String packageName) { |
| 127 |
Objects.requireNonNull(packageName); |
| 128 |
mPackageName = packageName; |
| 129 |
} |
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
public @NonNull Builder setStatusCode(@StatusCode int value) { |
| 135 |
checkNotUsed(); |
| 136 |
mBuilderFieldsSet |= 0x1; |
| 137 |
mStatusCode = value; |
| 138 |
return this; |
| 139 |
} |
| 140 |
|
| 141 |
|
| 142 |
public @NonNull AmbientContextDetectionServiceStatus build() { |
| 143 |
checkNotUsed(); |
| 144 |
mBuilderFieldsSet |= 0x2; |
| 145 |
|
| 146 |
if ((mBuilderFieldsSet & 0x1) == 0) { |
| 147 |
mStatusCode = AmbientContextManager.STATUS_UNKNOWN; |
| 148 |
} |
| 149 |
AmbientContextDetectionServiceStatus o = new AmbientContextDetectionServiceStatus( |
| 150 |
mStatusCode, |
| 151 |
mPackageName); |
| 152 |
return o; |
| 153 |
} |
| 154 |
|
| 155 |
private void checkNotUsed() { |
| 156 |
if ((mBuilderFieldsSet & 0x2) != 0) { |
| 157 |
throw new IllegalStateException( |
| 158 |
"This Builder should not be reused. Use a new Builder instance instead"); |
| 159 |
} |
| 160 |
} |
| 161 |
} |
| 162 |
} |