Code example for Context

Methods: enforceCallingOrSelfPermission

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