| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.content; |
| 18 |
|
| 19 |
import android.accounts.Account; |
| 20 |
import android.annotation.Nullable; |
| 21 |
import android.os.Bundle; |
| 22 |
import android.os.Parcel; |
| 23 |
import android.os.Parcelable; |
| 24 |
|
| 25 |
import java.util.Objects; |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
public class PeriodicSync implements Parcelable { |
| 31 |
|
| 32 |
public final Account account; |
| 33 |
|
| 34 |
public final String authority; |
| 35 |
|
| 36 |
public final Bundle extras; |
| 37 |
|
| 38 |
public final long period; |
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
public final long flexTime; |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
public PeriodicSync(Account account, String authority, Bundle extras, long periodInSeconds) { |
| 49 |
this.account = account; |
| 50 |
this.authority = authority; |
| 51 |
if (extras == null) { |
| 52 |
this.extras = new Bundle(); |
| 53 |
} else { |
| 54 |
this.extras = new Bundle(extras); |
| 55 |
} |
| 56 |
this.period = periodInSeconds; |
| 57 |
|
| 58 |
this.flexTime = 0L; |
| 59 |
} |
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
public PeriodicSync(PeriodicSync other) { |
| 66 |
this.account = other.account; |
| 67 |
this.authority = other.authority; |
| 68 |
this.extras = new Bundle(other.extras); |
| 69 |
this.period = other.period; |
| 70 |
this.flexTime = other.flexTime; |
| 71 |
} |
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
public PeriodicSync(Account account, String authority, Bundle extras, |
| 78 |
long period, long flexTime) { |
| 79 |
this.account = account; |
| 80 |
this.authority = authority; |
| 81 |
this.extras = new Bundle(extras); |
| 82 |
this.period = period; |
| 83 |
this.flexTime = flexTime; |
| 84 |
} |
| 85 |
|
| 86 |
private PeriodicSync(Parcel in) { |
| 87 |
this.account = in.readParcelable(null, android.accounts.Account.class); |
| 88 |
this.authority = in.readString(); |
| 89 |
this.extras = in.readBundle(); |
| 90 |
this.period = in.readLong(); |
| 91 |
this.flexTime = in.readLong(); |
| 92 |
} |
| 93 |
|
| 94 |
@Override |
| 95 |
public int describeContents() { |
| 96 |
return 0; |
| 97 |
} |
| 98 |
|
| 99 |
@Override |
| 100 |
public void writeToParcel(Parcel dest, int flags) { |
| 101 |
dest.writeParcelable(account, flags); |
| 102 |
dest.writeString(authority); |
| 103 |
dest.writeBundle(extras); |
| 104 |
dest.writeLong(period); |
| 105 |
dest.writeLong(flexTime); |
| 106 |
} |
| 107 |
|
| 108 |
public static final @android.annotation.NonNull Creator<PeriodicSync> CREATOR = new Creator<PeriodicSync>() { |
| 109 |
@Override |
| 110 |
public PeriodicSync createFromParcel(Parcel source) { |
| 111 |
return new PeriodicSync(source); |
| 112 |
} |
| 113 |
|
| 114 |
@Override |
| 115 |
public PeriodicSync[] newArray(int size) { |
| 116 |
return new PeriodicSync[size]; |
| 117 |
} |
| 118 |
}; |
| 119 |
|
| 120 |
@Override |
| 121 |
public boolean equals(@Nullable Object o) { |
| 122 |
if (o == this) { |
| 123 |
return true; |
| 124 |
} |
| 125 |
if (!(o instanceof PeriodicSync)) { |
| 126 |
return false; |
| 127 |
} |
| 128 |
final PeriodicSync other = (PeriodicSync) o; |
| 129 |
return account.equals(other.account) |
| 130 |
&& authority.equals(other.authority) |
| 131 |
&& period == other.period |
| 132 |
&& syncExtrasEquals(extras, other.extras); |
| 133 |
} |
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
public static boolean syncExtrasEquals(Bundle b1, Bundle b2) { |
| 140 |
if (b1.size() != b2.size()) { |
| 141 |
return false; |
| 142 |
} |
| 143 |
if (b1.isEmpty()) { |
| 144 |
return true; |
| 145 |
} |
| 146 |
for (String key : b1.keySet()) { |
| 147 |
if (!b2.containsKey(key)) { |
| 148 |
return false; |
| 149 |
} |
| 150 |
|
| 151 |
|
| 152 |
if (!Objects.equals(b1.get(key), b2.get(key))) { |
| 153 |
return false; |
| 154 |
} |
| 155 |
} |
| 156 |
return true; |
| 157 |
} |
| 158 |
|
| 159 |
@Override |
| 160 |
public String toString() { |
| 161 |
return "account: " + account + |
| 162 |
", authority: " + authority + |
| 163 |
". period: " + period + "s " + |
| 164 |
", flex: " + flexTime; |
| 165 |
} |
| 166 |
} |