blob: d3f2eed8126f0e43ab63a4148ca1527fdb7e12d8 [file] [log] [blame]
Fred Quintanad5e4fdc2010-03-30 15:16:21 -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
19import android.accounts.Account;
Mathew Inwood5c0d3542018-08-14 13:54:31 +010020import android.annotation.UnsupportedAppUsage;
Mathew Inwood31755f92018-12-20 13:53:36 +000021import android.os.Build;
Fred Quintanad5e4fdc2010-03-30 15:16:21 -070022import android.os.Parcel;
Fred Quintanac6a69552010-09-27 17:05:04 -070023import android.os.Parcelable;
Fred Quintanad5e4fdc2010-03-30 15:16:21 -070024
25/**
26 * Information about the sync operation that is currently underway.
27 */
Fred Quintanac6a69552010-09-27 17:05:04 -070028public class SyncInfo implements Parcelable {
Matthew Williamsf39549e2016-01-19 23:04:04 +000029 /**
30 * Used when the caller receiving this object doesn't have permission to access the accounts
31 * on device.
32 * @See Manifest.permission.GET_ACCOUNTS
33 */
34 private static final Account REDACTED_ACCOUNT = new Account("*****", "*****");
35
Fred Quintanad5e4fdc2010-03-30 15:16:21 -070036 /** @hide */
Mathew Inwood5c0d3542018-08-14 13:54:31 +010037 @UnsupportedAppUsage
Fred Quintanad5e4fdc2010-03-30 15:16:21 -070038 public final int authorityId;
39
40 /**
Matthew Williams5a9decd2014-06-04 09:25:11 -070041 * The {@link Account} that is currently being synced.
Fred Quintanad5e4fdc2010-03-30 15:16:21 -070042 */
43 public final Account account;
44
45 /**
Matthew Williams5a9decd2014-06-04 09:25:11 -070046 * The authority of the provider that is currently being synced.
Fred Quintanad5e4fdc2010-03-30 15:16:21 -070047 */
48 public final String authority;
49
50 /**
51 * The start time of the current sync operation in milliseconds since boot.
52 * This is represented in elapsed real time.
53 * See {@link android.os.SystemClock#elapsedRealtime()}.
54 */
55 public final long startTime;
56
Matthew Williamsf39549e2016-01-19 23:04:04 +000057 /**
58 * Creates a SyncInfo object with an unusable Account. Used when the caller receiving this
59 * object doesn't have access to the accounts on the device.
60 * @See Manifest.permission.GET_ACCOUNTS
61 * @hide
62 */
63 public static SyncInfo createAccountRedacted(
64 int authorityId, String authority, long startTime) {
65 return new SyncInfo(authorityId, REDACTED_ACCOUNT, authority, startTime);
66 }
67
Fred Quintanad5e4fdc2010-03-30 15:16:21 -070068 /** @hide */
Mathew Inwood5c0d3542018-08-14 13:54:31 +010069 @UnsupportedAppUsage
Matthew Williams5a9decd2014-06-04 09:25:11 -070070 public SyncInfo(int authorityId, Account account, String authority, long startTime) {
Fred Quintanad5e4fdc2010-03-30 15:16:21 -070071 this.authorityId = authorityId;
72 this.account = account;
73 this.authority = authority;
74 this.startTime = startTime;
75 }
76
77 /** @hide */
Matthew Williamsa7456e42013-11-12 14:41:02 -080078 public SyncInfo(SyncInfo other) {
79 this.authorityId = other.authorityId;
80 this.account = new Account(other.account.name, other.account.type);
81 this.authority = other.authority;
82 this.startTime = other.startTime;
83 }
84
85 /** @hide */
Fred Quintanad5e4fdc2010-03-30 15:16:21 -070086 public int describeContents() {
87 return 0;
88 }
89
90 /** @hide */
91 public void writeToParcel(Parcel parcel, int flags) {
92 parcel.writeInt(authorityId);
Matthew Williams56dbf8f2013-07-26 12:56:39 -070093 parcel.writeParcelable(account, flags);
Fred Quintanad5e4fdc2010-03-30 15:16:21 -070094 parcel.writeString(authority);
95 parcel.writeLong(startTime);
96 }
97
98 /** @hide */
Mathew Inwood31755f92018-12-20 13:53:36 +000099 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
Fred Quintanad5e4fdc2010-03-30 15:16:21 -0700100 SyncInfo(Parcel parcel) {
101 authorityId = parcel.readInt();
Matthew Williams56dbf8f2013-07-26 12:56:39 -0700102 account = parcel.readParcelable(Account.class.getClassLoader());
Fred Quintanad5e4fdc2010-03-30 15:16:21 -0700103 authority = parcel.readString();
104 startTime = parcel.readLong();
Fred Quintanad5e4fdc2010-03-30 15:16:21 -0700105 }
106
107 /** @hide */
Mathew Inwood5c0d3542018-08-14 13:54:31 +0100108 @UnsupportedAppUsage
Jeff Sharkey9e8f83d2019-02-28 12:06:45 -0700109 public static final @android.annotation.NonNull Creator<SyncInfo> CREATOR = new Creator<SyncInfo>() {
Fred Quintanad5e4fdc2010-03-30 15:16:21 -0700110 public SyncInfo createFromParcel(Parcel in) {
111 return new SyncInfo(in);
112 }
113
114 public SyncInfo[] newArray(int size) {
115 return new SyncInfo[size];
116 }
117 };
118}