Fred Quintana | d5e4fdc | 2010-03-30 15:16:21 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package android.content; |
| 18 | |
| 19 | import android.accounts.Account; |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 20 | import android.annotation.UnsupportedAppUsage; |
Mathew Inwood | 31755f9 | 2018-12-20 13:53:36 +0000 | [diff] [blame] | 21 | import android.os.Build; |
Fred Quintana | d5e4fdc | 2010-03-30 15:16:21 -0700 | [diff] [blame] | 22 | import android.os.Parcel; |
Fred Quintana | c6a6955 | 2010-09-27 17:05:04 -0700 | [diff] [blame] | 23 | import android.os.Parcelable; |
Fred Quintana | d5e4fdc | 2010-03-30 15:16:21 -0700 | [diff] [blame] | 24 | |
| 25 | /** |
| 26 | * Information about the sync operation that is currently underway. |
| 27 | */ |
Fred Quintana | c6a6955 | 2010-09-27 17:05:04 -0700 | [diff] [blame] | 28 | public class SyncInfo implements Parcelable { |
Matthew Williams | f39549e | 2016-01-19 23:04:04 +0000 | [diff] [blame] | 29 | /** |
| 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 Quintana | d5e4fdc | 2010-03-30 15:16:21 -0700 | [diff] [blame] | 36 | /** @hide */ |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 37 | @UnsupportedAppUsage |
Fred Quintana | d5e4fdc | 2010-03-30 15:16:21 -0700 | [diff] [blame] | 38 | public final int authorityId; |
| 39 | |
| 40 | /** |
Matthew Williams | 5a9decd | 2014-06-04 09:25:11 -0700 | [diff] [blame] | 41 | * The {@link Account} that is currently being synced. |
Fred Quintana | d5e4fdc | 2010-03-30 15:16:21 -0700 | [diff] [blame] | 42 | */ |
| 43 | public final Account account; |
| 44 | |
| 45 | /** |
Matthew Williams | 5a9decd | 2014-06-04 09:25:11 -0700 | [diff] [blame] | 46 | * The authority of the provider that is currently being synced. |
Fred Quintana | d5e4fdc | 2010-03-30 15:16:21 -0700 | [diff] [blame] | 47 | */ |
| 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 Williams | f39549e | 2016-01-19 23:04:04 +0000 | [diff] [blame] | 57 | /** |
| 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 Quintana | d5e4fdc | 2010-03-30 15:16:21 -0700 | [diff] [blame] | 68 | /** @hide */ |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 69 | @UnsupportedAppUsage |
Matthew Williams | 5a9decd | 2014-06-04 09:25:11 -0700 | [diff] [blame] | 70 | public SyncInfo(int authorityId, Account account, String authority, long startTime) { |
Fred Quintana | d5e4fdc | 2010-03-30 15:16:21 -0700 | [diff] [blame] | 71 | this.authorityId = authorityId; |
| 72 | this.account = account; |
| 73 | this.authority = authority; |
| 74 | this.startTime = startTime; |
| 75 | } |
| 76 | |
| 77 | /** @hide */ |
Matthew Williams | a7456e4 | 2013-11-12 14:41:02 -0800 | [diff] [blame] | 78 | 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 Quintana | d5e4fdc | 2010-03-30 15:16:21 -0700 | [diff] [blame] | 86 | public int describeContents() { |
| 87 | return 0; |
| 88 | } |
| 89 | |
| 90 | /** @hide */ |
| 91 | public void writeToParcel(Parcel parcel, int flags) { |
| 92 | parcel.writeInt(authorityId); |
Matthew Williams | 56dbf8f | 2013-07-26 12:56:39 -0700 | [diff] [blame] | 93 | parcel.writeParcelable(account, flags); |
Fred Quintana | d5e4fdc | 2010-03-30 15:16:21 -0700 | [diff] [blame] | 94 | parcel.writeString(authority); |
| 95 | parcel.writeLong(startTime); |
| 96 | } |
| 97 | |
| 98 | /** @hide */ |
Mathew Inwood | 31755f9 | 2018-12-20 13:53:36 +0000 | [diff] [blame] | 99 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
Fred Quintana | d5e4fdc | 2010-03-30 15:16:21 -0700 | [diff] [blame] | 100 | SyncInfo(Parcel parcel) { |
| 101 | authorityId = parcel.readInt(); |
Matthew Williams | 56dbf8f | 2013-07-26 12:56:39 -0700 | [diff] [blame] | 102 | account = parcel.readParcelable(Account.class.getClassLoader()); |
Fred Quintana | d5e4fdc | 2010-03-30 15:16:21 -0700 | [diff] [blame] | 103 | authority = parcel.readString(); |
| 104 | startTime = parcel.readLong(); |
Fred Quintana | d5e4fdc | 2010-03-30 15:16:21 -0700 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | /** @hide */ |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 108 | @UnsupportedAppUsage |
Fred Quintana | d5e4fdc | 2010-03-30 15:16:21 -0700 | [diff] [blame] | 109 | public static final Creator<SyncInfo> CREATOR = new Creator<SyncInfo>() { |
| 110 | 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 | } |