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; 20 import android.os.Parcel; 21 import android.os.Parcelable; 22 23 /** 24 * Information about the sync operation that is currently underway. 25 */ 26 public class SyncInfo implements Parcelable { 27 /** 28 * Used when the caller receiving this object doesn't have permission to access the accounts 29 * on device. 30 * @See Manifest.permission.GET_ACCOUNTS 31 */ 32 private static final Account REDACTED_ACCOUNT = new Account("*****", "*****"); 33 34 /** @hide */ 35 public final int authorityId; 36 37 /** 38 * The {@link Account} that is currently being synced. 39 */ 40 public final Account account; 41 42 /** 43 * The authority of the provider that is currently being synced. 44 */ 45 public final String authority; 46 47 /** 48 * The start time of the current sync operation in milliseconds since boot. 49 * This is represented in elapsed real time. 50 * See {@link android.os.SystemClock#elapsedRealtime()}. 51 */ 52 public final long startTime; 53 54 /** 55 * Creates a SyncInfo object with an unusable Account. Used when the caller receiving this 56 * object doesn't have access to the accounts on the device. 57 * @See Manifest.permission.GET_ACCOUNTS 58 * @hide 59 */ createAccountRedacted( int authorityId, String authority, long startTime)60 public static SyncInfo createAccountRedacted( 61 int authorityId, String authority, long startTime) { 62 return new SyncInfo(authorityId, REDACTED_ACCOUNT, authority, startTime); 63 } 64 65 /** @hide */ SyncInfo(int authorityId, Account account, String authority, long startTime)66 public SyncInfo(int authorityId, Account account, String authority, long startTime) { 67 this.authorityId = authorityId; 68 this.account = account; 69 this.authority = authority; 70 this.startTime = startTime; 71 } 72 73 /** @hide */ SyncInfo(SyncInfo other)74 public SyncInfo(SyncInfo other) { 75 this.authorityId = other.authorityId; 76 this.account = new Account(other.account.name, other.account.type); 77 this.authority = other.authority; 78 this.startTime = other.startTime; 79 } 80 81 /** @hide */ describeContents()82 public int describeContents() { 83 return 0; 84 } 85 86 /** @hide */ writeToParcel(Parcel parcel, int flags)87 public void writeToParcel(Parcel parcel, int flags) { 88 parcel.writeInt(authorityId); 89 parcel.writeParcelable(account, flags); 90 parcel.writeString(authority); 91 parcel.writeLong(startTime); 92 } 93 94 /** @hide */ SyncInfo(Parcel parcel)95 SyncInfo(Parcel parcel) { 96 authorityId = parcel.readInt(); 97 account = parcel.readParcelable(Account.class.getClassLoader()); 98 authority = parcel.readString(); 99 startTime = parcel.readLong(); 100 } 101 102 /** @hide */ 103 public static final Creator<SyncInfo> CREATOR = new Creator<SyncInfo>() { 104 public SyncInfo createFromParcel(Parcel in) { 105 return new SyncInfo(in); 106 } 107 108 public SyncInfo[] newArray(int size) { 109 return new SyncInfo[size]; 110 } 111 }; 112 } 113