List of usage examples for android.content ContentResolver getIsSyncable
public static int getIsSyncable(Account account, String authority)
From source file:org.andstatus.app.account.AccountData.java
public static AccountData fromAndroidAccount(MyContext myContext, Account androidAccount) { if (androidAccount == null) { throw new IllegalArgumentException(TAG + " account is null"); }/*from www . j a v a 2s .c om*/ android.accounts.AccountManager am = AccountManager.get(myContext.context()); AccountData accountData = fromJsonString(am.getUserData(androidAccount, KEY_ACCOUNT), true); accountData.setDataBoolean(MyAccount.KEY_IS_SYNCABLE, ContentResolver.getIsSyncable(androidAccount, MyProvider.AUTHORITY) != 0); accountData.setDataBoolean(MyAccount.KEY_SYNC_AUTOMATICALLY, ContentResolver.getSyncAutomatically(androidAccount, MyProvider.AUTHORITY)); accountData.setDataLong(MyPreferences.KEY_SYNC_FREQUENCY_SECONDS, getSyncFrequencySeconds(androidAccount)); return accountData; }
From source file:org.andstatus.app.account.AccountData.java
/** * @param result /*from w w w . ja v a 2 s . co m*/ * @return true if Android account changed */ void saveDataToAccount(MyContext myContext, Account androidAccount, SaveResult result) { AccountData oldData = fromAndroidAccount(myContext, androidAccount); result.changed = !this.equals(oldData); if (result.changed) { long syncFrequencySeconds = getDataLong(MyPreferences.KEY_SYNC_FREQUENCY_SECONDS, 0); if (syncFrequencySeconds > 0 && syncFrequencySeconds != getSyncFrequencySeconds(androidAccount)) { result.changed = true; setSyncFrequencySeconds(androidAccount, syncFrequencySeconds); } boolean isSyncable = getDataBoolean(MyAccount.KEY_IS_SYNCABLE, true); if (isSyncable != (ContentResolver.getIsSyncable(androidAccount, MyProvider.AUTHORITY) != 0)) { ContentResolver.setIsSyncable(androidAccount, MyProvider.AUTHORITY, isSyncable ? 1 : 0); } boolean syncAutomatically = getDataBoolean(MyAccount.KEY_SYNC_AUTOMATICALLY, true); if (syncAutomatically != ContentResolver.getSyncAutomatically(androidAccount, MyProvider.AUTHORITY)) { // We need to preserve sync on/off during backup/restore. // don't know about "network tickles"... See: // http://stackoverflow.com/questions/5013254/what-is-a-network-tickle-and-how-to-i-go-about-sending-one ContentResolver.setSyncAutomatically(androidAccount, MyProvider.AUTHORITY, syncAutomatically); } android.accounts.AccountManager am = AccountManager.get(myContext.context()); am.setUserData(androidAccount, KEY_ACCOUNT, toJsonString()); result.savedToAccountManager = true; } result.success = true; }
From source file:eu.masconsult.bgbanking.activity.HomeActivity.java
@Override public boolean onCreateOptionsMenu(Menu menu) { super.onCreateOptionsMenu(menu); MenuItem refreshItem = menu.add(R.string.menu_item_refresh); refreshItem.setIcon(R.drawable.ic_menu_refresh); refreshItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW); refreshItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { @Override//from w w w.ja v a 2 s . c om public boolean onMenuItemClick(MenuItem item) { AccountManager accountManager = AccountManager.get(HomeActivity.this); if (accountManager == null) { return false; } long cnt = 0; Bank[] banks = Bank.values(); for (Bank bank : banks) { for (Account account : accountManager .getAccountsByType(bank.getAccountType(HomeActivity.this))) { Log.v(TAG, String.format("account: %s, %s, %s", account.name, account.type, ContentResolver.getIsSyncable(account, BankingContract.AUTHORITY))); Bundle bundle = new Bundle(); bundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true); ContentResolver.requestSync(account, BankingContract.AUTHORITY, bundle); cnt++; } } EasyTracker.getTracker().trackEvent("ui_action", "menu_item_click", "refresh", cnt); return true; } }); MenuItem addAccountItem = menu.add(R.string.menu_item_add_account); addAccountItem.setIcon(R.drawable.ic_menu_add); addAccountItem .setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW); addAccountItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { addAccount(); EasyTracker.getTracker().trackEvent("ui_action", "menu_item_click", "add_account", 1l); return true; } }); MenuItem sendFeedback = menu.add(R.string.menu_item_send_feedback); sendFeedback.setIcon(R.drawable.ic_menu_start_conversation); sendFeedback.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM); sendFeedback.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { PackageInfo manager; try { manager = getPackageManager().getPackageInfo(getPackageName(), 0); } catch (NameNotFoundException e) { manager = new PackageInfo(); manager.versionCode = 0; manager.versionName = "undef"; } try { startActivity(new Intent(Intent.ACTION_SEND).setType("plain/text") .putExtra(Intent.EXTRA_EMAIL, new String[] { "bgbanks@masconsult.eu" }) .putExtra(Intent.EXTRA_SUBJECT, "BG Banks v" + manager.versionName + "-" + manager.versionCode + " feedback")); EasyTracker.getTracker().trackEvent("ui_action", "menu_item_click", "send_feedback", 1l); } catch (ActivityNotFoundException e) { Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_SHORT).show(); } return true; } }); return true; }
From source file:com.granita.contacticloudsync.syncadapter.AccountSettings.java
public Long getSyncInterval(String authority) { if (ContentResolver.getIsSyncable(account, authority) <= 0) return null; if (ContentResolver.getSyncAutomatically(account, authority)) { List<PeriodicSync> syncs = ContentResolver.getPeriodicSyncs(account, authority); if (syncs.isEmpty()) return SYNC_INTERVAL_MANUALLY; else//from w w w.ja v a 2 s. c om return syncs.get(0).period; } else return SYNC_INTERVAL_MANUALLY; }
From source file:at.bitfire.davdroid.AccountSettings.java
public Long getSyncInterval(@NonNull String authority) { if (ContentResolver.getIsSyncable(account, authority) <= 0) return null; if (ContentResolver.getSyncAutomatically(account, authority)) { List<PeriodicSync> syncs = ContentResolver.getPeriodicSyncs(account, authority); if (syncs.isEmpty()) return SYNC_INTERVAL_MANUALLY; else/* w ww. j a v a2 s . c om*/ return syncs.get(0).period; } else return SYNC_INTERVAL_MANUALLY; }
From source file:de.spiritcroc.syncsettings.SelectSyncActivity.java
private void loadSyncs(boolean skipPermissionCheck) { // Permission to read accounts required if (!skipPermissionCheck && ContextCompat.checkSelfPermission(this, Manifest.permission.GET_ACCOUNTS) != PackageManager.PERMISSION_GRANTED) { ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.GET_ACCOUNTS }, REQUEST_PERMISSION_GET_ACCOUNTS); return;/* w w w . jav a 2s .c om*/ } syncs.clear(); // Syncs with no account will be master sync setting syncs.add(new Sync(null, getString(R.string.sync_master_on))); syncs.add(new Sync(null, getString(R.string.sync_master_off))); syncs.add(new Sync(null, getString(R.string.sync_master_toggle))); // Get user accounts AccountManager accountManager = AccountManager.get(getApplicationContext()); Account[] accounts = accountManager.getAccounts(); // Get authorities ArrayList<String> authorities = Util.getAuthorities(); // Get available account/authority combinations if (DEBUG) Log.d(LOG_TAG, "Found accounts: " + accounts.length); for (Account account : accounts) { if (DEBUG) Log.d(LOG_TAG, "Found account " + account.name); for (int i = 0; i < authorities.size(); i++) { if (ContentResolver.getIsSyncable(account, authorities.get(i)) > 0) { syncs.add(new Sync(account, authorities.get(i))); if (DEBUG) Log.d(LOG_TAG, "Added authority " + authorities.get(i)); } } } // Build expandable list groups.clear(); for (int i = 0; i < syncs.size(); i++) { if (syncs.get(i).account != null && !groups.contains(syncs.get(i).account)) { groups.add(syncs.get(i).account); } } final String ROOT = "ROOT_NAME"; final String CHILD = "CHILD_NAME"; List<Map<String, String>> groupData = new ArrayList<Map<String, String>>() { { // Add master sync group: add(new HashMap<String, String>() { { put(ROOT, getString(R.string.sync_master)); } }); // Add accounts: for (int i = 0; i < groups.size(); i++) { final int j = i; add(new HashMap<String, String>() { { put(ROOT, groups.get(j).name + " (" + groups.get(j).type + ")"); } }); } } }; final List<List<Map<String, String>>> listOfChildGroups = new ArrayList<>(); // Add master sync items: List<Map<String, String>> masterChildGroup = new ArrayList<Map<String, String>>() { { for (int j = 0; j < syncs.size(); j++) { final Sync sync = syncs.get(j); if (sync.account == null) { add(new HashMap<String, String>() { { put(CHILD, sync.authority); } }); } else { break; } } } }; // Add account data: listOfChildGroups.add(masterChildGroup); for (int i = 0; i < groups.size(); i++) { final int x = i; List<Map<String, String>> childGroup = new ArrayList<Map<String, String>>() { { for (int j = 0; j < syncs.size(); j++) { final Sync sync = syncs.get(j); if (sync.account != null && sync.account.equals(groups.get(x))) { add(new HashMap<String, String>() { { put(CHILD, sync.authority); } }); } } } }; listOfChildGroups.add(childGroup); } listView.setAdapter(new SimpleExpandableListAdapter(this, groupData, android.R.layout.simple_expandable_list_item_1, new String[] { ROOT }, new int[] { android.R.id.text1 }, listOfChildGroups, android.R.layout.simple_expandable_list_item_1, new String[] { CHILD }, new int[] { android.R.id.text1 })); }
From source file:com.mobileglobe.android.customdialer.common.model.AccountTypeManager.java
/** * Loads account list and corresponding account types (potentially with data sets). Always * called on a background thread.//from ww w .j ava 2s .co m */ protected void loadAccountsInBackground() { if (Log.isLoggable(Constants.PERFORMANCE_TAG, Log.DEBUG)) { Log.d(Constants.PERFORMANCE_TAG, "AccountTypeManager.loadAccountsInBackground start"); } TimingLogger timings = new TimingLogger(TAG, "loadAccountsInBackground"); final long startTime = SystemClock.currentThreadTimeMillis(); final long startTimeWall = SystemClock.elapsedRealtime(); // Account types, keyed off the account type and data set concatenation. final Map<AccountTypeWithDataSet, AccountType> accountTypesByTypeAndDataSet = Maps.newHashMap(); // The same AccountTypes, but keyed off {@link RawContacts#ACCOUNT_TYPE}. Since there can // be multiple account types (with different data sets) for the same type of account, each // type string may have multiple AccountType entries. final Map<String, List<AccountType>> accountTypesByType = Maps.newHashMap(); final List<AccountWithDataSet> allAccounts = Lists.newArrayList(); final List<AccountWithDataSet> contactWritableAccounts = Lists.newArrayList(); final List<AccountWithDataSet> groupWritableAccounts = Lists.newArrayList(); final Set<String> extensionPackages = Sets.newHashSet(); final AccountManager am = mAccountManager; final SyncAdapterType[] syncs = ContentResolver.getSyncAdapterTypes(); final AuthenticatorDescription[] auths = am.getAuthenticatorTypes(); // First process sync adapters to find any that provide contact data. for (SyncAdapterType sync : syncs) { if (!ContactsContract.AUTHORITY.equals(sync.authority)) { // Skip sync adapters that don't provide contact data. continue; } // Look for the formatting details provided by each sync // adapter, using the authenticator to find general resources. final String type = sync.accountType; final AuthenticatorDescription auth = findAuthenticator(auths, type); if (auth == null) { Log.w(TAG, "No authenticator found for type=" + type + ", ignoring it."); continue; } AccountType accountType; if (GoogleAccountType.ACCOUNT_TYPE.equals(type)) { accountType = new GoogleAccountType(mContext, auth.packageName); } else if (ExchangeAccountType.isExchangeType(type)) { accountType = new ExchangeAccountType(mContext, auth.packageName, type); } else if (SamsungAccountType.isSamsungAccountType(mContext, type, auth.packageName)) { accountType = new SamsungAccountType(mContext, auth.packageName, type); } else { Log.d(TAG, "Registering external account type=" + type + ", packageName=" + auth.packageName); accountType = new ExternalAccountType(mContext, auth.packageName, false); } if (!accountType.isInitialized()) { if (accountType.isEmbedded()) { throw new IllegalStateException( "Problem initializing embedded type " + accountType.getClass().getCanonicalName()); } else { // Skip external account types that couldn't be initialized. continue; } } accountType.accountType = auth.type; accountType.titleRes = auth.labelId; accountType.iconRes = auth.iconId; addAccountType(accountType, accountTypesByTypeAndDataSet, accountTypesByType); // Check to see if the account type knows of any other non-sync-adapter packages // that may provide other data sets of contact data. extensionPackages.addAll(accountType.getExtensionPackageNames()); } // If any extension packages were specified, process them as well. if (!extensionPackages.isEmpty()) { Log.d(TAG, "Registering " + extensionPackages.size() + " extension packages"); for (String extensionPackage : extensionPackages) { ExternalAccountType accountType = new ExternalAccountType(mContext, extensionPackage, true); if (!accountType.isInitialized()) { // Skip external account types that couldn't be initialized. continue; } if (!accountType.hasContactsMetadata()) { Log.w(TAG, "Skipping extension package " + extensionPackage + " because" + " it doesn't have the CONTACTS_STRUCTURE metadata"); continue; } if (TextUtils.isEmpty(accountType.accountType)) { Log.w(TAG, "Skipping extension package " + extensionPackage + " because" + " the CONTACTS_STRUCTURE metadata doesn't have the accountType" + " attribute"); continue; } Log.d(TAG, "Registering extension package account type=" + accountType.accountType + ", dataSet=" + accountType.dataSet + ", packageName=" + extensionPackage); addAccountType(accountType, accountTypesByTypeAndDataSet, accountTypesByType); } } timings.addSplit("Loaded account types"); Account[] accounts = mAccountManager.getAccounts(); for (Account account : accounts) { boolean syncable = ContentResolver.getIsSyncable(account, ContactsContract.AUTHORITY) > 0; if (syncable) { List<AccountType> accountTypes = accountTypesByType.get(account.type); if (accountTypes != null) { // Add an account-with-data-set entry for each account type that is // authenticated by this account. for (AccountType accountType : accountTypes) { AccountWithDataSet accountWithDataSet = new AccountWithDataSet(account.name, account.type, accountType.dataSet); allAccounts.add(accountWithDataSet); if (accountType.areContactsWritable()) { contactWritableAccounts.add(accountWithDataSet); } if (accountType.isGroupMembershipEditable()) { groupWritableAccounts.add(accountWithDataSet); } } } } } Collections.sort(allAccounts, ACCOUNT_COMPARATOR); Collections.sort(contactWritableAccounts, ACCOUNT_COMPARATOR); Collections.sort(groupWritableAccounts, ACCOUNT_COMPARATOR); timings.addSplit("Loaded accounts"); synchronized (this) { mAccountTypesWithDataSets = accountTypesByTypeAndDataSet; mAccounts = allAccounts; mContactWritableAccounts = contactWritableAccounts; mGroupWritableAccounts = groupWritableAccounts; mInvitableAccountTypes = findAllInvitableAccountTypes(mContext, allAccounts, accountTypesByTypeAndDataSet); } timings.dumpToLog(); final long endTimeWall = SystemClock.elapsedRealtime(); final long endTime = SystemClock.currentThreadTimeMillis(); Log.i(TAG, "Loaded meta-data for " + mAccountTypesWithDataSets.size() + " account types, " + mAccounts.size() + " accounts in " + (endTimeWall - startTimeWall) + "ms(wall) " + (endTime - startTime) + "ms(cpu)"); if (mInitializationLatch != null) { mInitializationLatch.countDown(); mInitializationLatch = null; } if (Log.isLoggable(Constants.PERFORMANCE_TAG, Log.DEBUG)) { Log.d(Constants.PERFORMANCE_TAG, "AccountTypeManager.loadAccountsInBackground finish"); } // Check filter validity since filter may become obsolete after account update. It must be // done from UI thread. mMainThreadHandler.post(mCheckFilterValidityRunnable); }
From source file:com.android.exchange.SyncManager.java
/** * See if we need to change the syncInterval for any of our PIM mailboxes based on changes * to settings in the AccountManager (sync settings). * This code is called 1) when SyncManager starts, and 2) when SyncManager is running and there * are changes made (this is detected via a SyncStatusObserver) *//*from w ww .j a v a 2 s .c om*/ private void updatePIMSyncSettings(Account providerAccount, int mailboxType, String authority) { ContentValues cv = new ContentValues(); long mailboxId = Mailbox.findMailboxOfType(this, providerAccount.mId, mailboxType); // Presumably there is one, but if not, it's ok. Just move on... if (mailboxId != Mailbox.NO_MAILBOX) { // Create an AccountManager style Account android.accounts.Account acct = new android.accounts.Account(providerAccount.mEmailAddress, Email.EXCHANGE_ACCOUNT_MANAGER_TYPE); // Get the mailbox; this happens rarely so it's ok to get it all Mailbox mailbox = Mailbox.restoreMailboxWithId(this, mailboxId); if (mailbox == null) return; int syncInterval = mailbox.mSyncInterval; // If we're syncable, look further... if (ContentResolver.getIsSyncable(acct, authority) > 0) { // If we're supposed to sync automatically (push), set to push if it's not if (ContentResolver.getSyncAutomatically(acct, authority)) { if (syncInterval == Mailbox.CHECK_INTERVAL_NEVER || syncInterval > 0) { log("Sync for " + mailbox.mDisplayName + " in " + acct.name + ": push"); cv.put(MailboxColumns.SYNC_INTERVAL, Mailbox.CHECK_INTERVAL_PUSH); } // If we're NOT supposed to push, and we're not set up that way, change it } else if (syncInterval != Mailbox.CHECK_INTERVAL_NEVER) { log("Sync for " + mailbox.mDisplayName + " in " + acct.name + ": manual"); cv.put(MailboxColumns.SYNC_INTERVAL, Mailbox.CHECK_INTERVAL_NEVER); } // If not, set it to never check } else if (syncInterval != Mailbox.CHECK_INTERVAL_NEVER) { log("Sync for " + mailbox.mDisplayName + " in " + acct.name + ": manual"); cv.put(MailboxColumns.SYNC_INTERVAL, Mailbox.CHECK_INTERVAL_NEVER); } // If we've made a change, update the Mailbox, and kick if (cv.containsKey(MailboxColumns.SYNC_INTERVAL)) { mResolver.update(ContentUris.withAppendedId(Mailbox.CONTENT_URI, mailboxId), cv, null, null); kick("sync settings change"); } } }