Code example for Context

Methods: enforceCallingOrSelfPermission

0
            restoreCallingIdentity(identityToken);
        } 
    } 
 
    public boolean getSyncAutomatically(Account account, String providerName) {
        mContext.enforceCallingOrSelfPermission(Manifest.permission.READ_SYNC_SETTINGS,
                "no permission to read the sync settings"); 
        int userId = UserHandle.getCallingUserId();
 
        long identityToken = clearCallingIdentity();
        try { 
            SyncManager syncManager = getSyncManager();
            if (syncManager != null) {
                return syncManager.getSyncStorageEngine().getSyncAutomatically(
                        account, userId, providerName);
            } 
        } finally { 
            restoreCallingIdentity(identityToken);
        } 
        return false; 
    }