1/*
2 * Copyright (C) 2010 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
19import android.os.Parcelable;
20import android.os.Bundle;
21import android.os.Parcel;
22import android.accounts.Account;
23
24/**
25 * Value type that contains information about a periodic sync. Is parcelable, making it suitable
26 * for passing in an IPC.
27 */
28public class PeriodicSync implements Parcelable {
29    /** The account to be synced */
30    public final Account account;
31    /** The authority of the sync */
32    public final String authority;
33    /** Any extras that parameters that are to be passed to the sync adapter. */
34    public final Bundle extras;
35    /** How frequently the sync should be scheduled, in seconds. */
36    public final long period;
37
38    /** Creates a new PeriodicSync, copying the Bundle */
39    public PeriodicSync(Account account, String authority, Bundle extras, long period) {
40        this.account = account;
41        this.authority = authority;
42        this.extras = new Bundle(extras);
43        this.period = period;
44    }
45
46    public int describeContents() {
47        return 0;
48    }
49
50    public void writeToParcel(Parcel dest, int flags) {
51        account.writeToParcel(dest, flags);
52        dest.writeString(authority);
53        dest.writeBundle(extras);
54        dest.writeLong(period);
55    }
56
57    public static final Creator<PeriodicSync> CREATOR = new Creator<PeriodicSync>() {
58        public PeriodicSync createFromParcel(Parcel source) {
59            return new PeriodicSync(Account.CREATOR.createFromParcel(source),
60                    source.readString(), source.readBundle(), source.readLong());
61        }
62
63        public PeriodicSync[] newArray(int size) {
64            return new PeriodicSync[size];
65        }
66    };
67
68    public boolean equals(Object o) {
69        if (o == this) {
70            return true;
71        }
72
73        if (!(o instanceof PeriodicSync)) {
74            return false;
75        }
76
77        final PeriodicSync other = (PeriodicSync) o;
78
79        return account.equals(other.account)
80                && authority.equals(other.authority)
81                && period == other.period
82                && SyncStorageEngine.equals(extras, other.extras);
83    }
84}
85