Code example for Field

Methods: setAccessible, setInt

0
     
    private void setPolicyMask(Object policy, String maskFieldName, int mask) {
        Class<?> clazz = policy.getClass();
        try { 
            Field field = clazz.getDeclaredField(maskFieldName);
            field.setAccessible(true);
            field.setInt(policy, mask);
        } catch(Exception ex) {
            Log.e(TAG, "Failed to set penalty mask in " + clazz.getSimpleName(), ex);
        } 
    } 
     
    private boolean isPenaltyLogSet(Object policy, String maskFieldName, int penaltyLogMask) {
        Integer mask = getPolicyMask(policy, maskFieldName);
        if (mask == null) {
            return false; 
        }         
        return (mask & penaltyLogMask) != 0;        
    } 
     
    @TargetApi(9)