133fe908589dca6a7f58aa9f56d73f74a48ac42f6Mindy Pereira/**
233fe908589dca6a7f58aa9f56d73f74a48ac42f6Mindy Pereira * Copyright (c) 2012, Google Inc.
333fe908589dca6a7f58aa9f56d73f74a48ac42f6Mindy Pereira *
433fe908589dca6a7f58aa9f56d73f74a48ac42f6Mindy Pereira * Licensed under the Apache License, Version 2.0 (the "License");
533fe908589dca6a7f58aa9f56d73f74a48ac42f6Mindy Pereira * you may not use this file except in compliance with the License.
633fe908589dca6a7f58aa9f56d73f74a48ac42f6Mindy Pereira * You may obtain a copy of the License at
733fe908589dca6a7f58aa9f56d73f74a48ac42f6Mindy Pereira *
833fe908589dca6a7f58aa9f56d73f74a48ac42f6Mindy Pereira *     http://www.apache.org/licenses/LICENSE-2.0
933fe908589dca6a7f58aa9f56d73f74a48ac42f6Mindy Pereira *
1033fe908589dca6a7f58aa9f56d73f74a48ac42f6Mindy Pereira * Unless required by applicable law or agreed to in writing, software
1133fe908589dca6a7f58aa9f56d73f74a48ac42f6Mindy Pereira * distributed under the License is distributed on an "AS IS" BASIS,
1233fe908589dca6a7f58aa9f56d73f74a48ac42f6Mindy Pereira * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1333fe908589dca6a7f58aa9f56d73f74a48ac42f6Mindy Pereira * See the License for the specific language governing permissions and
1433fe908589dca6a7f58aa9f56d73f74a48ac42f6Mindy Pereira * limitations under the License.
1533fe908589dca6a7f58aa9f56d73f74a48ac42f6Mindy Pereira */
1633fe908589dca6a7f58aa9f56d73f74a48ac42f6Mindy Pereira
1733fe908589dca6a7f58aa9f56d73f74a48ac42f6Mindy Pereirapackage com.android.mail.providers;
1833fe908589dca6a7f58aa9f56d73f74a48ac42f6Mindy Pereira
19c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yangimport android.content.ContentResolver;
200d0f8b061faae060529af4da339eed2d728ef1bdScott Kennedyimport android.content.ContentValues;
2133fe908589dca6a7f58aa9f56d73f74a48ac42f6Mindy Pereiraimport android.database.Cursor;
22d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedyimport android.database.MatrixCursor;
23cfb7f33ff8ef9dc60b9143af32de64c7a3d71f36Mindy Pereiraimport android.net.Uri;
2433fe908589dca6a7f58aa9f56d73f74a48ac42f6Mindy Pereiraimport android.os.Parcel;
251ddcf0f2bf44d3c9db89112ef52510d9b2433ac4Vikram Aggarwalimport android.os.Parcelable;
26518ee42d4f5cfbcac07dc61fdcac4de8c32c0e26Mindy Pereiraimport android.text.TextUtils;
27518ee42d4f5cfbcac07dc61fdcac4de8c32c0e26Mindy Pereira
28177097fad8fc26b8a215f9f1af6dd5fd2c8eb06cVikram Aggarwalimport com.android.mail.content.CursorCreator;
29177097fad8fc26b8a215f9f1af6dd5fd2c8eb06cVikram Aggarwalimport com.android.mail.content.ObjectCursor;
301617481de7c1f9b8dfcd25ba9828e933cf9d5490Andy Huangimport com.android.mail.providers.UIProvider.AccountCapabilities;
31d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedyimport com.android.mail.providers.UIProvider.AccountColumns;
32b287833c2645e2502792821e54d7226cfad59955Marc Blankimport com.android.mail.providers.UIProvider.SyncStatus;
33b334c9035e9b7a38766bb66c29da2208525d1e11Paul Westbrookimport com.android.mail.utils.LogTag;
34b287833c2645e2502792821e54d7226cfad59955Marc Blankimport com.android.mail.utils.LogUtils;
35b287833c2645e2502792821e54d7226cfad59955Marc Blankimport com.android.mail.utils.Utils;
36db8f2f9ad5dcb1d52c399520129d89b1ca38f423Paul Westbrookimport com.google.common.base.Objects;
371617481de7c1f9b8dfcd25ba9828e933cf9d5490Andy Huangimport com.google.common.collect.Lists;
3833fe908589dca6a7f58aa9f56d73f74a48ac42f6Mindy Pereira
391617481de7c1f9b8dfcd25ba9828e933cf9d5490Andy Huangimport org.json.JSONArray;
406dde178687e85aaab9b3f8e9c124c3ab99b77d5aVikram Aggarwalimport org.json.JSONException;
416dde178687e85aaab9b3f8e9c124c3ab99b77d5aVikram Aggarwalimport org.json.JSONObject;
426dde178687e85aaab9b3f8e9c124c3ab99b77d5aVikram Aggarwal
43d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedyimport java.util.HashMap;
441617481de7c1f9b8dfcd25ba9828e933cf9d5490Andy Huangimport java.util.List;
45d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedyimport java.util.Map;
461617481de7c1f9b8dfcd25ba9828e933cf9d5490Andy Huang
473e16687b074895bc6cc63a1ed93abf7033586fd2Tony Mantlerpublic class Account implements Parcelable {
48b1f573c59ec20f9149443e1e0cc8b64ff3a07feaPaul Westbrook    private static final String SETTINGS_KEY = "settings";
49b1f573c59ec20f9149443e1e0cc8b64ff3a07feaPaul Westbrook
5033fe908589dca6a7f58aa9f56d73f74a48ac42f6Mindy Pereira    /**
513e16687b074895bc6cc63a1ed93abf7033586fd2Tony Mantler     * Human readable account name. Not guaranteed to be the account's email address, nor to match
523e16687b074895bc6cc63a1ed93abf7033586fd2Tony Mantler     * the system account manager.
533e16687b074895bc6cc63a1ed93abf7033586fd2Tony Mantler     */
5479b1156803585952a4851221dc9fa9974e606433Tony Mantler    // TODO: Make this private and add getDisplayName() accessor
553e16687b074895bc6cc63a1ed93abf7033586fd2Tony Mantler    public final String name;
563e16687b074895bc6cc63a1ed93abf7033586fd2Tony Mantler
573e16687b074895bc6cc63a1ed93abf7033586fd2Tony Mantler    /**
58bb036ff794f022bba2f501e155ef9c412e0e452eTony Mantler     * The real name associated with the account, e.g. "John Doe"
59bb036ff794f022bba2f501e155ef9c412e0e452eTony Mantler     */
60bb036ff794f022bba2f501e155ef9c412e0e452eTony Mantler    private final String senderName;
61bb036ff794f022bba2f501e155ef9c412e0e452eTony Mantler
62bb036ff794f022bba2f501e155ef9c412e0e452eTony Mantler    /**
633e16687b074895bc6cc63a1ed93abf7033586fd2Tony Mantler     * Account manager name. MUST MATCH SYSTEM ACCOUNT MANAGER NAME
643e16687b074895bc6cc63a1ed93abf7033586fd2Tony Mantler     */
653e16687b074895bc6cc63a1ed93abf7033586fd2Tony Mantler
663e16687b074895bc6cc63a1ed93abf7033586fd2Tony Mantler    private final String accountManagerName;
673e16687b074895bc6cc63a1ed93abf7033586fd2Tony Mantler
683e16687b074895bc6cc63a1ed93abf7033586fd2Tony Mantler    /**
693e16687b074895bc6cc63a1ed93abf7033586fd2Tony Mantler     * Account type. MUST MATCH SYSTEM ACCOUNT MANAGER TYPE
703e16687b074895bc6cc63a1ed93abf7033586fd2Tony Mantler     */
713e16687b074895bc6cc63a1ed93abf7033586fd2Tony Mantler
723e16687b074895bc6cc63a1ed93abf7033586fd2Tony Mantler    private final String type;
733e16687b074895bc6cc63a1ed93abf7033586fd2Tony Mantler
743e16687b074895bc6cc63a1ed93abf7033586fd2Tony Mantler    /**
75b90a813b107d8f43236e2d3fe12f299d94c82ce8Tony Mantler     * Cached android.accounts.Account based on the above two values
76b90a813b107d8f43236e2d3fe12f299d94c82ce8Tony Mantler     */
77b90a813b107d8f43236e2d3fe12f299d94c82ce8Tony Mantler
78b90a813b107d8f43236e2d3fe12f299d94c82ce8Tony Mantler    private android.accounts.Account amAccount;
79b90a813b107d8f43236e2d3fe12f299d94c82ce8Tony Mantler
80b90a813b107d8f43236e2d3fe12f299d94c82ce8Tony Mantler    /**
8133fe908589dca6a7f58aa9f56d73f74a48ac42f6Mindy Pereira     * The version of the UI provider schema from which this account provider
8233fe908589dca6a7f58aa9f56d73f74a48ac42f6Mindy Pereira     * will return results.
8333fe908589dca6a7f58aa9f56d73f74a48ac42f6Mindy Pereira     */
842861b6a649090ce1401b4bb04dd87df5bb26472bPaul Westbrook    public final int providerVersion;
8533fe908589dca6a7f58aa9f56d73f74a48ac42f6Mindy Pereira
8633fe908589dca6a7f58aa9f56d73f74a48ac42f6Mindy Pereira    /**
8733fe908589dca6a7f58aa9f56d73f74a48ac42f6Mindy Pereira     * The uri to directly access the information for this account.
8833fe908589dca6a7f58aa9f56d73f74a48ac42f6Mindy Pereira     */
89cfb7f33ff8ef9dc60b9143af32de64c7a3d71f36Mindy Pereira    public final Uri uri;
9033fe908589dca6a7f58aa9f56d73f74a48ac42f6Mindy Pereira
9133fe908589dca6a7f58aa9f56d73f74a48ac42f6Mindy Pereira    /**
9233fe908589dca6a7f58aa9f56d73f74a48ac42f6Mindy Pereira     * The possible capabilities that this account supports.
9333fe908589dca6a7f58aa9f56d73f74a48ac42f6Mindy Pereira     */
942861b6a649090ce1401b4bb04dd87df5bb26472bPaul Westbrook    public final int capabilities;
9533fe908589dca6a7f58aa9f56d73f74a48ac42f6Mindy Pereira
9633fe908589dca6a7f58aa9f56d73f74a48ac42f6Mindy Pereira    /**
9733fe908589dca6a7f58aa9f56d73f74a48ac42f6Mindy Pereira     * The content provider uri to return the list of top level folders for this
9833fe908589dca6a7f58aa9f56d73f74a48ac42f6Mindy Pereira     * account.
9933fe908589dca6a7f58aa9f56d73f74a48ac42f6Mindy Pereira     */
100cfb7f33ff8ef9dc60b9143af32de64c7a3d71f36Mindy Pereira    public final Uri folderListUri;
10131d7967c857d7486f27329135dffb3a2977b54e2Mindy Pereira    /**
102009f1b55b555638fd7276f8b996243a5d4ba7681Tony Mantler     * The content provider uri to return the list of all real folders for this
10331d7967c857d7486f27329135dffb3a2977b54e2Mindy Pereira     * account.
10431d7967c857d7486f27329135dffb3a2977b54e2Mindy Pereira     */
10531d7967c857d7486f27329135dffb3a2977b54e2Mindy Pereira    public Uri fullFolderListUri;
10633fe908589dca6a7f58aa9f56d73f74a48ac42f6Mindy Pereira    /**
107009f1b55b555638fd7276f8b996243a5d4ba7681Tony Mantler     * The content provider uri to return the list of all real and synthetic folders for this
108009f1b55b555638fd7276f8b996243a5d4ba7681Tony Mantler     * account.
109009f1b55b555638fd7276f8b996243a5d4ba7681Tony Mantler     */
110009f1b55b555638fd7276f8b996243a5d4ba7681Tony Mantler    public Uri allFolderListUri;
111009f1b55b555638fd7276f8b996243a5d4ba7681Tony Mantler    /**
11233fe908589dca6a7f58aa9f56d73f74a48ac42f6Mindy Pereira     * The content provider uri that can be queried for search results.
11333fe908589dca6a7f58aa9f56d73f74a48ac42f6Mindy Pereira     */
114cfb7f33ff8ef9dc60b9143af32de64c7a3d71f36Mindy Pereira    public final Uri searchUri;
11533fe908589dca6a7f58aa9f56d73f74a48ac42f6Mindy Pereira
11633fe908589dca6a7f58aa9f56d73f74a48ac42f6Mindy Pereira    /**
11792551d057965689f1952faeb06763f0762bc717fMindy Pereira     * The custom from addresses for this account or null if there are none.
11833fe908589dca6a7f58aa9f56d73f74a48ac42f6Mindy Pereira     */
1191883b346928322a9f045bc5b7426ddcd6af9beb3Mindy Pereira    public String accountFromAddresses;
12033fe908589dca6a7f58aa9f56d73f74a48ac42f6Mindy Pereira
12133fe908589dca6a7f58aa9f56d73f74a48ac42f6Mindy Pereira    /**
12282cc5665cb18801022cd60cd52abcd16a50debdcMindy Pereira     * The content provider uri that can be used to expunge message from this
12382cc5665cb18801022cd60cd52abcd16a50debdcMindy Pereira     * account. NOTE: This might be better to be an update operation on the
12482cc5665cb18801022cd60cd52abcd16a50debdcMindy Pereira     * messageUri.
12582cc5665cb18801022cd60cd52abcd16a50debdcMindy Pereira     */
126cfb7f33ff8ef9dc60b9143af32de64c7a3d71f36Mindy Pereira    public final Uri expungeMessageUri;
12782cc5665cb18801022cd60cd52abcd16a50debdcMindy Pereira
12896b5c357860f46a7bd5f867774a53d5cc5069defMindy Pereira    /**
12996b5c357860f46a7bd5f867774a53d5cc5069defMindy Pereira     * The content provider uri that can be used to undo the last operation
13096b5c357860f46a7bd5f867774a53d5cc5069defMindy Pereira     * performed.
13196b5c357860f46a7bd5f867774a53d5cc5069defMindy Pereira     */
132cfb7f33ff8ef9dc60b9143af32de64c7a3d71f36Mindy Pereira    public final Uri undoUri;
13396b5c357860f46a7bd5f867774a53d5cc5069defMindy Pereira
1349600dac67c5b3844b3a43a229bf3c309d84f978cMindy Pereira    /**
1359912eee82731d0cbf2c6cf35e62c8388c2a9ee79Paul Westbrook     * Uri for EDIT intent that will cause the settings screens for this account type to be
1362861b6a649090ce1401b4bb04dd87df5bb26472bPaul Westbrook     * shown.
1372861b6a649090ce1401b4bb04dd87df5bb26472bPaul Westbrook     */
138dac00547ce8d44a964e4510315168ee413e55a75Mindy Pereira    public final Uri settingsIntentUri;
1399600dac67c5b3844b3a43a229bf3c309d84f978cMindy Pereira
1409ace18a77e1c61700291f6116bb8162c8fce1fadMarc Blank    /**
14194e440d7fb9bb54ba4b22e348a2e22f3cf8e0167Paul Westbrook     * Uri for VIEW intent that will cause the help screens for this account type to be
14294e440d7fb9bb54ba4b22e348a2e22f3cf8e0167Paul Westbrook     * shown.
14394e440d7fb9bb54ba4b22e348a2e22f3cf8e0167Paul Westbrook     */
144cfb7f33ff8ef9dc60b9143af32de64c7a3d71f36Mindy Pereira    public final Uri helpIntentUri;
14594e440d7fb9bb54ba4b22e348a2e22f3cf8e0167Paul Westbrook
14694e440d7fb9bb54ba4b22e348a2e22f3cf8e0167Paul Westbrook    /**
147517743ef4e3e4ac103a3c096b9e3c894da7ed87aPaul Westbrook     * Uri for VIEW intent that will cause the send feedback screens for this account type to be
148517743ef4e3e4ac103a3c096b9e3c894da7ed87aPaul Westbrook     * shown.
149517743ef4e3e4ac103a3c096b9e3c894da7ed87aPaul Westbrook     */
150517743ef4e3e4ac103a3c096b9e3c894da7ed87aPaul Westbrook    public final Uri sendFeedbackIntentUri;
151517743ef4e3e4ac103a3c096b9e3c894da7ed87aPaul Westbrook
152517743ef4e3e4ac103a3c096b9e3c894da7ed87aPaul Westbrook    /**
153122f7c2cf45cd5f07462a7b0a553f82828a8b1a2Paul Westbrook     * Uri for VIEW intent that will cause the reauthentication screen for this account to be
154122f7c2cf45cd5f07462a7b0a553f82828a8b1a2Paul Westbrook     * shown.
155122f7c2cf45cd5f07462a7b0a553f82828a8b1a2Paul Westbrook     */
156122f7c2cf45cd5f07462a7b0a553f82828a8b1a2Paul Westbrook    public final Uri reauthenticationIntentUri;
157122f7c2cf45cd5f07462a7b0a553f82828a8b1a2Paul Westbrook
158122f7c2cf45cd5f07462a7b0a553f82828a8b1a2Paul Westbrook    /**
1599ace18a77e1c61700291f6116bb8162c8fce1fadMarc Blank     * The sync status of the account
1609ace18a77e1c61700291f6116bb8162c8fce1fadMarc Blank     */
1619ace18a77e1c61700291f6116bb8162c8fce1fadMarc Blank    public final int syncStatus;
1629ace18a77e1c61700291f6116bb8162c8fce1fadMarc Blank
163518ee42d4f5cfbcac07dc61fdcac4de8c32c0e26Mindy Pereira    /**
16423755e2109c3f97e3b51857e4a81355b1a3995a7Mindy Pereira     * Uri for VIEW intent that will cause the compose screen for this account type to be
16523755e2109c3f97e3b51857e4a81355b1a3995a7Mindy Pereira     * shown.
16623755e2109c3f97e3b51857e4a81355b1a3995a7Mindy Pereira     */
167cfb7f33ff8ef9dc60b9143af32de64c7a3d71f36Mindy Pereira    public final Uri composeIntentUri;
16823755e2109c3f97e3b51857e4a81355b1a3995a7Mindy Pereira
169898cd38018ff4331e79262451f464efa9dc5d43eMindy Pereira    public final String mimeType;
17023755e2109c3f97e3b51857e4a81355b1a3995a7Mindy Pereira    /**
17130fd47bf1947da5ad813cb957b6cbe569dce563aMindy Pereira     * URI for recent folders for this account.
17227e85f244604c8de53b76b135e0dd6f2bf3cad96Vikram Aggarwal     */
17327e85f244604c8de53b76b135e0dd6f2bf3cad96Vikram Aggarwal    public final Uri recentFolderListUri;
174b287833c2645e2502792821e54d7226cfad59955Marc Blank    /**
175b287833c2645e2502792821e54d7226cfad59955Marc Blank     * The color used for this account in combined view (Email)
176b287833c2645e2502792821e54d7226cfad59955Marc Blank     */
177b287833c2645e2502792821e54d7226cfad59955Marc Blank    public final int color;
17827d89ada3e8d1b17357a7064e1f47f3c15686412Vikram Aggarwal    /**
17927d89ada3e8d1b17357a7064e1f47f3c15686412Vikram Aggarwal     * URI for default recent folders for this account, if any.
18027d89ada3e8d1b17357a7064e1f47f3c15686412Vikram Aggarwal     */
18127d89ada3e8d1b17357a7064e1f47f3c15686412Vikram Aggarwal    public final Uri defaultRecentFolderListUri;
182b1f573c59ec20f9149443e1e0cc8b64ff3a07feaPaul Westbrook    /**
183b1f573c59ec20f9149443e1e0cc8b64ff3a07feaPaul Westbrook     * Settings object for this account.
184b1f573c59ec20f9149443e1e0cc8b64ff3a07feaPaul Westbrook     */
185b1f573c59ec20f9149443e1e0cc8b64ff3a07feaPaul Westbrook    public final Settings settings;
186b1f573c59ec20f9149443e1e0cc8b64ff3a07feaPaul Westbrook
187b378d64bab3c7517794ad7e2aee1d06c074e99eeMindy Pereira    /**
188b378d64bab3c7517794ad7e2aee1d06c074e99eeMindy Pereira     * URI for forcing a manual sync of this account.
189b378d64bab3c7517794ad7e2aee1d06c074e99eeMindy Pereira     */
190b378d64bab3c7517794ad7e2aee1d06c074e99eeMindy Pereira    public final Uri manualSyncUri;
191b378d64bab3c7517794ad7e2aee1d06c074e99eeMindy Pereira
1921617481de7c1f9b8dfcd25ba9828e933cf9d5490Andy Huang    /**
1939982fdb413d09b8e391dbc96a114987b1b87bb62Mark Wei     * URI for account type specific supplementary account info on outgoing links, if any.
1949982fdb413d09b8e391dbc96a114987b1b87bb62Mark Wei     */
1959982fdb413d09b8e391dbc96a114987b1b87bb62Mark Wei    public final Uri viewIntentProxyUri;
1969982fdb413d09b8e391dbc96a114987b1b87bb62Mark Wei
1979982fdb413d09b8e391dbc96a114987b1b87bb62Mark Wei    /**
198b8361c9f8938b74977316319885998aae09aab77Paul Westbrook     * URI for querying for the account cookies to be used when displaying inline content in a
199b8361c9f8938b74977316319885998aae09aab77Paul Westbrook     * conversation
200b8361c9f8938b74977316319885998aae09aab77Paul Westbrook     */
201b8361c9f8938b74977316319885998aae09aab77Paul Westbrook    public final Uri accoutCookieQueryUri;
202b8361c9f8938b74977316319885998aae09aab77Paul Westbrook
203b8361c9f8938b74977316319885998aae09aab77Paul Westbrook    /**
2040d0f8b061faae060529af4da339eed2d728ef1bdScott Kennedy     * URI to be used with an update() ContentResolver call with a {@link ContentValues} object
2050d0f8b061faae060529af4da339eed2d728ef1bdScott Kennedy     * where the keys are from the {@link AccountColumns.SettingsColumns}, and the values are the
2060d0f8b061faae060529af4da339eed2d728ef1bdScott Kennedy     * new values.
2070d0f8b061faae060529af4da339eed2d728ef1bdScott Kennedy     */
2080d0f8b061faae060529af4da339eed2d728ef1bdScott Kennedy    public final Uri updateSettingsUri;
2090d0f8b061faae060529af4da339eed2d728ef1bdScott Kennedy
2100d0f8b061faae060529af4da339eed2d728ef1bdScott Kennedy    /**
2113617b41394337774fb2e6fcf9fef1ac9eca00482Alice Yang     * Whether message transforms (HTML DOM manipulation) feature is enabled.
2123617b41394337774fb2e6fcf9fef1ac9eca00482Alice Yang     */
2133617b41394337774fb2e6fcf9fef1ac9eca00482Alice Yang    public final int enableMessageTransforms;
214c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang
215c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang    /**
216c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang     * Sync authority used by the mail app.  This can be used in
217c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang     * {@link ContentResolver#getSyncAutomatically} calls to check for whether sync is enabled
218c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang     * for this account and mail app.
219c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang     */
220c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang    public final String syncAuthority;
221c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang
22259e69095bd558a1e6ae890ce79b7b848331d0cc6Tony Mantler    public final Uri quickResponseUri;
22359e69095bd558a1e6ae890ce79b7b848331d0cc6Tony Mantler
2243617b41394337774fb2e6fcf9fef1ac9eca00482Alice Yang    /**
2251617481de7c1f9b8dfcd25ba9828e933cf9d5490Andy Huang     * Transient cache of parsed {@link #accountFromAddresses}, plus an entry for the main account
2261617481de7c1f9b8dfcd25ba9828e933cf9d5490Andy Huang     * address.
2271617481de7c1f9b8dfcd25ba9828e933cf9d5490Andy Huang     */
2281617481de7c1f9b8dfcd25ba9828e933cf9d5490Andy Huang    private transient List<ReplyFromAccount> mReplyFroms;
2291617481de7c1f9b8dfcd25ba9828e933cf9d5490Andy Huang
230b334c9035e9b7a38766bb66c29da2208525d1e11Paul Westbrook    private static final String LOG_TAG = LogTag.getLogTag();
2316dde178687e85aaab9b3f8e9c124c3ab99b77d5aVikram Aggarwal
23227e85f244604c8de53b76b135e0dd6f2bf3cad96Vikram Aggarwal    /**
233b1f573c59ec20f9149443e1e0cc8b64ff3a07feaPaul Westbrook     * Return a serialized String for this account.
234518ee42d4f5cfbcac07dc61fdcac4de8c32c0e26Mindy Pereira     */
2356dde178687e85aaab9b3f8e9c124c3ab99b77d5aVikram Aggarwal    public synchronized String serialize() {
2366dde178687e85aaab9b3f8e9c124c3ab99b77d5aVikram Aggarwal        JSONObject json = new JSONObject();
2376dde178687e85aaab9b3f8e9c124c3ab99b77d5aVikram Aggarwal        try {
23859e69095bd558a1e6ae890ce79b7b848331d0cc6Tony Mantler            json.put(AccountColumns.NAME, name);
23959e69095bd558a1e6ae890ce79b7b848331d0cc6Tony Mantler            json.put(AccountColumns.TYPE, type);
240bb036ff794f022bba2f501e155ef9c412e0e452eTony Mantler            json.put(AccountColumns.SENDER_NAME, senderName);
2413e16687b074895bc6cc63a1ed93abf7033586fd2Tony Mantler            json.put(AccountColumns.ACCOUNT_MANAGER_NAME, accountManagerName);
24259e69095bd558a1e6ae890ce79b7b848331d0cc6Tony Mantler            json.put(AccountColumns.PROVIDER_VERSION, providerVersion);
24359e69095bd558a1e6ae890ce79b7b848331d0cc6Tony Mantler            json.put(AccountColumns.URI, uri);
24459e69095bd558a1e6ae890ce79b7b848331d0cc6Tony Mantler            json.put(AccountColumns.CAPABILITIES, capabilities);
24559e69095bd558a1e6ae890ce79b7b848331d0cc6Tony Mantler            json.put(AccountColumns.FOLDER_LIST_URI, folderListUri);
24659e69095bd558a1e6ae890ce79b7b848331d0cc6Tony Mantler            json.put(AccountColumns.FULL_FOLDER_LIST_URI, fullFolderListUri);
247009f1b55b555638fd7276f8b996243a5d4ba7681Tony Mantler            json.put(AccountColumns.ALL_FOLDER_LIST_URI, allFolderListUri);
24859e69095bd558a1e6ae890ce79b7b848331d0cc6Tony Mantler            json.put(AccountColumns.SEARCH_URI, searchUri);
24959e69095bd558a1e6ae890ce79b7b848331d0cc6Tony Mantler            json.put(AccountColumns.ACCOUNT_FROM_ADDRESSES, accountFromAddresses);
25059e69095bd558a1e6ae890ce79b7b848331d0cc6Tony Mantler            json.put(AccountColumns.EXPUNGE_MESSAGE_URI, expungeMessageUri);
25159e69095bd558a1e6ae890ce79b7b848331d0cc6Tony Mantler            json.put(AccountColumns.UNDO_URI, undoUri);
25259e69095bd558a1e6ae890ce79b7b848331d0cc6Tony Mantler            json.put(AccountColumns.SETTINGS_INTENT_URI, settingsIntentUri);
25359e69095bd558a1e6ae890ce79b7b848331d0cc6Tony Mantler            json.put(AccountColumns.HELP_INTENT_URI, helpIntentUri);
25459e69095bd558a1e6ae890ce79b7b848331d0cc6Tony Mantler            json.put(AccountColumns.SEND_FEEDBACK_INTENT_URI, sendFeedbackIntentUri);
25559e69095bd558a1e6ae890ce79b7b848331d0cc6Tony Mantler            json.put(AccountColumns.REAUTHENTICATION_INTENT_URI, reauthenticationIntentUri);
25659e69095bd558a1e6ae890ce79b7b848331d0cc6Tony Mantler            json.put(AccountColumns.SYNC_STATUS, syncStatus);
25759e69095bd558a1e6ae890ce79b7b848331d0cc6Tony Mantler            json.put(AccountColumns.COMPOSE_URI, composeIntentUri);
25859e69095bd558a1e6ae890ce79b7b848331d0cc6Tony Mantler            json.put(AccountColumns.MIME_TYPE, mimeType);
25959e69095bd558a1e6ae890ce79b7b848331d0cc6Tony Mantler            json.put(AccountColumns.RECENT_FOLDER_LIST_URI, recentFolderListUri);
26059e69095bd558a1e6ae890ce79b7b848331d0cc6Tony Mantler            json.put(AccountColumns.COLOR, color);
26159e69095bd558a1e6ae890ce79b7b848331d0cc6Tony Mantler            json.put(AccountColumns.DEFAULT_RECENT_FOLDER_LIST_URI, defaultRecentFolderListUri);
26259e69095bd558a1e6ae890ce79b7b848331d0cc6Tony Mantler            json.put(AccountColumns.MANUAL_SYNC_URI, manualSyncUri);
26359e69095bd558a1e6ae890ce79b7b848331d0cc6Tony Mantler            json.put(AccountColumns.VIEW_INTENT_PROXY_URI, viewIntentProxyUri);
26459e69095bd558a1e6ae890ce79b7b848331d0cc6Tony Mantler            json.put(AccountColumns.ACCOUNT_COOKIE_QUERY_URI, accoutCookieQueryUri);
26559e69095bd558a1e6ae890ce79b7b848331d0cc6Tony Mantler            json.put(AccountColumns.UPDATE_SETTINGS_URI, updateSettingsUri);
26659e69095bd558a1e6ae890ce79b7b848331d0cc6Tony Mantler            json.put(AccountColumns.ENABLE_MESSAGE_TRANSFORMS, enableMessageTransforms);
26759e69095bd558a1e6ae890ce79b7b848331d0cc6Tony Mantler            json.put(AccountColumns.SYNC_AUTHORITY, syncAuthority);
26859e69095bd558a1e6ae890ce79b7b848331d0cc6Tony Mantler            json.put(AccountColumns.QUICK_RESPONSE_URI, quickResponseUri);
269b1f573c59ec20f9149443e1e0cc8b64ff3a07feaPaul Westbrook            if (settings != null) {
270b1f573c59ec20f9149443e1e0cc8b64ff3a07feaPaul Westbrook                json.put(SETTINGS_KEY, settings.toJSON());
271b1f573c59ec20f9149443e1e0cc8b64ff3a07feaPaul Westbrook            }
2726dde178687e85aaab9b3f8e9c124c3ab99b77d5aVikram Aggarwal        } catch (JSONException e) {
273b1f573c59ec20f9149443e1e0cc8b64ff3a07feaPaul Westbrook            LogUtils.wtf(LOG_TAG, e, "Could not serialize account with name %s", name);
2746dde178687e85aaab9b3f8e9c124c3ab99b77d5aVikram Aggarwal        }
2756dde178687e85aaab9b3f8e9c124c3ab99b77d5aVikram Aggarwal        return json.toString();
2766dde178687e85aaab9b3f8e9c124c3ab99b77d5aVikram Aggarwal    }
277518ee42d4f5cfbcac07dc61fdcac4de8c32c0e26Mindy Pereira
278518ee42d4f5cfbcac07dc61fdcac4de8c32c0e26Mindy Pereira    /**
2796dde178687e85aaab9b3f8e9c124c3ab99b77d5aVikram Aggarwal     * Create a new instance of an Account object using a serialized instance created previously
2806dde178687e85aaab9b3f8e9c124c3ab99b77d5aVikram Aggarwal     * using {@link #serialize()}. This returns null if the serialized instance was invalid or does
2816dde178687e85aaab9b3f8e9c124c3ab99b77d5aVikram Aggarwal     * not represent a valid account object.
282518ee42d4f5cfbcac07dc61fdcac4de8c32c0e26Mindy Pereira     *
283a4836711cf7909575bfb25720232c22c201efd06Tony Mantler     * @param serializedAccount JSON encoded account object
284a4836711cf7909575bfb25720232c22c201efd06Tony Mantler     * @return Account object
285518ee42d4f5cfbcac07dc61fdcac4de8c32c0e26Mindy Pereira     */
2866dde178687e85aaab9b3f8e9c124c3ab99b77d5aVikram Aggarwal    public static Account newinstance(String serializedAccount) {
2876dde178687e85aaab9b3f8e9c124c3ab99b77d5aVikram Aggarwal        // The heavy lifting is done by Account(name, type, serializedAccount). This method
2886dde178687e85aaab9b3f8e9c124c3ab99b77d5aVikram Aggarwal        // is a wrapper to check for errors and exceptions and return back a null in cases
2896dde178687e85aaab9b3f8e9c124c3ab99b77d5aVikram Aggarwal        // something breaks.
290a4836711cf7909575bfb25720232c22c201efd06Tony Mantler        JSONObject json;
2916dde178687e85aaab9b3f8e9c124c3ab99b77d5aVikram Aggarwal        try {
2926dde178687e85aaab9b3f8e9c124c3ab99b77d5aVikram Aggarwal            json = new JSONObject(serializedAccount);
2936dde178687e85aaab9b3f8e9c124c3ab99b77d5aVikram Aggarwal            final String name = (String) json.get(UIProvider.AccountColumns.NAME);
2946dde178687e85aaab9b3f8e9c124c3ab99b77d5aVikram Aggarwal            final String type = (String) json.get(UIProvider.AccountColumns.TYPE);
2956dde178687e85aaab9b3f8e9c124c3ab99b77d5aVikram Aggarwal            return new Account(name, type, serializedAccount);
2966dde178687e85aaab9b3f8e9c124c3ab99b77d5aVikram Aggarwal        } catch (JSONException e) {
2975ee9dc48884714e9005a1409e7002a0e04bad313mindyp            LogUtils.w(LOG_TAG, e, "Could not create an account from this input: \"%s\"",
298b1f573c59ec20f9149443e1e0cc8b64ff3a07feaPaul Westbrook                    serializedAccount);
2996dde178687e85aaab9b3f8e9c124c3ab99b77d5aVikram Aggarwal            return null;
3006dde178687e85aaab9b3f8e9c124c3ab99b77d5aVikram Aggarwal        }
3016dde178687e85aaab9b3f8e9c124c3ab99b77d5aVikram Aggarwal    }
302518ee42d4f5cfbcac07dc61fdcac4de8c32c0e26Mindy Pereira
303518ee42d4f5cfbcac07dc61fdcac4de8c32c0e26Mindy Pereira    /**
3046dde178687e85aaab9b3f8e9c124c3ab99b77d5aVikram Aggarwal     * Construct a new Account instance from a previously serialized string. This calls
3056dde178687e85aaab9b3f8e9c124c3ab99b77d5aVikram Aggarwal     * {@link android.accounts.Account#Account(String, String)} with name and type given as the
3066dde178687e85aaab9b3f8e9c124c3ab99b77d5aVikram Aggarwal     * first two arguments.
3076dde178687e85aaab9b3f8e9c124c3ab99b77d5aVikram Aggarwal     *
3086dde178687e85aaab9b3f8e9c124c3ab99b77d5aVikram Aggarwal     * <p>
3096dde178687e85aaab9b3f8e9c124c3ab99b77d5aVikram Aggarwal     * This is private. Public uses should go through the safe {@link #newinstance(String)} method.
3106dde178687e85aaab9b3f8e9c124c3ab99b77d5aVikram Aggarwal     * </p>
3113e16687b074895bc6cc63a1ed93abf7033586fd2Tony Mantler     * @param acctName name of account in {@link android.accounts.Account}
3123e16687b074895bc6cc63a1ed93abf7033586fd2Tony Mantler     * @param acctType type of account in {@link android.accounts.Account}
3136dde178687e85aaab9b3f8e9c124c3ab99b77d5aVikram Aggarwal     * @param jsonAccount string obtained from {@link #serialize()} on a valid account.
3146dde178687e85aaab9b3f8e9c124c3ab99b77d5aVikram Aggarwal     * @throws JSONException
315518ee42d4f5cfbcac07dc61fdcac4de8c32c0e26Mindy Pereira     */
3163e16687b074895bc6cc63a1ed93abf7033586fd2Tony Mantler    private Account(String acctName, String acctType, String jsonAccount) throws JSONException {
3173e16687b074895bc6cc63a1ed93abf7033586fd2Tony Mantler        name = acctName;
3183e16687b074895bc6cc63a1ed93abf7033586fd2Tony Mantler        type = acctType;
3196dde178687e85aaab9b3f8e9c124c3ab99b77d5aVikram Aggarwal        final JSONObject json = new JSONObject(jsonAccount);
320bb036ff794f022bba2f501e155ef9c412e0e452eTony Mantler        senderName = json.optString(AccountColumns.SENDER_NAME);
321389c3347fcd11ffe7aa16782389613acf28f951cTony Mantler        final String amName = json.optString(AccountColumns.ACCOUNT_MANAGER_NAME);
3223e16687b074895bc6cc63a1ed93abf7033586fd2Tony Mantler        // We need accountManagerName to be filled in, but we might be dealing with an old cache
3233e16687b074895bc6cc63a1ed93abf7033586fd2Tony Mantler        // entry which doesn't have it, so use the display name instead in that case as a fallback
3243e16687b074895bc6cc63a1ed93abf7033586fd2Tony Mantler        if (TextUtils.isEmpty(amName)) {
3253e16687b074895bc6cc63a1ed93abf7033586fd2Tony Mantler            accountManagerName = name;
3263e16687b074895bc6cc63a1ed93abf7033586fd2Tony Mantler        } else {
3273e16687b074895bc6cc63a1ed93abf7033586fd2Tony Mantler            accountManagerName = amName;
3283e16687b074895bc6cc63a1ed93abf7033586fd2Tony Mantler        }
329db77b36aa9bdda2ebadccc4188715563a95f9bf0Alice Yang        providerVersion = json.getInt(AccountColumns.PROVIDER_VERSION);
330db77b36aa9bdda2ebadccc4188715563a95f9bf0Alice Yang        uri = Uri.parse(json.optString(AccountColumns.URI));
331db77b36aa9bdda2ebadccc4188715563a95f9bf0Alice Yang        capabilities = json.getInt(AccountColumns.CAPABILITIES);
332b378d64bab3c7517794ad7e2aee1d06c074e99eeMindy Pereira        folderListUri = Utils
333db77b36aa9bdda2ebadccc4188715563a95f9bf0Alice Yang                .getValidUri(json.optString(AccountColumns.FOLDER_LIST_URI));
334b378d64bab3c7517794ad7e2aee1d06c074e99eeMindy Pereira        fullFolderListUri = Utils.getValidUri(json
335db77b36aa9bdda2ebadccc4188715563a95f9bf0Alice Yang                .optString(AccountColumns.FULL_FOLDER_LIST_URI));
336009f1b55b555638fd7276f8b996243a5d4ba7681Tony Mantler        allFolderListUri = Utils.getValidUri(json
337009f1b55b555638fd7276f8b996243a5d4ba7681Tony Mantler                .optString(AccountColumns.ALL_FOLDER_LIST_URI));
338db77b36aa9bdda2ebadccc4188715563a95f9bf0Alice Yang        searchUri = Utils.getValidUri(json.optString(AccountColumns.SEARCH_URI));
339db77b36aa9bdda2ebadccc4188715563a95f9bf0Alice Yang        accountFromAddresses = json.optString(AccountColumns.ACCOUNT_FROM_ADDRESSES,
340b37723f1d9d1a1b95a238fc05adbff2a3b1df88dmindyp                "");
341b378d64bab3c7517794ad7e2aee1d06c074e99eeMindy Pereira        expungeMessageUri = Utils.getValidUri(json
342db77b36aa9bdda2ebadccc4188715563a95f9bf0Alice Yang                .optString(AccountColumns.EXPUNGE_MESSAGE_URI));
343db77b36aa9bdda2ebadccc4188715563a95f9bf0Alice Yang        undoUri = Utils.getValidUri(json.optString(AccountColumns.UNDO_URI));
344b378d64bab3c7517794ad7e2aee1d06c074e99eeMindy Pereira        settingsIntentUri = Utils.getValidUri(json
345db77b36aa9bdda2ebadccc4188715563a95f9bf0Alice Yang                .optString(AccountColumns.SETTINGS_INTENT_URI));
346db77b36aa9bdda2ebadccc4188715563a95f9bf0Alice Yang        helpIntentUri = Utils.getValidUri(json.optString(AccountColumns.HELP_INTENT_URI));
347b378d64bab3c7517794ad7e2aee1d06c074e99eeMindy Pereira        sendFeedbackIntentUri = Utils.getValidUri(json
348db77b36aa9bdda2ebadccc4188715563a95f9bf0Alice Yang                .optString(AccountColumns.SEND_FEEDBACK_INTENT_URI));
349122f7c2cf45cd5f07462a7b0a553f82828a8b1a2Paul Westbrook        reauthenticationIntentUri = Utils.getValidUri(
350db77b36aa9bdda2ebadccc4188715563a95f9bf0Alice Yang                json.optString(AccountColumns.REAUTHENTICATION_INTENT_URI));
351db77b36aa9bdda2ebadccc4188715563a95f9bf0Alice Yang        syncStatus = json.optInt(AccountColumns.SYNC_STATUS);
352db77b36aa9bdda2ebadccc4188715563a95f9bf0Alice Yang        composeIntentUri = Utils.getValidUri(json.optString(AccountColumns.COMPOSE_URI));
353db77b36aa9bdda2ebadccc4188715563a95f9bf0Alice Yang        mimeType = json.optString(AccountColumns.MIME_TYPE);
354b378d64bab3c7517794ad7e2aee1d06c074e99eeMindy Pereira        recentFolderListUri = Utils.getValidUri(json
355db77b36aa9bdda2ebadccc4188715563a95f9bf0Alice Yang                .optString(AccountColumns.RECENT_FOLDER_LIST_URI));
356db77b36aa9bdda2ebadccc4188715563a95f9bf0Alice Yang        color = json.optInt(AccountColumns.COLOR, 0);
357b378d64bab3c7517794ad7e2aee1d06c074e99eeMindy Pereira        defaultRecentFolderListUri = Utils.getValidUri(json
358db77b36aa9bdda2ebadccc4188715563a95f9bf0Alice Yang                .optString(AccountColumns.DEFAULT_RECENT_FOLDER_LIST_URI));
359b378d64bab3c7517794ad7e2aee1d06c074e99eeMindy Pereira        manualSyncUri = Utils
360db77b36aa9bdda2ebadccc4188715563a95f9bf0Alice Yang                .getValidUri(json.optString(AccountColumns.MANUAL_SYNC_URI));
3619982fdb413d09b8e391dbc96a114987b1b87bb62Mark Wei        viewIntentProxyUri = Utils
362db77b36aa9bdda2ebadccc4188715563a95f9bf0Alice Yang                .getValidUri(json.optString(AccountColumns.VIEW_INTENT_PROXY_URI));
363b8361c9f8938b74977316319885998aae09aab77Paul Westbrook        accoutCookieQueryUri = Utils.getValidUri(
364db77b36aa9bdda2ebadccc4188715563a95f9bf0Alice Yang                json.optString(AccountColumns.ACCOUNT_COOKIE_QUERY_URI));
3650d0f8b061faae060529af4da339eed2d728ef1bdScott Kennedy        updateSettingsUri = Utils.getValidUri(
366db77b36aa9bdda2ebadccc4188715563a95f9bf0Alice Yang                json.optString(AccountColumns.UPDATE_SETTINGS_URI));
3673617b41394337774fb2e6fcf9fef1ac9eca00482Alice Yang        enableMessageTransforms = json.optInt(AccountColumns.ENABLE_MESSAGE_TRANSFORMS);
368c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang        syncAuthority = json.optString(AccountColumns.SYNC_AUTHORITY);
36959e69095bd558a1e6ae890ce79b7b848331d0cc6Tony Mantler        quickResponseUri = Utils.getValidUri(json.optString(AccountColumns.QUICK_RESPONSE_URI));
370b1f573c59ec20f9149443e1e0cc8b64ff3a07feaPaul Westbrook
37119e5908550fa9aac54be1647462b06be0e724440Paul Westbrook        final Settings jsonSettings = Settings.newInstance(json.optJSONObject(SETTINGS_KEY));
37219e5908550fa9aac54be1647462b06be0e724440Paul Westbrook        if (jsonSettings != null) {
37319e5908550fa9aac54be1647462b06be0e724440Paul Westbrook            settings = jsonSettings;
37419e5908550fa9aac54be1647462b06be0e724440Paul Westbrook        } else {
37519e5908550fa9aac54be1647462b06be0e724440Paul Westbrook            LogUtils.e(LOG_TAG, new Throwable(),
37619e5908550fa9aac54be1647462b06be0e724440Paul Westbrook                    "Unexpected null settings in Account(name, type, jsonAccount)");
37719e5908550fa9aac54be1647462b06be0e724440Paul Westbrook            settings = Settings.EMPTY_SETTINGS;
37819e5908550fa9aac54be1647462b06be0e724440Paul Westbrook        }
379518ee42d4f5cfbcac07dc61fdcac4de8c32c0e26Mindy Pereira    }
380518ee42d4f5cfbcac07dc61fdcac4de8c32c0e26Mindy Pereira
38133fe908589dca6a7f58aa9f56d73f74a48ac42f6Mindy Pereira    public Account(Cursor cursor) {
3823e16687b074895bc6cc63a1ed93abf7033586fd2Tony Mantler        name = cursor.getString(cursor.getColumnIndex(UIProvider.AccountColumns.NAME));
383bb036ff794f022bba2f501e155ef9c412e0e452eTony Mantler        senderName = cursor.getString(cursor.getColumnIndex(UIProvider.AccountColumns.SENDER_NAME));
3843e16687b074895bc6cc63a1ed93abf7033586fd2Tony Mantler        type = cursor.getString(cursor.getColumnIndex(UIProvider.AccountColumns.TYPE));
3853e16687b074895bc6cc63a1ed93abf7033586fd2Tony Mantler        accountManagerName = cursor.getString(
3863e16687b074895bc6cc63a1ed93abf7033586fd2Tony Mantler                cursor.getColumnIndex(UIProvider.AccountColumns.ACCOUNT_MANAGER_NAME));
387d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy        accountFromAddresses = cursor.getString(
388d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy                cursor.getColumnIndex(UIProvider.AccountColumns.ACCOUNT_FROM_ADDRESSES));
389d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy
390d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy        final int capabilitiesColumnIndex =
391d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy                cursor.getColumnIndex(UIProvider.AccountColumns.CAPABILITIES);
392d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy        if (capabilitiesColumnIndex != -1) {
393d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy            capabilities = cursor.getInt(capabilitiesColumnIndex);
394d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy        } else {
395d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy            capabilities = 0;
396d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy        }
397d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy
398d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy        providerVersion =
399d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy                cursor.getInt(cursor.getColumnIndex(UIProvider.AccountColumns.PROVIDER_VERSION));
400d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy        uri = Uri.parse(cursor.getString(cursor.getColumnIndex(UIProvider.AccountColumns.URI)));
401d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy        folderListUri = Uri.parse(
402d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy                cursor.getString(cursor.getColumnIndex(UIProvider.AccountColumns.FOLDER_LIST_URI)));
403d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy        fullFolderListUri = Utils.getValidUri(cursor.getString(
404d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy                cursor.getColumnIndex(UIProvider.AccountColumns.FULL_FOLDER_LIST_URI)));
405009f1b55b555638fd7276f8b996243a5d4ba7681Tony Mantler        allFolderListUri = Utils.getValidUri(cursor.getString(
406009f1b55b555638fd7276f8b996243a5d4ba7681Tony Mantler                cursor.getColumnIndex(UIProvider.AccountColumns.ALL_FOLDER_LIST_URI)));
407d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy        searchUri = Utils.getValidUri(
408d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy                cursor.getString(cursor.getColumnIndex(UIProvider.AccountColumns.SEARCH_URI)));
409d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy        expungeMessageUri = Utils.getValidUri(cursor.getString(
410d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy                cursor.getColumnIndex(UIProvider.AccountColumns.EXPUNGE_MESSAGE_URI)));
411d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy        undoUri = Utils.getValidUri(
412d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy                cursor.getString(cursor.getColumnIndex(UIProvider.AccountColumns.UNDO_URI)));
413d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy        settingsIntentUri = Utils.getValidUri(cursor.getString(
414d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy                cursor.getColumnIndex(UIProvider.AccountColumns.SETTINGS_INTENT_URI)));
415d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy        helpIntentUri = Utils.getValidUri(
416d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy                cursor.getString(cursor.getColumnIndex(UIProvider.AccountColumns.HELP_INTENT_URI)));
417d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy        sendFeedbackIntentUri = Utils.getValidUri(cursor.getString(
418d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy                cursor.getColumnIndex(UIProvider.AccountColumns.SEND_FEEDBACK_INTENT_URI)));
419d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy        reauthenticationIntentUri = Utils.getValidUri(cursor.getString(
420d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy                cursor.getColumnIndex(UIProvider.AccountColumns.REAUTHENTICATION_INTENT_URI)));
421d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy        syncStatus = cursor.getInt(cursor.getColumnIndex(UIProvider.AccountColumns.SYNC_STATUS));
422d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy        composeIntentUri = Utils.getValidUri(
423d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy                cursor.getString(cursor.getColumnIndex(UIProvider.AccountColumns.COMPOSE_URI)));
424d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy        mimeType = cursor.getString(cursor.getColumnIndex(UIProvider.AccountColumns.MIME_TYPE));
425d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy        recentFolderListUri = Utils.getValidUri(cursor.getString(
426d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy                cursor.getColumnIndex(UIProvider.AccountColumns.RECENT_FOLDER_LIST_URI)));
427d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy        color = cursor.getInt(cursor.getColumnIndex(UIProvider.AccountColumns.COLOR));
428d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy        defaultRecentFolderListUri = Utils.getValidUri(cursor.getString(
429d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy                cursor.getColumnIndex(UIProvider.AccountColumns.DEFAULT_RECENT_FOLDER_LIST_URI)));
430d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy        manualSyncUri = Utils.getValidUri(
431d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy                cursor.getString(cursor.getColumnIndex(UIProvider.AccountColumns.MANUAL_SYNC_URI)));
432d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy        viewIntentProxyUri = Utils.getValidUri(cursor.getString(
433d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy                cursor.getColumnIndex(UIProvider.AccountColumns.VIEW_INTENT_PROXY_URI)));
434d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy        accoutCookieQueryUri = Utils.getValidUri(cursor.getString(
435d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy                cursor.getColumnIndex(UIProvider.AccountColumns.ACCOUNT_COOKIE_QUERY_URI)));
436d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy        updateSettingsUri = Utils.getValidUri(cursor.getString(
437d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy                cursor.getColumnIndex(UIProvider.AccountColumns.UPDATE_SETTINGS_URI)));
4383617b41394337774fb2e6fcf9fef1ac9eca00482Alice Yang        enableMessageTransforms = cursor.getInt(
4393617b41394337774fb2e6fcf9fef1ac9eca00482Alice Yang                cursor.getColumnIndex(AccountColumns.ENABLE_MESSAGE_TRANSFORMS));
440c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang        syncAuthority = cursor.getString(
441c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang                cursor.getColumnIndex(AccountColumns.SYNC_AUTHORITY));
442db77b36aa9bdda2ebadccc4188715563a95f9bf0Alice Yang        if (TextUtils.isEmpty(syncAuthority)) {
443db77b36aa9bdda2ebadccc4188715563a95f9bf0Alice Yang            LogUtils.e(LOG_TAG, "Unexpected empty syncAuthority from cursor");
444db77b36aa9bdda2ebadccc4188715563a95f9bf0Alice Yang        }
44559e69095bd558a1e6ae890ce79b7b848331d0cc6Tony Mantler        quickResponseUri = Utils.getValidUri(cursor.getString(
44659e69095bd558a1e6ae890ce79b7b848331d0cc6Tony Mantler                cursor.getColumnIndex(AccountColumns.QUICK_RESPONSE_URI)));
447b1f573c59ec20f9149443e1e0cc8b64ff3a07feaPaul Westbrook        settings = new Settings(cursor);
44833fe908589dca6a7f58aa9f56d73f74a48ac42f6Mindy Pereira    }
44933fe908589dca6a7f58aa9f56d73f74a48ac42f6Mindy Pereira
450a9b93f35035dc4badd0ac40f4016e1ff809b26b0Vikram Aggarwal    /**
451aa8d291fea7b25c5d19ba2974a2b1a6d1b71dd8cVikram Aggarwal     * Returns an array of all Accounts located at this cursor. This method returns a zero length
452aa8d291fea7b25c5d19ba2974a2b1a6d1b71dd8cVikram Aggarwal     * array if no account was found.  This method does not close the cursor.
453a9b93f35035dc4badd0ac40f4016e1ff809b26b0Vikram Aggarwal     * @param cursor cursor pointing to the list of accounts
454a9b93f35035dc4badd0ac40f4016e1ff809b26b0Vikram Aggarwal     * @return the array of all accounts stored at this cursor.
455a9b93f35035dc4badd0ac40f4016e1ff809b26b0Vikram Aggarwal     */
456177097fad8fc26b8a215f9f1af6dd5fd2c8eb06cVikram Aggarwal    public static Account[] getAllAccounts(ObjectCursor<Account> cursor) {
457a9b93f35035dc4badd0ac40f4016e1ff809b26b0Vikram Aggarwal        final int initialLength = cursor.getCount();
458a9b93f35035dc4badd0ac40f4016e1ff809b26b0Vikram Aggarwal        if (initialLength <= 0 || !cursor.moveToFirst()) {
459a9b93f35035dc4badd0ac40f4016e1ff809b26b0Vikram Aggarwal            // Return zero length account array rather than null
460a9b93f35035dc4badd0ac40f4016e1ff809b26b0Vikram Aggarwal            return new Account[0];
461a9b93f35035dc4badd0ac40f4016e1ff809b26b0Vikram Aggarwal        }
462a9b93f35035dc4badd0ac40f4016e1ff809b26b0Vikram Aggarwal
463636c1a1bf144e28a8a1ab022dfcfba83c7b1ca1bVikram Aggarwal        final Account[] allAccounts = new Account[initialLength];
464aa8d291fea7b25c5d19ba2974a2b1a6d1b71dd8cVikram Aggarwal        int i = 0;
465aa8d291fea7b25c5d19ba2974a2b1a6d1b71dd8cVikram Aggarwal        do {
466177097fad8fc26b8a215f9f1af6dd5fd2c8eb06cVikram Aggarwal            allAccounts[i++] = cursor.getModel();
467aa8d291fea7b25c5d19ba2974a2b1a6d1b71dd8cVikram Aggarwal        } while (cursor.moveToNext());
468aa8d291fea7b25c5d19ba2974a2b1a6d1b71dd8cVikram Aggarwal        // Ensure that the length of the array is accurate
469aa8d291fea7b25c5d19ba2974a2b1a6d1b71dd8cVikram Aggarwal        assert (i == initialLength);
470a9b93f35035dc4badd0ac40f4016e1ff809b26b0Vikram Aggarwal        return allAccounts;
471a9b93f35035dc4badd0ac40f4016e1ff809b26b0Vikram Aggarwal    }
472a9b93f35035dc4badd0ac40f4016e1ff809b26b0Vikram Aggarwal
4733e16687b074895bc6cc63a1ed93abf7033586fd2Tony Mantler    public android.accounts.Account getAccountManagerAccount() {
474b90a813b107d8f43236e2d3fe12f299d94c82ce8Tony Mantler        if (amAccount == null) {
475b90a813b107d8f43236e2d3fe12f299d94c82ce8Tony Mantler            // We don't really need to synchronize this
476b90a813b107d8f43236e2d3fe12f299d94c82ce8Tony Mantler            // as worst case is we'd create an extra identical object and throw it away
477b90a813b107d8f43236e2d3fe12f299d94c82ce8Tony Mantler            amAccount = new android.accounts.Account(accountManagerName, type);
478b90a813b107d8f43236e2d3fe12f299d94c82ce8Tony Mantler        }
479b90a813b107d8f43236e2d3fe12f299d94c82ce8Tony Mantler        return amAccount;
4803e16687b074895bc6cc63a1ed93abf7033586fd2Tony Mantler    }
4813e16687b074895bc6cc63a1ed93abf7033586fd2Tony Mantler
482d92e9f3d45cfedd3ebfedcf0805283007053e091Mindy Pereira    public boolean supportsCapability(int capability) {
483d92e9f3d45cfedd3ebfedcf0805283007053e091Mindy Pereira        return (capabilities & capability) != 0;
484846488982a7a93f48ec36b616657fad10c62d8f5Mindy Pereira    }
485846488982a7a93f48ec36b616657fad10c62d8f5Mindy Pereira
486dfa1dec0cfdc263c51e971dc3c41b90386a24340Paul Westbrook    public boolean isAccountSyncRequired() {
487dfa1dec0cfdc263c51e971dc3c41b90386a24340Paul Westbrook        return (syncStatus & SyncStatus.INITIAL_SYNC_NEEDED) == SyncStatus.INITIAL_SYNC_NEEDED;
488dfa1dec0cfdc263c51e971dc3c41b90386a24340Paul Westbrook    }
489dfa1dec0cfdc263c51e971dc3c41b90386a24340Paul Westbrook
490dfa1dec0cfdc263c51e971dc3c41b90386a24340Paul Westbrook    public boolean isAccountInitializationRequired() {
491dfa1dec0cfdc263c51e971dc3c41b90386a24340Paul Westbrook        return (syncStatus & SyncStatus.ACCOUNT_INITIALIZATION_REQUIRED) ==
492dfa1dec0cfdc263c51e971dc3c41b90386a24340Paul Westbrook                SyncStatus.ACCOUNT_INITIALIZATION_REQUIRED;
493dfa1dec0cfdc263c51e971dc3c41b90386a24340Paul Westbrook    }
494dfa1dec0cfdc263c51e971dc3c41b90386a24340Paul Westbrook
495dfa1dec0cfdc263c51e971dc3c41b90386a24340Paul Westbrook    /**
496dfa1dec0cfdc263c51e971dc3c41b90386a24340Paul Westbrook     * Returns true when when the UI provider has indicated that the account has been initialized,
497dfa1dec0cfdc263c51e971dc3c41b90386a24340Paul Westbrook     * and sync is not required.
498dfa1dec0cfdc263c51e971dc3c41b90386a24340Paul Westbrook     */
499dfa1dec0cfdc263c51e971dc3c41b90386a24340Paul Westbrook    public boolean isAccountReady() {
500dfa1dec0cfdc263c51e971dc3c41b90386a24340Paul Westbrook        return !isAccountInitializationRequired() && !isAccountSyncRequired();
5012d50bcdca57756ecad20d21da0d936243215b79cPaul Westbrook    }
5022d50bcdca57756ecad20d21da0d936243215b79cPaul Westbrook
503db77b36aa9bdda2ebadccc4188715563a95f9bf0Alice Yang    public Account(Parcel in, ClassLoader loader) {
5043e16687b074895bc6cc63a1ed93abf7033586fd2Tony Mantler        name = in.readString();
505bb036ff794f022bba2f501e155ef9c412e0e452eTony Mantler        senderName = in.readString();
5063e16687b074895bc6cc63a1ed93abf7033586fd2Tony Mantler        type = in.readString();
5073e16687b074895bc6cc63a1ed93abf7033586fd2Tony Mantler        accountManagerName = in.readString();
508db77b36aa9bdda2ebadccc4188715563a95f9bf0Alice Yang        providerVersion = in.readInt();
509db77b36aa9bdda2ebadccc4188715563a95f9bf0Alice Yang        uri = in.readParcelable(null);
510db77b36aa9bdda2ebadccc4188715563a95f9bf0Alice Yang        capabilities = in.readInt();
511db77b36aa9bdda2ebadccc4188715563a95f9bf0Alice Yang        folderListUri = in.readParcelable(null);
512db77b36aa9bdda2ebadccc4188715563a95f9bf0Alice Yang        fullFolderListUri = in.readParcelable(null);
513009f1b55b555638fd7276f8b996243a5d4ba7681Tony Mantler        allFolderListUri = in.readParcelable(null);
514db77b36aa9bdda2ebadccc4188715563a95f9bf0Alice Yang        searchUri = in.readParcelable(null);
515db77b36aa9bdda2ebadccc4188715563a95f9bf0Alice Yang        accountFromAddresses = in.readString();
516db77b36aa9bdda2ebadccc4188715563a95f9bf0Alice Yang        expungeMessageUri = in.readParcelable(null);
517db77b36aa9bdda2ebadccc4188715563a95f9bf0Alice Yang        undoUri = in.readParcelable(null);
518db77b36aa9bdda2ebadccc4188715563a95f9bf0Alice Yang        settingsIntentUri = in.readParcelable(null);
519db77b36aa9bdda2ebadccc4188715563a95f9bf0Alice Yang        helpIntentUri = in.readParcelable(null);
520db77b36aa9bdda2ebadccc4188715563a95f9bf0Alice Yang        sendFeedbackIntentUri = in.readParcelable(null);
521db77b36aa9bdda2ebadccc4188715563a95f9bf0Alice Yang        reauthenticationIntentUri = in.readParcelable(null);
522db77b36aa9bdda2ebadccc4188715563a95f9bf0Alice Yang        syncStatus = in.readInt();
523db77b36aa9bdda2ebadccc4188715563a95f9bf0Alice Yang        composeIntentUri = in.readParcelable(null);
524db77b36aa9bdda2ebadccc4188715563a95f9bf0Alice Yang        mimeType = in.readString();
525db77b36aa9bdda2ebadccc4188715563a95f9bf0Alice Yang        recentFolderListUri = in.readParcelable(null);
526db77b36aa9bdda2ebadccc4188715563a95f9bf0Alice Yang        color = in.readInt();
527db77b36aa9bdda2ebadccc4188715563a95f9bf0Alice Yang        defaultRecentFolderListUri = in.readParcelable(null);
528db77b36aa9bdda2ebadccc4188715563a95f9bf0Alice Yang        manualSyncUri = in.readParcelable(null);
529db77b36aa9bdda2ebadccc4188715563a95f9bf0Alice Yang        viewIntentProxyUri = in.readParcelable(null);
530db77b36aa9bdda2ebadccc4188715563a95f9bf0Alice Yang        accoutCookieQueryUri = in.readParcelable(null);
531db77b36aa9bdda2ebadccc4188715563a95f9bf0Alice Yang        updateSettingsUri = in.readParcelable(null);
532db77b36aa9bdda2ebadccc4188715563a95f9bf0Alice Yang        enableMessageTransforms = in.readInt();
533db77b36aa9bdda2ebadccc4188715563a95f9bf0Alice Yang        syncAuthority = in.readString();
534db77b36aa9bdda2ebadccc4188715563a95f9bf0Alice Yang        if (TextUtils.isEmpty(syncAuthority)) {
535db77b36aa9bdda2ebadccc4188715563a95f9bf0Alice Yang            LogUtils.e(LOG_TAG, "Unexpected empty syncAuthority from Parcel");
536db77b36aa9bdda2ebadccc4188715563a95f9bf0Alice Yang        }
537db77b36aa9bdda2ebadccc4188715563a95f9bf0Alice Yang        quickResponseUri = in.readParcelable(null);
538db77b36aa9bdda2ebadccc4188715563a95f9bf0Alice Yang        final int hasSettings = in.readInt();
539db77b36aa9bdda2ebadccc4188715563a95f9bf0Alice Yang        if (hasSettings == 0) {
540db77b36aa9bdda2ebadccc4188715563a95f9bf0Alice Yang            LogUtils.e(LOG_TAG, new Throwable(), "Unexpected null settings in Account(Parcel)");
541db77b36aa9bdda2ebadccc4188715563a95f9bf0Alice Yang            settings = Settings.EMPTY_SETTINGS;
542db77b36aa9bdda2ebadccc4188715563a95f9bf0Alice Yang        } else {
543db77b36aa9bdda2ebadccc4188715563a95f9bf0Alice Yang            settings = in.readParcelable(loader);
544db77b36aa9bdda2ebadccc4188715563a95f9bf0Alice Yang        }
545db77b36aa9bdda2ebadccc4188715563a95f9bf0Alice Yang    }
546db77b36aa9bdda2ebadccc4188715563a95f9bf0Alice Yang
547732600e38891db139bae02dc91dd0c5b0987e8e9Andy Huang    @Override
54833fe908589dca6a7f58aa9f56d73f74a48ac42f6Mindy Pereira    public void writeToParcel(Parcel dest, int flags) {
5493e16687b074895bc6cc63a1ed93abf7033586fd2Tony Mantler        dest.writeString(name);
550bb036ff794f022bba2f501e155ef9c412e0e452eTony Mantler        dest.writeString(senderName);
5513e16687b074895bc6cc63a1ed93abf7033586fd2Tony Mantler        dest.writeString(type);
5523e16687b074895bc6cc63a1ed93abf7033586fd2Tony Mantler        dest.writeString(accountManagerName);
55333fe908589dca6a7f58aa9f56d73f74a48ac42f6Mindy Pereira        dest.writeInt(providerVersion);
554cfb7f33ff8ef9dc60b9143af32de64c7a3d71f36Mindy Pereira        dest.writeParcelable(uri, 0);
55533fe908589dca6a7f58aa9f56d73f74a48ac42f6Mindy Pereira        dest.writeInt(capabilities);
556cfb7f33ff8ef9dc60b9143af32de64c7a3d71f36Mindy Pereira        dest.writeParcelable(folderListUri, 0);
55731d7967c857d7486f27329135dffb3a2977b54e2Mindy Pereira        dest.writeParcelable(fullFolderListUri, 0);
558009f1b55b555638fd7276f8b996243a5d4ba7681Tony Mantler        dest.writeParcelable(allFolderListUri, 0);
559cfb7f33ff8ef9dc60b9143af32de64c7a3d71f36Mindy Pereira        dest.writeParcelable(searchUri, 0);
56092551d057965689f1952faeb06763f0762bc717fMindy Pereira        dest.writeString(accountFromAddresses);
561cfb7f33ff8ef9dc60b9143af32de64c7a3d71f36Mindy Pereira        dest.writeParcelable(expungeMessageUri, 0);
562cfb7f33ff8ef9dc60b9143af32de64c7a3d71f36Mindy Pereira        dest.writeParcelable(undoUri, 0);
563dac00547ce8d44a964e4510315168ee413e55a75Mindy Pereira        dest.writeParcelable(settingsIntentUri, 0);
564cfb7f33ff8ef9dc60b9143af32de64c7a3d71f36Mindy Pereira        dest.writeParcelable(helpIntentUri, 0);
565517743ef4e3e4ac103a3c096b9e3c894da7ed87aPaul Westbrook        dest.writeParcelable(sendFeedbackIntentUri, 0);
566122f7c2cf45cd5f07462a7b0a553f82828a8b1a2Paul Westbrook        dest.writeParcelable(reauthenticationIntentUri, 0);
5679ace18a77e1c61700291f6116bb8162c8fce1fadMarc Blank        dest.writeInt(syncStatus);
568cfb7f33ff8ef9dc60b9143af32de64c7a3d71f36Mindy Pereira        dest.writeParcelable(composeIntentUri, 0);
569898cd38018ff4331e79262451f464efa9dc5d43eMindy Pereira        dest.writeString(mimeType);
57027e85f244604c8de53b76b135e0dd6f2bf3cad96Vikram Aggarwal        dest.writeParcelable(recentFolderListUri, 0);
571b287833c2645e2502792821e54d7226cfad59955Marc Blank        dest.writeInt(color);
57227d89ada3e8d1b17357a7064e1f47f3c15686412Vikram Aggarwal        dest.writeParcelable(defaultRecentFolderListUri, 0);
573b971a8fcc31e54c645c5a096bf75077d6e1bc5baMindy Pereira        dest.writeParcelable(manualSyncUri, 0);
5749982fdb413d09b8e391dbc96a114987b1b87bb62Mark Wei        dest.writeParcelable(viewIntentProxyUri, 0);
575233f562368e4e3af9ca86b16d1b0a151df6157eaPaul Westbrook        dest.writeParcelable(accoutCookieQueryUri, 0);
5760d0f8b061faae060529af4da339eed2d728ef1bdScott Kennedy        dest.writeParcelable(updateSettingsUri, 0);
5773617b41394337774fb2e6fcf9fef1ac9eca00482Alice Yang        dest.writeInt(enableMessageTransforms);
578c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang        dest.writeString(syncAuthority);
57959e69095bd558a1e6ae890ce79b7b848331d0cc6Tony Mantler        dest.writeParcelable(quickResponseUri, 0);
58019e5908550fa9aac54be1647462b06be0e724440Paul Westbrook        if (settings == null) {
58119e5908550fa9aac54be1647462b06be0e724440Paul Westbrook            LogUtils.e(LOG_TAG, "unexpected null settings object in writeToParcel");
582a4836711cf7909575bfb25720232c22c201efd06Tony Mantler            dest.writeInt(0);
583a4836711cf7909575bfb25720232c22c201efd06Tony Mantler        } else {
584a4836711cf7909575bfb25720232c22c201efd06Tony Mantler            dest.writeInt(1);
585a4836711cf7909575bfb25720232c22c201efd06Tony Mantler            dest.writeParcelable(settings, 0);
58619e5908550fa9aac54be1647462b06be0e724440Paul Westbrook        }
5878a8c50d8fcc4f20549c9f395edbad017a940e72bMindy Pereira    }
5888a8c50d8fcc4f20549c9f395edbad017a940e72bMindy Pereira
589db8f2f9ad5dcb1d52c399520129d89b1ca38f423Paul Westbrook    @Override
5903e16687b074895bc6cc63a1ed93abf7033586fd2Tony Mantler    public int describeContents() {
5913e16687b074895bc6cc63a1ed93abf7033586fd2Tony Mantler        return 0;
5923e16687b074895bc6cc63a1ed93abf7033586fd2Tony Mantler    }
5933e16687b074895bc6cc63a1ed93abf7033586fd2Tony Mantler
5943e16687b074895bc6cc63a1ed93abf7033586fd2Tony Mantler    @Override
595db8f2f9ad5dcb1d52c399520129d89b1ca38f423Paul Westbrook    public String toString() {
5960ad577a90cbdc7d12cd18ef11a713bb7e38e58bfTony Mantler        // JSON is readable enough.
5970ad577a90cbdc7d12cd18ef11a713bb7e38e58bfTony Mantler        return serialize();
598db8f2f9ad5dcb1d52c399520129d89b1ca38f423Paul Westbrook    }
599db8f2f9ad5dcb1d52c399520129d89b1ca38f423Paul Westbrook
600db8f2f9ad5dcb1d52c399520129d89b1ca38f423Paul Westbrook    @Override
601db8f2f9ad5dcb1d52c399520129d89b1ca38f423Paul Westbrook    public boolean equals(Object o) {
602db8f2f9ad5dcb1d52c399520129d89b1ca38f423Paul Westbrook        if (o == this) {
603db8f2f9ad5dcb1d52c399520129d89b1ca38f423Paul Westbrook            return true;
604db8f2f9ad5dcb1d52c399520129d89b1ca38f423Paul Westbrook        }
605db8f2f9ad5dcb1d52c399520129d89b1ca38f423Paul Westbrook
606db8f2f9ad5dcb1d52c399520129d89b1ca38f423Paul Westbrook        if ((o == null) || (o.getClass() != this.getClass())) {
607db8f2f9ad5dcb1d52c399520129d89b1ca38f423Paul Westbrook            return false;
608db8f2f9ad5dcb1d52c399520129d89b1ca38f423Paul Westbrook        }
609db8f2f9ad5dcb1d52c399520129d89b1ca38f423Paul Westbrook
610db8f2f9ad5dcb1d52c399520129d89b1ca38f423Paul Westbrook        final Account other = (Account) o;
6114180c45904eca7b53f70ea6ca2ab241910bc9a2cTony Mantler        return TextUtils.equals(name, other.name) &&
612bb036ff794f022bba2f501e155ef9c412e0e452eTony Mantler                TextUtils.equals(senderName, other.senderName) &&
6134180c45904eca7b53f70ea6ca2ab241910bc9a2cTony Mantler                TextUtils.equals(accountManagerName, other.accountManagerName) &&
6144180c45904eca7b53f70ea6ca2ab241910bc9a2cTony Mantler                TextUtils.equals(type, other.type) &&
6154180c45904eca7b53f70ea6ca2ab241910bc9a2cTony Mantler                capabilities == other.capabilities &&
6164180c45904eca7b53f70ea6ca2ab241910bc9a2cTony Mantler                providerVersion == other.providerVersion &&
617db8f2f9ad5dcb1d52c399520129d89b1ca38f423Paul Westbrook                Objects.equal(uri, other.uri) &&
618db8f2f9ad5dcb1d52c399520129d89b1ca38f423Paul Westbrook                Objects.equal(folderListUri, other.folderListUri) &&
61931d7967c857d7486f27329135dffb3a2977b54e2Mindy Pereira                Objects.equal(fullFolderListUri, other.fullFolderListUri) &&
620009f1b55b555638fd7276f8b996243a5d4ba7681Tony Mantler                Objects.equal(allFolderListUri, other.allFolderListUri) &&
621db8f2f9ad5dcb1d52c399520129d89b1ca38f423Paul Westbrook                Objects.equal(searchUri, other.searchUri) &&
62292551d057965689f1952faeb06763f0762bc717fMindy Pereira                Objects.equal(accountFromAddresses, other.accountFromAddresses) &&
623db8f2f9ad5dcb1d52c399520129d89b1ca38f423Paul Westbrook                Objects.equal(expungeMessageUri, other.expungeMessageUri) &&
624db8f2f9ad5dcb1d52c399520129d89b1ca38f423Paul Westbrook                Objects.equal(undoUri, other.undoUri) &&
625db8f2f9ad5dcb1d52c399520129d89b1ca38f423Paul Westbrook                Objects.equal(settingsIntentUri, other.settingsIntentUri) &&
626db8f2f9ad5dcb1d52c399520129d89b1ca38f423Paul Westbrook                Objects.equal(helpIntentUri, other.helpIntentUri) &&
627517743ef4e3e4ac103a3c096b9e3c894da7ed87aPaul Westbrook                Objects.equal(sendFeedbackIntentUri, other.sendFeedbackIntentUri) &&
628122f7c2cf45cd5f07462a7b0a553f82828a8b1a2Paul Westbrook                Objects.equal(reauthenticationIntentUri, other.reauthenticationIntentUri) &&
629db8f2f9ad5dcb1d52c399520129d89b1ca38f423Paul Westbrook                (syncStatus == other.syncStatus) &&
630898cd38018ff4331e79262451f464efa9dc5d43eMindy Pereira                Objects.equal(composeIntentUri, other.composeIntentUri) &&
63127e85f244604c8de53b76b135e0dd6f2bf3cad96Vikram Aggarwal                TextUtils.equals(mimeType, other.mimeType) &&
632b287833c2645e2502792821e54d7226cfad59955Marc Blank                Objects.equal(recentFolderListUri, other.recentFolderListUri) &&
63327d89ada3e8d1b17357a7064e1f47f3c15686412Vikram Aggarwal                color == other.color &&
6346006991395131d7d1db4f883ff8c7a87498b6eecVikram Aggarwal                Objects.equal(defaultRecentFolderListUri, other.defaultRecentFolderListUri) &&
6359982fdb413d09b8e391dbc96a114987b1b87bb62Mark Wei                Objects.equal(viewIntentProxyUri, other.viewIntentProxyUri) &&
636233f562368e4e3af9ca86b16d1b0a151df6157eaPaul Westbrook                Objects.equal(accoutCookieQueryUri, other.accoutCookieQueryUri) &&
6370d0f8b061faae060529af4da339eed2d728ef1bdScott Kennedy                Objects.equal(updateSettingsUri, other.updateSettingsUri) &&
6383617b41394337774fb2e6fcf9fef1ac9eca00482Alice Yang                Objects.equal(enableMessageTransforms, other.enableMessageTransforms) &&
639c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang                Objects.equal(syncAuthority, other.syncAuthority) &&
64059e69095bd558a1e6ae890ce79b7b848331d0cc6Tony Mantler                Objects.equal(quickResponseUri, other.quickResponseUri) &&
6416006991395131d7d1db4f883ff8c7a87498b6eecVikram Aggarwal                Objects.equal(settings, other.settings);
642db8f2f9ad5dcb1d52c399520129d89b1ca38f423Paul Westbrook    }
643db8f2f9ad5dcb1d52c399520129d89b1ca38f423Paul Westbrook
644e0afef979657256a2014024babe51d099e254a57Vikram Aggarwal    /**
645e0afef979657256a2014024babe51d099e254a57Vikram Aggarwal     * Returns true if the two accounts differ in sync or server-side settings.
646e0afef979657256a2014024babe51d099e254a57Vikram Aggarwal     * This is <b>not</b> a replacement for {@link #equals(Object)}.
647a4836711cf7909575bfb25720232c22c201efd06Tony Mantler     * @param other Account object to compare
648a4836711cf7909575bfb25720232c22c201efd06Tony Mantler     * @return true if the two accounts differ in sync or server-side settings
649e0afef979657256a2014024babe51d099e254a57Vikram Aggarwal     */
650e0afef979657256a2014024babe51d099e254a57Vikram Aggarwal    public final boolean settingsDiffer(Account other) {
651e0afef979657256a2014024babe51d099e254a57Vikram Aggarwal        // If the other object doesn't exist, they differ significantly.
652e0afef979657256a2014024babe51d099e254a57Vikram Aggarwal        if (other == null) {
653e0afef979657256a2014024babe51d099e254a57Vikram Aggarwal            return true;
654e0afef979657256a2014024babe51d099e254a57Vikram Aggarwal        }
655e0afef979657256a2014024babe51d099e254a57Vikram Aggarwal        // Check all the server-side settings, the user-side settings and the sync status.
656e0afef979657256a2014024babe51d099e254a57Vikram Aggarwal        return ((this.syncStatus != other.syncStatus)
657e0afef979657256a2014024babe51d099e254a57Vikram Aggarwal                || !Objects.equal(accountFromAddresses, other.accountFromAddresses)
658e0afef979657256a2014024babe51d099e254a57Vikram Aggarwal                || color != other.color
659e0afef979657256a2014024babe51d099e254a57Vikram Aggarwal                || (this.settings.hashCode() != other.settings.hashCode()));
660e0afef979657256a2014024babe51d099e254a57Vikram Aggarwal    }
661e0afef979657256a2014024babe51d099e254a57Vikram Aggarwal
662db8f2f9ad5dcb1d52c399520129d89b1ca38f423Paul Westbrook    @Override
663db8f2f9ad5dcb1d52c399520129d89b1ca38f423Paul Westbrook    public int hashCode() {
664154d8cff5c56a0c4c2bf1cbabe42157bc482ac99Tony Mantler        return Objects.hashCode(name,
665bb036ff794f022bba2f501e155ef9c412e0e452eTony Mantler                senderName,
666154d8cff5c56a0c4c2bf1cbabe42157bc482ac99Tony Mantler                accountManagerName,
667154d8cff5c56a0c4c2bf1cbabe42157bc482ac99Tony Mantler                type,
668154d8cff5c56a0c4c2bf1cbabe42157bc482ac99Tony Mantler                capabilities,
669154d8cff5c56a0c4c2bf1cbabe42157bc482ac99Tony Mantler                providerVersion,
670154d8cff5c56a0c4c2bf1cbabe42157bc482ac99Tony Mantler                uri,
671154d8cff5c56a0c4c2bf1cbabe42157bc482ac99Tony Mantler                folderListUri,
672154d8cff5c56a0c4c2bf1cbabe42157bc482ac99Tony Mantler                fullFolderListUri,
673154d8cff5c56a0c4c2bf1cbabe42157bc482ac99Tony Mantler                allFolderListUri,
674154d8cff5c56a0c4c2bf1cbabe42157bc482ac99Tony Mantler                searchUri,
675154d8cff5c56a0c4c2bf1cbabe42157bc482ac99Tony Mantler                accountFromAddresses,
676154d8cff5c56a0c4c2bf1cbabe42157bc482ac99Tony Mantler                expungeMessageUri,
677154d8cff5c56a0c4c2bf1cbabe42157bc482ac99Tony Mantler                undoUri,
678154d8cff5c56a0c4c2bf1cbabe42157bc482ac99Tony Mantler                settingsIntentUri,
679154d8cff5c56a0c4c2bf1cbabe42157bc482ac99Tony Mantler                helpIntentUri,
680154d8cff5c56a0c4c2bf1cbabe42157bc482ac99Tony Mantler                sendFeedbackIntentUri,
681154d8cff5c56a0c4c2bf1cbabe42157bc482ac99Tony Mantler                reauthenticationIntentUri,
682154d8cff5c56a0c4c2bf1cbabe42157bc482ac99Tony Mantler                syncStatus,
683154d8cff5c56a0c4c2bf1cbabe42157bc482ac99Tony Mantler                composeIntentUri,
684154d8cff5c56a0c4c2bf1cbabe42157bc482ac99Tony Mantler                mimeType,
685154d8cff5c56a0c4c2bf1cbabe42157bc482ac99Tony Mantler                recentFolderListUri,
686154d8cff5c56a0c4c2bf1cbabe42157bc482ac99Tony Mantler                color,
687154d8cff5c56a0c4c2bf1cbabe42157bc482ac99Tony Mantler                defaultRecentFolderListUri,
688154d8cff5c56a0c4c2bf1cbabe42157bc482ac99Tony Mantler                viewIntentProxyUri,
689154d8cff5c56a0c4c2bf1cbabe42157bc482ac99Tony Mantler                accoutCookieQueryUri,
690154d8cff5c56a0c4c2bf1cbabe42157bc482ac99Tony Mantler                updateSettingsUri,
691154d8cff5c56a0c4c2bf1cbabe42157bc482ac99Tony Mantler                enableMessageTransforms,
692154d8cff5c56a0c4c2bf1cbabe42157bc482ac99Tony Mantler                syncAuthority,
693154d8cff5c56a0c4c2bf1cbabe42157bc482ac99Tony Mantler                quickResponseUri);
694db8f2f9ad5dcb1d52c399520129d89b1ca38f423Paul Westbrook    }
695db8f2f9ad5dcb1d52c399520129d89b1ca38f423Paul Westbrook
696b373e3ec0e488914635345627f5734af0f0ef76bAndy Huang    /**
697b373e3ec0e488914635345627f5734af0f0ef76bAndy Huang     * Returns whether two Accounts match, as determined by their base URIs.
698b373e3ec0e488914635345627f5734af0f0ef76bAndy Huang     * <p>For a deep object comparison, use {@link #equals(Object)}.
699b373e3ec0e488914635345627f5734af0f0ef76bAndy Huang     *
700b373e3ec0e488914635345627f5734af0f0ef76bAndy Huang     */
701b373e3ec0e488914635345627f5734af0f0ef76bAndy Huang    public boolean matches(Account other) {
702b373e3ec0e488914635345627f5734af0f0ef76bAndy Huang        return other != null && Objects.equal(uri, other.uri);
703b373e3ec0e488914635345627f5734af0f0ef76bAndy Huang    }
704b373e3ec0e488914635345627f5734af0f0ef76bAndy Huang
7051617481de7c1f9b8dfcd25ba9828e933cf9d5490Andy Huang    public List<ReplyFromAccount> getReplyFroms() {
7061617481de7c1f9b8dfcd25ba9828e933cf9d5490Andy Huang
7071617481de7c1f9b8dfcd25ba9828e933cf9d5490Andy Huang        if (mReplyFroms == null) {
7081617481de7c1f9b8dfcd25ba9828e933cf9d5490Andy Huang            mReplyFroms = Lists.newArrayList();
7091617481de7c1f9b8dfcd25ba9828e933cf9d5490Andy Huang
7101617481de7c1f9b8dfcd25ba9828e933cf9d5490Andy Huang            // skip if sending is unsupported
7111617481de7c1f9b8dfcd25ba9828e933cf9d5490Andy Huang            if (supportsCapability(AccountCapabilities.SENDING_UNAVAILABLE)) {
7121617481de7c1f9b8dfcd25ba9828e933cf9d5490Andy Huang                return mReplyFroms;
7131617481de7c1f9b8dfcd25ba9828e933cf9d5490Andy Huang            }
7141617481de7c1f9b8dfcd25ba9828e933cf9d5490Andy Huang
7151617481de7c1f9b8dfcd25ba9828e933cf9d5490Andy Huang            // add the main account address
716bb036ff794f022bba2f501e155ef9c412e0e452eTony Mantler            // TODO: name is incorrect here, use senderName once FromAddressSpinner is fixed
717bb036ff794f022bba2f501e155ef9c412e0e452eTony Mantler            // b/11292541
71879b1156803585952a4851221dc9fa9974e606433Tony Mantler            mReplyFroms.add(new ReplyFromAccount(this, uri, getEmailAddress(), name,
71979b1156803585952a4851221dc9fa9974e606433Tony Mantler                    getEmailAddress(), false /* isDefault */, false /* isCustom */));
7201617481de7c1f9b8dfcd25ba9828e933cf9d5490Andy Huang
7211617481de7c1f9b8dfcd25ba9828e933cf9d5490Andy Huang            if (!TextUtils.isEmpty(accountFromAddresses)) {
7221617481de7c1f9b8dfcd25ba9828e933cf9d5490Andy Huang                try {
7231617481de7c1f9b8dfcd25ba9828e933cf9d5490Andy Huang                    JSONArray accounts = new JSONArray(accountFromAddresses);
7241617481de7c1f9b8dfcd25ba9828e933cf9d5490Andy Huang
7251617481de7c1f9b8dfcd25ba9828e933cf9d5490Andy Huang                    for (int i = 0, len = accounts.length(); i < len; i++) {
7261617481de7c1f9b8dfcd25ba9828e933cf9d5490Andy Huang                        final ReplyFromAccount a = ReplyFromAccount.deserialize(this,
7271617481de7c1f9b8dfcd25ba9828e933cf9d5490Andy Huang                                accounts.getJSONObject(i));
7281617481de7c1f9b8dfcd25ba9828e933cf9d5490Andy Huang                        if (a != null) {
7291617481de7c1f9b8dfcd25ba9828e933cf9d5490Andy Huang                            mReplyFroms.add(a);
7301617481de7c1f9b8dfcd25ba9828e933cf9d5490Andy Huang                        }
7311617481de7c1f9b8dfcd25ba9828e933cf9d5490Andy Huang                    }
7321617481de7c1f9b8dfcd25ba9828e933cf9d5490Andy Huang
7331617481de7c1f9b8dfcd25ba9828e933cf9d5490Andy Huang                } catch (JSONException e) {
7341617481de7c1f9b8dfcd25ba9828e933cf9d5490Andy Huang                    LogUtils.e(LOG_TAG, e, "Unable to parse accountFromAddresses. name=%s", name);
7351617481de7c1f9b8dfcd25ba9828e933cf9d5490Andy Huang                }
7361617481de7c1f9b8dfcd25ba9828e933cf9d5490Andy Huang            }
7371617481de7c1f9b8dfcd25ba9828e933cf9d5490Andy Huang        }
7381617481de7c1f9b8dfcd25ba9828e933cf9d5490Andy Huang        return mReplyFroms;
7391617481de7c1f9b8dfcd25ba9828e933cf9d5490Andy Huang    }
7401617481de7c1f9b8dfcd25ba9828e933cf9d5490Andy Huang
7411617481de7c1f9b8dfcd25ba9828e933cf9d5490Andy Huang    /**
7421617481de7c1f9b8dfcd25ba9828e933cf9d5490Andy Huang     * @param fromAddress a raw email address, e.g. "user@domain.com"
7431617481de7c1f9b8dfcd25ba9828e933cf9d5490Andy Huang     * @return if the address belongs to this Account (either as the main address or as a
7441617481de7c1f9b8dfcd25ba9828e933cf9d5490Andy Huang     * custom-from)
7451617481de7c1f9b8dfcd25ba9828e933cf9d5490Andy Huang     */
7461617481de7c1f9b8dfcd25ba9828e933cf9d5490Andy Huang    public boolean ownsFromAddress(String fromAddress) {
7471617481de7c1f9b8dfcd25ba9828e933cf9d5490Andy Huang        for (ReplyFromAccount replyFrom : getReplyFroms()) {
7481617481de7c1f9b8dfcd25ba9828e933cf9d5490Andy Huang            if (TextUtils.equals(replyFrom.address, fromAddress)) {
7491617481de7c1f9b8dfcd25ba9828e933cf9d5490Andy Huang                return true;
7501617481de7c1f9b8dfcd25ba9828e933cf9d5490Andy Huang            }
7511617481de7c1f9b8dfcd25ba9828e933cf9d5490Andy Huang        }
7521617481de7c1f9b8dfcd25ba9828e933cf9d5490Andy Huang
7531617481de7c1f9b8dfcd25ba9828e933cf9d5490Andy Huang        return false;
7541617481de7c1f9b8dfcd25ba9828e933cf9d5490Andy Huang    }
7551617481de7c1f9b8dfcd25ba9828e933cf9d5490Andy Huang
75679b1156803585952a4851221dc9fa9974e606433Tony Mantler    public String getEmailAddress() {
75779b1156803585952a4851221dc9fa9974e606433Tony Mantler        return accountManagerName;
75879b1156803585952a4851221dc9fa9974e606433Tony Mantler    }
75979b1156803585952a4851221dc9fa9974e606433Tony Mantler
760bb036ff794f022bba2f501e155ef9c412e0e452eTony Mantler    /**
761bb036ff794f022bba2f501e155ef9c412e0e452eTony Mantler     * Returns the real name associated with the account, e.g. "John Doe" or null if no such name
762bb036ff794f022bba2f501e155ef9c412e0e452eTony Mantler     * has been configured
763bb036ff794f022bba2f501e155ef9c412e0e452eTony Mantler     * @return sender name
764bb036ff794f022bba2f501e155ef9c412e0e452eTony Mantler     */
765bb036ff794f022bba2f501e155ef9c412e0e452eTony Mantler    public String getSenderName() {
766bb036ff794f022bba2f501e155ef9c412e0e452eTony Mantler        return senderName;
767bb036ff794f022bba2f501e155ef9c412e0e452eTony Mantler    }
768bb036ff794f022bba2f501e155ef9c412e0e452eTony Mantler
769732600e38891db139bae02dc91dd0c5b0987e8e9Andy Huang    @SuppressWarnings("hiding")
7704473e8c92946914fbb7e86490ec32f481744c7afTony Mantler    public static final ClassLoaderCreator<Account> CREATOR = new ClassLoaderCreator<Account>() {
771732600e38891db139bae02dc91dd0c5b0987e8e9Andy Huang        @Override
7724473e8c92946914fbb7e86490ec32f481744c7afTony Mantler        public Account createFromParcel(Parcel source, ClassLoader loader) {
7734473e8c92946914fbb7e86490ec32f481744c7afTony Mantler            return new Account(source, loader);
7744473e8c92946914fbb7e86490ec32f481744c7afTony Mantler        }
7754473e8c92946914fbb7e86490ec32f481744c7afTony Mantler
7764473e8c92946914fbb7e86490ec32f481744c7afTony Mantler        @Override
7774473e8c92946914fbb7e86490ec32f481744c7afTony Mantler        public Account createFromParcel(Parcel source) {
7784473e8c92946914fbb7e86490ec32f481744c7afTony Mantler            return new Account(source, null);
77933fe908589dca6a7f58aa9f56d73f74a48ac42f6Mindy Pereira        }
78033fe908589dca6a7f58aa9f56d73f74a48ac42f6Mindy Pereira
781732600e38891db139bae02dc91dd0c5b0987e8e9Andy Huang        @Override
78233fe908589dca6a7f58aa9f56d73f74a48ac42f6Mindy Pereira        public Account[] newArray(int size) {
78333fe908589dca6a7f58aa9f56d73f74a48ac42f6Mindy Pereira            return new Account[size];
78433fe908589dca6a7f58aa9f56d73f74a48ac42f6Mindy Pereira        }
78533fe908589dca6a7f58aa9f56d73f74a48ac42f6Mindy Pereira    };
78673bffaf3f72db506de249d432fe1442af38c1e13Vikram Aggarwal
78773bffaf3f72db506de249d432fe1442af38c1e13Vikram Aggarwal    /**
788d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy     * Creates a {@link Map} where the column name is the key and the value is the value, which can
789d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy     * be used for populating a {@link MatrixCursor}.
790d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy     */
791a4836711cf7909575bfb25720232c22c201efd06Tony Mantler    public Map<String, Object> getValueMap() {
792d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy        // ImmutableMap.Builder does not allow null values
793d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy        final Map<String, Object> map = new HashMap<String, Object>();
794d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy
79559e69095bd558a1e6ae890ce79b7b848331d0cc6Tony Mantler        map.put(AccountColumns._ID, 0);
79659e69095bd558a1e6ae890ce79b7b848331d0cc6Tony Mantler        map.put(AccountColumns.NAME, name);
797bb036ff794f022bba2f501e155ef9c412e0e452eTony Mantler        map.put(AccountColumns.SENDER_NAME, senderName);
79859e69095bd558a1e6ae890ce79b7b848331d0cc6Tony Mantler        map.put(AccountColumns.TYPE, type);
7993e16687b074895bc6cc63a1ed93abf7033586fd2Tony Mantler        map.put(AccountColumns.ACCOUNT_MANAGER_NAME, accountManagerName);
80059e69095bd558a1e6ae890ce79b7b848331d0cc6Tony Mantler        map.put(AccountColumns.PROVIDER_VERSION, providerVersion);
80159e69095bd558a1e6ae890ce79b7b848331d0cc6Tony Mantler        map.put(AccountColumns.URI, uri);
80259e69095bd558a1e6ae890ce79b7b848331d0cc6Tony Mantler        map.put(AccountColumns.CAPABILITIES, capabilities);
80359e69095bd558a1e6ae890ce79b7b848331d0cc6Tony Mantler        map.put(AccountColumns.FOLDER_LIST_URI, folderListUri);
80459e69095bd558a1e6ae890ce79b7b848331d0cc6Tony Mantler        map.put(AccountColumns.FULL_FOLDER_LIST_URI, fullFolderListUri);
805009f1b55b555638fd7276f8b996243a5d4ba7681Tony Mantler        map.put(AccountColumns.ALL_FOLDER_LIST_URI, allFolderListUri);
80659e69095bd558a1e6ae890ce79b7b848331d0cc6Tony Mantler        map.put(AccountColumns.SEARCH_URI, searchUri);
80759e69095bd558a1e6ae890ce79b7b848331d0cc6Tony Mantler        map.put(AccountColumns.ACCOUNT_FROM_ADDRESSES, accountFromAddresses);
80859e69095bd558a1e6ae890ce79b7b848331d0cc6Tony Mantler        map.put(AccountColumns.EXPUNGE_MESSAGE_URI, expungeMessageUri);
80959e69095bd558a1e6ae890ce79b7b848331d0cc6Tony Mantler        map.put(AccountColumns.UNDO_URI, undoUri);
81059e69095bd558a1e6ae890ce79b7b848331d0cc6Tony Mantler        map.put(AccountColumns.SETTINGS_INTENT_URI, settingsIntentUri);
81159e69095bd558a1e6ae890ce79b7b848331d0cc6Tony Mantler        map.put(AccountColumns.HELP_INTENT_URI, helpIntentUri);
81259e69095bd558a1e6ae890ce79b7b848331d0cc6Tony Mantler        map.put(AccountColumns.SEND_FEEDBACK_INTENT_URI, sendFeedbackIntentUri);
81359e69095bd558a1e6ae890ce79b7b848331d0cc6Tony Mantler        map.put(AccountColumns.REAUTHENTICATION_INTENT_URI, reauthenticationIntentUri);
81459e69095bd558a1e6ae890ce79b7b848331d0cc6Tony Mantler        map.put(AccountColumns.SYNC_STATUS, syncStatus);
81559e69095bd558a1e6ae890ce79b7b848331d0cc6Tony Mantler        map.put(AccountColumns.COMPOSE_URI, composeIntentUri);
81659e69095bd558a1e6ae890ce79b7b848331d0cc6Tony Mantler        map.put(AccountColumns.MIME_TYPE, mimeType);
81759e69095bd558a1e6ae890ce79b7b848331d0cc6Tony Mantler        map.put(AccountColumns.RECENT_FOLDER_LIST_URI, recentFolderListUri);
81859e69095bd558a1e6ae890ce79b7b848331d0cc6Tony Mantler        map.put(AccountColumns.DEFAULT_RECENT_FOLDER_LIST_URI, defaultRecentFolderListUri);
81959e69095bd558a1e6ae890ce79b7b848331d0cc6Tony Mantler        map.put(AccountColumns.MANUAL_SYNC_URI, manualSyncUri);
82059e69095bd558a1e6ae890ce79b7b848331d0cc6Tony Mantler        map.put(AccountColumns.VIEW_INTENT_PROXY_URI, viewIntentProxyUri);
82159e69095bd558a1e6ae890ce79b7b848331d0cc6Tony Mantler        map.put(AccountColumns.ACCOUNT_COOKIE_QUERY_URI, accoutCookieQueryUri);
82259e69095bd558a1e6ae890ce79b7b848331d0cc6Tony Mantler        map.put(AccountColumns.COLOR, color);
82359e69095bd558a1e6ae890ce79b7b848331d0cc6Tony Mantler        map.put(AccountColumns.UPDATE_SETTINGS_URI, updateSettingsUri);
82459e69095bd558a1e6ae890ce79b7b848331d0cc6Tony Mantler        map.put(AccountColumns.ENABLE_MESSAGE_TRANSFORMS, enableMessageTransforms);
82559e69095bd558a1e6ae890ce79b7b848331d0cc6Tony Mantler        map.put(AccountColumns.SYNC_AUTHORITY, syncAuthority);
82659e69095bd558a1e6ae890ce79b7b848331d0cc6Tony Mantler        map.put(AccountColumns.QUICK_RESPONSE_URI, quickResponseUri);
827a4836711cf7909575bfb25720232c22c201efd06Tony Mantler        settings.getValueMap(map);
828d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy
829d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy        return map;
830d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy    }
831177097fad8fc26b8a215f9f1af6dd5fd2c8eb06cVikram Aggarwal
832177097fad8fc26b8a215f9f1af6dd5fd2c8eb06cVikram Aggarwal    /**
833177097fad8fc26b8a215f9f1af6dd5fd2c8eb06cVikram Aggarwal     * Public object that knows how to construct Accounts given Cursors.
834177097fad8fc26b8a215f9f1af6dd5fd2c8eb06cVikram Aggarwal     */
835177097fad8fc26b8a215f9f1af6dd5fd2c8eb06cVikram Aggarwal    public final static CursorCreator<Account> FACTORY = new CursorCreator<Account>() {
836177097fad8fc26b8a215f9f1af6dd5fd2c8eb06cVikram Aggarwal        @Override
837177097fad8fc26b8a215f9f1af6dd5fd2c8eb06cVikram Aggarwal        public Account createFromCursor(Cursor c) {
838177097fad8fc26b8a215f9f1af6dd5fd2c8eb06cVikram Aggarwal            return new Account(c);
839177097fad8fc26b8a215f9f1af6dd5fd2c8eb06cVikram Aggarwal        }
840177097fad8fc26b8a215f9f1af6dd5fd2c8eb06cVikram Aggarwal
841177097fad8fc26b8a215f9f1af6dd5fd2c8eb06cVikram Aggarwal        @Override
842177097fad8fc26b8a215f9f1af6dd5fd2c8eb06cVikram Aggarwal        public String toString() {
843177097fad8fc26b8a215f9f1af6dd5fd2c8eb06cVikram Aggarwal            return "Account CursorCreator";
844177097fad8fc26b8a215f9f1af6dd5fd2c8eb06cVikram Aggarwal        }
845177097fad8fc26b8a215f9f1af6dd5fd2c8eb06cVikram Aggarwal    };
84633fe908589dca6a7f58aa9f56d73f74a48ac42f6Mindy Pereira}
847