• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.compat.annotation.UnsupportedAppUsage;
21 import android.os.Build;
22 import android.os.Parcel;
23 import android.os.Parcelable;
24 
25 /**
26  * Information about the sync operation that is currently underway.
27  */
28 public class SyncInfo implements Parcelable {
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 
36     /** @hide */
37     @UnsupportedAppUsage
38     public final int authorityId;
39 
40     /**
41      * The {@link Account} that is currently being synced.
42      */
43     public final Account account;
44 
45     /**
46      * The authority of the provider that is currently being synced.
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 
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      */
createAccountRedacted( int authorityId, String authority, long startTime)63     public static SyncInfo createAccountRedacted(
64         int authorityId, String authority, long startTime) {
65             return new SyncInfo(authorityId, REDACTED_ACCOUNT, authority, startTime);
66     }
67 
68     /** @hide */
69     @UnsupportedAppUsage
SyncInfo(int authorityId, Account account, String authority, long startTime)70     public SyncInfo(int authorityId, Account account, String authority, long startTime) {
71         this.authorityId = authorityId;
72         this.account = account;
73         this.authority = authority;
74         this.startTime = startTime;
75     }
76 
77     /** @hide */
SyncInfo(SyncInfo other)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 */
describeContents()86     public int describeContents() {
87         return 0;
88     }
89 
90     /** @hide */
writeToParcel(Parcel parcel, int flags)91     public void writeToParcel(Parcel parcel, int flags) {
92         parcel.writeInt(authorityId);
93         parcel.writeParcelable(account, flags);
94         parcel.writeString(authority);
95         parcel.writeLong(startTime);
96     }
97 
98     /** @hide */
99     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
SyncInfo(Parcel parcel)100     SyncInfo(Parcel parcel) {
101         authorityId = parcel.readInt();
102         account = parcel.readParcelable(Account.class.getClassLoader());
103         authority = parcel.readString();
104         startTime = parcel.readLong();
105     }
106 
107     /** @hide */
108     @UnsupportedAppUsage
109     public static final @android.annotation.NonNull 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 }
119