Java Code Examples for android.content.SyncInfo

The following are top voted examples for showing how to use android.content.SyncInfo. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: android-wg-planer   File: SyncStatusManager.java   View source code 5 votes vote down vote up
@SuppressWarnings("deprecation")
private static boolean isSyncActive(Account account, String authority) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        for (SyncInfo syncInfo : ContentResolver.getCurrentSyncs()) {
            if (syncInfo.account.equals(account) && syncInfo.authority.equals(authority)) {
                return true;
            }
        }
        return false;
    } else {
        SyncInfo currentSync = ContentResolver.getCurrentSync();
        return currentSync != null && currentSync.account.equals(account) && currentSync.authority.equals(authority);
    }
}
 
Example 2
Project: android_maplib   File: AccountUtil.java   View source code 5 votes vote down vote up
public static boolean isSyncActive(Account account, String authority) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        return isSyncActiveHoneycomb(account, authority);
    } else {
        SyncInfo currentSync = ContentResolver.getCurrentSync();
        return currentSync != null && currentSync.account.equals(account) && currentSync.authority.equals(authority);
    }
}
 
Example 3
Project: android_maplib   File: AccountUtil.java   View source code 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public static boolean isSyncActiveHoneycomb(Account account, String authority) {
    for (SyncInfo syncInfo : ContentResolver.getCurrentSyncs()) {
        if (syncInfo.account.equals(account) && syncInfo.authority.equals(authority)) {
            return true;
        }
    }
    return false;
}
 
Example 4
Project: XPrivacy   File: XContentResolver.java   View source code 4 votes vote down vote up
@Override
protected void after(XParam param) throws Throwable {
	switch (mMethod) {
	case getCurrentSync:
		if (isRestricted(param))
			param.setResult(null);
		break;

	case getCurrentSyncs:
		if (isRestricted(param))
			param.setResult(new ArrayList<SyncInfo>());
		break;

	case getSyncAdapterTypes:
		if (isRestricted(param))
			param.setResult(new SyncAdapterType[0]);
		break;

	case openAssetFileDescriptor:
	case openFileDescriptor:
	case openInputStream:
	case openOutputStream:
	case openTypedAssetFileDescriptor:
	case openAssetFile:
	case openFile:
		if (param.args.length > 0 && param.args[0] instanceof Uri) {
			String uri = ((Uri) param.args[0]).toString();
			if (isRestrictedExtra(param, uri))
				param.setThrowable(new FileNotFoundException("XPrivacy"));
		}
		break;

	case Srv_call:
		handleCallAfter(param);
		break;

	case query:
	case Srv_query:
		handleUriAfter(param);
		break;

	case Srv_getCurrentSyncs:
	case Srv_getCurrentSyncsAsUser:
		if (param.getResult() != null)
			if (isRestricted(param)) {
				int uid = Binder.getCallingUid();
				@SuppressWarnings("unchecked")
				List<SyncInfo> listSync = (List<SyncInfo>) param.getResult();
				List<SyncInfo> listFiltered = new ArrayList<SyncInfo>();
				for (SyncInfo sync : listSync)
					if (XAccountManager.isAccountAllowed(sync.account, uid))
						listFiltered.add(sync);
				param.setResult(listFiltered);
			}
		break;
	}
}
 
Example 5
Project: smarper   File: XContentResolver.java   View source code 4 votes vote down vote up
@Override
protected void after(XParam param) throws Throwable {
	switch (mMethod) {
	case getCurrentSync:
		if (isRestricted(param))
			param.setResult(null);
		break;

	case getCurrentSyncs:
		if (isRestricted(param))
			param.setResult(new ArrayList<SyncInfo>());
		break;

	case getSyncAdapterTypes:
		if (isRestricted(param))
			param.setResult(new SyncAdapterType[0]);
		break;

	case openAssetFileDescriptor:
	case openFileDescriptor:
	case openInputStream:
	case openOutputStream:
	case openTypedAssetFileDescriptor:
	case openAssetFile:
	case openFile:
		if (param.args.length > 0 && param.args[0] instanceof Uri) {
			String uri = ((Uri) param.args[0]).toString();

			switch(getRestrictStateExtra(param, uri)){
				case 0:
					//Log.d("Smarper-Storage", "XContentResolver, " + mMethod + ": " + uri + " allowed");
					break;
				case 1:

					if (!SmarperUtil.forbiddenPathsInitialized)
						SmarperUtil.initializeForbiddenPaths();

					if (uri.startsWith(SmarperUtil.moviesURI.toString()) || uri.startsWith(SmarperUtil.dcimURI.toString()) || uri.startsWith(SmarperUtil.picturesURI.toString()) || uri.startsWith(SmarperUtil.musicURI.toString())){
						param.setThrowable(new FileNotFoundException("XPrivacy"));
						//Log.d("Smarper-Storage", "XContentResolver, " + mMethod + ": Obfuscating " + uri);
					}
					else{
						//
						//Log.d("Smarper-Storage", "ContentResolver: " + uri + " not in public folders list, not obfuscated!");
					}
					break;
				case 2:
					param.setThrowable(new FileNotFoundException("XPrivacy"));
					break;

			}

		}
		break;

	case Srv_call:
		handleCallAfter(param);
		break;

	case query:
	case Srv_query:
		handleUriAfter(param);
		break;

	case Srv_getCurrentSyncs:
	case Srv_getCurrentSyncsAsUser:
		if (param.getResult() != null)
			if (isRestricted(param)) {
				int uid = Binder.getCallingUid();
				@SuppressWarnings("unchecked")
				List<SyncInfo> listSync = (List<SyncInfo>) param.getResult();
				List<SyncInfo> listFiltered = new ArrayList<SyncInfo>();
				for (SyncInfo sync : listSync)
					if (XAccountManager.isAccountAllowed(sync.account, uid))
						listFiltered.add(sync);
				param.setResult(listFiltered);
			}
		break;
	}
}
 
Example 6
Project: xprivacy-mod   File: XContentResolver.java   View source code 4 votes vote down vote up
@Override
protected void after(XParam param) throws Throwable {
	switch (mMethod) {
	case getCurrentSync:
		if (isRestricted(param))
			param.setResult(null);
		break;

	case getCurrentSyncs:
		if (isRestricted(param))
			param.setResult(new ArrayList<SyncInfo>());
		break;

	case getSyncAdapterTypes:
		if (isRestricted(param))
			param.setResult(new SyncAdapterType[0]);
		break;

	case openAssetFileDescriptor:
	case openFileDescriptor:
	case openInputStream:
	case openOutputStream:
	case openTypedAssetFileDescriptor:
	case openAssetFile:
	case openFile:
		if (param.args.length > 0 && param.args[0] instanceof Uri) {
			String uri = ((Uri) param.args[0]).toString();
			if (isRestrictedExtra(param, uri))
				param.setThrowable(new FileNotFoundException("XPrivacy"));
		}
		break;

	case Srv_call:
		handleCallAfter(param);
		break;

	case query:
	case Srv_query:
		handleUriAfter(param);
		break;

	case Srv_getCurrentSyncs:
	case Srv_getCurrentSyncsAsUser:
		if (param.getResult() != null)
			if (isRestricted(param)) {
				int uid = Binder.getCallingUid();
				@SuppressWarnings("unchecked")
				List<SyncInfo> listSync = (List<SyncInfo>) param.getResult();
				List<SyncInfo> listFiltered = new ArrayList<SyncInfo>();
				for (SyncInfo sync : listSync)
					if (XAccountManager.isAccountAllowed(sync.account, uid))
						listFiltered.add(sync);
				param.setResult(listFiltered);
			}
		break;
	}
}
 
Example 7
Project: ntsync-android   File: HoneycombHelper.java   View source code 4 votes vote down vote up
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public static List<SyncInfo> getCurrentSyncs() {
	return ContentResolver.getCurrentSyncs();
}