blob: 4196f27f17f88e161afe2e9cc3917119028fbee4 [file] [log] [blame]
Fred Quintanace31b232009-05-04 16:01:15 -07001/*
2 * Copyright (C) 2009 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.content;
18
Nicolas Prevotd85fc722014-04-16 19:52:08 +010019import android.content.ContentProvider;
Fred Quintanace31b232009-05-04 16:01:15 -070020import android.net.Uri;
Fred Quintana89437372009-05-15 15:10:40 -070021import android.os.Parcelable;
22import android.os.Parcel;
Fred Quintanace31b232009-05-04 16:01:15 -070023
24/**
25 * Contains the result of the application of a {@link ContentProviderOperation}. It is guaranteed
26 * to have exactly one of {@link #uri} or {@link #count} set.
27 */
Fred Quintana89437372009-05-15 15:10:40 -070028public class ContentProviderResult implements Parcelable {
Fred Quintanace31b232009-05-04 16:01:15 -070029 public final Uri uri;
30 public final Integer count;
31
32 public ContentProviderResult(Uri uri) {
33 if (uri == null) throw new IllegalArgumentException("uri must not be null");
34 this.uri = uri;
35 this.count = null;
36 }
37
38 public ContentProviderResult(int count) {
39 this.count = count;
40 this.uri = null;
41 }
Fred Quintana89437372009-05-15 15:10:40 -070042
43 public ContentProviderResult(Parcel source) {
44 int type = source.readInt();
45 if (type == 1) {
46 count = source.readInt();
47 uri = null;
48 } else {
49 count = null;
50 uri = Uri.CREATOR.createFromParcel(source);
51 }
52 }
53
Nicolas Prevotd85fc722014-04-16 19:52:08 +010054 /** @hide */
55 public ContentProviderResult(ContentProviderResult cpr, int userId) {
56 uri = ContentProvider.maybeAddUserId(cpr.uri, userId);
57 count = cpr.count;
58 }
59
Fred Quintana89437372009-05-15 15:10:40 -070060 public void writeToParcel(Parcel dest, int flags) {
61 if (uri == null) {
62 dest.writeInt(1);
63 dest.writeInt(count);
64 } else {
65 dest.writeInt(2);
66 uri.writeToParcel(dest, 0);
67 }
68 }
69
70 public int describeContents() {
71 return 0;
72 }
73
74 public static final Creator<ContentProviderResult> CREATOR =
75 new Creator<ContentProviderResult>() {
76 public ContentProviderResult createFromParcel(Parcel source) {
77 return new ContentProviderResult(source);
78 }
79
80 public ContentProviderResult[] newArray(int size) {
81 return new ContentProviderResult[size];
82 }
83 };
Fred Quintana03d94902009-05-22 14:23:31 -070084
85 public String toString() {
86 if (uri != null) {
87 return "ContentProviderResult(uri=" + uri.toString() + ")";
88 }
89 return "ContentProviderResult(count=" + count + ")";
90 }
Nicolas Prevotd85fc722014-04-16 19:52:08 +010091}