1231cc608d06ffc31c24bf8aa8c8275bdd2636581Dianne Hackborn/*
2231cc608d06ffc31c24bf8aa8c8275bdd2636581Dianne Hackborn * Copyright (C) 2009 The Android Open Source Project
3231cc608d06ffc31c24bf8aa8c8275bdd2636581Dianne Hackborn *
4231cc608d06ffc31c24bf8aa8c8275bdd2636581Dianne Hackborn * Licensed under the Apache License, Version 2.0 (the "License");
5231cc608d06ffc31c24bf8aa8c8275bdd2636581Dianne Hackborn * you may not use this file except in compliance with the License.
6231cc608d06ffc31c24bf8aa8c8275bdd2636581Dianne Hackborn * You may obtain a copy of the License at
7231cc608d06ffc31c24bf8aa8c8275bdd2636581Dianne Hackborn *
8231cc608d06ffc31c24bf8aa8c8275bdd2636581Dianne Hackborn *      http://www.apache.org/licenses/LICENSE-2.0
9231cc608d06ffc31c24bf8aa8c8275bdd2636581Dianne Hackborn *
10231cc608d06ffc31c24bf8aa8c8275bdd2636581Dianne Hackborn * Unless required by applicable law or agreed to in writing, software
11231cc608d06ffc31c24bf8aa8c8275bdd2636581Dianne Hackborn * distributed under the License is distributed on an "AS IS" BASIS,
12231cc608d06ffc31c24bf8aa8c8275bdd2636581Dianne Hackborn * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13231cc608d06ffc31c24bf8aa8c8275bdd2636581Dianne Hackborn * See the License for the specific language governing permissions and
14231cc608d06ffc31c24bf8aa8c8275bdd2636581Dianne Hackborn * limitations under the License.
15231cc608d06ffc31c24bf8aa8c8275bdd2636581Dianne Hackborn */
16231cc608d06ffc31c24bf8aa8c8275bdd2636581Dianne Hackborn
17231cc608d06ffc31c24bf8aa8c8275bdd2636581Dianne Hackbornpackage android.content;
18231cc608d06ffc31c24bf8aa8c8275bdd2636581Dianne Hackborn
197a1355950172b7a549820e9a2cd4a9b2099ec32fDianne Hackbornimport android.accounts.Account;
20231cc608d06ffc31c24bf8aa8c8275bdd2636581Dianne Hackbornimport android.os.Parcel;
21c6a69559cb62bd20166c0c9684e64c60d779da38Fred Quintanaimport android.os.Parcelable;
22231cc608d06ffc31c24bf8aa8c8275bdd2636581Dianne Hackborn
231b487ec44b6b5594914d52fa427bec4f29a60541Fred Quintana/**
241b487ec44b6b5594914d52fa427bec4f29a60541Fred Quintana * Information about the sync operation that is currently underway.
251b487ec44b6b5594914d52fa427bec4f29a60541Fred Quintana */
26c6a69559cb62bd20166c0c9684e64c60d779da38Fred Quintanapublic class SyncInfo implements Parcelable {
27f39549e389edf62f43bacd95a1b8580d75ad77edMatthew Williams    /**
28f39549e389edf62f43bacd95a1b8580d75ad77edMatthew Williams     * Used when the caller receiving this object doesn't have permission to access the accounts
29f39549e389edf62f43bacd95a1b8580d75ad77edMatthew Williams     * on device.
30f39549e389edf62f43bacd95a1b8580d75ad77edMatthew Williams     * @See Manifest.permission.GET_ACCOUNTS
31f39549e389edf62f43bacd95a1b8580d75ad77edMatthew Williams     */
32f39549e389edf62f43bacd95a1b8580d75ad77edMatthew Williams    private static final Account REDACTED_ACCOUNT = new Account("*****", "*****");
33f39549e389edf62f43bacd95a1b8580d75ad77edMatthew Williams
34d5e4fdc8a4743abc0d9fe3cb952a78f9ad078c6bFred Quintana    /** @hide */
35d5e4fdc8a4743abc0d9fe3cb952a78f9ad078c6bFred Quintana    public final int authorityId;
361b487ec44b6b5594914d52fa427bec4f29a60541Fred Quintana
371b487ec44b6b5594914d52fa427bec4f29a60541Fred Quintana    /**
385a9decd589f3f6a512168fd669ee2c5d8daa238bMatthew Williams     * The {@link Account} that is currently being synced.
391b487ec44b6b5594914d52fa427bec4f29a60541Fred Quintana     */
40d5e4fdc8a4743abc0d9fe3cb952a78f9ad078c6bFred Quintana    public final Account account;
411b487ec44b6b5594914d52fa427bec4f29a60541Fred Quintana
421b487ec44b6b5594914d52fa427bec4f29a60541Fred Quintana    /**
435a9decd589f3f6a512168fd669ee2c5d8daa238bMatthew Williams     * The authority of the provider that is currently being synced.
441b487ec44b6b5594914d52fa427bec4f29a60541Fred Quintana     */
45d5e4fdc8a4743abc0d9fe3cb952a78f9ad078c6bFred Quintana    public final String authority;
461b487ec44b6b5594914d52fa427bec4f29a60541Fred Quintana
471b487ec44b6b5594914d52fa427bec4f29a60541Fred Quintana    /**
48d5e4fdc8a4743abc0d9fe3cb952a78f9ad078c6bFred Quintana     * The start time of the current sync operation in milliseconds since boot.
49d5e4fdc8a4743abc0d9fe3cb952a78f9ad078c6bFred Quintana     * This is represented in elapsed real time.
501b487ec44b6b5594914d52fa427bec4f29a60541Fred Quintana     * See {@link android.os.SystemClock#elapsedRealtime()}.
511b487ec44b6b5594914d52fa427bec4f29a60541Fred Quintana     */
52d5e4fdc8a4743abc0d9fe3cb952a78f9ad078c6bFred Quintana    public final long startTime;
531b487ec44b6b5594914d52fa427bec4f29a60541Fred Quintana
54f39549e389edf62f43bacd95a1b8580d75ad77edMatthew Williams    /**
55f39549e389edf62f43bacd95a1b8580d75ad77edMatthew Williams     * Creates a SyncInfo object with an unusable Account. Used when the caller receiving this
56f39549e389edf62f43bacd95a1b8580d75ad77edMatthew Williams     * object doesn't have access to the accounts on the device.
57f39549e389edf62f43bacd95a1b8580d75ad77edMatthew Williams     * @See Manifest.permission.GET_ACCOUNTS
58f39549e389edf62f43bacd95a1b8580d75ad77edMatthew Williams     * @hide
59f39549e389edf62f43bacd95a1b8580d75ad77edMatthew Williams     */
60f39549e389edf62f43bacd95a1b8580d75ad77edMatthew Williams    public static SyncInfo createAccountRedacted(
61f39549e389edf62f43bacd95a1b8580d75ad77edMatthew Williams        int authorityId, String authority, long startTime) {
62f39549e389edf62f43bacd95a1b8580d75ad77edMatthew Williams            return new SyncInfo(authorityId, REDACTED_ACCOUNT, authority, startTime);
63f39549e389edf62f43bacd95a1b8580d75ad77edMatthew Williams    }
64f39549e389edf62f43bacd95a1b8580d75ad77edMatthew Williams
651b487ec44b6b5594914d52fa427bec4f29a60541Fred Quintana    /** @hide */
665a9decd589f3f6a512168fd669ee2c5d8daa238bMatthew Williams    public SyncInfo(int authorityId, Account account, String authority, long startTime) {
67231cc608d06ffc31c24bf8aa8c8275bdd2636581Dianne Hackborn        this.authorityId = authorityId;
68231cc608d06ffc31c24bf8aa8c8275bdd2636581Dianne Hackborn        this.account = account;
69231cc608d06ffc31c24bf8aa8c8275bdd2636581Dianne Hackborn        this.authority = authority;
70231cc608d06ffc31c24bf8aa8c8275bdd2636581Dianne Hackborn        this.startTime = startTime;
71231cc608d06ffc31c24bf8aa8c8275bdd2636581Dianne Hackborn    }
721b487ec44b6b5594914d52fa427bec4f29a60541Fred Quintana
731b487ec44b6b5594914d52fa427bec4f29a60541Fred Quintana    /** @hide */
74a7456e46f4cb64524386b22e2596ea93c244c16fMatthew Williams    public SyncInfo(SyncInfo other) {
75a7456e46f4cb64524386b22e2596ea93c244c16fMatthew Williams        this.authorityId = other.authorityId;
76a7456e46f4cb64524386b22e2596ea93c244c16fMatthew Williams        this.account = new Account(other.account.name, other.account.type);
77a7456e46f4cb64524386b22e2596ea93c244c16fMatthew Williams        this.authority = other.authority;
78a7456e46f4cb64524386b22e2596ea93c244c16fMatthew Williams        this.startTime = other.startTime;
79a7456e46f4cb64524386b22e2596ea93c244c16fMatthew Williams    }
80a7456e46f4cb64524386b22e2596ea93c244c16fMatthew Williams
81a7456e46f4cb64524386b22e2596ea93c244c16fMatthew Williams    /** @hide */
82231cc608d06ffc31c24bf8aa8c8275bdd2636581Dianne Hackborn    public int describeContents() {
83231cc608d06ffc31c24bf8aa8c8275bdd2636581Dianne Hackborn        return 0;
84231cc608d06ffc31c24bf8aa8c8275bdd2636581Dianne Hackborn    }
85231cc608d06ffc31c24bf8aa8c8275bdd2636581Dianne Hackborn
861b487ec44b6b5594914d52fa427bec4f29a60541Fred Quintana    /** @hide */
87231cc608d06ffc31c24bf8aa8c8275bdd2636581Dianne Hackborn    public void writeToParcel(Parcel parcel, int flags) {
88231cc608d06ffc31c24bf8aa8c8275bdd2636581Dianne Hackborn        parcel.writeInt(authorityId);
8956dbf8f23677d28615e61ef2fbb0e738cca02528Matthew Williams        parcel.writeParcelable(account, flags);
90231cc608d06ffc31c24bf8aa8c8275bdd2636581Dianne Hackborn        parcel.writeString(authority);
91231cc608d06ffc31c24bf8aa8c8275bdd2636581Dianne Hackborn        parcel.writeLong(startTime);
92231cc608d06ffc31c24bf8aa8c8275bdd2636581Dianne Hackborn    }
93231cc608d06ffc31c24bf8aa8c8275bdd2636581Dianne Hackborn
941b487ec44b6b5594914d52fa427bec4f29a60541Fred Quintana    /** @hide */
95d5e4fdc8a4743abc0d9fe3cb952a78f9ad078c6bFred Quintana    SyncInfo(Parcel parcel) {
96231cc608d06ffc31c24bf8aa8c8275bdd2636581Dianne Hackborn        authorityId = parcel.readInt();
9756dbf8f23677d28615e61ef2fbb0e738cca02528Matthew Williams        account = parcel.readParcelable(Account.class.getClassLoader());
98231cc608d06ffc31c24bf8aa8c8275bdd2636581Dianne Hackborn        authority = parcel.readString();
99231cc608d06ffc31c24bf8aa8c8275bdd2636581Dianne Hackborn        startTime = parcel.readLong();
100231cc608d06ffc31c24bf8aa8c8275bdd2636581Dianne Hackborn    }
1011b487ec44b6b5594914d52fa427bec4f29a60541Fred Quintana
1021b487ec44b6b5594914d52fa427bec4f29a60541Fred Quintana    /** @hide */
103d5e4fdc8a4743abc0d9fe3cb952a78f9ad078c6bFred Quintana    public static final Creator<SyncInfo> CREATOR = new Creator<SyncInfo>() {
104d5e4fdc8a4743abc0d9fe3cb952a78f9ad078c6bFred Quintana        public SyncInfo createFromParcel(Parcel in) {
105d5e4fdc8a4743abc0d9fe3cb952a78f9ad078c6bFred Quintana            return new SyncInfo(in);
106231cc608d06ffc31c24bf8aa8c8275bdd2636581Dianne Hackborn        }
107231cc608d06ffc31c24bf8aa8c8275bdd2636581Dianne Hackborn
108d5e4fdc8a4743abc0d9fe3cb952a78f9ad078c6bFred Quintana        public SyncInfo[] newArray(int size) {
109d5e4fdc8a4743abc0d9fe3cb952a78f9ad078c6bFred Quintana            return new SyncInfo[size];
110231cc608d06ffc31c24bf8aa8c8275bdd2636581Dianne Hackborn        }
111231cc608d06ffc31c24bf8aa8c8275bdd2636581Dianne Hackborn    };
1126cb6f246fe9fa7bd2be88946f531a82576008be4Fred Quintana}
113