Account.java revision 679a8cc895ec75d3b578dbc77db1e9c04dd7f8b0
1/** 2 * Copyright (c) 2012, Google Inc. 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 17package com.android.mail.providers; 18 19import android.database.Cursor; 20import android.os.Parcel; 21import android.os.Parcelable; 22 23public class Account extends android.accounts.Account implements Parcelable { 24 /** 25 * The version of the UI provider schema from which this account provider 26 * will return results. 27 */ 28 public final int providerVersion; 29 30 /** 31 * The uri to directly access the information for this account. 32 */ 33 public final String accountUri; 34 35 /** 36 * The possible capabilities that this account supports. 37 */ 38 public final int capabilities; 39 40 /** 41 * The content provider uri to return the list of top level folders for this 42 * account. 43 */ 44 public final String folderListUri; 45 46 /** 47 * The content provider uri that can be queried for search results. 48 */ 49 public final String searchUri; 50 51 /** 52 * The content provider uri that can be queried to access the from addresses 53 * for this account. 54 */ 55 public final String accountFromAddressesUri; 56 57 /** 58 * The content provider uri that can be used to save (insert) new draft 59 * messages for this account. NOTE: This might be better to be an update 60 * operation on the messageUri. 61 */ 62 public final String saveDraftUri; 63 64 /** 65 * The content provider uri that can be used to send a message for this 66 * account. 67 * NOTE: This might be better to be an update operation on the 68 * messageUri. 69 */ 70 public final String sendMessageUri; 71 72 /** 73 * The content provider uri that can be used to expunge message from this 74 * account. NOTE: This might be better to be an update operation on the 75 * messageUri. 76 */ 77 public final String expungeMessageUri; 78 79 /** 80 * The content provider uri that can be used to undo the last operation 81 * performed. 82 */ 83 public final String undoUri; 84 85 /** 86 * Uri for VIEW intent that will cause the settings screens for this account type to be 87 * shown. 88 */ 89 public final String settingIntentUri; 90 91 /** 92 * The sync status of the account 93 */ 94 public final int syncStatus; 95 96 public Account(Parcel in) { 97 super(in); 98 providerVersion = in.readInt(); 99 accountUri = in.readString(); 100 capabilities = in.readInt(); 101 folderListUri = in.readString(); 102 searchUri = in.readString(); 103 accountFromAddressesUri = in.readString(); 104 saveDraftUri = in.readString(); 105 sendMessageUri = in.readString(); 106 expungeMessageUri = in.readString(); 107 undoUri = in.readString(); 108 settingIntentUri = in.readString(); 109 syncStatus = in.readInt(); 110 } 111 112 public Account(Cursor cursor) { 113 super(cursor.getString(UIProvider.ACCOUNT_NAME_COLUMN), "unknown"); 114 accountFromAddressesUri = cursor.getString(UIProvider.ACCOUNT_FROM_ADDRESSES_URI_COLUMN); 115 capabilities = cursor.getInt(UIProvider.ACCOUNT_CAPABILITIES_COLUMN); 116 providerVersion = cursor.getInt(UIProvider.ACCOUNT_PROVIDER_VERISON_COLUMN); 117 accountUri = cursor.getString(UIProvider.ACCOUNT_URI_COLUMN); 118 folderListUri = cursor.getString(UIProvider.ACCOUNT_FOLDER_LIST_URI_COLUMN); 119 searchUri = cursor.getString(UIProvider.ACCOUNT_SEARCH_URI_COLUMN); 120 saveDraftUri = cursor.getString(UIProvider.ACCOUNT_SAVE_DRAFT_URI_COLUMN); 121 sendMessageUri = cursor.getString(UIProvider.ACCOUNT_SEND_MESSAGE_URI_COLUMN); 122 expungeMessageUri = cursor.getString(UIProvider.ACCOUNT_EXPUNGE_MESSAGE_URI_COLUMN); 123 undoUri = cursor.getString(UIProvider.ACCOUNT_UNDO_URI_COLUMN); 124 settingIntentUri = cursor.getString(UIProvider.ACCOUNT_SETTINGS_INTENT_URI_COLUMN); 125 syncStatus = cursor.getInt(UIProvider.ACCOUNT_SYNC_STATUS_COLUMN); 126 } 127 128 public boolean supportsCapability(int capability) { 129 return (capabilities & capability) != 0; 130 } 131 132 @Override 133 public void writeToParcel(Parcel dest, int flags) { 134 super.writeToParcel(dest, flags); 135 dest.writeInt(providerVersion); 136 dest.writeString(accountUri); 137 dest.writeInt(capabilities); 138 dest.writeString(folderListUri); 139 dest.writeString(searchUri); 140 dest.writeString(accountFromAddressesUri); 141 dest.writeString(saveDraftUri); 142 dest.writeString(sendMessageUri); 143 dest.writeString(expungeMessageUri); 144 dest.writeString(undoUri); 145 dest.writeString(settingIntentUri); 146 dest.writeInt(syncStatus); 147 } 148 149 @SuppressWarnings("hiding") 150 public static final Creator<Account> CREATOR = new Creator<Account>() { 151 @Override 152 public Account createFromParcel(Parcel source) { 153 return new Account(source); 154 } 155 156 @Override 157 public Account[] newArray(int size) { 158 return new Account[size]; 159 } 160 }; 161} 162